mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jaeyeong Lee <lee@jaeyeong.cc>
To: Leon Romanovsky <leon@kernel.org>, Jason Gunthorpe <jgg@ziepe.ca>
Cc: Artemy Kovalyov <artemyko@mellanox.com>,
	Yishai Hadas <yishaih@mellanox.com>,
	linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: [PATCH v2] RDMA/mlx5: Preserve DEVX objects after failed output copy
Date: Sun, 22 Nov 2026 10:37:21 +0000	[thread overview]
Message-ID: <20261122103715.51731-1-lee@jaeyeong.cc> (raw)
In-Reply-To: <20261115135123.GD42525@unreal>

A DEVX create can successfully create and publish a hardware object
before uverbs_copy_to() returns an error. The error path currently
destroys the object directly and frees struct devx_obj without checking
whether destruction succeeded.

This is unsafe for DCTs. mlx5_core_destroy_dct() returns immediately if
the DRAIN_DCT command fails, leaving core_dct in qp_table.dct_xa. A later
DCT_DRAINED event retrieves the stale entry and completes the embedded
completion after devx_obj was freed.

The failure was reproduced by forcing DRAIN_DCT to fail and then
delivering a DCT_DRAINED event:

  BUG: KASAN: slab-use-after-free in complete+0x1a7/0x1b0
  Write of size 4 at addr ffff88800b112ca8 by task insmod/77
  Call Trace:
   complete+0x1a7/0x1b0
   rsc_event_notifier+0x1fc/0x410
   init_module+0x454/0xff0 [mlx5_dct_repro]

Initialize the object ID and indirect mkey bookkeeping before marking
the uobject as holding a valid hardware object. Mark it valid immediately
before copying the output. On a copy failure, the uverbs abort path now
invokes devx_obj_cleanup(). If destruction fails,
rdma_alloc_abort_uobject() commits the uobject, keeping its wrapper alive
for another cleanup attempt at file close.

Keep the direct unwind path for indirect mkey setup failures because
those occur before the uobject is marked valid. This avoids running
generic cleanup against partially initialized mkey bookkeeping.

The issue was found by NSCV static analysis.

Fixes: c5ae1954c47d3 ("IB/mlx5: Use mlx5 core to create/destroy a DEVX DCT")
Cc: stable@vger.kernel.org
Signed-off-by: Finder16 <nakamurajames123@gmail.com>
Signed-off-by: Jaeyeong Lee <lee@jaeyeong.cc>
---
Changes in v2:
- Include the KASAN reproducer trace and describe the failed DCT destroy
  path.
- Initialize obj_id and indirect mkey state before finalizing the uobject.
- Keep the direct unwind path for failures before uobject finalization.

 drivers/infiniband/hw/mlx5/devx.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/infiniband/hw/mlx5/devx.c b/drivers/infiniband/hw/mlx5/devx.c
index 5ba783bc7f9b7..fd41104fe42fe 100644
--- a/drivers/infiniband/hw/mlx5/devx.c
+++ b/drivers/infiniband/hw/mlx5/devx.c
@@ -1614,10 +1614,6 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_DEVX_OBJ_CREATE)(
 				   &obj_id);
 	WARN_ON(obj->dinlen > MLX5_MAX_DESTROY_INBOX_SIZE_DW * sizeof(u32));
 
-	err = uverbs_copy_to(attrs, MLX5_IB_ATTR_DEVX_OBJ_CREATE_CMD_OUT, cmd_out, cmd_out_len);
-	if (err)
-		goto obj_destroy;
-
 	if (opcode == MLX5_CMD_OP_CREATE_GENERAL_OBJECT)
 		obj_type = MLX5_GET(general_obj_in_cmd_hdr, cmd_in, obj_type);
 	obj->obj_id = get_enc_obj_id(opcode | obj_type << 16, obj_id);
@@ -1627,6 +1623,14 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_DEVX_OBJ_CREATE)(
 		if (err)
 			goto obj_destroy;
 	}
+
+	uverbs_finalize_uobj_create(attrs,
+				    MLX5_IB_ATTR_DEVX_OBJ_CREATE_HANDLE);
+	err = uverbs_copy_to(attrs, MLX5_IB_ATTR_DEVX_OBJ_CREATE_CMD_OUT,
+			     cmd_out, cmd_out_len);
+	if (err)
+		return err;
+
 	return 0;
 
 obj_destroy:

base-commit: 7404c82cbf1246e0e84e2ec21834d23c26f9a8ed
-- 
2.43.0



  reply	other threads:[~2026-11-22 10:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-11 10:53 [PATCH] RDMA/mlx5: Fix UAF after DEVX DCT create failure Jaeyeong Lee
2026-11-15 13:51 ` Leon Romanovsky
2026-11-22 10:37   ` Jaeyeong Lee [this message]
2026-11-22 10:39     ` [PATCH v2] RDMA/mlx5: Preserve DEVX objects after failed output copy Jaeyeong Lee

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=20261122103715.51731-1-lee@jaeyeong.cc \
    --to=lee@jaeyeong.cc \
    --cc=artemyko@mellanox.com \
    --cc=jgg@ziepe.ca \
    --cc=leon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=yishaih@mellanox.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®