]>
Commit | Line | Data |
---|---|---|
5861a31d GKH |
1 | From 29b37f42127f7da511560a40ea74f5047da40c13 Mon Sep 17 00:00:00 2001 |
2 | From: Herbert Xu <herbert@gondor.apana.org.au> | |
3 | Date: Tue, 13 Jan 2009 11:26:18 +1100 | |
4 | Subject: crypto: authenc - Fix zero-length IV crash | |
5 | ||
6 | From: Herbert Xu <herbert@gondor.apana.org.au> | |
7 | ||
8 | commit 29b37f42127f7da511560a40ea74f5047da40c13 upstream. | |
9 | ||
10 | As it is if an algorithm with a zero-length IV is used (e.g., | |
11 | NULL encryption) with authenc, authenc may generate an SG entry | |
12 | of length zero, which will trigger a BUG check in the hash layer. | |
13 | ||
14 | This patch fixes it by skipping the IV SG generation if the IV | |
15 | size is zero. | |
16 | ||
17 | Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> | |
18 | Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> | |
19 | ||
20 | --- | |
21 | crypto/authenc.c | 24 +++++++++++++++--------- | |
22 | 1 file changed, 15 insertions(+), 9 deletions(-) | |
23 | ||
24 | --- a/crypto/authenc.c | |
25 | +++ b/crypto/authenc.c | |
26 | @@ -157,16 +157,19 @@ static int crypto_authenc_genicv(struct | |
27 | dstp = sg_page(dst); | |
28 | vdst = PageHighMem(dstp) ? NULL : page_address(dstp) + dst->offset; | |
29 | ||
30 | - sg_init_table(cipher, 2); | |
31 | - sg_set_buf(cipher, iv, ivsize); | |
32 | - authenc_chain(cipher, dst, vdst == iv + ivsize); | |
33 | + if (ivsize) { | |
34 | + sg_init_table(cipher, 2); | |
35 | + sg_set_buf(cipher, iv, ivsize); | |
36 | + authenc_chain(cipher, dst, vdst == iv + ivsize); | |
37 | + dst = cipher; | |
38 | + } | |
39 | ||
40 | cryptlen = req->cryptlen + ivsize; | |
41 | - hash = crypto_authenc_hash(req, flags, cipher, cryptlen); | |
42 | + hash = crypto_authenc_hash(req, flags, dst, cryptlen); | |
43 | if (IS_ERR(hash)) | |
44 | return PTR_ERR(hash); | |
45 | ||
46 | - scatterwalk_map_and_copy(hash, cipher, cryptlen, | |
47 | + scatterwalk_map_and_copy(hash, dst, cryptlen, | |
48 | crypto_aead_authsize(authenc), 1); | |
49 | return 0; | |
50 | } | |
51 | @@ -284,11 +287,14 @@ static int crypto_authenc_iverify(struct | |
52 | srcp = sg_page(src); | |
53 | vsrc = PageHighMem(srcp) ? NULL : page_address(srcp) + src->offset; | |
54 | ||
55 | - sg_init_table(cipher, 2); | |
56 | - sg_set_buf(cipher, iv, ivsize); | |
57 | - authenc_chain(cipher, src, vsrc == iv + ivsize); | |
58 | + if (ivsize) { | |
59 | + sg_init_table(cipher, 2); | |
60 | + sg_set_buf(cipher, iv, ivsize); | |
61 | + authenc_chain(cipher, src, vsrc == iv + ivsize); | |
62 | + src = cipher; | |
63 | + } | |
64 | ||
65 | - return crypto_authenc_verify(req, cipher, cryptlen + ivsize); | |
66 | + return crypto_authenc_verify(req, src, cryptlen + ivsize); | |
67 | } | |
68 | ||
69 | static int crypto_authenc_decrypt(struct aead_request *req) |