Skip to content

Commit

Permalink
crypto: hash - Fix handling of small unaligned buffers
Browse files Browse the repository at this point in the history
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 <[email protected]>
Acked-by: David S. Miller <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
  • Loading branch information
slipszi authored and herbertx committed Aug 6, 2010
1 parent fc1caf6 commit 23a75ee
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions crypto/ahash.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@ static int hash_walk_next(struct crypto_hash_walk *walk)
walk->data = crypto_kmap(walk->pg, 0);
walk->data += offset;

if (offset & alignmask)
nbytes = alignmask + 1 - (offset & alignmask);
if (offset & alignmask) {
unsigned int unaligned = alignmask + 1 - (offset & alignmask);
if (nbytes > unaligned)
nbytes = unaligned;
}

walk->entrylen -= nbytes;
return nbytes;
Expand Down

0 comments on commit 23a75ee

Please sign in to comment.