]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/4.19.45/crypto-salsa20-don-t-access-already-freed-walk.iv.patch
Linux 4.19.45
[thirdparty/kernel/stable-queue.git] / releases / 4.19.45 / crypto-salsa20-don-t-access-already-freed-walk.iv.patch
CommitLineData
a4b7cc35
GKH
1From edaf28e996af69222b2cb40455dbb5459c2b875a Mon Sep 17 00:00:00 2001
2From: Eric Biggers <ebiggers@google.com>
3Date: Tue, 9 Apr 2019 23:46:30 -0700
4Subject: crypto: salsa20 - don't access already-freed walk.iv
5
6From: Eric Biggers <ebiggers@google.com>
7
8commit edaf28e996af69222b2cb40455dbb5459c2b875a upstream.
9
10If the user-provided IV needs to be aligned to the algorithm's
11alignmask, then skcipher_walk_virt() copies the IV into a new aligned
12buffer walk.iv. But skcipher_walk_virt() can fail afterwards, and then
13if the caller unconditionally accesses walk.iv, it's a use-after-free.
14
15salsa20-generic doesn't set an alignmask, so currently it isn't affected
16by this despite unconditionally accessing walk.iv. However this is more
17subtle than desired, and it was actually broken prior to the alignmask
18being removed by commit b62b3db76f73 ("crypto: salsa20-generic - cleanup
19and convert to skcipher API").
20
21Since salsa20-generic does not update the IV and does not need any IV
22alignment, update it to use req->iv instead of walk.iv.
23
24Fixes: 2407d60872dd ("[CRYPTO] salsa20: Salsa20 stream cipher")
25Cc: stable@vger.kernel.org
26Signed-off-by: Eric Biggers <ebiggers@google.com>
27Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
28Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
29
30---
31 crypto/salsa20_generic.c | 2 +-
32 1 file changed, 1 insertion(+), 1 deletion(-)
33
34--- a/crypto/salsa20_generic.c
35+++ b/crypto/salsa20_generic.c
36@@ -161,7 +161,7 @@ static int salsa20_crypt(struct skcipher
37
38 err = skcipher_walk_virt(&walk, req, true);
39
40- salsa20_init(state, ctx, walk.iv);
41+ salsa20_init(state, ctx, req->iv);
42
43 while (walk.nbytes > 0) {
44 unsigned int nbytes = walk.nbytes;