Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+7 -6
+7 -6
crypto/algif_skcipher.c
··· 454 454 455 455 used = min_t(unsigned long, used, seglen); 456 456 457 + used = af_alg_make_sg(&ctx->rsgl, from, used, 1); 458 + err = used; 459 + if (err < 0) 460 + goto unlock; 461 + 457 462 if (ctx->more || used < ctx->used) 458 463 used -= used % bs; 459 464 460 465 err = -EINVAL; 461 466 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; 468 468 469 469 ablkcipher_request_set_crypt(&ctx->req, sg, 470 470 ctx->rsgl.sg, used, ··· 476 476 crypto_ablkcipher_decrypt(&ctx->req), 477 477 &ctx->completion); 478 478 479 + free: 479 480 af_alg_free_sg(&ctx->rsgl); 480 481 481 482 if (err)