Skip to content

Commit

Permalink
[CRYPTO] xcbc: Fix crash with IPsec
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
  • Loading branch information
Joy Latten authored and herbertx committed Mar 6, 2008
1 parent 6212f2c commit 2f40a17
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion crypto/xcbc.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ static int crypto_xcbc_digest_update2(struct hash_desc *pdesc,
unsigned int offset = sg[i].offset;
unsigned int slen = sg[i].length;

if (unlikely(slen > nbytes))
slen = nbytes;

nbytes -= slen;

while (slen > 0) {
unsigned int len = min(slen, ((unsigned int)(PAGE_SIZE)) - offset);
char *p = crypto_kmap(pg, 0) + offset;
Expand Down Expand Up @@ -177,7 +182,6 @@ static int crypto_xcbc_digest_update2(struct hash_desc *pdesc,
offset = 0;
pg++;
}
nbytes-=sg[i].length;
i++;
} while (nbytes>0);

Expand Down

0 comments on commit 2f40a17

Please sign in to comment.