The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH rdma-next 0/8] RDMA/core: Fix restrack UAF in destroy flows
@ 2026-07-01 12:28 Edward Srouji
  2026-07-01 12:28 ` [PATCH rdma-next 1/8] RDMA/core: Add rdma_restrack_begin/abort/commit_del() operations Edward Srouji
                   ` (7 more replies)
  0 siblings, 8 replies; 10+ messages in thread
From: Edward Srouji @ 2026-07-01 12:28 UTC (permalink / raw)
  To: Jason Gunthorpe, Leon Romanovsky, Dennis Dalessandro,
	Gal Pressman, Steve Wise, Mark Bloch, Neta Ostrovsky, Mark Zhang,
	Mark Zhang, Majd Dibbiny, Yishai Hadas
  Cc: linux-rdma, linux-kernel, Edward Srouji, Patrisious Haddad,
	Michael Guralnik

The resource-tracking (restrack) database is the back-end for the netlink
"rdma resource show" interface which pins objects with
rdma_restrack_get().

QP/CQ/SRQ/PD/DMAH/counter destroy paths currently call
rdma_restrack_del() at the very end of ib_destroy_*_user() (or its
equivalent), i.e. after device->ops.destroy_*() has already freed the
vendor object. A concurrent netlink dump can therefore look the entry
up, take a reference via rdma_restrack_get(), and then dereference
already freed memory - most visibly through ib_query_qp() during
fill_res_qp_entry_query(), which produced the crash logged in patch 2.

Fix this by splitting the delete into a begin/commit/abort sequence:
begin_del() parks the entry as XA_ZERO_ENTRY (so lookups return NULL),
drops the birth reference and waits for in-flight readers to drain,
while keeping the index reserved. The destroy paths run begin_del()
first, then commit_del() on success or abort_del() on error.
abort_del() re-inserts into the reserved slot, so it needs no allocation
and cannot fail.

An earlier submission [1] carried the two preparatory cleanups that
removed broken restrack tracking for DCT and raw-packet RSS QPs (whose
IDs are never actually installed in the xarray) and those have been
picked up.  This series is a standalone resend of the remaining fixes,
rebased on top of rdma-next and reworked according to Jason's feedback.

There is a small race between rdma_restrack_begin_del() and
rdma_restrack_add() for a new QP with the same ID, whereas if
rdma_restrack_begin() was called, then the provider destroys that QP,
and recreates a new one with the same ID and calls rdma_restrack_add()
before rdma_restrack_commit_del() can be called, the addition of the new
QP to restrack would fail, the new QP creation would succeed but it
simply wont be tracked.
This wasn't fixed as the race-window is really small and the worst case
scenario is an untracked QP and fixing that would needlessly clutter the
code.

[1] https://lore.kernel.org/linux-rdma/20260607-restrack-uaf-fix-v1-0-d72e45eb76c2@nvidia.com/

Signed-off-by: Edward Srouji <edwards@nvidia.com>
---
Patrisious Haddad (8):
      RDMA/core: Add rdma_restrack_begin/abort/commit_del() operations
      RDMA/core: Fix use after free in ib_query_qp()
      RDMA/core: Fix potential use after free in ib_destroy_cq_user()
      RDMA/core: Fix potential use after free in ib_destroy_srq_user()
      RDMA/core: Fix potential use after free in counter_release()
      RDMA/core: Fix potential use after free in ib_free_cq()
      RDMA/core: Fix potential use after free in uverbs_free_dmah()
      RDMA/core: Fix potential use after free in ib_dealloc_pd_user()

 drivers/infiniband/core/counters.c              |   5 +-
 drivers/infiniband/core/cq.c                    |   2 +-
 drivers/infiniband/core/restrack.c              | 167 +++++++++++++++++++-----
 drivers/infiniband/core/restrack.h              |   3 +
 drivers/infiniband/core/uverbs_std_types_dmah.c |   7 +-
 drivers/infiniband/core/verbs.c                 |  28 +++-
 6 files changed, 167 insertions(+), 45 deletions(-)
---
base-commit: dc59e4fea9d83f03bad6bddf3fa2e52491777482
change-id: 20260701-restrack-uaf-fix-resub-6f434ec5844c

Best regards,
-- 
Edward Srouji <edwards@nvidia.com>


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2026-07-02 17:46 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-01 12:28 [PATCH rdma-next 0/8] RDMA/core: Fix restrack UAF in destroy flows Edward Srouji
2026-07-01 12:28 ` [PATCH rdma-next 1/8] RDMA/core: Add rdma_restrack_begin/abort/commit_del() operations Edward Srouji
2026-07-02 17:46   ` Jason Gunthorpe
2026-07-01 12:28 ` [PATCH rdma-next 2/8] RDMA/core: Fix use after free in ib_query_qp() Edward Srouji
2026-07-01 12:28 ` [PATCH rdma-next 3/8] RDMA/core: Fix potential use after free in ib_destroy_cq_user() Edward Srouji
2026-07-01 12:28 ` [PATCH rdma-next 4/8] RDMA/core: Fix potential use after free in ib_destroy_srq_user() Edward Srouji
2026-07-01 12:28 ` [PATCH rdma-next 5/8] RDMA/core: Fix potential use after free in counter_release() Edward Srouji
2026-07-01 12:28 ` [PATCH rdma-next 6/8] RDMA/core: Fix potential use after free in ib_free_cq() Edward Srouji
2026-07-01 12:28 ` [PATCH rdma-next 7/8] RDMA/core: Fix potential use after free in uverbs_free_dmah() Edward Srouji
2026-07-01 12:28 ` [PATCH rdma-next 8/8] RDMA/core: Fix potential use after free in ib_dealloc_pd_user() Edward Srouji

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox