From: sashiko-bot@kernel.org
To: "Daniel Wade" <danjwade95@gmail.com>
Cc: linux-rdma@vger.kernel.org
Subject: Re: [PATCH v2 3/3] RDMA/iwpm: keep the port-mapper request data inside the request
Date: Sun, 06 Dec 2026 07:10:45 +0000 [thread overview]
Message-ID: <sashiko-outbox-252235@kernel.org> (raw)
In-Reply-To: <20261206065723.147-4-danjwade95@gmail.com>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] RDMA/iwpm: data race on nlmsg_request->data.sa during
post-wait copy-out
- [Medium] RDMA/iwpm: nlmsg_request published before nlmsg_request->data
is initialized
- [Low] RDMA/iwpm: whole-struct copy reads uninitialized stack fields
from pm_msg
--
commit 5384e5afb7f8b54dc9f77b2c25ecb5a44fd3f7e4
Author: Daniel Wade <danjwade95@gmail.com>
RDMA/iwpm: keep the port-mapper request data inside the request
This commit embeds the port-mapper request data inside
struct iwpm_nlmsg_request instead of storing a pointer to the caller's
stack buffer in req_buffer, and moves the caller's kref_put() out of
iwpm_wait_complete_req() so the response can be copied back before the
request is freed.
> 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;
[Severity: Medium]
Can an early netlink reply race with this initialization of
nlmsg_request->data?
CPU0 CPU1
iwpm_register_pid()
iwpm_get_nlmsg_request()
list_add_tail(..., &iwpm_nlmsg_req_list)
iwpm_register_pid_cb()
iwpm_find_nlmsg_request()
strcmp(pm_msg->dev_name, dev_name)
<-- reads all-zero dev_name
nlmsg_request->data.dev = *pm_msg
iwpm_get_nlmsg_request() publishes the zero-allocated request on
iwpm_nlmsg_req_list before the caller populates nlmsg_request->data.
A privileged netlink reply with the next sequence number can match an
empty dev_name and register iwpm_user_pid without verifying the device.
The same window exists in iwpm_add_mapping() and
iwpm_add_and_query_mapping(), where a concurrent callback's write to
mapped_loc_addr can be overwritten by nlmsg_request->data.sa = *pm_msg.
Populating nlmsg_request->data before inserting the request onto
iwpm_nlmsg_req_list would close this window.
[ ... ]
> @@ -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;
[Severity: Low]
Does this whole-struct assignment copy uninitialized stack bytes from
pm_msg into nlmsg_request->data.sa?
iw_cm_map() leaves mapped_loc_addr and mapped_rem_addr uninitialized in
its stack pm_msg. Assigning *pm_msg here and in
iwpm_add_and_query_mapping() clobbers the zeroed heap fields with
uninitialized stack bytes.
Any completion path that skips writing those fields will then propagate
uninitialized stack memory instead of zeroes, and iwpm_add_mapping()
always copies the unwritten mapped_rem_addr back out.
Copying only the input fields in and output fields out, or
zero-initializing pm_msg in iw_cm_map(), would avoid this.
> @@ -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;
[Severity: Medium]
Can a second netlink reply race with this copy of nlmsg_request->data.sa?
CPU0 CPU1
iwpm_add_mapping()
iwpm_wait_complete_req()
... iwpm_add_mapping_cb() [reply 1]
memcpy(&pm_msg->mapped_loc_addr, ...)
up(&nlmsg_request->sem)
kref_put() /* kref 2 -> 1 */
*pm_msg = nlmsg_request->data.sa iwpm_add_mapping_cb() [reply 2]
<-- data race / torn read iwpm_find_nlmsg_request()
memcpy(&pm_msg->mapped_loc_addr, ...)
kref_put() /* unlinks here */
nlmsg_request is only unlinked from iwpm_nlmsg_req_list inside
iwpm_free_nlmsg_request() when kref reaches zero, and
iwpm_find_nlmsg_request() neither unlinks it nor checks request_done.
Because rdma_nl_rcv_msg() takes a shared read lock on
rdma_nl_types[index].sem, a second privileged reply on another netlink
socket can find the request and overwrite data.sa (or err_code) while
this function or iwpm_add_and_query_mapping() copies it out.
This causes a data race and can produce torn mapped_loc_addr or
mapped_rem_addr values. Unlinking or claiming the request under
iwpm_nlmsg_req_lock on the first reply or timeout would give the caller
exclusive access during copy-out.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261206065723.147-1-danjwade95@gmail.com?part=3
next prev parent reply other threads:[~2026-12-06 7:10 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-06 6:57 [PATCH v2 0/3] RDMA/iwpm: fix the port-mapper request lifetime Daniel Wade
2026-12-06 6:57 ` [PATCH v2 1/3] RDMA/iwpm: fix use-after-free of the netlink request object Daniel Wade
2026-12-06 6:57 ` [PATCH v2 2/3] RDMA/iwpm: reject a port-mapper reply meant for another request type Daniel Wade
2026-12-06 6:57 ` [PATCH v2 3/3] RDMA/iwpm: keep the port-mapper request data inside the request Daniel Wade
2026-12-06 7:10 ` sashiko-bot [this message]
2026-12-06 7:12 ` [PATCH v2 0/3] RDMA/iwpm: fix the port-mapper request lifetime sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-252235@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=danjwade95@gmail.com \
--cc=linux-rdma@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.