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=1795055546; b=q7iIL0o1xwqAP11RtITu7wO3yHjCrpvnqGZyYJfWc9nSWkE70BLMfgolBz478/5gC9hX 5qw+C8L1xv3e8EAxr2c5u092tJ2Jn0UVQNfYEbOFTBssgKxr2JlHVHQE66n/600cqj5W3 BNqA+OeDeowy+nDhBzsItASmSrfX27L1l3XlLgWdqUwA/bcg6ilo+UPhX0J1GQUYEuATL eymi9KcIZR2ZOw/0gew8ArX2XCSB7jklCQtG7z+44lNX4qum5X/5BzmSCi7tWufz3VBFt aeLcd0MPIuDRZ+ZmzBLfmI3lubIV9JfVp0OrUyU2+jARj3R3maTwrA7YzqhHbY793cg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795055546; 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=YyIrtUmLQpnhmzhojsaqcdyXXDmH2qDZEKidxPBLfUA=; b=Ncc8K6eSc/v8nO2yGHDQRgzq7tCgJ1F3ZiblJl0RnQGaHb/kAOfFkc0/Bj57OILQNLpG wF6lhOR6H5uAY5A+mB2Jvl4G4WusAkWexi2t93zXHsSid3+YLYfEbYKifY7vJs9A1IBXY sRzZJE1h2e849nrb9defulxIfO66OOGVDc+cr91f1khjx1PnZpVDId4UoG2k7gsioGTJL 7eAmNoZ+Z2b2snD3+etSdOEDR/IP4+AjZDLkLlfPKuIMueJ2uxeTXH+6jwH9R56lpu5li e94yn+gy6hnKOgB/pE7k5OvEvHaLS8b7/CHDuIE0V2J9uCyRgW8ay/n+CUr7tC46JCA== 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=IiZMbUL3; 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 45142606A333; Thu, 19 Nov 2026 02:32:26 +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=IiZMbUL3 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9D9931F000C4; Thu, 19 Nov 2026 02:32:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795055546; bh=YyIrtUmLQpnhmzhojsaqcdyXXDmH2qDZEKidxPBLfUA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=IiZMbUL37gcHMw28ofjYvTSRSfRQ5OqBvS5W1654KAy1oHDRn0lH8+YiUOOH6upId 99TR5Jn0RNxlQqsb1H7DTAf6eRkYtr6qxZ5RFNVIypznH0ka1loe5gVRrG3wFRzFjP 3SX4ZyPWNqmESg+Wk6H9KVcAmObRFwUOxr+Evz14= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Dairui Zhang , Leon Romanovsky , Sasha Levin Subject: [PATCH 5.15 1669/2214] IB/mad: fix UAF and double-free in RMPP receive reassembly Date: Wed, 18 Nov 2026 15:55:45 +0100 Message-ID: <20261118150118.613377552@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150009.797899913@linuxfoundation.org> References: <20261118150009.797899913@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 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Dairui Zhang [ Upstream commit 90e9b6357bec75f627cde1a85b5887215c80aad8 ] mad_rmpp_recv.state is protected by two locks that do not exclude each other: recv_timeout_handler() (port workqueue) uses agent->lock, continue_rmpp() (CQ softirq) uses rmpp_recv->lock. Nothing serializes the check-then-set sequence on the state word: T1 (CQ softirq) T2 (port workqueue) continue_rmpp() lock(rmpp_recv->lock) state == ACTIVE [passes] recv_timeout_handler() lock(agent->lock) state = TIMEOUT list_del(&rmpp_recv->list) unlock(agent->lock) destroy_rmpp_recv() wait_for_completion() [blocks on T1's ref] state = COMPLETE unlock(rmpp_recv->lock) complete_rmpp() queue cleanup_work (+10s) deref() [unblocks] kfree(rmpp_recv) ib_free_recv_mad(done_wc) +10s: recv_cleanup_handler() runs lock/list_del/destroy on the freed rmpp_recv -> UAF write and double free; nothing can cancel that cleanup_work anymore, the entry is already off agent->rmpp_list. done_wc is also returned to ib_mad_complete_recv() and freed again -> UAF read and double free. Reaching this requires sending MADs to a kernel RMPP agent from the InfiniBand/RoCE fabric: the per-port sa_query agent accepts subnet manager responses whose SLID/GID/TID are not authenticated on the fabric, and legacy user_mad agents registered without IB_USER_MAD_USER_RMPP start reassembly on any incoming RMPP DATA MAD with an attacker-chosen TID, no in-flight send required. The attacker controls segment timing and can run many transactions in parallel (agent->rmpp_list has no cap), so landing the microseconds-wide receive critical section on the 40-second timeout boundary is a matter of patience, not luck. Unify state transitions under rmpp_recv->lock in recv_timeout_handler(), keeping list manipulation under agent->lock (which preserves the agent->lock -> rmpp_recv->lock ordering used by continue_rmpp()). State check/set in both paths is then serialized, so the loser of the race always observes the final state and bails out. recv_cleanup_handler() needs no change: with transitions serialized, a cleanup_work can only be pending after COMPLETE, in which case the timeout handler exits early. The race is as old as the RMPP implementation itself. Fixes: fa619a77046b ("[PATCH] IB: Add RMPP implementation") Assisted-by: LLM Signed-off-by: Dairui Zhang Link: https://patch.msgid.link/20260922152342.1474845-1-zhangdairui@gmail.com Signed-off-by: Leon Romanovsky Signed-off-by: Sasha Levin --- drivers/infiniband/core/mad_rmpp.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/infiniband/core/mad_rmpp.c b/drivers/infiniband/core/mad_rmpp.c index 8af0619a39cda..2bdebd011dac5 100644 --- a/drivers/infiniband/core/mad_rmpp.c +++ b/drivers/infiniband/core/mad_rmpp.c @@ -245,12 +245,15 @@ static void recv_timeout_handler(struct work_struct *work) struct ib_mad_recv_wc *rmpp_wc; unsigned long flags; - spin_lock_irqsave(&rmpp_recv->agent->lock, flags); + spin_lock_irqsave(&rmpp_recv->lock, flags); if (rmpp_recv->state != RMPP_STATE_ACTIVE) { - spin_unlock_irqrestore(&rmpp_recv->agent->lock, flags); + spin_unlock_irqrestore(&rmpp_recv->lock, flags); return; } rmpp_recv->state = RMPP_STATE_TIMEOUT; + spin_unlock_irqrestore(&rmpp_recv->lock, flags); + + spin_lock_irqsave(&rmpp_recv->agent->lock, flags); list_del(&rmpp_recv->list); spin_unlock_irqrestore(&rmpp_recv->agent->lock, flags); -- 2.53.0