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=1796482531; b=BT+ILmO6RP23YDIO3b6Z/raJd+RA/oEAo3jJvfS2GkqaqQdasNZc7+W2xo+J44kqA9AZ 11Av1DPSH4bu3nOg/H8Gp06IGmODx9hXGDcBFKVTdIYXSp7LK3434YrlZgiMgtRLl/SRr dHWgEc9AOazg/mZaXt10XllNHJ52IOiHDqezGls3xF1a2dclaoNWGgSPwj/LKtZZRZz/z JBR48YR/DrytbYkK1fsKAFLYvga2oK01zkJB+dEdjrVj08xF4LV5j7xCMp6V48+7UCGza yg2cEPVl2nDWA+UJ4MSIU7m/PRukOsmN3aPDTtAaAbMUp8hzc6OUVA9yxF9+FYDSWFw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796482531; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=aulx1opy840hXLCj5Y2NpzRywhvja7cEG9+dtUtMoJk=; b=iJt4hOZlOAWF/3vQay3KOJfxwxheOrdd7MgcGQkgYmEJ2U8RJJbR0zpSgtXNRJX1QEzD IJKP13qh+VLmKbvlSBFcVZcshD1ZQLNAmELCh80RWMdhq2Ehn5xT/QWHPJGdtGORmRBq+ JwFXiBatTBKC9BkQtic9udt9aZNBbHSZ0LC8UiCIAOAoUUdl3cd0Ffwv4OJXa/uoT1R43 GlqPBewH86VSoKqvCiH5MXOkqpyhqHpSfkg4Y5PxeOlS7DdAl7h7Y3cTt/wZOkb4B2P0z Pcke8o8wNcVJgbE2YoG7Nbfq1JgBmYYSl4duyoeUL6ymMAJNc1TVpvFy1Mt0bZSusyQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=U1vc1xUu; 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 7D632606A322 for ; Sat, 5 Dec 2026 14:55:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=U1vc1xUu Received: by smtp.kernel.org (Postfix) with ESMTPSA id 28B4E1F0092B; Sat, 5 Dec 2026 14:55:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796482531; bh=aulx1opy840hXLCj5Y2NpzRywhvja7cEG9+dtUtMoJk=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=U1vc1xUu5Tw1mOZ8caoMDZrvzxqxDyOfSolc7wQn91ui2PfO23INCxjcvofwZaZt1 7jJq1lsDtJJCjRjfCXAnzixBPVJ/m+1JxT5D89W8aM/biu5qZi1kKaf9kSPQfrP7Nu 332I4qIB7B2zEdNwARFJSeu8JFnyxh29EC6gsNPkXRek9DpynYIJ9n4oFvWfWZq3GO Vhw9c/5sA/omRCUdcw/DaVWARPE1pbXea5tAp7hO2e4KkuqO9Tf2eGkNpV6vOex2rr FbCwZ7j4N7bktWjeZE2iHkt5Ly6fB26P0CgV9s7iloXE8NCzlCBC/53Xy26jbPAEdO we6y7B2d6blZg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 1/2] RDMA/iwpm: fix use-after-free of the netlink request object Reply-To: sashiko-reviews@lists.linux.dev To: "Daniel Wade" Cc: linux-rdma@vger.kernel.org In-Reply-To: <20261205144111.8366-1-danjwade95@gmail.com> References: <20261205144111.8366-1-danjwade95@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 14:55:30 +0000 X-Mailing-List: linux-rdma@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] RDMA/iwpm: stack use-after-return via req_buffer in netlink callbacks -- commit 77177fe8d60c7890fdb4f0b44b159bac9ca369db Author: Daniel Wade RDMA/iwpm: fix use-after-free of the netlink request object This commit changes iwpm_nlmsg_request lifetime management to take a single initial kref, look up requests with kref_get_unless_zero(), drop references with kref_put() on producer error paths, and call up() before kref_put() in the netlink callbacks. > diff --git a/drivers/infiniband/core/iwpm_util.c b/drivers/infiniband/cor= e/iwpm_util.c > index 215f70cfd1132..fff2a2b6bca39 100644 > --- a/drivers/infiniband/core/iwpm_util.c > +++ b/drivers/infiniband/core/iwpm_util.c [ ... ] > @@ -360,8 +359,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 =3D=3D echo_seq) { > - found_request =3D nlmsg_request; > - kref_get(&nlmsg_request->kref); > + if (kref_get_unless_zero(&nlmsg_request->kref)) > + found_request =3D nlmsg_request; > break; > } > } [Severity: High] Can netlink callbacks still read and write through nlmsg_request->req_buffer after iw_cm_map() returns and unwinds its stack frame? iw_cm_map() allocates pm_reg_msg and pm_msg on its stack and stores their addresses in nlmsg_request->req_buffer. The kref only pins nlmsg_request, not the caller's stack frame, and iwpm_wait_complete_req() returns immediately after kref_put() without waiting for in-flight callbacks: CPU0 CPU1 iw_cm_map() iwpm_add_mapping(&pm_msg, ...) iwpm_wait_complete_req() down_timeout() /* expires */ iwpm_add_mapping_cb() iwpm_find_nlmsg_request() kref_get_unless_zero() /* 1 -> 2 */ kref_put() /* 2 -> 1 */ return /* pm_msg popped */ memcpy(&pm_msg->mapped_loc_addr, ...) <-- stack use-after-return Because iwpm_find_nlmsg_request() leaves nlmsg_request linked on iwpm_nlmsg_req_list and rdma_nl_rcv_msg() only holds a shared down_read(), moving up(&nlmsg_request->sem) ahead of kref_put() in the callbacks also le= ts the waiter unwind its stack while a second callback can still look up the request via kref_get_unless_zero(). The same window exists on the producer error paths in iwpm_register_pid(), iwpm_add_mapping(), and iwpm_add_and_query_mapping() when kref_put() returns while a racing callback holds a reference. In iwpm_add_mapping_cb() and iwpm_add_and_query_mapping_cb(), this overwrit= es up to 256 bytes of a dead or reused kernel stack frame via memcpy(). Unlinking nlmsg_request on lookup under iwpm_nlmsg_req_lock and embedding t= he request/response data inside the kref-managed struct iwpm_nlmsg_request (copying it back to the caller only on success) would avoid exposing stack pointers to callbacks. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261205144111.8366= -1-danjwade95@gmail.com?part=3D1