From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 88AB846A607; Tue, 21 Jul 2026 15:48:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784648924; cv=none; b=Ukm5Ec6HcRIgVOaTpeVQQUlCqHnvaqSp5iyGS6OEoqWnrWh8iHW9rNiAmgIOmWqbXZIwuLDIQOWL1yVZZvNjMkcX74F01Z5jBQfv2fqHHmu3XXXHwJ6mM6h1+UMduuLvlT2o1K+IG4XMl9d3+Ya3h5wsUfniEwFZ/flO76bUHSE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784648924; c=relaxed/simple; bh=jIqkPFDv9SlZsV5XDxufCdgemd7ReQ2b00lFals17O0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DkChu04kk81vMoq39vYEBJHTz9gZ8qud9/i+xpJRMhlh9Du8nvXF/QvkFsmlLdmwW2VLDQccW6M4bjBmXB9QWXesgBEj2OhShgyERTKzOCE/7sqn2/kN7KUfZEYolSpzp/AwtGUjK286tm6tfnO6GGJnS20yWDuI/SC3Aq+DEHE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=p6pfYACU; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="p6pfYACU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B1ABC1F000E9; Tue, 21 Jul 2026 15:48:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784648923; bh=DOAe0oxiPv2Acio3msmcjMmvxBxiqY2XdiHHDTDJ3AA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=p6pfYACU4r6jiAdfY9t4dKf4WvOZaOGAV2Kk8OHZv3Xsb5PWR51vDP5InxBo6FgP6 f8niPyApHY0izqSpB0lhTrQo+bXdiOUNIJg1LpMa0liy+845Psit6uSa/uChsN65hW s9m/4O/pTPFYF58FADDuOhv97J+gRtSkSgGrobJc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Tristan Madani , Zhu Yanjun , Jason Gunthorpe , Sasha Levin Subject: [PATCH 7.1 0383/2077] RDMA/rxe: Fix TOCTOU heap overflow in get_srq_wqe Date: Tue, 21 Jul 2026 17:00:56 +0200 Message-ID: <20260721152601.730714075@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260721152552.646164743@linuxfoundation.org> References: <20260721152552.646164743@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Tristan Madani [ Upstream commit 22b8fbded65b8c441b634a185f8da67657df6c50 ] 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: 8700e3e7c485 ("Soft RoCE driver") Link: https://patch.msgid.link/r/20260518215040.1598586-2-tristan@talencesecurity.com Signed-off-by: Tristan Madani Reviewed-by: Zhu Yanjun Signed-off-by: Jason Gunthorpe Signed-off-by: Sasha Levin --- drivers/infiniband/sw/rxe/rxe_resp.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/infiniband/sw/rxe/rxe_resp.c b/drivers/infiniband/sw/rxe/rxe_resp.c index 9cb2f6fbf2dd6a..8a0a9739636014 100644 --- a/drivers/infiniband/sw/rxe/rxe_resp.c +++ b/drivers/infiniband/sw/rxe/rxe_resp.c @@ -264,6 +264,7 @@ static enum resp_states get_srq_wqe(struct rxe_qp *qp) struct rxe_recv_wqe *wqe; struct ib_event ev; unsigned int count; + unsigned int num_sge; size_t size; unsigned long flags; @@ -279,12 +280,13 @@ static enum resp_states get_srq_wqe(struct rxe_qp *qp) } /* don't trust user space data */ - if (unlikely(wqe->dma.num_sge > srq->rq.max_sge)) { + num_sge = wqe->dma.num_sge; + if (unlikely(num_sge > srq->rq.max_sge)) { spin_unlock_irqrestore(&srq->rq.consumer_lock, flags); rxe_dbg_qp(qp, "invalid num_sge in SRQ entry\n"); return RESPST_ERR_MALFORMED_WQE; } - size = sizeof(*wqe) + wqe->dma.num_sge*sizeof(struct rxe_sge); + size = sizeof(*wqe) + num_sge * sizeof(struct rxe_sge); memcpy(&qp->resp.srq_wqe, wqe, size); qp->resp.wqe = &qp->resp.srq_wqe.wqe; -- 2.53.0