Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793216348; b=XGH3TlgAPUR4871MCQe2oBIuRMdvVyMGlkydZbPgcaN27fV39IVE+DbKk+PXdhxH9E8e DyNFLc70YXZPxwhCxZw7pOdd/7VRr0qihz2Gd62NpRTxXEGIPy976s9EDs4kSgnYVok+p 3Bpq5RnoSCL85hQTyQ9SpEj+HgnWbZXI9NEjTZbEn74RuOGRJrQU9oUokUaL2CJx3zCMX eUKshYpozYI+D/FjZrnytCSNJZDCQcbPhEWwZYhHv7abPE4Ol8tTvdDOGG+5+wyH6ylBd iI1uKCImmwtUerW279Ru3xK6vDzpEq+Z/YPZoxMY6z7VAqLUO4F0kyDDY0LlxRkcaIA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793216348; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=R94nLHxMdeTaFBdZ5Z6VX/EP788epAWrYKyz60ShtNM=; b=zUnkD84Rz5dJts8afvMrYj35fRsCQ1OwrCYjqFXFQM2CIB30wujCM4JRtFCxh2sXgu7W gr2Y2k+Gsusgyq/VlC3738nNrs8Gw6I2unclIim0+srsGjwFNRKe3/2ryQ9vtTJFpLEi2 2HuBlgX5WA96SVU1m/ak3bv4RxiJ1dKIK9XTHuy0PkQrPqDN9rDsf0Jx+Pj6o9T/UL3BU twXH8M4WG4U3MhigJdMDTw+P8qnuvSeFsmckAdtBEzDTAAnY1BB83Yaw6RADNCHf9oYji OeCwJ/Vc6V3d2oiKRpHrbJeavh5ytfMqPxzVXtzfo2BTNHKSp5bsUkga/ZNXldSyHpQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=K7I0OjOD; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 65E7B606A31C; Wed, 28 Oct 2026 19:39:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=K7I0OjOD Received: by smtp.kernel.org (Postfix) with ESMTPSA id AA3F41F01825; Wed, 28 Oct 2026 19:39:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1793216348; bh=R94nLHxMdeTaFBdZ5Z6VX/EP788epAWrYKyz60ShtNM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=K7I0OjODSk8z74HT+2d2suQVwle8Ly3jNV0rWaBT4LujCGVUtGoGkO8c4pHoYsATq TqRVM/Ob8fRaJCAq3tWIFrWRz0g7CZ4wVQP/FCWjgoTtAL9GwDW6frytjap2krAs9H z6FzCiNNwGDiLDnXX3qejiPtixKycGycn5vkA9bQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Christopher Lusk , Namjae Jeon , Paulo Alcantara , Sasha Levin Subject: [PATCH 6.1 1527/1887] smb: client: fix request buffer leak in smb2_new_read_req() Date: Wed, 28 Oct 2026 18:00:23 +0100 Message-ID: <20261028170534.212162472@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261028170459.200466217@linuxfoundation.org> References: <20261028170459.200466217@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Christopher Lusk [ Upstream commit deb6468f4164640e4dc875f008aa449cf55987a5 ] smb2_new_read_req() allocates the request buffer with smb2_plain_req_init() but only publishes it to the caller with *buf = req at the very end of the function. Two error returns sit in between: rc = smb2_plain_req_init(SMB2_READ, io_parms->tcon, server, (void **) &req, total_len); if (rc) return rc; if (server == NULL) return -ECONNABORTED; [...] rdata->mr = smbd_register_mr(server->smbd_conn, &rdata->subreq.io_iter, true, need_invalidate); if (!rdata->mr) return -EAGAIN; On either of them the buffer is neither released nor handed back, so it is leaked. The caller cannot clean up after it: smb2_async_readv() does 'goto out' on a non-zero return, which skips the cifs_small_buf_release(buf) at async_readv_out, and buf has not been assigned at that point in any case. The write path has never had this problem. smb2_async_writev() registers the memory region inline and jumps to its release label instead of returning: wdata->mr = smbd_register_mr(...); if (!wdata->mr) { rc = -EAGAIN; goto async_writev_out; } Commit b7972092199f ("cifs: smbd: Retry on memory registration failure") changed both sides from -ENOBUFS to -EAGAIN in a single patch, which puts the two shapes next to each other. Only the -EAGAIN return is reachable in practice, because smb2_plain_req_init() calls smb2_reconnect() first and that already fails with -EIO when server is NULL, before anything is allocated. Both returns are given the same treatment here rather than leaving one of them correct only by accident. Because -EAGAIN is a replayable error, the failure also reaches the retry block at the end of smb2_async_readv(), which marks the subrequest NETFS_SREQ_NEED_RETRY, so a failing registration can be retried rather than ending the I/O, and every attempt that reaches it leaks another buffer. smb2_should_replay() short-circuits on tcon->retry, so on a hard mount the attempt count is not bounded by the retrans setting. Only the asynchronous read path is affected. The synchronous SMB2_read() caller passes rdata == NULL and the memory registration block is guarded on rdata. The memory registration failure path was pointed out by the Sashiko AI reviewer while it was reviewing an unrelated patch to smb2_async_readv(). Fixes: bd3dcc6a22a9 ("CIFS: SMBD: Upper layer performs SMB read via RDMA write through memory registration") Link: https://sashiko.dev/#/patchset/20260729192002.876156-1-clusk%40northecho.dev Link: https://lore.kernel.org/all/20260729192002.876156-1-clusk@northecho.dev/ Assisted-by: Claude:claude-opus-5 Signed-off-by: Christopher Lusk Signed-off-by: Namjae Jeon Signed-off-by: Paulo Alcantara Signed-off-by: Sasha Levin --- fs/smb/client/smb2pdu.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/fs/smb/client/smb2pdu.c b/fs/smb/client/smb2pdu.c index 8f23b8968beb4..e69b4bb9dc919 100644 --- a/fs/smb/client/smb2pdu.c +++ b/fs/smb/client/smb2pdu.c @@ -4287,8 +4287,10 @@ smb2_new_read_req(void **buf, unsigned int *total_len, if (rc) return rc; - if (server == NULL) - return -ECONNABORTED; + if (!server) { + rc = -ECONNABORTED; + goto free_req; + } shdr = &req->hdr; shdr->Id.SyncId.ProcessId = cpu_to_le32(io_parms->pid); @@ -4319,8 +4321,10 @@ smb2_new_read_req(void **buf, unsigned int *total_len, server->smbd_conn, rdata->pages, rdata->nr_pages, rdata->page_offset, rdata->tailsz, true, need_invalidate); - if (!rdata->mr) - return -EAGAIN; + if (!rdata->mr) { + rc = -EAGAIN; + goto free_req; + } req->Channel = SMB2_CHANNEL_RDMA_V1_INVALIDATE; if (need_invalidate) @@ -4363,6 +4367,10 @@ smb2_new_read_req(void **buf, unsigned int *total_len, *buf = req; return rc; + +free_req: + cifs_small_buf_release(req); + return rc; } static void -- 2.53.0