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=1796381113; b=OybVT4Iz+tT9JsownK2FkTV2STPiNM7S/YD9UFz9RWKDbnIxJDiqmM/A3gR6A3PhOSUq YcwkUtMzarmojAvSESs6T7rvxoom0YEsrelCQlX3ZQ5pcjfTpuqVjnPwmmPGROz/5g+PA Mvh+wwFKAg82HesZ7pnFO8E+fkms7q12i7P5SHhp0paHSvzekzl2xdokt/NH0mlLG6G8b Gonz6C50cMob20tt2s9CIC1jczfObaMLCLyXlMByPTNLb48qDJfMuhoAfLDD+344xngHw GA5mB1ZUmOYd/uuBw4JegNebKrXh91gq88XGPgOdBY31whQdt5lVG3VoF9TG/I5wVHA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381113; 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=oYEm74mk89NEkt9PXnuuAe5VSXCXOfCQQAfd3CoHWb0=; b=T9+BZKnkqEGi2kuJ5Nln0bzEjgfQMGI5QL/j7hqhFuTey+wTd7rt8DXVNOBq6yQo9GH6 x371EQV5UeBzsMrT5SNK/FGHhan0Q686qcWfyGlUJZ/Q5BLVepIWRDqQVGTlX9LP184cr 0kXUMdlnJt0Ui1jj+KVRjoLiwZuZSBI1FrRSICmdJC2jxRIVBT+/ac3cgdbyU9exKgC5h r+lb1evTZtWD+NX6rKvdlCHNNXhVVAWK2nLREywy9Kmo8z46HwheB/b12tkHXZMukeDZ+ PtdYNZY9NzDlResmfUyuAr8ASEK+EcQ/HZLO3wvWGvRyqXTXhmywkfoA/yBf8DlbAmA== 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=m8IeuFT2; 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 55111606A33C; Fri, 4 Dec 2026 10:45:13 +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=m8IeuFT2 Received: by smtp.kernel.org (Postfix) with ESMTPSA id BF0971F00933; Fri, 4 Dec 2026 10:45:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796381113; bh=oYEm74mk89NEkt9PXnuuAe5VSXCXOfCQQAfd3CoHWb0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=m8IeuFT2yvakIec1t77P1kjxe66GhCm5+GNstZWjiKHYXVHIAS28TOMOwFD5Kuy8H IpxCd6lGaVYwwPhFCC4ULjQNRlMtPC1dpJUJZHnzNnBGYqmGiG2hZznEdDYyhdcjdL +jDmTjgaSuENWG6iSnv/Z4+BmAbHHaLFmBoTlzB0= 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 7.3 563/742] RDMA/rtrs: Register client event handler after capability check Date: Fri, 4 Dec 2026 19:07:07 +0900 Message-ID: <20261204100650.102633973@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@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: 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 @@ -3186,16 +3186,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; }