Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Leon Romanovsky <leon@kernel.org>
To: Dairui Zhang <zhangdairui@gmail.com>
Cc: security@kernel.org, jgg@ziepe.ca, w@1wt.eu, stable@vger.kernel.org
Subject: Re: [PATCH] IB/mad: fix UAF and double-free in RMPP receive reassembly
Date: Tue, 22 Sep 2026 16:06:22 +0300	[thread overview]
Message-ID: <20260922130622.GH563127@unreal> (raw)
In-Reply-To: <20260922114719.1465335-1-zhangdairui@gmail.com>

On Tue, Sep 22, 2026 at 07:47:19PM +0800, Dairui Zhang wrote:
> mad_rmpp_recv.state is protected by two locks that do not exclude
> each other: recv_timeout_handler() (port workqueue) checks and sets
> RMPP_STATE_TIMEOUT under agent->lock, while continue_rmpp() (CQ
> softirq) checks and sets RMPP_STATE_COMPLETE under rmpp_recv->lock.
> Nothing serializes the check-then-set sequence.
> 
> If continue_rmpp() passes its state check while the timeout handler
> sets TIMEOUT and waits for the in-flight reference in
> destroy_rmpp_recv(), continue_rmpp() then sets COMPLETE and queues
> cleanup_work, after which the timeout handler frees rmpp_recv and
> the rmpp_wc. Ten seconds later recv_cleanup_handler() runs
> spin_lock/list_del/destroy on the freed rmpp_recv (UAF write,
> double free), and the already-freed done_wc is returned to
> ib_mad_complete_recv() and freed again (UAF read, double free).

Please ask from your AI tool to change this to be function ladder
instead of prose.

> 
> This is remotely triggerable: kernel RMPP reassembly serves the
> per-port sa_query agent (malicious or spoofed subnet manager;
> hi_tid routing is predictable and SLID/GID is spoofable on RoCE)

This requires being part of a trusted InfiniBand network segment, which
should not be the case in any real-world scenario.

> and user_mad agents registered via the legacy REG_AGENT ABI, where
> a remote RMPP DATA MAD on the request path starts reassembly with
> an attacker-chosen TID and no in-flight send required. On RoCE this
> is plain UDP/4791 with no authentication.
> 
> Unify state transitions under rmpp_recv->lock in
> recv_timeout_handler(), keeping list manipulation under agent->lock
> (which preserves the agent->lock -> rmpp_recv->lock ordering used
> by continue_rmpp()). State check/set in both paths is then
> serialized, so the loser of the race always observes the final
> state and bails out. recv_cleanup_handler() needs no change: with
> transitions serialized, a cleanup_work can only be pending after
> COMPLETE, in which case the timeout handler exits early.
> 
> The race is as old as the RMPP implementation itself.
> 
> Fixes: fa619a77046b ("[PATCH] IB: Add RMPP implementation")
> Cc: stable@vger.kernel.org
> Assisted-by: LLM
> Signed-off-by: Dairui Zhang <zhangdairui@gmail.com>
> ---
>  drivers/infiniband/core/mad_rmpp.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)

Please clean up the commit message and send the patch to the linux-rdma
mailing list. We apply patches submitted there and do not accept any
non-public code.

Thanks

  reply	other threads:[~2026-09-22 13:06 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20260921193238.1420558-1-zhangdairui@gmail.com>
2026-09-22 11:47 ` [PATCH] IB/mad: fix UAF and double-free in RMPP receive reassembly Dairui Zhang
2026-09-22 13:06   ` Leon Romanovsky [this message]
2026-09-22 15:23 Dairui Zhang
2026-09-29 13:29 ` Leon Romanovsky

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=20260922130622.GH563127@unreal \
    --to=leon@kernel.org \
    --cc=jgg@ziepe.ca \
    --cc=security@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=w@1wt.eu \
    --cc=zhangdairui@gmail.com \
    /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