From mboxrd@z Thu Jan 1 00:00:00 1970 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=1796381116; b=j7kep4G2rhmXA6d4C0OuyPGqdy8TRCFTPjENEu8+0l2DXa09yZyLACrf7zh/TbTGzuZM a/FLZdt9ySh0D2C/6Wci7qfcqSV9flQL8pELPAWBrinbsN6py5Hm2eguYBWkTCKJYyxAT 5Vwz7HPYfbh1FoAmZRN23h5xx7Q1gHQ1jFSAoufZgGGMHiGkYldm78p8NdYn9GULqsgvZ MNt0KOBj8aWnbkmO3kvZKCevhdeltXLzjPF4JkKjdjVOecESy6CcNI29njWx6W4Zf+Z0y FaxDhhcONWsE5Kc6hwAulxxPlg+1bLIyweAbF4OhUxlephefl/TUDibTYxbkVH8CTPA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381116; 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=E1TTmnhpTumvhIHs9+Gwl4RdxLV3c1/OKFavFhns3mY=; b=ZPRtMSK5O049oKKS6OLnl2ieaAQePZtYkGl/2JAsn4ex4n7xZRH/P/kYuy8n83ev+Fl+ KfXO/DKZ31y1PxiqnbISQ292f4PwAwpO985ms94CaQlgnwFpPkqSb4X2HnEJjQSLcuZ1q FeO0w0BCvyt5Gb3VheXonHP35B9nsKK36mDmpJ8YnWTmw1LxG9lzhLHhePSXH8JB+L68f NxIrl+zqKTMWiSiR6QOub8LfG447bhdzpHOrMT8Iohhp8bdlhvUSYmRyOiJGgASO2iX11 8o2bRJb3nHOeXeLFGHJeahvrQbLOxxl8N/i+6whUvrWXlCLU0mgzvmoI1hpHV0qRZeQ== 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=GsQbwg1X; 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 20682606A33F; Fri, 4 Dec 2026 10:45:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=GsQbwg1X Received: by smtp.kernel.org (Postfix) with ESMTPSA id 404231F00A09; Fri, 4 Dec 2026 10:45:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796381115; bh=E1TTmnhpTumvhIHs9+Gwl4RdxLV3c1/OKFavFhns3mY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=GsQbwg1XxungtYqPANSsw+DfQ/og/BYsb7vplWFTuIXjcGWo1XQpAm5cUIFfcR81C 9NcXGgHJUY6DFpPYnfFkMj0zp0TJBdT2ASMlZKbDDhf+kzK4v+Mrkt4NBuY6kEypwU 5xDzGVxZ1HqipxotyDLIoKVNA274OYa48jtQBQ0s= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Deep Shah , Leon Romanovsky Subject: [PATCH 7.3 564/742] RDMA/siw: Fix use-after-free in siw_mem_id2obj() Date: Fri, 4 Dec 2026 19:07:08 +0900 Message-ID: <20261204100650.131472119@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@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 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Deep Shah commit a70672b9b3ac7d8945f67cd199c1bb680d5d5f64 upstream. siw_mem_id2obj() finds a siw_mem with xa_load() under rcu_read_lock() and then takes a reference with kref_get_unless_zero(). This is only safe if the object stays allocated until RCU readers are done with it. siw_free_mem() frees it with kfree() as soon as the last reference is dropped, so a lookup that races with the final put reads freed memory. This happens when an MR is deregistered while an incoming RDMA WRITE looks up its STag: BUG: KASAN: slab-use-after-free in siw_mem_id2obj+0xe5/0x310 Read of size 4 at addr ff110001042aed88 by task repro-rcu2/90 Call Trace: siw_mem_id2obj+0xe5/0x310 siw_proc_write+0x282/0x430 siw_tcp_rx_data+0x12e/0xbf0 __tcp_read_sock+0x12c/0x440 siw_qp_llp_data_ready+0x147/0x260 Allocated by task 89: siw_mr_add_mem+0xb2/0x2a0 siw_reg_user_mr+0x19f/0x380 ib_uverbs_reg_mr+0x2a7/0x4c0 Freed by task 89: kfree+0x301/0x530 siw_dereg_mr+0x31/0x50 ib_dereg_mr_user+0xb9/0x200 Free siw_mem with kfree_rcu(). A lookup that loses the race then sees a zero refcount and fails. The umem or PBL is still released at the last put, since a failed lookup never touches it. Fixes: 2251334dcac9 ("rdma/siw: application buffer management") Cc: stable@vger.kernel.org Signed-off-by: Deep Shah Link: https://patch.msgid.link/20261102064437.23976-1-deepshah146@gmail.com Signed-off-by: Leon Romanovsky Signed-off-by: Greg Kroah-Hartman --- drivers/infiniband/sw/siw/siw.h | 1 + drivers/infiniband/sw/siw/siw_mem.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) --- a/drivers/infiniband/sw/siw/siw.h +++ b/drivers/infiniband/sw/siw/siw.h @@ -157,6 +157,7 @@ struct siw_mem { void *mem_obj; }; struct ib_pd *pd; + struct rcu_head rcu; }; struct siw_mr { --- a/drivers/infiniband/sw/siw/siw_mem.c +++ b/drivers/infiniband/sw/siw/siw_mem.c @@ -115,7 +115,7 @@ void siw_free_mem(struct kref *ref) else kfree(mem->pbl); } - kfree(mem); + kfree_rcu(mem, rcu); } /*