Skip to content

Commit 2f40a17

Browse files
Joy Lattenherbertx
authored andcommitted
[CRYPTO] xcbc: Fix crash with IPsec
When using aes-xcbc-mac for authentication in IPsec, the kernel crashes. It seems this algorithm doesn't account for the space IPsec may make in scatterlist for authtag. Thus when crypto_xcbc_digest_update2() gets called, nbytes may be less than sg[i].length. Since nbytes is an unsigned number, it wraps at the end of the loop allowing us to go back into loop and causing crash in memcpy. I used update function in digest.c to model this fix. Please let me know if it looks ok. Signed-off-by: Joy Latten <latten@austin.ibm.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 6212f2c commit 2f40a17

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

‎crypto/xcbc.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ static int crypto_xcbc_digest_update2(struct hash_desc *pdesc,
124124
unsigned int offset = sg[i].offset;
125125
unsigned int slen = sg[i].length;
126126

127+
if (unlikely(slen > nbytes))
128+
slen = nbytes;
129+
130+
nbytes -= slen;
131+
127132
while (slen > 0) {
128133
unsigned int len = min(slen, ((unsigned int)(PAGE_SIZE)) - offset);
129134
char *p = crypto_kmap(pg, 0) + offset;
@@ -177,7 +182,6 @@ static int crypto_xcbc_digest_update2(struct hash_desc *pdesc,
177182
offset = 0;
178183
pg++;
179184
}
180-
nbytes-=sg[i].length;
181185
i++;
182186
} while (nbytes>0);
183187

0 commit comments

Comments
 (0)