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 CC590285C92; Mon, 22 Sep 2025 19:38:31 +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=1758569911; cv=none; b=jWlTRXUWOK+7QmqUlTYVKTv3BahFJlVRvevjGdu2WF70botZ2lfWsfhslTt6oPaoQySHCBcO8YHaiNDcYVvd8HgsqOqdKoJn8Ev7dF9+7WqIF2Wug0g3Mh23XnJAjqYusvT7CV4zmHmULGMI6iI4xtyb7nIlhIjQa9N7yDwUgd4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758569911; c=relaxed/simple; bh=mT49cnbSicRNBcTPDgfR8n/mx1ziYtnXDbygEzUwCaU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oDNfJ7FbFuQ1ZkVUC0UgcdGbwX2ViprIEiXoXLt+fSJn8TrFaU7B7JYZLG8LP+6ZTsZ9KIRL/as2p8vVsoWGA9jCqqpZMeRu8LGUG2DpLQUF8yyHT0qng6rZtgH4vK0WOpMLRaOmTXpr7ZVASgCAccst5fdhaCeF1M/YS59AJfo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=nyDBcy6N; 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="nyDBcy6N" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 649ACC4CEF0; Mon, 22 Sep 2025 19:38:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1758569911; bh=mT49cnbSicRNBcTPDgfR8n/mx1ziYtnXDbygEzUwCaU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nyDBcy6NMkMVsB6n6uf3ok/Niw5sRzWLDdxrJQFzcNH7mu8Ko9GdYTaPF/gSgWCh1 HRS4Loh1QR5HM/E9MUOlPTsgMBfiUQZPpQxNtfr7QMX5Tsr85vWft7r9E8GugiHi/u bzOcuadOYm/cgUUZNJXudtxeHFjKowR2hf2JhcKE= 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 Subject: [PATCH 6.12 037/105] crypto: af_alg - Disallow concurrent writes in af_alg_sendmsg Date: Mon, 22 Sep 2025 21:29:20 +0200 Message-ID: <20250922192409.887639865@linuxfoundation.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250922192408.913556629@linuxfoundation.org> References: <20250922192408.913556629@linuxfoundation.org> User-Agent: quilt/0.68 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 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Herbert Xu commit 1b34cbbf4f011a121ef7b2d7d6e6920a036d5285 upstream. 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: Greg Kroah-Hartman --- crypto/af_alg.c | 7 +++++++ include/crypto/if_alg.h | 10 ++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) --- a/crypto/af_alg.c +++ b/crypto/af_alg.c @@ -970,6 +970,12 @@ int af_alg_sendmsg(struct socket *sock, } lock_sock(sk); + if (ctx->write) { + release_sock(sk); + return -EBUSY; + } + ctx->write = true; + if (ctx->init && !ctx->more) { if (ctx->used) { err = -EINVAL; @@ -1104,6 +1110,7 @@ int af_alg_sendmsg(struct socket *sock, unlock: af_alg_data_wakeup(sk); + ctx->write = false; release_sock(sk); return copied ?: err; --- a/include/crypto/if_alg.h +++ b/include/crypto/if_alg.h @@ -135,6 +135,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;