All of lore.kernel.org
 help / color / mirror / Atom feed
From: Herbert Xu <herbert@gondor.apana.org.au>
To: Linux Crypto Mailing List <linux-crypto@vger.kernel.org>,
	Stephan Mueller <smueller@chronox.de>
Subject: [PATCH] crypto: algif_aead - Only wake up when ctx->more is zero
Date: Fri, 29 May 2020 23:18:11 +1000	[thread overview]
Message-ID: <20200529131811.GA9137@gondor.apana.org.au> (raw)
In-Reply-To: <20200529124048.GA7283@gondor.apana.org.au>

AEAD does not support partial requests so we must not wake up
while ctx->more is set.  While we're fixing this also change
algif_skcipher to only wake up when at least a block is available
as otherwise we'd just fail straight away with -EINVAL.

Fixes: 2d97591ef43d ("crypto: af_alg - consolidation of...")
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

diff --git a/crypto/af_alg.c b/crypto/af_alg.c
index b1cd3535c5256..474a9511f0ed4 100644
--- a/crypto/af_alg.c
+++ b/crypto/af_alg.c
@@ -738,9 +738,10 @@ EXPORT_SYMBOL_GPL(af_alg_wmem_wakeup);
  *
  * @sk socket of connection to user space
  * @flags If MSG_DONTWAIT is set, then only report if function would sleep
+ * @min Set to minimum request size if partial requests are allowed.
  * @return 0 when writable memory is available, < 0 upon error
  */
-int af_alg_wait_for_data(struct sock *sk, unsigned flags)
+int af_alg_wait_for_data(struct sock *sk, unsigned flags, unsigned min)
 {
 	DEFINE_WAIT_FUNC(wait, woken_wake_function);
 	struct alg_sock *ask = alg_sk(sk);
@@ -758,7 +759,8 @@ int af_alg_wait_for_data(struct sock *sk, unsigned flags)
 		if (signal_pending(current))
 			break;
 		timeout = MAX_SCHEDULE_TIMEOUT;
-		if (sk_wait_event(sk, &timeout, (ctx->used || !ctx->more),
+		if (sk_wait_event(sk, &timeout,
+				  (min && ctx->used >= min) || !ctx->more,
 				  &wait)) {
 			err = 0;
 			break;
diff --git a/crypto/algif_aead.c b/crypto/algif_aead.c
index eb1910b6d434c..efea00046be65 100644
--- a/crypto/algif_aead.c
+++ b/crypto/algif_aead.c
@@ -107,7 +107,7 @@ static int _aead_recvmsg(struct socket *sock, struct msghdr *msg,
 	size_t processed = 0;		/* [in]  TX bufs to be consumed */
 
 	if (!ctx->used) {
-		err = af_alg_wait_for_data(sk, flags);
+		err = af_alg_wait_for_data(sk, flags, 0);
 		if (err)
 			return err;
 	}
diff --git a/crypto/algif_skcipher.c b/crypto/algif_skcipher.c
index 24dd2fc2431cc..5b334fd9432c0 100644
--- a/crypto/algif_skcipher.c
+++ b/crypto/algif_skcipher.c
@@ -62,7 +62,7 @@ static int _skcipher_recvmsg(struct socket *sock, struct msghdr *msg,
 	size_t len = 0;
 
 	if (!ctx->used) {
-		err = af_alg_wait_for_data(sk, flags);
+		err = af_alg_wait_for_data(sk, flags, bs);
 		if (err)
 			return err;
 	}
diff --git a/include/crypto/if_alg.h b/include/crypto/if_alg.h
index 56527c85d1222..e1e5525473e4c 100644
--- a/include/crypto/if_alg.h
+++ b/include/crypto/if_alg.h
@@ -226,7 +226,7 @@ unsigned int af_alg_count_tsgl(struct sock *sk, size_t bytes, size_t offset);
 void af_alg_pull_tsgl(struct sock *sk, size_t used, struct scatterlist *dst,
 		      size_t dst_offset);
 void af_alg_wmem_wakeup(struct sock *sk);
-int af_alg_wait_for_data(struct sock *sk, unsigned flags);
+int af_alg_wait_for_data(struct sock *sk, unsigned flags, unsigned min);
 int af_alg_sendmsg(struct socket *sock, struct msghdr *msg, size_t size,
 		   unsigned int ivsize);
 ssize_t af_alg_sendpage(struct socket *sock, struct page *page,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

  reply	other threads:[~2020-05-29 13:18 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-29  4:54 [PATCH] crypto: algif_skcipher - Cap recv SG list at ctx->used Herbert Xu
2020-05-29  6:06 ` Stephan Mueller
2020-05-29 12:40 ` [PATCH] crypto: algif_skcipher - Do not perform zero-length ops Herbert Xu
2020-05-29 13:18   ` Herbert Xu [this message]
2020-05-29 14:23     ` [v2 PATCH] crypto: algif_aead - Only wake up when ctx->more is zero Herbert Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200529131811.GA9137@gondor.apana.org.au \
    --to=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=smueller@chronox.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.