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=1796382093; b=ELWrd9/YKoicaN0uyP4emx0Ci7vWW3X9JnAbUvwNa+IQKrixUckA/yzB/6sw4NJ952BF XTx9MwXy1w97tncMzkVvvIvBtlERIRS3hUdMsCLECCmw/HNk0q1KN7w2qDnOzACruvita sc+nmMKeghGLvjQiO3T9AirU/rk0V2nUpiY1TLlSmE59IQHdrcIjjcZhn4MlWu32oErnf 7BAGJlU8wQc3QZ3nmdJEZx268DxXU0A3OkQ5Ejj7oQoKTAiIZmmqguIjV1H9N5+dQRbHq l3B6nWGo8L7FiCZsPxFf25brzjQKcRlaNUtltvqtdFCdHmS1UqqdYmeGL4uKkFm5MNQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382093; 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=HqPD7eDu0rVGLobf0uYCFJy8R7hjiPaFMYybQiWO6fU=; b=bHEk73uU4cZo9C9+R0pFTEIGQdRbJXKveFKlU/VOSOoOeKLf1+/EnZpw6OFk2h3QyHIA FLulQQlpquJz7rz624L4TbiiSPtFwHS6BQWcCzHItLCnuc8a0BC+HBOw//jAugGi5nXt7 XGzqrOd7ckr6H+o007FIW9ujhYCaTXStmK7w16Mk6Gk9I8DNnO/Pi6rR5gRgAOmghM2Xs KKaxXGWDdxML5UOSy7Zuu7nTzaL1EYmv5fMGSKsK3D7fkFNVJHVk37JLOeaqfXOCJu+nq aKHAkeZhMfaBB6EwB0Yzj/z3gKBt1TQM/Ihll2VjdctrsSiH0Dp/YAGAFQ5l0P1KT2w== 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=biNGbO6f; 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 5FE46606A322; Fri, 4 Dec 2026 11:01:33 +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=biNGbO6f Received: by smtp.kernel.org (Postfix) with ESMTPSA id 854161F000CE; Fri, 4 Dec 2026 11:01:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796382092; bh=HqPD7eDu0rVGLobf0uYCFJy8R7hjiPaFMYybQiWO6fU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=biNGbO6fRf7SkcW1/E1EuPWqRsP8Suv8CEuUw0rCaf65/BTKz27nMrIkCWRhlnMei HGSNYURZ+Y43FvTsM0Dq896XwYZ1GoIoWLB5BA1lbSOQg+jsuwZQQoI0rAy+lj8FS8 Iq+Ey0fe7Vb/TlA8isD+vfD84vnLqNO9afcN08Dw= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Alexei Starovoitov , Sasha Levin Subject: [PATCH 6.18 304/703] bpf: Add the symbol of a prog before its id Date: Fri, 4 Dec 2026 19:03:23 +0900 Message-ID: <20261204100635.863843179@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@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 6.18-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 a076c1bc41ac3..c4059cd3027ce 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -3094,6 +3094,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; @@ -3112,7 +3115,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