diff mbox

crypto: algif_skcipher - Fixed blocking recvmsg

Message ID 20141127143811.GA25283@gondor.apana.org.au (mailing list archive)
State Accepted
Delegated to: Herbert Xu
Headers show

Commit Message

Herbert Xu Nov. 27, 2014, 2:38 p.m. UTC
As most (all?) users of algif_skcipher are single-threaded and
therefore always write before reading from an algif_skcipher
socket, they never block and exercise that code-path.

It turns out that code path doesn't even work because we never
reload ctx->used after waking up so we never even see the new
data and immediately return an error (and a loud WARN_ON).
    
This patch fixes this by always reloading ctx->used.

Reported-by: Stephan Mueller <smueller@chronox.de>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>


Thanks,

Comments

Stephan Mueller Nov. 27, 2014, 2:45 p.m. UTC | #1
Am Donnerstag, 27. November 2014, 22:38:12 schrieb Herbert Xu:

Hi Herbert,

>As most (all?) users of algif_skcipher are single-threaded and
>therefore always write before reading from an algif_skcipher
>socket, they never block and exercise that code-path.
>
>It turns out that code path doesn't even work because we never
>reload ctx->used after waking up so we never even see the new
>data and immediately return an error (and a loud WARN_ON).
>
>This patch fixes this by always reloading ctx->used.
>
>Reported-by: Stephan Mueller <smueller@chronox.de>
>Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Acked-by: Stephan Mueller <smueller@chronox.de>
>
>diff --git a/crypto/algif_skcipher.c b/crypto/algif_skcipher.c
>index 3438996..f80e652 100644
>--- a/crypto/algif_skcipher.c
>+++ b/crypto/algif_skcipher.c
>@@ -448,14 +448,13 @@ static int skcipher_recvmsg(struct kiocb *unused,
>struct socket *sock, while (!sg->length)
> 				sg++;
>
>-			used = ctx->used;
>-			if (!used) {
>+			if (!ctx->used) {
> 				err = skcipher_wait_for_data(sk, flags);
> 				if (err)
> 					goto unlock;
> 			}
>
>-			used = min_t(unsigned long, used, seglen);
>+			used = min_t(unsigned long, ctx->used, seglen);
>
> 			used = af_alg_make_sg(&ctx->rsgl, from, used, 
1);
> 			err = used;
>
>Thanks,


Ciao
Stephan
--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/crypto/algif_skcipher.c b/crypto/algif_skcipher.c
index 3438996..f80e652 100644
--- a/crypto/algif_skcipher.c
+++ b/crypto/algif_skcipher.c
@@ -448,14 +448,13 @@  static int skcipher_recvmsg(struct kiocb *unused, struct socket *sock,
 			while (!sg->length)
 				sg++;
 
-			used = ctx->used;
-			if (!used) {
+			if (!ctx->used) {
 				err = skcipher_wait_for_data(sk, flags);
 				if (err)
 					goto unlock;
 			}
 
-			used = min_t(unsigned long, used, seglen);
+			used = min_t(unsigned long, ctx->used, seglen);
 
 			used = af_alg_make_sg(&ctx->rsgl, from, used, 1);
 			err = used;