Skip to content

Commit 23a75ee

Browse files
slipsziherbertx
authored andcommitted
crypto: hash - Fix handling of small unaligned buffers
If a scatterwalk chain contains an entry with an unaligned offset then hash_walk_next() will cut off the next step at the next alignment point. However, if the entry ends before the next alignment point then we a loop, which leads to a kernel oops. Fix this by checking whether the next aligment point is before the end of the current entry. Signed-off-by: Szilveszter Ördög <slipszi@gmail.com> Acked-by: David S. Miller <davem@davemloft.net> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent fc1caf6 commit 23a75ee

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

‎crypto/ahash.c‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,11 @@ static int hash_walk_next(struct crypto_hash_walk *walk)
4747
walk->data = crypto_kmap(walk->pg, 0);
4848
walk->data += offset;
4949

50-
if (offset & alignmask)
51-
nbytes = alignmask + 1 - (offset & alignmask);
50+
if (offset & alignmask) {
51+
unsigned int unaligned = alignmask + 1 - (offset & alignmask);
52+
if (nbytes > unaligned)
53+
nbytes = unaligned;
54+
}
5255

5356
walk->entrylen -= nbytes;
5457
return nbytes;

0 commit comments

Comments
 (0)