Skip to content

Commit 0cabf2a

Browse files
committed
crypto: skcipher - Fix crash on zero-length input
The skcipher walk interface doesn't handle zero-length input properly as the old blkcipher walk interface did. This is due to the fact that the length check is done too late. This patch moves the length check forward so that it does the right thing. Fixes: b286d8b ("crypto: skcipher - Add skcipher walk...") Cc: <[email protected]> Reported-by: Stephan Müller <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 9039f3e commit 0cabf2a

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

crypto/skcipher.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -426,14 +426,9 @@ static int skcipher_copy_iv(struct skcipher_walk *walk)
426426

427427
static int skcipher_walk_first(struct skcipher_walk *walk)
428428
{
429-
walk->nbytes = 0;
430-
431429
if (WARN_ON_ONCE(in_irq()))
432430
return -EDEADLK;
433431

434-
if (unlikely(!walk->total))
435-
return 0;
436-
437432
walk->buffer = NULL;
438433
if (unlikely(((unsigned long)walk->iv & walk->alignmask))) {
439434
int err = skcipher_copy_iv(walk);
@@ -452,10 +447,15 @@ static int skcipher_walk_skcipher(struct skcipher_walk *walk,
452447
{
453448
struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
454449

450+
walk->total = req->cryptlen;
451+
walk->nbytes = 0;
452+
453+
if (unlikely(!walk->total))
454+
return 0;
455+
455456
scatterwalk_start(&walk->in, req->src);
456457
scatterwalk_start(&walk->out, req->dst);
457458

458-
walk->total = req->cryptlen;
459459
walk->iv = req->iv;
460460
walk->oiv = req->iv;
461461

@@ -509,6 +509,11 @@ static int skcipher_walk_aead_common(struct skcipher_walk *walk,
509509
struct crypto_aead *tfm = crypto_aead_reqtfm(req);
510510
int err;
511511

512+
walk->nbytes = 0;
513+
514+
if (unlikely(!walk->total))
515+
return 0;
516+
512517
walk->flags &= ~SKCIPHER_WALK_PHYS;
513518

514519
scatterwalk_start(&walk->in, req->src);

0 commit comments

Comments
 (0)