diff mbox

crypto: algif_hash - Only export and import on sockets with data

Message ID 20151030121651.GA23757@gondor.apana.org.au (mailing list archive)
State Superseded
Delegated to: Herbert Xu
Headers show

Commit Message

Herbert Xu Oct. 30, 2015, 12:16 p.m. UTC
On Fri, Oct 30, 2015 at 12:10:51PM +0100, Stephan Mueller wrote:
> Am Freitag, 30. Oktober 2015, 14:02:27 schrieb Harsh Jain:
> 
> Hi Harsh,
> 
> >Hi Stephan,
> >
> >If we add sendmsg() in between 2 accept calls then the setkey problem
> >will happen?
> >
> >handle->opfd = accept(handle->tfmfd, NULL, 0);
> >sendmsg()
> >handle->opfd = accept(handle->opfd, NULL, 0);
> >sendmsg()
> >handle->opfd = accept(handle->opfd, NULL, 0);
> 
> Without testing, I would very much expect that, because the setkey does not 
> apply to the subordinate tfm.

setkey should be needed as the subsequent accept will all be based
on the same parent fd, meaning that they will all use a single tfm.

Please try the following patch.

---8<---
The hash_accept call fails to work on sockets that have not received
any data.  For some algorithm implementations it may cause crashes.

This patch fixes this by ensuring that we only export and import on
sockets that have received data.

Cc: stable@vger.kernel.org
Reported-by: Harsh Jain <harshjain.prof@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Comments

Stephan Mueller Oct. 30, 2015, 11:45 p.m. UTC | #1
Am Freitag, 30. Oktober 2015, 20:16:51 schrieb Herbert Xu:

Hi Herbert,

> 
> setkey should be needed as the subsequent accept will all be based
> on the same parent fd, meaning that they will all use a single tfm.
> 
> Please try the following patch.

Testing complete: patch solves the oops and allows to successfully perform 
HMAC even when having subsequent accepts and operating on those subsequent 
accepts.
diff mbox

Patch

diff --git a/crypto/algif_hash.c b/crypto/algif_hash.c
index 1396ad0..bbda6b4 100644
--- a/crypto/algif_hash.c
+++ b/crypto/algif_hash.c
@@ -181,11 +181,14 @@  static int hash_accept(struct socket *sock, struct socket *newsock, int flags)
 	struct sock *sk2;
 	struct alg_sock *ask2;
 	struct hash_ctx *ctx2;
+	bool more = ctx->more;
 	int err;
 
-	err = crypto_ahash_export(req, state);
-	if (err)
-		return err;
+	if (more) {
+		err = crypto_ahash_export(req, state);
+		if (err)
+			return err;
+	}
 
 	err = af_alg_accept(ask->parent, newsock);
 	if (err)
@@ -194,12 +197,14 @@  static int hash_accept(struct socket *sock, struct socket *newsock, int flags)
 	sk2 = newsock->sk;
 	ask2 = alg_sk(sk2);
 	ctx2 = ask2->private;
-	ctx2->more = 1;
+	ctx2->more = more;
 
-	err = crypto_ahash_import(&ctx2->req, state);
-	if (err) {
-		sock_orphan(sk2);
-		sock_put(sk2);
+	if (more) {
+		err = crypto_ahash_import(&ctx2->req, state);
+		if (err) {
+			sock_orphan(sk2);
+			sock_put(sk2);
+		}
 	}
 
 	return err;