mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Stellman <astellman@stellman-greene.com>
To: Zhu Yanjun <zyjzyj2000@gmail.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>, Leon Romanovsky <leon@kernel.org>,
	linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH rdma-next] RDMA/rxe: Fix NULL dereference when invalidating an unbound MW
Date: Thu, 19 Nov 2026 10:13:27 -0500	[thread overview]
Message-ID: <20261119151327.95446-1-astellman@stellman-greene.com> (raw)

A type 2 memory window has no QP or MR attached while it is in
RXE_MW_STATE_FREE, which is its state after it is allocated and again
after it is invalidated. rxe_check_invalidate_mw() rejects
RXE_MW_STATE_INVALID but not RXE_MW_STATE_FREE, so invalidating a FREE
window reaches rxe_do_invalidate_mw(), which dereferences the NULL
mw->qp and mw->mr.

An IB_WR_LOCAL_INV for the rkey of a type 2 MW that was never bound
panics the kernel. So does a second IB_WR_LOCAL_INV for the same rkey
after a bind and an invalidate, and a received SEND with Invalidate
naming a never-bound window's rkey.

The first case, run by an unprivileged user under KASAN:

  BUG: KASAN: null-ptr-deref in rxe_invalidate_mw+0x156/0x310
  Write of size 4 at addr 00000000000003b4 by task kworker/u8:1/30
  Workqueue: rxe_wq do_work
  Call Trace:
   rxe_invalidate_mw+0x156/0x310
   rxe_requester+0x20d4/0x5640
   rxe_sender+0xe/0x30
   do_work+0x144/0x470
  Kernel panic - not syncing: Fatal exception in interrupt

Only invalidate a window in RXE_MW_STATE_VALID. rxe_invalidate_mw()
now returns -EINVAL for a FREE window, as it does for a type 1 window.

The issue was found by Claude Opus 5.5 running Quality Playbook, an
LLM-driven code review tool:
https://github.com/andrewstellman/quality-playbook
The fix and this changelog were drafted with the same tool and reviewed
by me.

Fixes: 3902b429ca14 ("RDMA/rxe: Implement invalidate MW operations")
Signed-off-by: Andrew Stellman <astellman@stellman-greene.com>
---

Tested in QEMU with KASAN on v7.4-rc3, and on v7.4-rc3 with the RDMA
code from rdma for-next (7404c82cbf12). The reproducers are short
libibverbs programs; I can send them off-list.

 drivers/infiniband/sw/rxe/rxe_mw.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/infiniband/sw/rxe/rxe_mw.c b/drivers/infiniband/sw/rxe/rxe_mw.c
index a2e3a6ce0946..82a20a96a351 100644
--- a/drivers/infiniband/sw/rxe/rxe_mw.c
+++ b/drivers/infiniband/sw/rxe/rxe_mw.c
@@ -228,7 +228,7 @@ int rxe_bind_mw(struct rxe_qp *qp, struct rxe_send_wqe *wqe)
 
 static int rxe_check_invalidate_mw(struct rxe_qp *qp, struct rxe_mw *mw)
 {
-	if (unlikely(mw->state == RXE_MW_STATE_INVALID))
+	if (unlikely(mw->state != RXE_MW_STATE_VALID))
 		return -EINVAL;
 
 	/* o10-37.2.26 */

base-commit: 7404c82cbf1246e0e84e2ec21834d23c26f9a8ed
-- 
2.43.0


             reply	other threads:[~2026-11-19 15:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 15:13 Andrew Stellman [this message]
2026-11-22 15:09 ` 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=20261119151327.95446-1-astellman@stellman-greene.com \
    --to=astellman@stellman-greene.com \
    --cc=jgg@ziepe.ca \
    --cc=leon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=zyjzyj2000@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

all inboxes | Powered by JetHome®