From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3D8482FD1DD; Tue, 30 Sep 2025 15:15:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759245327; cv=none; b=ZPWiarDwDPRHqpWmnVWe1MJMFWowfnFhkF2FiG5TOxkVy+VnoMgwxQv/MLn9ns4qvCCxkHF1+UpYg2iotbbHwaXMoOv4WK2cEb6/mKbI1xg86byDLnXcuzpGaVgPbGvpTrzakCObR3a8cLrmaBizCYvTndVzR0xiKg4F8n4YulY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759245327; c=relaxed/simple; bh=p5I6cKm8PngDhq8J9y8YubLrosmSQJwi2VMjUsrqz40=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uEiQnFkiMr8el024pZJAjpB91xDsiFiUiYm0nHAqPYvaq/zMFliJFQ+N4ZLYJCqfKtmbnn4NjNANiPh9Wg7gYhPTEPxnkwNRKkM6FsiebmLk9jRMoT8vlITBnSMbboqOGM9oLNqZOKmxjSU36pBCE1tWCYKRnq3f3MA+eDtUQZo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=tyn0IjSJ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="tyn0IjSJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 516A3C4CEF0; Tue, 30 Sep 2025 15:15:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1759245326; bh=p5I6cKm8PngDhq8J9y8YubLrosmSQJwi2VMjUsrqz40=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tyn0IjSJedpPQUuaw2RZT4Tnjiw6553AIclCLXdHtiOXDoUhvTPq9RtcA88lFHNMa sTuou4yMQZ9XbQD6FId89yarCjlsYPgawp5CdANEbXW4noqqsrQ7w6rZXkkWE2TZ4y Phq/k86eDyhfW7YIp2p5O/6deu02gczZ2GPXpoaA= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Muhammad Alifa Ramdhan , Bing-Jhong Billy Jheng , Herbert Xu , Sasha Levin Subject: [PATCH 5.15 136/151] crypto: af_alg - Disallow concurrent writes in af_alg_sendmsg Date: Tue, 30 Sep 2025 16:47:46 +0200 Message-ID: <20250930143833.015740346@linuxfoundation.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250930143827.587035735@linuxfoundation.org> References: <20250930143827.587035735@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Herbert Xu [ Upstream commit 1b34cbbf4f011a121ef7b2d7d6e6920a036d5285 ] Issuing two writes to the same af_alg socket is bogus as the data will be interleaved in an unpredictable fashion. Furthermore, concurrent writes may create inconsistencies in the internal socket state. Disallow this by adding a new ctx->write field that indiciates exclusive ownership for writing. Fixes: 8ff590903d5 ("crypto: algif_skcipher - User-space interface for skcipher operations") Reported-by: Muhammad Alifa Ramdhan Reported-by: Bing-Jhong Billy Jheng Signed-off-by: Herbert Xu Signed-off-by: Sasha Levin --- crypto/af_alg.c | 7 +++++++ include/crypto/if_alg.h | 10 ++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/crypto/af_alg.c b/crypto/af_alg.c index aa93501e27b95..24c273f53e90a 100644 --- a/crypto/af_alg.c +++ b/crypto/af_alg.c @@ -862,6 +862,12 @@ int af_alg_sendmsg(struct socket *sock, struct msghdr *msg, size_t size, } lock_sock(sk); + if (ctx->write) { + release_sock(sk); + return -EBUSY; + } + ctx->write = true; + if (ctx->init && !ctx->more) { if (ctx->used) { err = -EINVAL; @@ -969,6 +975,7 @@ int af_alg_sendmsg(struct socket *sock, struct msghdr *msg, size_t size, unlock: af_alg_data_wakeup(sk); + ctx->write = false; release_sock(sk); return copied ?: err; diff --git a/include/crypto/if_alg.h b/include/crypto/if_alg.h index a406e281ae571..1424200fe88cf 100644 --- a/include/crypto/if_alg.h +++ b/include/crypto/if_alg.h @@ -136,6 +136,7 @@ struct af_alg_async_req { * SG? * @enc: Cryptographic operation to be performed when * recvmsg is invoked. + * @write: True if we are in the middle of a write. * @init: True if metadata has been sent. * @len: Length of memory allocated for this data structure. * @inflight: Non-zero when AIO requests are in flight. @@ -151,10 +152,11 @@ struct af_alg_ctx { size_t used; atomic_t rcvused; - bool more; - bool merge; - bool enc; - bool init; + u32 more:1, + merge:1, + enc:1, + write:1, + init:1; unsigned int len; -- 2.51.0