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=1796383608; b=dAi0AJfGZiP0ow/6bvMTwEmpm2S1WBBujhQo/l66Eln9djqDjhd3VaCG7xYdwcBKcGTv gZcT5wkhJKVNcSz4Ta+12avT2o2PZRzHFXrTjFC7irz89g9Dup4wAH25NyTvYDiot8h/o DspREzxhJ3gINshylthbTaPTPb023yGssQ/lsP9ovCKlIF6iGWqIT/Tlwgw2MzvttyrSK XyZ9pEqVv2Sq5zRCy5rfxyt6ZEaj3tG42SyRqo9Gm9EFBLL/1wI1Qi03c9d8kC+DDWzf+ 2cOALSZOIK6uGeiPfe4TTNNUpFhukEFWgsd4XI5dl2VW4PB9Kbie42siu/cUtFQQ8tQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796383608; 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=LcrpZN0i2Qr9e7DTmt9lzPGFViQElZYCueiZnUX4OWU=; b=tvQUjLqPMYWO0cy5sTC39R+sC2vOkOkUKgZZxLfFnmTVrNkzsKSYL5rnswSiur9PGM5s Blg9GFEtS+m4feO/jaMRMNmDdZR/g4A6uHLQpnvJ+w7YYa0nIj85ZQ0TuNYtz/vBZb9zv HZGa+W+ZXcPJAiySbrnvycAtC0415nfB6uIzU8QB+r74TPi7R4XhszTeRoyA4xBv8I+ka +nethruJBL7Rs4i+hz6Nx0Otd1V0dqYEG7mh59YHvrQpo69eVhCByC6O9U64hXQf7S3tG 7ozZIvHQFv4mu1p0O7IpqccElS4qOi18sso8rMW9QeBG3Pb4EghW5Gdg2Hw8xtgmgAg== 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="sX71/6ws"; 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 F1E89606A322; Fri, 4 Dec 2026 11:26:47 +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=sX71/6ws Received: by smtp.kernel.org (Postfix) with ESMTPSA id 66AD91F000C2; Fri, 4 Dec 2026 11:26:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796383607; bh=LcrpZN0i2Qr9e7DTmt9lzPGFViQElZYCueiZnUX4OWU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=sX71/6ws+II5GyRb8Kl4j4VOxIK3ws8NxyzCkK2UVa/h9dhjDuE+/WIlYmwAxjjf2 t+/wulffJL6DZCGXpA4jvVRJjf3Qrm/enyQnCVeYG6BVYRLvTvoQWlvLQgxj8dDbfd 8ouWUATGDk1YQpEuwcgniTI4RHLBFtyEezWLra9I= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Alexei Starovoitov , Sasha Levin Subject: [PATCH 6.12 295/555] bpf: Add the symbol of a prog before its id Date: Fri, 4 Dec 2026 19:05:38 +0900 Message-ID: <20261204100620.370644778@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: Alexei Starovoitov [ Upstream commit f7a40c2de8d4abdea6d1e21122b447b593e28bd9 ] A prog can be taken by its id and run before bpf_prog_kallsyms_add(). bpf_throw() does not find the main prog and oopses: KASAN: null-ptr-deref in range [0x0000000000000568-0x000000000000056f] RIP: 0010:bpf_throw+0x129/0x220 The exception table is found by the same symbol. Add the symbol first. bpf_prog_free() removes it when there is no id. Fixes: 3dec541b2e63 ("bpf: Add support for BTF pointers to x86 JIT") Fixes: f18b03fabaa9 ("bpf: Implement BPF exceptions") Signed-off-by: Alexei Starovoitov Link: https://patch.msgid.link/20261125032938.670542-15-alexei.starovoitov@gmail.com Signed-off-by: Sasha Levin --- kernel/bpf/syscall.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 2626189f746ba..6657e4fbd8bb3 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -2854,6 +2854,9 @@ static int bpf_prog_load(union bpf_attr *attr, bpfptr_t uattr, u32 uattr_size) if (err < 0) goto free_used_maps; + /* bpf_throw() and faults look for the symbol. The prog can run once it has the id. */ + bpf_prog_kallsyms_add(prog); + err = bpf_prog_alloc_id(prog); if (err) goto free_used_maps; @@ -2872,7 +2875,6 @@ static int bpf_prog_load(union bpf_attr *attr, bpfptr_t uattr, u32 uattr_size) * Also, any failure handling from this point onwards must * be using bpf_prog_put() given the program is exposed. */ - bpf_prog_kallsyms_add(prog); perf_event_bpf_event(prog, PERF_BPF_EVENT_PROG_LOAD, 0); bpf_audit_prog(prog, BPF_AUDIT_LOAD); -- 2.53.0