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 847B12D0C94; Sat, 12 Sep 2026 19:39:18 +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=1789241959; cv=none; b=F9wIR81hb8JUCdJVcCmIZXdDSmhbYL/GZrMJtj9/g3oRT15u0zlnzU1cNjU+cZ4hp4E1RJEUYEX00NVP99ByXUa4RwwIraB1goKTKpmnEB+Pe+h3su5WF/3S+8GDuJac271VGVuhDHzujDgu7DSC/ZWt2g/LWP5xJd9UBGXVjMg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789241959; c=relaxed/simple; bh=c4KOf2FauJA4sPlX3yY9nwnc5O38IbegU2wxyGG4Yts=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cOF0tKYWpG231CHMUpSlBxbvQSm6w6EsUuhLejnlK6UH4zZ4jpg2IQHntW9yDG1WNHjL2SE0CW0PiQMFTCosMOmjRe5Gxx96w/5WHyUpHIBaJ+N5r9wGCBgn7iXzEK5xcc8J97zlzQTPeCYDamVpx/ZQ8c+8d2tAkVXpqsrkHAc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=RZTzxBiM; 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="RZTzxBiM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C92E11F000FF; Sat, 12 Sep 2026 19:39:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789241958; bh=1+/LZPI4dSHAliJKroke5vbJGApqJSKwGe9M9639eGc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=RZTzxBiMOomVR5mDd9YNWvlHwnA6WC3SYCgWM3NdczkfFssbddfTT0mjz71ZcBrWn 9RHFiqXNtwSDVg3UAYEb/7PxjFnibwZtyQFXFHSxj2WY4+7XzxMIlH98dxnjRkjZJU 39RMYWaS75nAharUjACNMrwxyQLiYjmCMZ4vi69w= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Tristan Madani , Zhu Yanjun , Jason Gunthorpe , Bjoern Doebel , Sasha Levin Subject: [PATCH 5.10 200/798] RDMA/rxe: Fix TOCTOU heap overflow in get_srq_wqe Date: Sat, 12 Sep 2026 08:57:08 +0200 Message-ID: <20260912065521.664646716@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260912065516.948645775@linuxfoundation.org> References: <20260912065516.948645775@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 5.10-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 [doebel: cherry-picked from v6.1.178 (3cfa2a3adc51), accomodate for context changes] Signed-off-by: Bjoern Doebel 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 55b5146424e61..d22d95f5e2e3c 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; + unsigned int num_sge; size_t size; if (srq->error) @@ -306,12 +307,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_bh(&srq->rq.consumer_lock); 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); + 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