Skip to content

Commit 4751041

Browse files
Eric Biggersgregkh
authored andcommitted
crypto: x86/aegis - Add missing error checks
commit 3d9eb18 upstream. The skcipher_walk functions can allocate memory and can fail, so checking for errors is necessary. Fixes: 1d373d4 ("crypto: x86 - Add optimized AEGIS implementations") Cc: stable@vger.kernel.org Signed-off-by: Eric Biggers <ebiggers@kernel.org> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 02caf91 commit 4751041

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

arch/x86/crypto/aegis128-aesni-glue.c

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,12 @@ static void crypto_aegis128_aesni_process_ad(
104104
}
105105
}
106106

107-
static __always_inline void
107+
static __always_inline int
108108
crypto_aegis128_aesni_process_crypt(struct aegis_state *state,
109109
struct skcipher_walk *walk, bool enc)
110110
{
111+
int err = 0;
112+
111113
while (walk->nbytes >= AEGIS128_BLOCK_SIZE) {
112114
if (enc)
113115
aegis128_aesni_enc(state, walk->src.virt.addr,
@@ -120,7 +122,8 @@ crypto_aegis128_aesni_process_crypt(struct aegis_state *state,
120122
round_down(walk->nbytes,
121123
AEGIS128_BLOCK_SIZE));
122124
kernel_fpu_end();
123-
skcipher_walk_done(walk, walk->nbytes % AEGIS128_BLOCK_SIZE);
125+
err = skcipher_walk_done(walk,
126+
walk->nbytes % AEGIS128_BLOCK_SIZE);
124127
kernel_fpu_begin();
125128
}
126129

@@ -134,9 +137,10 @@ crypto_aegis128_aesni_process_crypt(struct aegis_state *state,
134137
walk->dst.virt.addr,
135138
walk->nbytes);
136139
kernel_fpu_end();
137-
skcipher_walk_done(walk, 0);
140+
err = skcipher_walk_done(walk, 0);
138141
kernel_fpu_begin();
139142
}
143+
return err;
140144
}
141145

142146
static struct aegis_ctx *crypto_aegis128_aesni_ctx(struct crypto_aead *aead)
@@ -169,7 +173,7 @@ static int crypto_aegis128_aesni_setauthsize(struct crypto_aead *tfm,
169173
return 0;
170174
}
171175

172-
static __always_inline void
176+
static __always_inline int
173177
crypto_aegis128_aesni_crypt(struct aead_request *req,
174178
struct aegis_block *tag_xor,
175179
unsigned int cryptlen, bool enc)
@@ -178,20 +182,24 @@ crypto_aegis128_aesni_crypt(struct aead_request *req,
178182
struct aegis_ctx *ctx = crypto_aegis128_aesni_ctx(tfm);
179183
struct skcipher_walk walk;
180184
struct aegis_state state;
185+
int err;
181186

182187
if (enc)
183-
skcipher_walk_aead_encrypt(&walk, req, false);
188+
err = skcipher_walk_aead_encrypt(&walk, req, false);
184189
else
185-
skcipher_walk_aead_decrypt(&walk, req, false);
190+
err = skcipher_walk_aead_decrypt(&walk, req, false);
191+
if (err)
192+
return err;
186193

187194
kernel_fpu_begin();
188195

189196
aegis128_aesni_init(&state, &ctx->key, req->iv);
190197
crypto_aegis128_aesni_process_ad(&state, req->src, req->assoclen);
191-
crypto_aegis128_aesni_process_crypt(&state, &walk, enc);
192-
aegis128_aesni_final(&state, tag_xor, req->assoclen, cryptlen);
193-
198+
err = crypto_aegis128_aesni_process_crypt(&state, &walk, enc);
199+
if (err == 0)
200+
aegis128_aesni_final(&state, tag_xor, req->assoclen, cryptlen);
194201
kernel_fpu_end();
202+
return err;
195203
}
196204

197205
static int crypto_aegis128_aesni_encrypt(struct aead_request *req)
@@ -200,8 +208,11 @@ static int crypto_aegis128_aesni_encrypt(struct aead_request *req)
200208
struct aegis_block tag = {};
201209
unsigned int authsize = crypto_aead_authsize(tfm);
202210
unsigned int cryptlen = req->cryptlen;
211+
int err;
203212

204-
crypto_aegis128_aesni_crypt(req, &tag, cryptlen, true);
213+
err = crypto_aegis128_aesni_crypt(req, &tag, cryptlen, true);
214+
if (err)
215+
return err;
205216

206217
scatterwalk_map_and_copy(tag.bytes, req->dst,
207218
req->assoclen + cryptlen, authsize, 1);
@@ -216,11 +227,14 @@ static int crypto_aegis128_aesni_decrypt(struct aead_request *req)
216227
struct aegis_block tag;
217228
unsigned int authsize = crypto_aead_authsize(tfm);
218229
unsigned int cryptlen = req->cryptlen - authsize;
230+
int err;
219231

220232
scatterwalk_map_and_copy(tag.bytes, req->src,
221233
req->assoclen + cryptlen, authsize, 0);
222234

223-
crypto_aegis128_aesni_crypt(req, &tag, cryptlen, false);
235+
err = crypto_aegis128_aesni_crypt(req, &tag, cryptlen, false);
236+
if (err)
237+
return err;
224238

225239
return crypto_memneq(tag.bytes, zeros.bytes, authsize) ? -EBADMSG : 0;
226240
}

0 commit comments

Comments
 (0)