From: Bjoern Doebel <doebel@amazon.de>
To: <stable@vger.kernel.org>
Cc: <gregkh@linuxfoundation.org>, <sashal@kernel.org>,
<linux-rdma@vger.kernel.org>,
Tristan Madani <tristan@talencesecurity.com>,
Bob Pearson <rpearsonhpe@gmail.com>,
Dan Carpenter <dan.carpenter@linaro.org>,
Jason Gunthorpe <jgg@nvidia.com>,
Zhu Yanjun <yanjun.zhu@linux.dev>, <doebel@amazon.de>
Subject: [PATCH 5.10.y 1/4] RDMA/rxe: Fix over copying in get_srq_wqe
Date: Thu, 3 Sep 2026 20:08:48 +0000 [thread overview]
Message-ID: <20260903200851.566276-2-doebel@amazon.de> (raw)
In-Reply-To: <20260903200851.566276-1-doebel@amazon.de>
From: Bob Pearson <rpearsonhpe@gmail.com>
[ Upstream commit ec0fa2445c18ec49a0b7ee0aaa82d1ec00968fc9 ]
Currently get_srq_wqe() in rxe_resp.c copies the maximum possible number
of bytes from the wqe into the QPs copy of the SRQ wqe. This is usually
extra work and risks reading past the end of the SRQ circular buffer if
the SRQ is configured with less than the maximum possible number of SGEs.
Check the number of SGEs is not too large.
Compute the actual number of bytes in the WR and copy only those.
Fixes: 8700e3e7c485 ("Soft RoCE driver")
Link: https://lore.kernel.org/r/20210618045742.204195-5-rpearsonhpe@gmail.com
Signed-off-by: Bob Pearson <rpearsonhpe@gmail.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
[doebel: context adjustment from upstream patch to 5.10. needed as a prerequisite
for "RDMA/rxe: Fix TOCTOU heap overflow in get_srq_wqe" ]
Signed-off-by: Bjoern Doebel <doebel@amazon.de>
---
drivers/infiniband/sw/rxe/rxe_resp.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/drivers/infiniband/sw/rxe/rxe_resp.c b/drivers/infiniband/sw/rxe/rxe_resp.c
index 83c03212099a2..38e6535196849 100644
--- a/drivers/infiniband/sw/rxe/rxe_resp.c
+++ b/drivers/infiniband/sw/rxe/rxe_resp.c
@@ -292,6 +292,7 @@ static enum resp_states get_srq_wqe(struct rxe_qp *qp)
struct rxe_queue *q = srq->rq.queue;
struct rxe_recv_wqe *wqe;
struct ib_event ev;
+ size_t size;
if (srq->error)
return RESPST_ERR_RNR;
@@ -304,8 +305,13 @@ static enum resp_states get_srq_wqe(struct rxe_qp *qp)
return RESPST_ERR_RNR;
}
- /* note kernel and user space recv wqes have same size */
- memcpy(&qp->resp.srq_wqe, wqe, sizeof(qp->resp.srq_wqe));
+ /* don't trust user space data */
+ if (unlikely(wqe->dma.num_sge > srq->rq.max_sge)) {
+ pr_warn("%s: invalid num_sge in SRQ entry\n", __func__);
+ return RESPST_ERR_MALFORMED_WQE;
+ }
+ size = sizeof(wqe) + wqe->dma.num_sge*sizeof(struct rxe_sge);
+ memcpy(&qp->resp.srq_wqe, wqe, size);
qp->resp.wqe = &qp->resp.srq_wqe.wqe;
advance_consumer(q);
--
2.50.1
next prev parent reply other threads:[~2026-09-03 20:09 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-03 20:08 [PATCH 5.10.y 0/4] RDMA/rxe: Fix TOCTOU heap overflow in get_srq_wqe Bjoern Doebel
2026-09-03 20:08 ` Bjoern Doebel [this message]
2026-09-03 20:08 ` [PATCH 5.10.y 2/4] RDMA/rxe: Missing unlock on error in get_srq_wqe() Bjoern Doebel
2026-09-03 20:08 ` [PATCH 5.10.y 3/4] RDMA/rxe: Use the correct size of wqe when processing SRQ Bjoern Doebel
2026-09-03 20:08 ` [PATCH 5.10.y 4/4] RDMA/rxe: Fix TOCTOU heap overflow in get_srq_wqe Bjoern Doebel
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=20260903200851.566276-2-doebel@amazon.de \
--to=doebel@amazon.de \
--cc=dan.carpenter@linaro.org \
--cc=gregkh@linuxfoundation.org \
--cc=jgg@nvidia.com \
--cc=linux-rdma@vger.kernel.org \
--cc=rpearsonhpe@gmail.com \
--cc=sashal@kernel.org \
--cc=stable@vger.kernel.org \
--cc=tristan@talencesecurity.com \
--cc=yanjun.zhu@linux.dev \
/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