summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.hengli.com.au>2010-11-30 17:06:03 +0800
committerMiloslav Trmač <mitr@redhat.com>2010-11-30 14:28:39 +0100
commit9e43ee6d3b352093775245386edd319c4f099c50 (patch)
tree42beb50449bdbb7e70f685ae83734eba8f55f6e5
parentd0dfeb6032a3ed33487dfe0d69367b74f207f587 (diff)
downloadkernel-crypto-9e43ee6d3b352093775245386edd319c4f099c50.tar.gz
kernel-crypto-9e43ee6d3b352093775245386edd319c4f099c50.tar.xz
kernel-crypto-9e43ee6d3b352093775245386edd319c4f099c50.zip
crypto: algif_skcipher - Handle unaligned receive buffer
Hi: This patch fixes unexpected EINVAL failures on recvmsg when encrypting/decrypting due to unaligned receive buffers. commit bc97e57eb21f8db55bf0e1f182d384e75b2e3c99 Author: Herbert Xu <herbert@gondor.apana.org.au> Date: Tue Nov 30 17:04:31 2010 +0800 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>
-rw-r--r--crypto/algif_skcipher.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/crypto/algif_skcipher.c b/crypto/algif_skcipher.c
index 9b2f440e88a..f677b31b430 100644
--- a/crypto/algif_skcipher.c
+++ b/crypto/algif_skcipher.c
@@ -464,17 +464,17 @@ static int skcipher_recvmsg(struct kiocb *unused, struct socket *sock,
used = min_t(unsigned long, used, seglen);
+ used = af_alg_make_sg(&ctx->rsgl, from, used, 1);
+ err = used;
+ if (err < 0)
+ goto unlock;
+
if (ctx->more || used < ctx->used)
used -= used % bs;
err = -EINVAL;
if (!used)
- goto unlock;
-
- used = af_alg_make_sg(&ctx->rsgl, from, used, 1);
- err = used;
- if (err < 0)
- goto unlock;
+ goto free;
ablkcipher_request_set_crypt(&ctx->req, sg,
ctx->rsgl.sg, used,
@@ -486,6 +486,7 @@ static int skcipher_recvmsg(struct kiocb *unused, struct socket *sock,
crypto_ablkcipher_decrypt(&ctx->req),
&ctx->completion);
+free:
af_alg_free_sg(&ctx->rsgl);
if (err)