Skip to contentSkip to conversation

Patch "crypto: af_alg - wait for data at beginning of recvmsg" has been added to the 4.14-stable tree

PATCH [email protected] 1 participant 1 message Dec 27, 2017

Subsystems (2)
lore
Share & tools
lore

[email protected]

author maintainer Applied
#0 lore raw

This is a note to let you know that I've just added the patch titled

crypto: af_alg - wait for data at beginning of recvmsg

to the 4.14-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
crypto-af_alg-wait-for-data-at-beginning-of-recvmsg.patch
and it can be found in the queue-4.14 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.

Quoted 1 line

From 11edb555966ed2c66c533d17c604f9d7e580a829 Mon Sep 17 00:00:00 2001

From: Stephan Mueller <[email protected]>
Date: Wed, 29 Nov 2017 12:02:23 +0100
Subject: crypto: af_alg - wait for data at beginning of recvmsg

From: Stephan Mueller <[email protected]>

commit 11edb555966ed2c66c533d17c604f9d7e580a829 upstream.

The wait for data is a non-atomic operation that can sleep and therefore potentially release the socket lock. The release of the socket lock allows another thread to modify the context data structure. The waiting operation for new data therefore must be called at the beginning of recvmsg. This prevents a race condition where checks of the members of the context data structure are performed by recvmsg while there is a potential for modification of these values.

Fixes e870456d8e7c ("crypto: algif_skcipher - overhaul memory management")
Fixes d887c52d6ae4 ("crypto: algif_aead - overhaul memory management")
---
 crypto/af_alg.c         |    6 ------
 crypto/algif_aead.c     |    6 ++++++
 crypto/algif_skcipher.c |    6 ++++++
 3 files changed, 12 insertions(+), 6 deletions(-)
crypto/af_alg.c +0 -6
@@ -1165,12 +1165,6 @@ int af_alg_get_rsgl(struct sock *sk, str
 		if (!af_alg_readable(sk))
 			break;
 
-		if (!ctx->used) {
-			err = af_alg_wait_for_data(sk, flags);
-			if (err)
-				return err;
-		}
-
 		seglen = min_t(size_t, (maxsize - len),
 			       msg_data_left(msg));
 
crypto/algif_aead.c +6 -0
@@ -111,6 +111,12 @@ static int _aead_recvmsg(struct socket *
 	size_t usedpages = 0;		/* [in]  RX bufs to be used from user */
 	size_t processed = 0;		/* [in]  TX bufs to be consumed */
 
+	if (!ctx->used) {
+		err = af_alg_wait_for_data(sk, flags);
+		if (err)
+			return err;
+	}
+
 	/*
 	 * Data length provided by caller via sendmsg/sendpage that has not
 	 * yet been processed.
crypto/algif_skcipher.c +6 -0
@@ -72,6 +72,12 @@ static int _skcipher_recvmsg(struct sock
 	int err = 0;
 	size_t len = 0;
 
+	if (!ctx->used) {
+		err = af_alg_wait_for_data(sk, flags);
+		if (err)
+			return err;
+	}
+
 	/* Allocate cipher request for current operation. */
 	areq = af_alg_alloc_areq(sk, sizeof(struct af_alg_async_req) +
 				     crypto_skcipher_reqsize(tfm));

Patches currently in stable-queue which might be from [email protected] are

queue-4.14/crypto-af_alg-wait-for-data-at-beginning-of-recvmsg.patch queue-4.14/crypto-af_alg-fix-race-accessing-cipher-request.patch