Patch "crypto: skcipher - set walk.iv for zero-length inputs" has been added to the 4.14-stable tree
Subsystems (2)
This is a note to let you know that I've just added the patch titled
crypto: skcipher - set walk.iv for zero-length inputs
to the 4.14-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
crypto-skcipher-set-walk.iv-for-zero-length-inputs.patch
and it can be found in the queue-4.14 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
Quoted 1 line
From
2b4f27c36bcd46e820ddb9a8e6fe6a63fa4250b8Mon Sep 17 00:00:00 2001
From: Eric Biggers <[email protected]>
Date: Wed, 29 Nov 2017 01:18:57 -0800
Subject: crypto: skcipher - set walk.iv for zero-length inputs
From: Eric Biggers <[email protected]>
commit 2b4f27c36bcd46e820ddb9a8e6fe6a63fa4250b8 upstream.
All the ChaCha20 algorithms as well as the ARM bit-sliced AES-XTS algorithms call skcipher_walk_virt(), then access the IV (walk.iv) before checking whether any bytes need to be processed (walk.nbytes).
But if the input is empty, then skcipher_walk_virt() doesn't set the IV, and the algorithms crash trying to use the uninitialized IV pointer.
Fix it by setting the IV earlier in skcipher_walk_virt(). Also fix it for the AEAD walk functions.
This isn't a perfect solution because we can't actually align the IV to ->cra_alignmask unless there are bytes to process, for one because the temporary buffer for the aligned IV is freed by skcipher_walk_done(), which is only called when there are bytes to process. Thus, algorithms that require aligned IVs will still need to avoid accessing the IV when walk.nbytes == 0. Still, many algorithms/architectures are fine with IVs having any alignment, and even for those that aren't, a misaligned pointer bug is much less severe than an uninitialized pointer bug.
This change also matches the behavior of the older blkcipher_walk API.
--- crypto/skcipher.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
crypto/skcipher.c +4 -6
@@ -449,6 +449,8 @@ static int skcipher_walk_skcipher(struct walk->total = req->cryptlen; walk->nbytes =0 ; + walk->iv = req->iv; + walk->oiv = req->iv;if (unlikely (!walk->total))return 0 ;
@@ -456,9 +458,6 @@ static int skcipher_walk_skcipher(structscatterwalk_start (&walk->in, req->src);scatterwalk_start (&walk->out, req->dst); - walk->iv = req->iv; - walk->oiv = req->iv; - walk->flags &= ~SKCIPHER_WALK_SLEEP ; walk->flags |= req->base.flags &CRYPTO_TFM_REQ_MAY_SLEEP ?SKCIPHER_WALK_SLEEP :0 ;
@@ -510,6 +509,8 @@ static int skcipher_walk_aead_common(strint err; walk->nbytes =0 ; + walk->iv = req->iv; + walk->oiv = req->iv;if (unlikely (!walk->total))return 0 ;
@@ -525,9 +526,6 @@ static int skcipher_walk_aead_common(strscatterwalk_done (&walk->in,0 , walk->total);scatterwalk_done (&walk->out,0 , walk->total); - walk->iv = req->iv; - walk->oiv = req->iv; -if (req->base.flags &CRYPTO_TFM_REQ_MAY_SLEEP ) walk->flags |=SKCIPHER_WALK_SLEEP ;else
Patches currently in stable-queue which might be from [email protected] are
queue-4.14/crypto-skcipher-set-walk.iv-for-zero-length-inputs.patch