Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
* [PATCH v6 0/2] RDMA/rxe: fix TOCTOU races in send WQE processing
@ 2026-10-26  0:14 Tristan Madani
  2026-10-26  0:14 ` [PATCH v6 1/2] RDMA/rxe: copy send WQE to kernel buffer before processing Tristan Madani
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Tristan Madani @ 2026-10-26  0:14 UTC (permalink / raw)
  To: linux-rdma; +Cc: jgg, leon, zyjzyj2000, yanjun.zhu, rpearsonhpe

The SoftRoCE driver maps its send work queue into userspace for direct
posting. The kernel reads WQE fields directly from this shared mapping,
which allows a concurrent userspace thread to modify fields between
kernel reads -- classic TOCTOU.

This series copies each send WQE to a kernel-private buffer before
processing, in both the requester (patch 1) and completer (patch 2)
paths.

v6 adds post-copy sanitization of attacker-controlled fields to address
the automated review findings from v4/v5:

  - wr_opcode_mask() OOB: both patches now reject opcodes >
    IB_WR_ATOMIC_WRITE before the array access.

  - num_sge clamp: both patches now clamp dma.num_sge against
    qp->sq.max_sge immediately after copy, before any SGE walk.

  - sge_offset / resid / cur_sge: the requester already had a
    num_sge + cur_sge bounds check after req_next_wqe() (lines
    754-760 of rxe_req.c). With the copy, these fields are now
    frozen, so the existing check is sufficient.

  - FORTIFY_SOURCE: struct rxe_send_wqe ends with a flex array
    (__DECLARE_FLEX_ARRAY in rxe_dma_info), so __builtin_object_size
    returns (size_t)-1 for the memcpy. This is identical to the
    merged receive-path fix (d6ab440240a04) and is a tooling
    limitation, not a bug.

  - Flush/retry/posted-state paths: these write directly to shared
    memory (flush, posted) or invalidate the cache and take a fresh
    copy (retry), identical to pre-patch behavior. Not affected by
    this series.

Changes since v5:
  - Added opcode bounds check after copy in both requester and
    completer to prevent OOB access via wr_opcode_mask().
  - Added num_sge clamp in requester after copy (completer already
    had it in v5).
  - Resent as standalone patchset from the correct sender address.

Changes since v4:
  - Resent from the correct sender address. No code changes vs v4.

Changes since v3:
  - Copy the full queue element (max_sge SGEs) instead of computing a
    per-WQE copy size from num_sge. This ensures inline data (which
    shares the flex array with SGEs) is always captured, and eliminates
    a TOCTOU on the copy size itself.
  - Clamp dma.num_sge against qp->sq.max_sge after copy (patch 2)
    instead of against the global RXE_MAX_SGE constant.
  - Invalidate the cached copy on QP reset (rxe_qp_reset), on the
    ERR flush path, and on the RESET state check in the requester.
    This prevents stale-cache reuse after state transitions.
  - Each patch now also touches rxe_qp.c for the reset invalidation.

Changes since v2:
  - Addressed review comments on naming and ordering.
  - Writeback status using WRITE_ONCE() instead of plain store.
  - Added smp_store_release() in requester for state transitions.

Changes since v1:
  - Split into per-path patches (requester, completer).
  - Cache the local copy across retransmits and multi-packet operations.
  - Added writeback of completion status and rd_atomic state.

Tristan Madani (2):
  RDMA/rxe: copy send WQE to kernel buffer before processing
  RDMA/rxe: copy send WQE to kernel buffer in completer path

 drivers/infiniband/sw/rxe/rxe_comp.c  | 60 +++++++++++++++++++++++++-
 drivers/infiniband/sw/rxe/rxe_qp.c    |  2 +
 drivers/infiniband/sw/rxe/rxe_req.c   | 64 +++++++++++++++++++++++++--
 drivers/infiniband/sw/rxe/rxe_verbs.h | 12 +++++
 4 files changed, 132 insertions(+), 6 deletions(-)

-- 
2.47.3

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

end of thread, other threads:[~2026-10-26 16:15 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-26  0:14 [PATCH v6 0/2] RDMA/rxe: fix TOCTOU races in send WQE processing Tristan Madani
2026-10-26  0:14 ` [PATCH v6 1/2] RDMA/rxe: copy send WQE to kernel buffer before processing Tristan Madani
2026-10-26  1:43   ` sashiko-bot
2026-10-26  0:14 ` [PATCH v6 2/2] RDMA/rxe: copy send WQE to kernel buffer in completer path Tristan Madani
2026-10-26  1:39   ` sashiko-bot
2026-10-26 16:15 ` [PATCH v6 0/2] RDMA/rxe: fix TOCTOU races in send WQE processing Zhu Yanjun

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