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=1796389148; b=sTbLUHBmgXfG8xh3bMCXIdUXQw0HPwQhQwQLAOLmTIivKyFkmR9m5WO1NKDqedRtOkWx K+ZvmoFDl5K35ezoDD0saQloIhfXUPs6QNoYorMYXFw4yY67kXMb6dQDt3wzMcZpvwGCk Si4+iwmORm102/QPlX8ckaFErXLJQQCVCYDht74MyZC3bevtTGG2y9f4bqh/oQADTU0am 7KxCfYzMovnWD4OR/vfox/bgIoyzry3l0nU62s5lV2Q3HHtTWMXBlO9KbX2RkYG7xctzg lozjQICFbfa24OUpfsIRaG4GOjsAU7JCs9cs6WReqgvE55FqG+LvLkyv4gElBxguEsA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796389148; 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=SfcNr3H1rUmImLBhaCU8cdWE2f1s8bqVy65rBwhlc6M=; b=K63pm60xEeLSVh69caRyjX/AmdbcTLg95W+16M6+LsihJILKpVdh9M90nBUTVJjEwIyx m66LPi+PBciYxZeZw6RD5RkhjJjnYBvuBBfK0p1vmDvVV+00u4zJ94fXrD28f+l6sdK9c i2ky54KrGvqYxUeq+G0m8CO0P0OlmGCbU8oe/VTo8NkIB0T5FHRP56I9c4Z0kznk82SBA 7Jww7QLhjcvI9UWxR6YTeSxgFgsVfXtU7E4CpnbACZW/kg4uAfeq4WiMxo7S69tNBZZQK kjpxLpK71e8hi+fKz8ceCo+wT7Nu438C6OTut1Gst2fzdm/mTeCeFRIXrPFHQ++8Tfg== 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=rMLPqfqw; 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 650DC606A32C; Fri, 4 Dec 2026 12:59:08 +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=rMLPqfqw Received: by smtp.kernel.org (Postfix) with ESMTPSA id AF4DD1F000C2; Fri, 4 Dec 2026 12:59:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796389148; bh=SfcNr3H1rUmImLBhaCU8cdWE2f1s8bqVy65rBwhlc6M=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=rMLPqfqwsJi6s7zxxNyqPLTW7eKWj2iDHkftNzL5dtMjgKooOnexCB7xcNE//1Qrs HOJUNVfbSqJnRNgAT+LQEfuoWAQgZ6z52FTSaDPTrzp5/1DWc9t0XVYIoe3Gzu1rhG Mvj8mM/QQWGUjOuI0Bj074dutrg1SFmbY3crJ2bg= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Alexei Starovoitov , Sasha Levin Subject: [PATCH 6.1 0881/1059] bpf: Add the symbol of a prog before its id Date: Fri, 4 Dec 2026 19:06:52 +0900 Message-ID: <20261204100706.833563842@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@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.1-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 2aa15b0aa0c0e..4d1a3523105ef 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -2657,6 +2657,9 @@ static int bpf_prog_load(union bpf_attr *attr, bpfptr_t uattr) 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; @@ -2675,7 +2678,6 @@ static int bpf_prog_load(union bpf_attr *attr, bpfptr_t uattr) * 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