Skip to content

Commit

Permalink
crypto: lrw - don't access already-freed walk.iv
Browse files Browse the repository at this point in the history
If the user-provided IV needs to be aligned to the algorithm's
alignmask, then skcipher_walk_virt() copies the IV into a new aligned
buffer walk.iv.  But skcipher_walk_virt() can fail afterwards, and then
if the caller unconditionally accesses walk.iv, it's a use-after-free.

Fix this in the LRW template by checking the return value of
skcipher_walk_virt().

This bug was detected by my patches that improve testmgr to fuzz
algorithms against their generic implementation.  When the extra
self-tests were run on a KASAN-enabled kernel, a KASAN use-after-free
splat occured during lrw(aes) testing.

Fixes: c778f96 ("crypto: lrw - Optimize tweak computation")
Cc: <[email protected]> # v4.20+
Cc: Ondrej Mosnacek <[email protected]>
Signed-off-by: Eric Biggers <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
  • Loading branch information
ebiggers authored and herbertx committed Apr 18, 2019
1 parent 11fe71f commit aec286c
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion crypto/lrw.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,10 @@ static int xor_tweak(struct skcipher_request *req, bool second_pass)
}

err = skcipher_walk_virt(&w, req, false);
iv = (__be32 *)w.iv;
if (err)
return err;

iv = (__be32 *)w.iv;
counter[0] = be32_to_cpu(iv[3]);
counter[1] = be32_to_cpu(iv[2]);
counter[2] = be32_to_cpu(iv[1]);
Expand Down

0 comments on commit aec286c

Please sign in to comment.