Skip to content

Commit 3cfa2a3

Browse files
Tristan Madanigregkh
authored andcommitted
RDMA/rxe: Fix TOCTOU heap overflow in get_srq_wqe
[ Upstream commit 22b8fbd ] get_srq_wqe() reads wqe->dma.num_sge from the shared receive queue buffer, which is mapped into userspace. It validates num_sge against max_sge, but then re-reads the same field to calculate the memcpy size. A concurrent userspace thread can modify num_sge between validation and use, causing a heap buffer overflow when copying the WQE into qp->resp.srq_wqe. Read num_sge into a local variable and use it for both the bounds check and the size calculation. Fixes: 8700e3e ("Soft RoCE driver") Link: https://patch.msgid.link/r/20260518215040.1598586-2-tristan@talencesecurity.com Signed-off-by: Tristan Madani <tristan@talencesecurity.com> Reviewed-by: Zhu Yanjun <yanjun.zhu@linux.dev> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent b401454 commit 3cfa2a3

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

drivers/infiniband/sw/rxe/rxe_resp.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ static enum resp_states get_srq_wqe(struct rxe_qp *qp)
300300
struct rxe_recv_wqe *wqe;
301301
struct ib_event ev;
302302
unsigned int count;
303+
unsigned int num_sge;
303304
size_t size;
304305
unsigned long flags;
305306

@@ -315,12 +316,13 @@ static enum resp_states get_srq_wqe(struct rxe_qp *qp)
315316
}
316317

317318
/* don't trust user space data */
318-
if (unlikely(wqe->dma.num_sge > srq->rq.max_sge)) {
319+
num_sge = wqe->dma.num_sge;
320+
if (unlikely(num_sge > srq->rq.max_sge)) {
319321
spin_unlock_irqrestore(&srq->rq.consumer_lock, flags);
320322
pr_warn("%s: invalid num_sge in SRQ entry\n", __func__);
321323
return RESPST_ERR_MALFORMED_WQE;
322324
}
323-
size = sizeof(*wqe) + wqe->dma.num_sge*sizeof(struct rxe_sge);
325+
size = sizeof(*wqe) + num_sge * sizeof(struct rxe_sge);
324326
memcpy(&qp->resp.srq_wqe, wqe, size);
325327

326328
qp->resp.wqe = &qp->resp.srq_wqe.wqe;

0 commit comments

Comments
 (0)