diff options
author | Eric Biggers <ebiggers@google.com> | 2017-11-29 04:18:57 -0500 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2017-12-11 06:29:53 -0500 |
commit | 2b4f27c36bcd46e820ddb9a8e6fe6a63fa4250b8 (patch) | |
tree | f185bfdebe3769da7a82ea02cd394b3ed9736e91 | |
parent | 50c4c4e268a2d7a3e58ebb698ac74da0de40ae36 (diff) |
crypto: skcipher - set walk.iv for zero-length inputs
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.
Fixes: 0cabf2af6f5a ("crypto: skcipher - Fix crash on zero-length input")
Reported-by: syzbot <syzkaller@googlegroups.com>
Cc: <stable@vger.kernel.org> # v4.14+
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r-- | crypto/skcipher.c | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/crypto/skcipher.c b/crypto/skcipher.c index 778e0ff42bfa..11af5fd6a443 100644 --- a/crypto/skcipher.c +++ b/crypto/skcipher.c | |||
@@ -449,6 +449,8 @@ static int skcipher_walk_skcipher(struct skcipher_walk *walk, | |||
449 | 449 | ||
450 | walk->total = req->cryptlen; | 450 | walk->total = req->cryptlen; |
451 | walk->nbytes = 0; | 451 | walk->nbytes = 0; |
452 | walk->iv = req->iv; | ||
453 | walk->oiv = req->iv; | ||
452 | 454 | ||
453 | if (unlikely(!walk->total)) | 455 | if (unlikely(!walk->total)) |
454 | return 0; | 456 | return 0; |
@@ -456,9 +458,6 @@ static int skcipher_walk_skcipher(struct skcipher_walk *walk, | |||
456 | scatterwalk_start(&walk->in, req->src); | 458 | scatterwalk_start(&walk->in, req->src); |
457 | scatterwalk_start(&walk->out, req->dst); | 459 | scatterwalk_start(&walk->out, req->dst); |
458 | 460 | ||
459 | walk->iv = req->iv; | ||
460 | walk->oiv = req->iv; | ||
461 | |||
462 | walk->flags &= ~SKCIPHER_WALK_SLEEP; | 461 | walk->flags &= ~SKCIPHER_WALK_SLEEP; |
463 | walk->flags |= req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP ? | 462 | walk->flags |= req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP ? |
464 | SKCIPHER_WALK_SLEEP : 0; | 463 | SKCIPHER_WALK_SLEEP : 0; |
@@ -510,6 +509,8 @@ static int skcipher_walk_aead_common(struct skcipher_walk *walk, | |||
510 | int err; | 509 | int err; |
511 | 510 | ||
512 | walk->nbytes = 0; | 511 | walk->nbytes = 0; |
512 | walk->iv = req->iv; | ||
513 | walk->oiv = req->iv; | ||
513 | 514 | ||
514 | if (unlikely(!walk->total)) | 515 | if (unlikely(!walk->total)) |
515 | return 0; | 516 | return 0; |
@@ -525,9 +526,6 @@ static int skcipher_walk_aead_common(struct skcipher_walk *walk, | |||
525 | scatterwalk_done(&walk->in, 0, walk->total); | 526 | scatterwalk_done(&walk->in, 0, walk->total); |
526 | scatterwalk_done(&walk->out, 0, walk->total); | 527 | scatterwalk_done(&walk->out, 0, walk->total); |
527 | 528 | ||
528 | walk->iv = req->iv; | ||
529 | walk->oiv = req->iv; | ||
530 | |||
531 | if (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) | 529 | if (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) |
532 | walk->flags |= SKCIPHER_WALK_SLEEP; | 530 | walk->flags |= SKCIPHER_WALK_SLEEP; |
533 | else | 531 | else |