From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.48 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796540274; b=P6HlGxpNHoTe2a/emNc/fZx22Bl3C2w5VAGPz9aCRQwmsja5TkTGAZWP+Jep6sUWAvEh GMygIZK07TEBylmXDMOuPnWrbQUSGTg5eGwQYnRTeYvkguzDZZaZ+UzWcHhMxU+JbxoH0 gx1Oe6ZkHzDvtGC9V5PlMUlOMq7l0ct1iDveJPSpNUSxTFhKumEd/15ExpwrCTeY7x1ip Jf6Poob46nGftaB1dRD6ju7njgdptD5iji+ulgCV6eL+J6OIlk8hV6Xfhfp0pSAdp4Rj1 FZpfYbFOwwwHOmq9PH8xGE/9EiCaIdNZDYWLaXrq3OU3sWct12X7TQxDiDBylcuXKyQ== 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=z87iOD8PIlZsqMsgCvNRka9A+qQffELXQaUvigeHl5dRWiAwr1uGdUDJdYWyoUG32X1Q CkdmzENrDY4aTzQiLyCX8x/bzcQvoZ6/OafjuDrMtKY5+ZVeb2mw/p5T/J6OZbkQMLmHJ J9fmWaDr29JaU/7y4Nul8cuyE5vjVWB2gJbKa2cQBwuX+2DQ5kLuPdGtv6Y7bm2iTR2ov TG67bAqppP90/uRRsCW+vdhMy+Ll8/H4WgqD0pRYLD6CfkMfU27oI0RZTdraBVw4rXe+B VXD8Y/5t8s/PU3k2GBg1hlXBINmeoEUW5CT9SGV2hvhSfJmAcwBYf+yk2vRUKJAr/YA== 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.48 Received: from mail-dl1-f48.google.com (mail-dl1-f48.google.com [74.125.82.48]) (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 9DA68606A684 for ; Sun, 6 Dec 2026 06:57:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9DA68606A684 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-f48.google.com with SMTP id a92af1059eb24-1b546061d58so5323699c88.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=OTYg/10Lbs5ohjYW7HOugqsi0lL7rF0WGkOtsT8YpuYGxn6o4gAR+bbfF7wB3k5gtY Q8wHjQR2ybv9701yCbizU6eD0kLodQ0H9mtw/4CDaIJDyDE73ckRt/ihxpZ0SpteXwaU QLx84BFNWAolNVJ48FSge2L0CgbSg7SOgH5jYoBO1oA5xvqs7e1RaL7238SpvOOlkJ67 +kBxqjuJjCTIbzlRxsH+Tpq3A3XokE/MmaCnGRcbEURnE+macB+ZwWIvCjG8AHoXkDNW DlRWTOnCEJARalQQbCraSWGaw+KABm0yTmnh46FpMQ0Q4QSaMk12BOp1R4T1bHIqyBBy ZGgw== X-Forwarded-Encrypted: i=1; AL+hErET4RqaXiV4+UgKypTx/7Kxtz0Lkry40De3f39cEhtGjTBOQX54Sr91mOGgxcXhu14J7gE8/Sz/joG4@vger.kernel.org X-Gm-Message-State: APuU4Z8++Rl6DU/r4UR2EkyvYb2hVBM+k+jyVLf6Ef6FXzUrFGrfvhym 2MER46vFg2F9ybDJjMMVQtHH7oySbZSyBjQy/GLU9MLoxBYZBp4orXdu X-Gm-Gg: AZFdTZdLtSIY12GryTu7P7U/Tjyx1Go9q3IRglaKY0FY6DhGqUgOttlD/ToSIwuzHOe oGi725hl39/GYw2n3Cuwy67kulAfvsppNjgpa1zFEkx2RT+QHvB2DogQrSV3lofFtAlnAwJO5S7 WW4EYzC7YGnuhF8XlrhSgpfkpi/bdl+lQTzJAX9Skj3Ou4BkkBnhrR7ZymMHZKKHfbVBkmMDjgd Am8AMG/iM7AUtKhL18Yx/QEB6sfBKZO/GNV59nyRjmiI0WrEhoNL50r1XYYOO+yrwqY+EwSZvxw 9pUFPEGIdfcIKTdzI9IM+nZUNUZlOaLaACVk94ZBc+GLb3k4d8OcwglweVPNoEVsyjAYqYlEPwh usw+6hirxtGQlneVJ+GHDXX+4Fbs/mvVqgdCp3WxGesIE3YTUaFddf6NWZZJuyB+up7Tkcz04bL 96olV91d39K4WO0cw0XL3dlscn3BVqjSzbM39gh+c9x0pg2omTtVriYeLLMf/JFEYw4V1uwok+F ON6M+AjhW4aUvhrdSSqGfNQV8znY0h4os8wbiXajMUaxyZw7fG1PnZpY+vdneoOt4JHU396SBhn +mPkb9SgpvqCFTcMl04GCPh7uFfWMtEAdGIkvu68mqT5I5VdV4BeOvEIVh5nD8W2i51VcBoZfYq gIWMd0hpXLfvhHF6heNoajY5X8UT+TyEeQgOypx3M5b+208kUgrEyCTHUgwy5Lx7viZaRydbtDe 52kz52NhSFsmSMRKKGQ8yqlG7mbORLDB+6KMkRp8rMpJqQiUhlSXwCfyQKvtZNSUDNmMc0hPJdJ BOx7hyFVzSMFdhevjrGVwZ7T4grLfof5iZ8iGLoNEy+GGiOZKhLIgn8Qdpbol0AyaZR5d4oQM1N 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-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 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);