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=1796382643; b=4XNdsIIIUDsKQHASEmdRviqKS4tb/GPyZBeglUDehg0You1evVtNcruRGRCUVYEvgnjS YtGLPCKyJCRxkius8ULPcZ4iSfcGw/bN55ytUOI/SO0aCJyK3/48qG0YUnqn1BWBdiibx qW6eU0IoSKpcMk05FUm/T68WfdWp1U8xeYE4++Y4MkAbQ7poMUcph5vH2Q547+7DgWSnk R6rAgEcI38vc2h+vYaYNfImx7um9GARNvSNDaQnK/ymAdk/OMjdvs938M0zEs0uM7ltgf D6SBNcsLGjT0DRglgatlaDHKSfPhjK1zTKHSfRDkIgus7XIc44k9e26kNhimO9fomZA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382643; 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=Zq00QBGz+Gs7nZhkyfWt0s/19AvnisV+SFN9Ib//OuU=; b=xDRd8unnKSsneefZ0XgOv0MD0NQXmuy2c0p45ujibfNrBn6hQSRr0yKKz9LcdIQ5x8Z+ ubnqQNVNKDDU1uvXWUfjv1YaL69M72ohER2qsIEjDu90STvq9GWsEsiov1mewnw+Xt9sZ g+hQoNhA0NbrptyebxXz+BYqA90eXJiwW/cHi9NTcN81JcNeFXclXaDxLckKhuAfgXY/J Mez5MHD8HVPRg/z+iTZD0iivnzs4jXzNh+5oNCfhQyqIwy+fDCkpegQlwaskjiGSSyyKy +/cQiLGH9ZmWOZyyWnu+dzl74x2bZWGgigsWWpdw9GcwvBV4jHo1yOSdxoFwj+F0gUQ== 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="bkSSTSi/"; 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 97968606A33A; Fri, 4 Dec 2026 11:10:43 +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=bkSSTSi/ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 142101F000C2; Fri, 4 Dec 2026 11:10:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796382643; bh=Zq00QBGz+Gs7nZhkyfWt0s/19AvnisV+SFN9Ib//OuU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=bkSSTSi/SJ+Nc06NsGpFSNbZ8JnHP3pIQ4MkMiitKN8Vv4Zb/Le3OiDNNvBRrwiXz OP7oMjEgSWHuW2/aSDFcLacTmhzDD84IePw0/AuyIyiNcIDAtX+8Wfs1Dv4iA6+bUV yH8h98hSU8g4kzrmCs6h17rCobFt0AknpZIXh+JE= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Deep Shah , Leon Romanovsky Subject: [PATCH 6.18 501/703] RDMA/siw: Fix use-after-free in siw_mem_id2obj() Date: Fri, 4 Dec 2026 19:06:40 +0900 Message-ID: <20261204100641.129961136@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@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.18-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 @@ -117,7 +117,7 @@ void siw_free_mem(struct kref *ref) else kfree(mem->pbl); } - kfree(mem); + kfree_rcu(mem, rcu); } /*