Skip to content

Commit

Permalink
crypto: algif_skcipher - Handle unaligned receive buffer
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
herbertx committed Nov 30, 2010
1 parent 0f6bb83 commit bc97e57
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions crypto/algif_skcipher.c
Original file line number Diff line number Diff line change
Expand Up @@ -454,17 +454,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,
Expand All @@ -476,6 +476,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)
Expand Down

0 comments on commit bc97e57

Please sign in to comment.