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=1796383934; b=aclAN79vRSpB+yXR+CeJH6XMw7aK9R0fII4HWk9xG91fbYnGDxV15ilSpVHRrhYz4Dt9 9+qLkJRjO8jhfSrTY76vMMVI0rLz1MUuRM28UDoOmnUlSpE+fnjz7KiR0Rw78W44UR9Xt 4CaJOsUo0N6qfaf+ULDKdNuVq6PnNogB4CELilMDyU/SOgVJ7vRJMbLNCe4zp0wkSi+fI hZRvbc2fv2cSoKyZtZKmE0pJEmgyGPW17yKHYUe+H4roSECD5AcX9b6vaJ04A2I2POwKm 8wDZcDuvsrPsnYwV3BM1LcJbx/9z7OTa1r9nDxWuHw6Dj0tAHz4rktTO7eo+SRq5Mxg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796383934; 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=1cMkBtHiiNUQJ6xdOxcMvZSx4LRoT6IabdBznSF4Tag=; b=BRtGO194iw03qACGOe+szWdOTu9WmX4IQlQ10UB4ANjsQxoC9diSG1L4zx1VmISvrwZ3 tRcyy8FWBoPcnMyBD0MmVnkKoj+zh7N9LSQwQcWim5SMUxzqJOtjoNeHFwx34ScC9hPEW PlKuEwtsgW4teok7s/IihlOGe8PeCzWyedsye8JZY2wK2EzvHNXOmOEOxGO6TF7Fi7SGR aJkZD6RiOATh8N+z2yeEPIv8RE62eR/WY0RGvcMrT06bTJ9pP/OKiMRqgYj/3eRfKsmm3 PLV6CIUvKUm+MnW7L07+VMr05dde7AYeMXrV9F0u7fG9I6cya1lFqzLJdJ04vk/sgiQ== 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=qXiY08Uz; 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 BA75D606A322; Fri, 4 Dec 2026 11:32:14 +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=qXiY08Uz Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1CA5F1F000CE; Fri, 4 Dec 2026 11:32:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796383934; bh=1cMkBtHiiNUQJ6xdOxcMvZSx4LRoT6IabdBznSF4Tag=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=qXiY08Uz1IM3PowUAtxyAs4DrUIvJFXTLiSfrUSuvYNplGdz94KS4+E1JKIOR6smQ 7W3DdFeV6/58wb+tyhqFUYIsZrq+/NdgBzGCMICQmh478+WYtSOl8/M3Ef84H+YHG+ 9xZ+q6+jk09g8c6RpNFbt89sRhaSgZ7ASbeRUlHc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Deep Shah , Leon Romanovsky Subject: [PATCH 6.12 429/555] RDMA/siw: Fix use-after-free in siw_mem_id2obj() Date: Fri, 4 Dec 2026 19:07:52 +0900 Message-ID: <20261204100625.996791473@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100603.988357525@linuxfoundation.org> References: <20261204100603.988357525@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-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 @@ -156,6 +156,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 @@ -141,7 +141,7 @@ void siw_free_mem(struct kref *ref) else kfree(mem->pbl); } - kfree(mem); + kfree_rcu(mem, rcu); } /*