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=1796386451; b=rO+KisNEfeKLopAet3w7XgRx6dgTnx1lZCNpODJkfo5E2hrFwSH/P4Z1phKpj+d+RYzA /l2338jl/RLZBePuJGrfUgbSFTC0r129XoGq48CM8ttPczOsST3u0raP8EY/Wjj9h2D+N GXVqn7co/DVI8aGGj369QVeMen3VTALc1PoDWlpjagzwiWmtwwEott9uLbx+uB0RXl02K 1gnIn6oySlU5QSFcOz5RDaM27q9fX4djaaUDDsI+845E5ZAXl6usZoRCFlESNa5woCfmD AyPOT5skdDuMrCNYa3lNVUS83ccobMYi4dsovYbeOE+yyq2L/iv04wQS/NZo94TiswQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796386451; 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=MGE0IgFkvR7w4kRCNs2eH/0pbv33XgbsUzkRs+nFwfs=; b=pGA8/4b8FiIHTq2uRG+BcOCwX+ZjEsKNwlkWOljrG8XdT++VBwqlZLjNYfrIom8D1AIe 2vKmoHM6mEt2fNxe2jP1n1/zlQGuDgrcPCG//4NT7RtvRElvNNCnEuyBjy1WFoEXhkvw/ roVR8FJHdUlIeQs8hxVwGMVLSfAX1xp0EMdoTRxgZFTLMxFerNPvSwoaa3nHd5PHAacbt rCfGS8a9/qW1ThE3FPUmv4iH1plw76+1ctsa4V1ZqXBN6vxBu+BL1PTYoNTcTqhVnE6G/ 9Vx2KiNY71t4Hk6SKmXv/X7gPcbWxQBAfn0ebUpHR35oF8s0P3BZ1loJEHPTH0ZmmRw== 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=ZX9Rt+DR; 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 D2264606A32C; Fri, 4 Dec 2026 12:14:11 +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=ZX9Rt+DR Received: by smtp.kernel.org (Postfix) with ESMTPSA id 169891F000C2; Fri, 4 Dec 2026 12:14:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796386451; bh=MGE0IgFkvR7w4kRCNs2eH/0pbv33XgbsUzkRs+nFwfs=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ZX9Rt+DR42HujEGRRqpNcP7HIifa9qxagT4LaoUaNS/3j4Su5/J/th1zh+A74lgok +RrxjBaCq4xfWyqKzqxiHtJuWDzY2tpMxiJ/t4gKfZB2eissXZIO6aB29qAuEuQ1/3 Me4D3PY1z9Q9rX6HC7/AbGQlPL3P3gej2PZTomLA= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Alexei Starovoitov , Sasha Levin Subject: [PATCH 6.6 0967/1167] bpf: Add the symbol of a prog before its id Date: Fri, 4 Dec 2026 19:06:34 +0900 Message-ID: <20261204100727.380706750@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@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.6-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 cd34ce0faa388..459117e49c187 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -2757,6 +2757,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; @@ -2775,7 +2778,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