From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.49 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796540274; b=aBOClpbeD606ze0rz6zmhUup3Kjqw1npFu0l6ZgHynEu9c3g0wscI+4mokLKpPYpksM0 GpagjyaZB51/wW1qcEqs14ejqmECFBHi7aa9k2+o8Dw1BaoqW0m/QYhYCjCRce0Gg6N+P AaIgSgTgbWcuY8iwnUD6gb01POvtWjDyEJpfyI65NirV0vy8cB4nt+9BVvzo3wMMt0Ffv XGhSaosTVwc+8m2nu2tOWtgZaFQwtbxp3GAUVxLUzCe2DSsBZJy8n46BXm/l7emNzzmKO 30IDcAOoFsypN35PsOOyJnxamkrAgpV21VyAR3TgGOgW9ni5QTe/n1uUX53bqsGeinA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796540274; 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:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=0fDijxueeoWDBK/2szOod8V+L4v4WaTZ7qy3ZwF1uXY=; b=fskQQtaTl5a+mzURm/3T1dR22zVSCk7HUZvnAssa3C2EsmlqFTwDU2tFxiaPhs69DRTP E9k3grdpa1aqxvTlCfWBmz/v8RNgdv1lMyWdyFWa8ipOL0+fIRG39E/jBpbFeqaWEC4ZV G76Rip5AIQkWA3Q441aLqnZ6sEJYYzFAxIqn3k4afzDVvuhVwKKEUb8hjTMENh1W7j330 2Rhx8Z70Z5VfsrEH++NRGC1Kk3FYWwSLr8B2+tPYwn+MIMEyPLhE41unoUn2SAGiI6eNh SqwJyPo7H+e4eZh6Vknfdk3dspfvmPDm8BGQhwrEjKgA/fKpsC/aiWeDjAmLmFqM8aA== 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=kuMOyhpY; arc=none smtp.remote-ip=74.125.82.49 Received: from mail-dl1-f49.google.com (mail-dl1-f49.google.com [74.125.82.49]) (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 918EE606A683 for ; Sun, 6 Dec 2026 06:57:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 918EE606A683 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=kuMOyhpY Received: by mail-dl1-f49.google.com with SMTP id a92af1059eb24-1b546061d58so5323698c88.1 for ; Sat, 05 Dec 2026 22:57:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796540273; x=1797145073; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=0fDijxueeoWDBK/2szOod8V+L4v4WaTZ7qy3ZwF1uXY=; b=kuMOyhpYxn8+/4yV8ONBJSYEmmQtYS07aT+VKL4nMuPeSnoLbGGLKYzTSOv19VT6QB i07eT4BfTjnbU/Kkwi02btEMwXDuMcLCRnRKpgXBvVdIdOsCTaeStvLpB+nLWzotbH5u caZyG0g1ivI/JMU1kUCkyfQf4GKyQz69wFS+LMWYgk89ebY6JmSJRr5Euj9aTRx2sKZh fNkCIiuwyZKv974pef6pYBiQZzpNqx00m00m6bJrb1gwCa0osUO8aojvZWnoIE3tFYDb bU5b1bHCo7+eZS4sFO8iF7HgS3Jru5MVnK/LruynFOTranVAMCyjCXl6Hp5gqiOQT1Q3 MxCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796540273; x=1797145073; h=content-transfer-encoding:mime-version:references:in-reply-to :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=0fDijxueeoWDBK/2szOod8V+L4v4WaTZ7qy3ZwF1uXY=; b=lEaIOz89KeQkHgsSJJp8Sr7TQAB4m3DaK5rz1WkhFiY3YPz6w4IUZGm7hGqbsLM/Wo b0LSOM/y+SmJkQReQFBJtVRM47a9V85xT80SYZ1SBsycdAa1kzUTfvqIohGavczXz1eE Mc2EokvL2iAZJA754GqrORzmQ3INRx1fSpy/oo5eg97J9UjaMU2LP44UPbVhwZ1uoX77 eWm2J4NM/w12t/1yVB7W9vQl4PVKIbvUI+QNyT1vRvx/nKzp2JRr0Hq6k8PKcahJMiJP /VYcZbUr5e0vHm5C/NYd+IQo9KfqYHNap6mDivoXPdzqvi0LjehHVUM/OWqwmaCBeFRh ZRBQ== X-Forwarded-Encrypted: i=1; AL+hErEo0a5Z2rVUZwn+fxTy/qaoVjGBNx3NvvsV2bxWkPAqXlv+CAsXaWdYSlQp+Cwg6VUV/uSEVpqV8gSwTL4=@vger.kernel.org X-Gm-Message-State: APuU4Z8BecK1vqsjgEk9TdsVqitgRp5B4aIO30Sil5UT/ed5nd2NBMXW Jqfn8czz2xJohc9SzG46hEa6AdrmhW4sTMxaN5GbP21QwqjPg4YB5UiL X-Gm-Gg: AZFdTZdTjH+KHPtHJy7ERBz7A20ymeA7le8ZByixxY+gAswpUNBhPnNtS84X1k5fOdw 9UEXfQI8NztoEadv8XK3wvZkigMoaLxj+l35/cCC5cplinmZU3oF2kOZ6MQigibScR+pe38aYYV r/4nMI5jsfytDbj7MftBDQ4QyguSRl5BtxndINCZLI62k8k1lSTb9+Z2b0cgSsmdFd/5nY08dM1 EUcIlIDsdMsGOTup7KxoKWbd9cGSWP3NClUhQxrnpYyOCI1TR3Pp4j7mSejkW+pDcg8kz07mHnT 3Xzv2eQzfifqWWbdsVavREs5qIgHn8Ex9SIGnanUvk4CFgTWRIQY5XgTuM51+s4G0f0/C9B9GhB o+7ysDmmG6COZrI6E/3C3r+vgDgvH7TjOXXvriFZXOXAH4/YnpLayY7WNwPWvdcrW3RaTU4PL9W emBbggt6DrH/ec+mcdPBUX2t8w9fruBfe+woJFVc8Q3iTXCFQUmDhIpaJRHSa+saeoZjtFc2vxR 49Nr3T0RcdnMyTl+eHQoUONGxLmkFO4ruGllKEALIPmPB84QjVhSHwx0wVctqbyNawsslBnwPf/ AheDfGvl87ceQ8bS4R1jnZNH+4PwFAEiXUX/XghVj7st/DO7BtAs9SIEJUYO+3gMR/ULKR8tNy9 t+unDr+hNJmet/Hr3Q40nTE5OtQOzJPhyLyfDwleU2WhT61s6C0j0DnUiw93ZBiGbCLjFGVxRnO x5lmI/579dC7JQCCLq74Ij/qEhohASnNFk5RMDdpkrwoh5bYWJX8GrmCu8T611Gjz7zhEj76hFH Zscr/X52BXJISLm7QwOfEc+2vswprGKus8OIdZGP9arDr2P82b3Qrb5tfk9qCatfRGw7XJRgBql X-Received: by 2002:a05:7023:e4f:20b0:1b5:d5fc:eed6 with SMTP id a92af1059eb24-1b5d7108a88mr7057422c88.28.1796540272504; Sat, 05 Dec 2026 22:57:52 -0800 (PST) Received: from localhost.localdomain (14-201-175-51.tpgi.com.au. [14.201.175.51]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b5d6323d8esm24830242c88.0.2026.12.05.22.57.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2026 22:57:52 -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 v2 3/3] RDMA/iwpm: keep the port-mapper request data inside the request Date: Sun, 6 Dec 2026 17:27:23 +1030 Message-Id: <20261206065723.147-4-danjwade95@gmail.com> X-Mailer: git-send-email 2.39.0.windows.2 In-Reply-To: <20261206065723.147-1-danjwade95@gmail.com> References: <20261206065723.147-1-danjwade95@gmail.com> X-Mailing-List: linux-kernel@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 iw_cm_map() keeps pm_reg_msg and pm_msg on its stack and publishes their addresses in req_buffer, where any netlink callback can reach them. The kref pins the request, not the frame. So after the ten second timeout the producer returns and unwinds, and a callback that already took a reference still writes through req_buffer into a frame that has gone. Move the data into the request itself. The op check added by the previous patch is what keeps each callback on the member its producer wrote. Copy the answer back to the caller after the wait returns. The caller now drops its own reference once it has copied, so iwpm_wait_complete_req() no longer drops it. iwpm_register_pid() also set req_buffer only after the multicast, so a reply that arrived first found it NULL. The data is now in place before the message goes out. Fixes: 30dc5e63d6a5 ("RDMA/core: Add support for iWARP Port Mapper user space service") Signed-off-by: Daniel Wade --- Notes: v2: new patch. This is the stack use-after-return raised against v1 1/2, https://lore.kernel.org/all/sashiko-outbox-251664@kernel.org/ removed at the source rather than guarded. Tested on the same kernel with both a success and an error reply to ADD_MAPPING, so the copy-out runs under KASAN: twelve stale probes all report no matching request, and KASAN stays silent. drivers/infiniband/core/iwpm_msg.c | 19 +++++++++++++------ drivers/infiniband/core/iwpm_util.c | 1 - drivers/infiniband/core/iwpm_util.h | 9 +++++++-- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/drivers/infiniband/core/iwpm_msg.c b/drivers/infiniband/core/iwpm_msg.c index 1d77349db51e5..ecf7e12674732 100644 --- a/drivers/infiniband/core/iwpm_msg.c +++ b/drivers/infiniband/core/iwpm_msg.c @@ -106,6 +106,7 @@ int iwpm_register_pid(struct iwpm_dev_data *pm_msg, u8 nl_client) goto pid_query_error; nlmsg_end(skb, nlh); + nlmsg_request->data.dev = *pm_msg; pr_debug("%s: Multicasting a nlmsg (dev = %s ifname = %s iwpm = %s)\n", __func__, pm_msg->dev_name, pm_msg->if_name, iwpm_ulib_name); @@ -117,8 +118,8 @@ int iwpm_register_pid(struct iwpm_dev_data *pm_msg, u8 nl_client) err_str = "Unable to send a nlmsg"; goto pid_query_error; } - nlmsg_request->req_buffer = pm_msg; ret = iwpm_wait_complete_req(nlmsg_request); + kref_put(&nlmsg_request->kref, iwpm_free_nlmsg_request); return ret; pid_query_error: pr_info("%s: %s (client = %u)\n", __func__, err_str, nl_client); @@ -195,7 +196,7 @@ int iwpm_add_mapping(struct iwpm_sa_data *pm_msg, u8 nl_client) } nlmsg_end(skb, nlh); - nlmsg_request->req_buffer = pm_msg; + nlmsg_request->data.sa = *pm_msg; ret = rdma_nl_unicast_wait(&init_net, skb, iwpm_user_pid); if (ret) { @@ -205,6 +206,9 @@ int iwpm_add_mapping(struct iwpm_sa_data *pm_msg, u8 nl_client) goto add_mapping_error; } ret = iwpm_wait_complete_req(nlmsg_request); + if (!ret) + *pm_msg = nlmsg_request->data.sa; + kref_put(&nlmsg_request->kref, iwpm_free_nlmsg_request); return ret; add_mapping_error: pr_info("%s: %s (client = %u)\n", __func__, err_str, nl_client); @@ -286,7 +290,7 @@ int iwpm_add_and_query_mapping(struct iwpm_sa_data *pm_msg, u8 nl_client) } nlmsg_end(skb, nlh); - nlmsg_request->req_buffer = pm_msg; + nlmsg_request->data.sa = *pm_msg; ret = rdma_nl_unicast_wait(&init_net, skb, iwpm_user_pid); if (ret) { @@ -295,6 +299,9 @@ int iwpm_add_and_query_mapping(struct iwpm_sa_data *pm_msg, u8 nl_client) goto query_mapping_error; } ret = iwpm_wait_complete_req(nlmsg_request); + if (!ret) + *pm_msg = nlmsg_request->data.sa; + kref_put(&nlmsg_request->kref, iwpm_free_nlmsg_request); return ret; query_mapping_error: pr_info("%s: %s (client = %u)\n", __func__, err_str, nl_client); @@ -414,7 +421,7 @@ int iwpm_register_pid_cb(struct sk_buff *skb, struct netlink_callback *cb) kref_put(&nlmsg_request->kref, iwpm_free_nlmsg_request); return -EINVAL; } - pm_msg = nlmsg_request->req_buffer; + pm_msg = &nlmsg_request->data.dev; nl_client = nlmsg_request->nl_client; dev_name = (char *)nla_data(nltb[IWPM_NLA_RREG_IBDEV_NAME]); iwpm_name = (char *)nla_data(nltb[IWPM_NLA_RREG_ULIB_NAME]); @@ -493,7 +500,7 @@ int iwpm_add_mapping_cb(struct sk_buff *skb, struct netlink_callback *cb) kref_put(&nlmsg_request->kref, iwpm_free_nlmsg_request); return -EINVAL; } - pm_msg = nlmsg_request->req_buffer; + pm_msg = &nlmsg_request->data.sa; local_sockaddr = (struct sockaddr_storage *) nla_data(nltb[IWPM_NLA_RMANAGE_ADDR]); mapped_sockaddr = (struct sockaddr_storage *) @@ -577,7 +584,7 @@ int iwpm_add_and_query_mapping_cb(struct sk_buff *skb, kref_put(&nlmsg_request->kref, iwpm_free_nlmsg_request); return -EINVAL; } - pm_msg = nlmsg_request->req_buffer; + pm_msg = &nlmsg_request->data.sa; local_sockaddr = (struct sockaddr_storage *) nla_data(nltb[IWPM_NLA_RQUERY_LOCAL_ADDR]); remote_sockaddr = (struct sockaddr_storage *) diff --git a/drivers/infiniband/core/iwpm_util.c b/drivers/infiniband/core/iwpm_util.c index 2b336e1781b33..c0218e93ab7da 100644 --- a/drivers/infiniband/core/iwpm_util.c +++ b/drivers/infiniband/core/iwpm_util.c @@ -379,7 +379,6 @@ int iwpm_wait_complete_req(struct iwpm_nlmsg_request *nlmsg_request) } else { ret = nlmsg_request->err_code; } - kref_put(&nlmsg_request->kref, iwpm_free_nlmsg_request); return ret; } diff --git a/drivers/infiniband/core/iwpm_util.h b/drivers/infiniband/core/iwpm_util.h index 007d232982c84..860f953f47c55 100644 --- a/drivers/infiniband/core/iwpm_util.h +++ b/drivers/infiniband/core/iwpm_util.h @@ -64,11 +64,14 @@ struct iwpm_nlmsg_request { struct list_head inprocess_list; __u32 nlmsg_seq; - void *req_buffer; u16 nl_op; u8 nl_client; u8 request_done; u16 err_code; + union { + struct iwpm_dev_data dev; + struct iwpm_sa_data sa; + } data; struct semaphore sem; struct kref kref; }; @@ -127,7 +130,9 @@ struct iwpm_nlmsg_request *iwpm_find_nlmsg_request(__u32 echo_seq); * iwpm_wait_complete_req - Block while servicing the netlink request * @nlmsg_request: Netlink message request to service * - * Wakes up, after the request is completed or expired + * Wakes up, after the request is completed or expired. + * The caller keeps its reference, so nlmsg_request->data stays + * readable until the caller drops it. * Returns 0 if the request is complete without error */ int iwpm_wait_complete_req(struct iwpm_nlmsg_request *nlmsg_request);