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=1796329583; b=WQm3dgC6a4crG//8VEGKFjA/vzjay/iHrWmapN5MplNE12ukaZdUVk4BmqVXqLFtseRc NpJw4O54/2IYn/0UpHB9RxZP5V4WIU8pD8+sY/i+3anydl4TF+I1ToF+QBw+aptvOX3Ol Qkj7UOo1VLeiCB9JK+YRXzRP8OfjFMuFwTrAJpXZtDHXB9lfPw0ZS2UevqjCcbZs7NQLS 6cU0UNpC12qdPsD4JdIB7qCD+OylI0K16v6nc7IXRJUOcdMUx/EntlJ76Ln/CzEc/cG8S dD5cg2U31p32KiYf8T7PXFDP86xj6w3yIRqwvNwHXqsPRdk5sGXsD4vKL0mvMMv1HKA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796329583; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=ADu8sZ65Ay13NeH+O4r73YiJJ3sVl8fEw5RMdlyyscE=; b=BN3Ie0PTYX3l3wyI1whj3uoaOERzu8zdV21g0HiTonR1Yr0tiKAoo8xR/fNWE2HG2myq Qj5RU5T2Ot0j9k4rB+Pek3iJ3KxC+VzMz3Hmu6WLysex63Q0ft5VFkiuQolCJxSVWdImf 6KR8S0PJ6+WPOow6f2fvPaEfEvmxQYTqmKo+rIM8lYdYiNUOd4Ispd9Bwcn2XDFcKoTgn nDqI+vcTNlWJ2i6R4i1GXD1rjgEU+EJFrLm2MhcdU6TQn5sTpqkaaighAS0IKa/HYKt1m B8JTGYc4VfhhnY148dZjvxl76YxPnuygLJ+aDi7GsgmwE5/rCTJPKVxDPL00MAEZZUg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="ohVr/zQB"; 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 C3501606A683; Thu, 3 Dec 2026 20:26:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ohVr/zQB Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2652D1F000C2; Thu, 3 Dec 2026 20:26:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796329583; bh=ADu8sZ65Ay13NeH+O4r73YiJJ3sVl8fEw5RMdlyyscE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ohVr/zQBPh4wNRp6y7fciKc8ER2eCXWnKy9M5fX1b0WcJb6yKLs+6tNYolPZdSn1r gU8gtW4zuOzAR9ievVJyz+lNm8mrzc4hGjEbU9jgFTjdx88tppKkkpR1WMtrZiFOD9 Lfrwqu2K2f2gpHTo58GC1pRUo6l491WAazF5/z6mQ/E62uhOc5rgXa53IQ/VdedqGw a7ujkMD/VoB6/nVF1QYTmAnlhzA3ztD7Lx1J+2Y6QfGEBCXZ+Ybq2HIjn3q+ilyl7h 6ehv7hdJgXrBanLk2uQSYWSNURLm3JRxMsg8+xnsSjxd63/r8XjpE6TfP+EaseIoEP K0XTpjxubUuGw== From: Chris Mason To: bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, jolsa@kernel.org, song@kernel.org Cc: eddyz87@gmail.com, memxor@gmail.com, martin.lau@linux.dev, yonghong.song@linux.dev, emil@etsalapatis.com, ihor.solodrai@linux.dev, rostedt@goodmis.org, mhiramat@kernel.org, mathieu.desnoyers@efficios.com, mjambigi@linux.ibm.com, petr.pavlu@suse.com, linux-trace-kernel@vger.kernel.org, linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org, mason@kernel.org Subject: [PATCH bpf 1/2] bpf: Reject raw tracepoint links on coming modules Date: Thu, 3 Dec 2026 15:26:16 -0500 Message-ID: <20261203202617.31741-2-mason@kernel.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261203202617.31741-1-mason@kernel.org> References: <20261203202617.31741-1-mason@kernel.org> X-Mailing-List: linux-kernel@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 bpf_raw_tp_link_release() hits a use-after-free on link->btp if the tracepoint's module fails to load after the link was created. link->btp points into the module's data, and the link holds a module reference to keep it valid. But a failed load frees the module without checking refcnt, and try_module_get() in bpf_get_raw_tracepoint_module() succeeds for a module in MODULE_STATE_COMING: module load raw tracepoint link =========== =================== prepare_coming_module() bpf_event_notify() list_add() bpf_raw_tp_link_attach() bpf_get_raw_tracepoint() try_module_get() link->btp = btp do_init_module() mod->init() fails free_module() bpf_raw_tp_link_release() bpf_probe_unregister() btp->tp /* use after free */ The fix used here is to pin a module only once it is live, as btf_try_get_module() does. Fixes: a38d1107f937 ("bpf: support raw tracepoints in modules") Signed-off-by: Chris Mason --- kernel/trace/bpf_trace.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index 19e6b51bb2f00..7ad178c3d04db 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -65,7 +65,9 @@ static struct bpf_raw_event_map *bpf_get_raw_tracepoint_module(const char *name) for (i = 0; i < btm->module->num_bpf_raw_events; ++i) { btp = &btm->module->bpf_raw_events[i]; if (!strcmp(btp->tp->name, name)) { - if (try_module_get(btm->module)) + /* A failed load frees the module despite references */ + if (btm->module->state == MODULE_STATE_LIVE && + try_module_get(btm->module)) ret = btp; goto out; } -- 2.55.0