From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.180 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796481691; b=A8Ri52xvVerYdm5GkP0AAx7p9WzXE00KVJycUREwJtJLY6Bw2rMBQNYzcoaJexDKRPzH JgqGjDe5M3FTvlQrSB0ONAlLiQeVwHr9r5Uu9P+qOFDMGkBinKyQnVhE9q2CmD2t8PmJ0 5R0YqYig2iN6LDUer2K44onXG04zNS8m0/d+2VmmVslx8Ckmw6wOfXJdHqKVx+1xy4flg J6c3KDk5A4ULIc35e4soKSmdGDEn3pth5FzmUjz0DzV6fnMRM+ycMJpuFcb7MB8qVS7wu baY0X/gsJ8X/ZGDIIM+Lo9xKFiY0fyNAioTAAmmPg6MObMKJxZf8QSmwcIKHw0RholQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796481691; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-Id:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=hIZpl7Ldbt7D42xPp/QAtsvAMVFj+ukUhRPPlTSeBAI=; b=QpPRWYCq7n7uYBgDSa1SdOukhYTq7od0aYpZkz8wEqJJrqsP2pWy9ZqmzYLL8udCpGIy tdSRZSqP2YX67hM+2+y1//zVeyw/xN8iY15XeA7M/fCXM5nHQnWU/opE99sBW2rcYfCLf uXN2w10No0XsMT4oroO+K/dVa0vRJUsOp7dxenyMps+O/ocfMUOhoBMEXyuXOBpnuUxLN SjcAK5ZavPuMkuHtsLaXxTEPxj7znvCjZLHxDBR6nFqZ23nH1yoZu5hxufJ2Oj2T8bIyI hTC686Jml5nGyDtOykebNzg/kMtqnw2ferHjl+rsMsDzGLoDexJOzer2MbBnfEcjo+g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="zIkMN/BP"; arc=none smtp.remote-ip=74.125.82.180 Received: from mail-dy1-f180.google.com (mail-dy1-f180.google.com [74.125.82.180]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CF4BF606A32F for ; Sat, 5 Dec 2026 14:41:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CF4BF606A32F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=zIkMN/BP Received: by mail-dy1-f180.google.com with SMTP id 5a478bee46e88-386bd881d39so3404481eec.1 for ; Sat, 05 Dec 2026 06:41:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796481690; x=1797086490; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=hIZpl7Ldbt7D42xPp/QAtsvAMVFj+ukUhRPPlTSeBAI=; b=zIkMN/BPQuy7a5p+rukRbajJK5jeCeliPuHHQCptrH1R0PurYNgnZiSZ9ZN93HIBc2 GQ6zT/ejSM2ZknVyq1K+4/dGUaNLNPnCQ7bD4H1fuHldFhkSG82FU93Ily7AHmiQGVDW QRubZV49UcyZcBl5jrfQWNHGv9ODy1DR4y7qZIQdCczMD5KeP0lJ4LGFQbEPSMa23Syp zXcjqeEcWSAenttqzyyuhkU5ricOcyyxuwoks/2kekdQm5xx5qfj9M6Wvt9ySE+TBgr8 FsUkR0X6OV/8v6vN52wiOjl+hLp7QSujY86p5LZTe6a/g87EBduKFT63nQpmBPE8u+/s BZyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796481690; x=1797086490; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=hIZpl7Ldbt7D42xPp/QAtsvAMVFj+ukUhRPPlTSeBAI=; b=uAdcWOdLzCaaypUG7kJKOkDccoq+c+Uwp///mwfgBdb6rmLWIQAd0S0Isxkib9sF0X lckoGkOprR5r+mRQrUdi2P4i57/jjwjvpIW78+AVI5F5Z3Vd/y86dIaXdM4uXk016BNy TDGiCZU6c7fkAH/AXPxpZylBaDd9ZYhARbjinavjsJy1u2O/GjPJ/jW2BF86vTWK7+0N XY21SLt2xcLm/dA7BDtNgdZCKKUs39EqXzib03h9FTaG3cH7tzpLvUlyyiFtWJVkm4lL ycr7Q/pXnvkJZxwCcU4avnVC76kZGKGxpEDwj2xqtpMI3piutvSPff8JSLaG7AvhYjNX kBow== X-Forwarded-Encrypted: i=1; AL+hErEQU/xTfJ07LItmaaZ3DRuzYABXSskH7Ns9FaHY8yeaZ8GyH7CcpELC6RgUKxWkYkgjarQT6erSl8y2@vger.kernel.org X-Gm-Message-State: AB4q+uGkSclppB09Af+Z1E/myMMWGcHRicOuoFWf4b5XZnne2+dgJlPY 5yF2EFKLsEv6p5QiAlTpJ4IQhy6e+h1X7oLpm57EKySsBs4nSe7buGfq X-Gm-Gg: AZFdTZeFwtvCHo5WmejToZuvTSgRQb3t7vzWdIlCKq31SNQLl7YFvSKYMyYzcFf91Kr 7sEWStF3oEo1UFRyXxVuz3Sxo+x/Gs+xmiI6mcdIXoATutVe8Sw6cEmozd41KcDFpSCnkJGsqqR yxpuHyeS9gHKK/Pwl2TNF3KN2d0RAB/GRckLsfngpY+JVeUX87AW4Igj2vPTNLhFS2wt3AcUKHq TcOmmftNv1Nh+VmUrDQOaxe7pl442xZjY1nXMzIuxO5j7cpXH2xITtLEohOdF02E0meYsbmpMw3 aqPMM4LYiPJNs/aIyQ8fqXRSOiDHMfHOtoSN/s/5kHvHsupdxiLg5k3PPj0kh/KD6/cJKIm2HXe BpfY7YE8TCCdovg5+DlcORSk85pnKwB0nOqW9efs4sSYCQILIoeH6x7QgWDfPJW3fDaSkvgGBQp 3LJNups4TuYLerOldUQ+sCPb4IPpBmOAExHacytEJTMtxnURC+8vw66eQWye2T0kXoxw/vNfD/w qZFnr+zhJaEaXMgf9U4m+vEncR2QV4iC8ZcV5nnQZQzBmgiLthsWFUtnaDGVQU1SldD+9KTtHcv //tLy/gYhOyU4pSQz+fRVQvOGRZe7rTndg9O64b5obPJSyOSw+zNhpjHffpN2PLHMvOPTJGiavD BaFheuI/EuYjGU3m0SbQdRhCWgVzbfAFPGj2uv3QEk8M696P+gDLdaGKyxuAczpKmHSnYQlWa8b UGVMLWvR8y5dUR/t0f4C5/X1csmfm2s5RNhIkSk8XR5uXnV8RcO5UJ2x7WEyoy20m9ytmPtLVrP M5n+bdjcyINM+2x7pjIWvXWVF4jexo4qErh2l8XY1UBlQ6OEb0j2xg= X-Received: by 2002:a05:693c:638e:10b0:378:314:4042 with SMTP id 5a478bee46e88-387520d0588mr5381494eec.14.1796481689683; Sat, 05 Dec 2026 06:41:29 -0800 (PST) Received: from localhost.localdomain (14-201-175-51.tpgi.com.au. [14.201.175.51]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-387521f1360sm20149926eec.20.2026.12.05.06.41.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2026 06:41:29 -0800 (PST) From: Daniel Wade To: Jason Gunthorpe , Leon Romanovsky Cc: Jeffin Philip , Shuangpeng Bai , linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] RDMA/iwpm: fix use-after-free of the netlink request object Date: Sun, 6 Dec 2026 01:11:10 +1030 Message-Id: <20261205144111.8366-1-danjwade95@gmail.com> X-Mailer: git-send-email 2.39.0.windows.2 X-Mailing-List: linux-rdma@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 iwpm_get_nlmsg_request() takes two references but only one is ever dropped, so the request is never freed. It stays on iwpm_nlmsg_req_list with req_buffer still pointing at iw_cm_map()'s stack frame. The three producer error paths get rid of it by calling iwpm_free_nlmsg_request() directly. That frees the object while a netlink callback is still holding it, and the callback then calls up() on the semaphore inside it. A reply can quote the sequence number of a listen that has already returned. That finds the stale request and reads through req_buffer into another function's frame: BUG: KASAN: stack-out-of-bounds in iwpm_compare_sockaddr+0x1d5/0x1f0 Read of size 2 at addr ffff888008227678 by task init/1 CPU: 1 UID: 0 PID: 1 Comm: init Not tainted 7.4.0-rc3 #1 PREEMPT(lazy) Call Trace: iwpm_compare_sockaddr+0x1d5/0x1f0 iwpm_add_and_query_mapping_cb+0x1fb/0x680 netlink_dump+0x48f/0x11a0 __netlink_dump_start+0x652/0x8c0 rdma_nl_rcv_msg+0x3ee/0x4e0 rdma_nl_rcv_skb.constprop.0.isra.0+0x21d/0x370 netlink_unicast+0x68f/0x940 netlink_sendmsg+0x810/0xf20 __sys_sendto+0x337/0x390 __x64_sys_sendto+0xdb/0x1b0 do_syscall_64+0xdf/0x4c0 entry_SYSCALL_64_after_hwframe+0x77/0x7f This frame has 1 object: [32, 88) 'nltb' Take one reference. Look the request up with kref_get_unless_zero() and release it with kref_put() on every path. Wake the waiter before the callback drops its reference. Reported-by: Shuangpeng Bai Closes: https://lore.kernel.org/all/20261105233640.1667884-1-shuangpeng.kernel@gmail.com/ Fixes: 30dc5e63d6a5 ("RDMA/core: Add support for iWARP Port Mapper user space service") Cc: stable@vger.kernel.org Signed-off-by: Daniel Wade --- Notes: Reproduced on v7.4-rc3 with CONFIG_RDMA_SIW and KASAN, on an unmodified kernel with no inserted delay and no error injection. Before the patch four completed requests were still findable and the stale lookup tripped KASAN; after it all twelve probes report no matching request and KASAN is silent. drivers/infiniband/core/iwpm_msg.c | 22 +++++++++++----------- drivers/infiniband/core/iwpm_util.c | 5 ++--- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/drivers/infiniband/core/iwpm_msg.c b/drivers/infiniband/core/iwpm_msg.c index 1b10f2973ad9d..d050aa0db30fb 100644 --- a/drivers/infiniband/core/iwpm_msg.c +++ b/drivers/infiniband/core/iwpm_msg.c @@ -122,7 +122,7 @@ int iwpm_register_pid(struct iwpm_dev_data *pm_msg, u8 nl_client) pr_info("%s: %s (client = %u)\n", __func__, err_str, nl_client); dev_kfree_skb(skb); if (nlmsg_request) - iwpm_free_nlmsg_request(&nlmsg_request->kref); + kref_put(&nlmsg_request->kref, iwpm_free_nlmsg_request); return ret; } @@ -207,7 +207,7 @@ int iwpm_add_mapping(struct iwpm_sa_data *pm_msg, u8 nl_client) add_mapping_error_nowarn: dev_kfree_skb(skb); if (nlmsg_request) - iwpm_free_nlmsg_request(&nlmsg_request->kref); + kref_put(&nlmsg_request->kref, iwpm_free_nlmsg_request); return ret; } @@ -296,7 +296,7 @@ int iwpm_add_and_query_mapping(struct iwpm_sa_data *pm_msg, u8 nl_client) query_mapping_error_nowarn: dev_kfree_skb(skb); if (nlmsg_request) - iwpm_free_nlmsg_request(&nlmsg_request->kref); + kref_put(&nlmsg_request->kref, iwpm_free_nlmsg_request); return ret; } @@ -431,10 +431,10 @@ int iwpm_register_pid_cb(struct sk_buff *skb, struct netlink_callback *cb) iwpm_set_registration(nl_client, IWPM_REG_VALID); register_pid_response_exit: nlmsg_request->request_done = 1; - /* always for found nlmsg_request */ - kref_put(&nlmsg_request->kref, iwpm_free_nlmsg_request); barrier(); up(&nlmsg_request->sem); + /* always for found nlmsg_request */ + kref_put(&nlmsg_request->kref, iwpm_free_nlmsg_request); return 0; } @@ -503,10 +503,10 @@ int iwpm_add_mapping_cb(struct sk_buff *skb, struct netlink_callback *cb) add_mapping_response_exit: nlmsg_request->request_done = 1; - /* always for found request */ - kref_put(&nlmsg_request->kref, iwpm_free_nlmsg_request); barrier(); up(&nlmsg_request->sem); + /* always for found request */ + kref_put(&nlmsg_request->kref, iwpm_free_nlmsg_request); return 0; } @@ -601,10 +601,10 @@ int iwpm_add_and_query_mapping_cb(struct sk_buff *skb, "query_mapping: Mapped remote sockaddr:"); query_mapping_response_exit: nlmsg_request->request_done = 1; - /* always for found request */ - kref_put(&nlmsg_request->kref, iwpm_free_nlmsg_request); barrier(); up(&nlmsg_request->sem); + /* always for found request */ + kref_put(&nlmsg_request->kref, iwpm_free_nlmsg_request); return 0; } @@ -800,10 +800,10 @@ int iwpm_mapping_error_cb(struct sk_buff *skb, struct netlink_callback *cb) atomic_set(&echo_nlmsg_seq, cb->nlh->nlmsg_seq); nlmsg_request->err_code = err_code; nlmsg_request->request_done = 1; - /* always for found request */ - kref_put(&nlmsg_request->kref, iwpm_free_nlmsg_request); barrier(); up(&nlmsg_request->sem); + /* always for found request */ + kref_put(&nlmsg_request->kref, iwpm_free_nlmsg_request); return 0; } diff --git a/drivers/infiniband/core/iwpm_util.c b/drivers/infiniband/core/iwpm_util.c index 51af8c1c49f9e..639ea80373ea6 100644 --- a/drivers/infiniband/core/iwpm_util.c +++ b/drivers/infiniband/core/iwpm_util.c @@ -315,7 +315,6 @@ struct iwpm_nlmsg_request *iwpm_get_nlmsg_request(__u32 nlmsg_seq, return NULL; kref_init(&nlmsg_request->kref); - kref_get(&nlmsg_request->kref); nlmsg_request->nlmsg_seq = nlmsg_seq; nlmsg_request->nl_client = nl_client; nlmsg_request->request_done = 0; @@ -357,8 +356,8 @@ struct iwpm_nlmsg_request *iwpm_find_nlmsg_request(__u32 echo_seq) list_for_each_entry(nlmsg_request, &iwpm_nlmsg_req_list, inprocess_list) { if (nlmsg_request->nlmsg_seq == echo_seq) { - found_request = nlmsg_request; - kref_get(&nlmsg_request->kref); + if (kref_get_unless_zero(&nlmsg_request->kref)) + found_request = nlmsg_request; break; } }