From mboxrd@z Thu Jan 1 00:00:00 1970 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=1796383932; b=VAMELbCW9XqH7R9k9awzU1k2UkzVn9DEFlmsCjMK0ftQZ7ombH2x+/o2pKTowNr47sFF YEI20dwjUH5OWFgeJyfWITb5eL7MFA8MsJ+9m0lQusRK7NnZj8gjQHbHgwLo56+FbBo6P leQ5CKWn1IOvXaZ/Jk1Vf/t63Z51SEjWrPtsgYpfEP4BKumwSPtdKTDCLKxKYepdtEjSO 7yfG5A5236WZRy5OXsHbAjyflG1UCXYQmMHUoIhXuDVCxYkbMd0oI7JAY6lPv2D2xTGhW DONu48CuzWQoupI+nhAcYVpw44TkK3or/u1eVAHu8jdGYWiGfQvNDBfYAV5U+fJ+tXw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796383932; 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=DN//VKVleeIL2dTCCJ864LuA6Maiz+2MaAfaZH2g0vQ=; b=VOe4cQEZbwluc0SEbm0ceH7oDrkkW3j13bCCcabkpKeNym7vAxuRJREiNZ5NjESsq0RS PBe+JhPssa8Iv2KwzY37jG73oDoGrtKoqpka6M60l3jFIrpoBBSgALUBflMA6VAd8DZfD V7VKFZmX8jn/OouDBhrSj9NHLF1EpOBVIGe8H3vcW/y1XQWqGmoOegghfMM6q3tMWGMMk NDXl4rbjJLAGbU7O+kSSGrHBJhkNbu1bLsvfYtKAlOZVHtRqQpZY3DmoNqLTsn73VtSD6 kFUw5Yak9QPqK4nqRAqF096xxjeBmMZdc4O0qa7BvRVau/aT4ckXZ46opEwXrtwUjDw== 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=Hivdjvl4; 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 3BA2E606A330; Fri, 4 Dec 2026 11:32:12 +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=Hivdjvl4 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 593581F000CE; Fri, 4 Dec 2026 11:32:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796383931; bh=DN//VKVleeIL2dTCCJ864LuA6Maiz+2MaAfaZH2g0vQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Hivdjvl49f2B3zzqt7QVCDHaTnVS5nq/R/8vHjps5p9IVohkC+br3GHsuwKX18C2w gRaUNdOa0DW1yqwfUwX7CQHIsijwPM/BiyOZB8DSOlZZa4badM84doY5GPCr9C84Tg hfcW2hpmGIx9b0aIms4/tPhcL0CPqAhK5skC/QOA= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Jaeyeong Lee , Jack Wang , Leon Romanovsky Subject: [PATCH 6.12 428/555] RDMA/rtrs: Register client event handler after capability check Date: Fri, 4 Dec 2026 19:07:51 +0900 Message-ID: <20261204100625.966336215@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100603.988357525@linuxfoundation.org> References: <20261204100603.988357525@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jaeyeong Lee commit 90d95fbc1bcc8464f6d8c6891c62bad4c0dc2d58 upstream. rtrs_clt_ib_dev_init() registers dev->event_handler before checking IB_DEVICE_MEM_MGT_EXTENSIONS. If the device does not provide that capability, init returns -ENOTSUPP and rtrs_ib_dev_find_or_add() frees dev through out_free_pd without calling the deinit callback. The embedded event handler therefore remains on the IB device's list after its storage has been freed. A later IB event walks the dangling list entry and accesses freed memory. The issue was found by static analysis. A focused out-of-tree test module on an x86_64 QEMU/KASAN kernel temporarily cleared only IB_DEVICE_MEM_MGT_EXTENSIONS on a SIW device, exercised the real rtrs_clt_ib_dev_init() callback through rtrs_ib_dev_find_or_add(), restored the capabilities, and dispatched IB_EVENT_DEVICE_FATAL. KASAN reported an 8-byte slab-use-after-free read in ib_dispatch_event_clients(), with both the allocation and free originating in rtrs_ib_dev_find_or_add(). Move the capability check before event handler registration. The check is a prerequisite for successful client initialization. Registration cannot fail and init returns success immediately afterwards, so every installed handler is now owned by a successfully initialized device and is removed by the existing deinit callback. Fixes: 667db86bcbe8 ("RDMA/rtrs: Register ib event handler") Cc: stable@vger.kernel.org Signed-off-by: Jaeyeong Lee Link: https://patch.msgid.link/179378222423.73361.3247716499619173751@jaeyeong.cc Acked-by: Jack Wang Signed-off-by: Leon Romanovsky Signed-off-by: Greg Kroah-Hartman --- drivers/infiniband/ulp/rtrs/rtrs-clt.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) --- a/drivers/infiniband/ulp/rtrs/rtrs-clt.c +++ b/drivers/infiniband/ulp/rtrs/rtrs-clt.c @@ -3167,16 +3167,16 @@ void rtrs_clt_ib_event_handler(struct ib static int rtrs_clt_ib_dev_init(struct rtrs_ib_dev *dev) { - INIT_IB_EVENT_HANDLER(&dev->event_handler, dev->ib_dev, - rtrs_clt_ib_event_handler); - ib_register_event_handler(&dev->event_handler); - if (!(dev->ib_dev->attrs.device_cap_flags & IB_DEVICE_MEM_MGT_EXTENSIONS)) { pr_err("Memory registrations not supported.\n"); return -ENOTSUPP; } + INIT_IB_EVENT_HANDLER(&dev->event_handler, dev->ib_dev, + rtrs_clt_ib_event_handler); + ib_register_event_handler(&dev->event_handler); + return 0; }