Skip to content

Commit bc97e57

Browse files
committed
crypto: algif_skcipher - Handle unaligned receive buffer
As it is if user-space passes through a receive buffer that's not aligned to to the cipher block size, we'll end up encrypting or decrypting a partial block which causes a spurious EINVAL to be returned. This patch fixes this by moving the partial block test after the af_alg_make_sg call. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 0f6bb83 commit bc97e57

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

‎crypto/algif_skcipher.c‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -454,17 +454,17 @@ static int skcipher_recvmsg(struct kiocb *unused, struct socket *sock,
454454

455455
used = min_t(unsigned long, used, seglen);
456456

457+
used = af_alg_make_sg(&ctx->rsgl, from, used, 1);
458+
err = used;
459+
if (err < 0)
460+
goto unlock;
461+
457462
if (ctx->more || used < ctx->used)
458463
used -= used % bs;
459464

460465
err = -EINVAL;
461466
if (!used)
462-
goto unlock;
463-
464-
used = af_alg_make_sg(&ctx->rsgl, from, used, 1);
465-
err = used;
466-
if (err < 0)
467-
goto unlock;
467+
goto free;
468468

469469
ablkcipher_request_set_crypt(&ctx->req, sg,
470470
ctx->rsgl.sg, used,
@@ -476,6 +476,7 @@ static int skcipher_recvmsg(struct kiocb *unused, struct socket *sock,
476476
crypto_ablkcipher_decrypt(&ctx->req),
477477
&ctx->completion);
478478

479+
free:
479480
af_alg_free_sg(&ctx->rsgl);
480481

481482
if (err)

0 commit comments

Comments
 (0)