]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-4.4/crypto-gcm-fix-incompatibility-between-gcm-and-gcm_base.patch
drop drm-rockchip-shutdown-drm-subsystem-on-shutdown.patch from 4.4.y and 4.9.y
[thirdparty/kernel/stable-queue.git] / queue-4.4 / crypto-gcm-fix-incompatibility-between-gcm-and-gcm_base.patch
1 From f699594d436960160f6d5ba84ed4a222f20d11cd Mon Sep 17 00:00:00 2001
2 From: Eric Biggers <ebiggers@google.com>
3 Date: Thu, 18 Apr 2019 14:43:02 -0700
4 Subject: crypto: gcm - fix incompatibility between "gcm" and "gcm_base"
5
6 From: Eric Biggers <ebiggers@google.com>
7
8 commit f699594d436960160f6d5ba84ed4a222f20d11cd upstream.
9
10 GCM instances can be created by either the "gcm" template, which only
11 allows choosing the block cipher, e.g. "gcm(aes)"; or by "gcm_base",
12 which allows choosing the ctr and ghash implementations, e.g.
13 "gcm_base(ctr(aes-generic),ghash-generic)".
14
15 However, a "gcm_base" instance prevents a "gcm" instance from being
16 registered using the same implementations. Nor will the instance be
17 found by lookups of "gcm". This can be used as a denial of service.
18 Moreover, "gcm_base" instances are never tested by the crypto
19 self-tests, even if there are compatible "gcm" tests.
20
21 The root cause of these problems is that instances of the two templates
22 use different cra_names. Therefore, fix these problems by making
23 "gcm_base" instances set the same cra_name as "gcm" instances, e.g.
24 "gcm(aes)" instead of "gcm_base(ctr(aes-generic),ghash-generic)".
25
26 This requires extracting the block cipher name from the name of the ctr
27 algorithm. It also requires starting to verify that the algorithms are
28 really ctr and ghash, not something else entirely. But it would be
29 bizarre if anyone were actually using non-gcm-compatible algorithms with
30 gcm_base, so this shouldn't break anyone in practice.
31
32 Fixes: d00aa19b507b ("[CRYPTO] gcm: Allow block cipher parameter")
33 Cc: stable@vger.kernel.org
34 Signed-off-by: Eric Biggers <ebiggers@google.com>
35 Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
36 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
37
38
39 ---
40 crypto/gcm.c | 34 +++++++++++-----------------------
41 1 file changed, 11 insertions(+), 23 deletions(-)
42
43 --- a/crypto/gcm.c
44 +++ b/crypto/gcm.c
45 @@ -616,7 +616,6 @@ static void crypto_gcm_free(struct aead_
46
47 static int crypto_gcm_create_common(struct crypto_template *tmpl,
48 struct rtattr **tb,
49 - const char *full_name,
50 const char *ctr_name,
51 const char *ghash_name)
52 {
53 @@ -657,7 +656,8 @@ static int crypto_gcm_create_common(stru
54 goto err_free_inst;
55
56 err = -EINVAL;
57 - if (ghash->digestsize != 16)
58 + if (strcmp(ghash->base.cra_name, "ghash") != 0 ||
59 + ghash->digestsize != 16)
60 goto err_drop_ghash;
61
62 crypto_set_skcipher_spawn(&ctx->ctr, aead_crypto_instance(inst));
63 @@ -669,24 +669,24 @@ static int crypto_gcm_create_common(stru
64
65 ctr = crypto_skcipher_spawn_alg(&ctx->ctr);
66
67 - /* We only support 16-byte blocks. */
68 + /* The skcipher algorithm must be CTR mode, using 16-byte blocks. */
69 err = -EINVAL;
70 - if (ctr->cra_ablkcipher.ivsize != 16)
71 + if (strncmp(ctr->cra_name, "ctr(", 4) != 0 ||
72 + ctr->cra_ablkcipher.ivsize != 16 ||
73 + ctr->cra_blocksize != 1)
74 goto out_put_ctr;
75
76 - /* Not a stream cipher? */
77 - if (ctr->cra_blocksize != 1)
78 + err = -ENAMETOOLONG;
79 + if (snprintf(inst->alg.base.cra_name, CRYPTO_MAX_ALG_NAME,
80 + "gcm(%s", ctr->cra_name + 4) >= CRYPTO_MAX_ALG_NAME)
81 goto out_put_ctr;
82
83 - err = -ENAMETOOLONG;
84 if (snprintf(inst->alg.base.cra_driver_name, CRYPTO_MAX_ALG_NAME,
85 "gcm_base(%s,%s)", ctr->cra_driver_name,
86 ghash_alg->cra_driver_name) >=
87 CRYPTO_MAX_ALG_NAME)
88 goto out_put_ctr;
89
90 - memcpy(inst->alg.base.cra_name, full_name, CRYPTO_MAX_ALG_NAME);
91 -
92 inst->alg.base.cra_flags = (ghash->base.cra_flags | ctr->cra_flags) &
93 CRYPTO_ALG_ASYNC;
94 inst->alg.base.cra_priority = (ghash->base.cra_priority +
95 @@ -727,7 +727,6 @@ static int crypto_gcm_create(struct cryp
96 {
97 const char *cipher_name;
98 char ctr_name[CRYPTO_MAX_ALG_NAME];
99 - char full_name[CRYPTO_MAX_ALG_NAME];
100
101 cipher_name = crypto_attr_alg_name(tb[1]);
102 if (IS_ERR(cipher_name))
103 @@ -737,12 +736,7 @@ static int crypto_gcm_create(struct cryp
104 CRYPTO_MAX_ALG_NAME)
105 return -ENAMETOOLONG;
106
107 - if (snprintf(full_name, CRYPTO_MAX_ALG_NAME, "gcm(%s)", cipher_name) >=
108 - CRYPTO_MAX_ALG_NAME)
109 - return -ENAMETOOLONG;
110 -
111 - return crypto_gcm_create_common(tmpl, tb, full_name,
112 - ctr_name, "ghash");
113 + return crypto_gcm_create_common(tmpl, tb, ctr_name, "ghash");
114 }
115
116 static struct crypto_template crypto_gcm_tmpl = {
117 @@ -756,7 +750,6 @@ static int crypto_gcm_base_create(struct
118 {
119 const char *ctr_name;
120 const char *ghash_name;
121 - char full_name[CRYPTO_MAX_ALG_NAME];
122
123 ctr_name = crypto_attr_alg_name(tb[1]);
124 if (IS_ERR(ctr_name))
125 @@ -766,12 +759,7 @@ static int crypto_gcm_base_create(struct
126 if (IS_ERR(ghash_name))
127 return PTR_ERR(ghash_name);
128
129 - if (snprintf(full_name, CRYPTO_MAX_ALG_NAME, "gcm_base(%s,%s)",
130 - ctr_name, ghash_name) >= CRYPTO_MAX_ALG_NAME)
131 - return -ENAMETOOLONG;
132 -
133 - return crypto_gcm_create_common(tmpl, tb, full_name,
134 - ctr_name, ghash_name);
135 + return crypto_gcm_create_common(tmpl, tb, ctr_name, ghash_name);
136 }
137
138 static struct crypto_template crypto_gcm_base_tmpl = {