Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Daniel Wade" <danjwade95@gmail.com>
Cc: linux-rdma@vger.kernel.org
Subject: Re: [PATCH 1/2] RDMA/iwpm: fix use-after-free of the netlink request object
Date: Sat, 05 Dec 2026 14:55:30 +0000	[thread overview]
Message-ID: <sashiko-outbox-251664@kernel.org> (raw)
In-Reply-To: <20261205144111.8366-1-danjwade95@gmail.com>

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 <danjwade95@gmail.com>

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/core/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 == echo_seq) {
> -			found_request = nlmsg_request;
> -			kref_get(&nlmsg_request->kref);
> +			if (kref_get_unless_zero(&nlmsg_request->kref))
> +				found_request = 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 lets
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 overwrites
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 the
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.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261205144111.8366-1-danjwade95@gmail.com?part=1

      parent reply	other threads:[~2026-12-05 14:55 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-05 14:41 [PATCH 1/2] RDMA/iwpm: fix use-after-free of the netlink request object Daniel Wade
2026-12-05 14:41 ` [PATCH 2/2] RDMA/iwpm: reject a port-mapper reply meant for another request type Daniel Wade
2026-12-05 14:55   ` sashiko-bot
2026-12-05 14:55 ` sashiko-bot [this message]

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-251664@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox