提交 bc97e57e 编写于 作者: H Herbert Xu

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: NHerbert Xu <herbert@gondor.apana.org.au>
上级 0f6bb83c
...@@ -454,17 +454,17 @@ static int skcipher_recvmsg(struct kiocb *unused, struct socket *sock, ...@@ -454,17 +454,17 @@ static int skcipher_recvmsg(struct kiocb *unused, struct socket *sock,
used = min_t(unsigned long, used, seglen); 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) if (ctx->more || used < ctx->used)
used -= used % bs; used -= used % bs;
err = -EINVAL; err = -EINVAL;
if (!used) if (!used)
goto unlock; goto free;
used = af_alg_make_sg(&ctx->rsgl, from, used, 1);
err = used;
if (err < 0)
goto unlock;
ablkcipher_request_set_crypt(&ctx->req, sg, ablkcipher_request_set_crypt(&ctx->req, sg,
ctx->rsgl.sg, used, ctx->rsgl.sg, used,
...@@ -476,6 +476,7 @@ static int skcipher_recvmsg(struct kiocb *unused, struct socket *sock, ...@@ -476,6 +476,7 @@ static int skcipher_recvmsg(struct kiocb *unused, struct socket *sock,
crypto_ablkcipher_decrypt(&ctx->req), crypto_ablkcipher_decrypt(&ctx->req),
&ctx->completion); &ctx->completion);
free:
af_alg_free_sg(&ctx->rsgl); af_alg_free_sg(&ctx->rsgl);
if (err) if (err)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册