Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795020458; b=nWS9OtuhwRX6ELu8EspEQkwj6bhhlGp4jt7CfYoT05b4e7iLEFF/Eu6G6Gw9E+6xSHWw DbGSmpZm1Z9/DU+xepyeVuefctM7USW+PXawbpMwuZf/S/WsCEUvAsUOLJpSijCJOWNdp +MoZtRVtQYHCdsmAnnTXaaJVcWZ9AZuA/bK1aO1XOUweS1oaIFRQVUWjrf976ZECbGS0g sQu3PBZ5CcBrFzkOQ+/EEWgynlChucXJ0VH6GTG7ELiUpOJEyLk6lVMwuaglXStg9LObl YYPfMJx6WVGRbO76x0jpuZSXHljO1hz70yBEFwXfXMgCk+AeHmU9coPnIUsfQmuZInw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795020458; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=hq9Bfpomm8Hnqp48PoXjInlTnpZz0a5m2RJvvY2p4Rg=; b=wZqYzrlKyZKJPAfkQ1Rc9qnT4SRTv0PulbVBl9rR8S1oj3XBWc/huzz8JbPR79tobvBC zXiE4X7Ms5ei1NFMwmXa/rNQzyK+uZ66Ri74MRiZ4pZDkhUYHtFoL6Jzmce9HWmo1+5eg aCvcFsjBF5rzmtMVzgktZIQnYBb13gMP/ZaS2hUtkZysDYXnjpAL/OnYOESjv2EcEe1gm Yd8fuUHOBhMInDzdjOEGSauIQYu/Gg5H3eYQ8mX06s+W++bps22/LRD8wgPSVYPReoDJ1 it4whOeIO3rLdwqGFuvW2pCm1Ihi7Agwp+YrO2N/i4EO5YErvP6PgPL5LhAS/UfLOag== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b="PoZ2tfd/"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A3109606A31C; Wed, 18 Nov 2026 16:47:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=PoZ2tfd/ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 089FB1F000C4; Wed, 18 Nov 2026 16:47:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795020458; bh=hq9Bfpomm8Hnqp48PoXjInlTnpZz0a5m2RJvvY2p4Rg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=PoZ2tfd/2lfMbUM98DcaRpl0bSC4ULvBZGestZB1sthN5FLfXU28u5beMA+SBbqrW A8eo5Fb5tVIAccZYfXwjZG3pecH/R3/YpxnL+FKAv6QihUE+ioZjvlGlPkGG56EIOR lqJF1MvMlk3omfa1Pv59IS47SVmg/xTWggrYPQLA= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Youngsung Ahn , Leon Romanovsky , Sasha Levin Subject: [PATCH 7.3 1958/2651] RDMA/rxe: refuse to destroy a QP with type 2 MWs still bound Date: Wed, 18 Nov 2026 15:53:18 +0100 Message-ID: <20261118150357.028262370@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150247.972732815@linuxfoundation.org> References: <20261118150247.972732815@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Youngsung Ahn [ Upstream commit 9e61a2ac6590e9c42d2eeef687749781334b300f ] Binding a type 2 memory window takes a reference on the QP: rxe_do_bind_mw() does rxe_get(qp) and stores it in mw->qp. That reference is released only when the window is invalidated (rxe_do_invalidate_mw() on IB_WR_LOCAL_INV) or the window itself is destroyed (rxe_mw_cleanup()). rxe_qp_chk_destroy() does not account for those references -- it only refuses when qp->mcg_num is non-zero. So an unprivileged user can bind a type 2 MW to a QP and then destroy the QP while the binding is still live. __rxe_cleanup() cannot drop the QP refcount to zero (the MW still holds a reference), hits its -ETIMEDOUT path, and frees the QP anyway; mw->qp is left dangling. When the MW is later invalidated or deallocated, rxe_mw_cleanup()/rxe_do_invalidate_mw() do rxe_put(mw->qp) on the freed struct rxe_qp -- a use-after-free write (refcount_dec, and complete()/list work if it reaches zero) reachable from userspace. IB_WR_BIND_MW is a local operation, so no peer is required. Track the number of type 2 MWs bound to a QP and refuse to destroy the QP while that count is non-zero, returning -EBUSY exactly as the existing multicast-attachment check does. The window must be invalidated or deallocated, which drops the reference and the count, before the QP can be destroyed. Fixes: 8700e3e7c485 ("Soft RoCE driver") Signed-off-by: Youngsung Ahn Link: https://patch.msgid.link/20260930182223.2511145-1-ays511.kr@gmail.com Signed-off-by: Leon Romanovsky Signed-off-by: Sasha Levin --- drivers/infiniband/sw/rxe/rxe_mw.c | 3 +++ drivers/infiniband/sw/rxe/rxe_qp.c | 10 ++++++++++ drivers/infiniband/sw/rxe/rxe_verbs.h | 1 + 3 files changed, 14 insertions(+) diff --git a/drivers/infiniband/sw/rxe/rxe_mw.c b/drivers/infiniband/sw/rxe/rxe_mw.c index bddb7a2578313..a2e3a6ce09463 100644 --- a/drivers/infiniband/sw/rxe/rxe_mw.c +++ b/drivers/infiniband/sw/rxe/rxe_mw.c @@ -161,6 +161,7 @@ static void rxe_do_bind_mw(struct rxe_qp *qp, struct rxe_send_wqe *wqe, if (mw->ibmw.type == IB_MW_TYPE_2) { rxe_get(qp); + atomic_inc(&qp->mw_bind_num); mw->qp = qp; } } @@ -245,6 +246,7 @@ static void rxe_do_invalidate_mw(struct rxe_mw *mw) /* valid type 2 MW will always have a QP pointer */ qp = mw->qp; mw->qp = NULL; + atomic_dec(&qp->mw_bind_num); rxe_put(qp); /* valid type 2 MW will always have an MR pointer */ @@ -332,6 +334,7 @@ void rxe_mw_cleanup(struct rxe_pool_elem *elem) struct rxe_qp *qp = mw->qp; mw->qp = NULL; + atomic_dec(&qp->mw_bind_num); rxe_put(qp); } diff --git a/drivers/infiniband/sw/rxe/rxe_qp.c b/drivers/infiniband/sw/rxe/rxe_qp.c index 311f285d78a6b..fea55bc3b0cb9 100644 --- a/drivers/infiniband/sw/rxe/rxe_qp.c +++ b/drivers/infiniband/sw/rxe/rxe_qp.c @@ -858,6 +858,16 @@ int rxe_qp_chk_destroy(struct rxe_qp *qp) return -EBUSY; } + /* An attempt to destroy a QP while it still holds references for + * bound type 2 memory windows will fail immediately. Otherwise the + * QP is freed with those references outstanding and the windows are + * left pointing at freed memory (use-after-free). + */ + if (atomic_read(&qp->mw_bind_num)) { + rxe_dbg_qp(qp, "Attempt to destroy while type 2 MWs are bound\n"); + return -EBUSY; + } + return 0; } diff --git a/drivers/infiniband/sw/rxe/rxe_verbs.h b/drivers/infiniband/sw/rxe/rxe_verbs.h index 0f5ffd94643f9..80df376e61eea 100644 --- a/drivers/infiniband/sw/rxe/rxe_verbs.h +++ b/drivers/infiniband/sw/rxe/rxe_verbs.h @@ -261,6 +261,7 @@ struct rxe_qp { struct rxe_av alt_av; atomic_t mcg_num; + atomic_t mw_bind_num; struct sk_buff_head req_pkts; struct sk_buff_head resp_pkts; -- 2.53.0