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=1796380447; b=N2fSFKBUGnO/wv247U8pihK/BJH2YqFPZDDLs/qKfsExo9cZDhNu26PJFR6hIOdzhA5N idGNwE1aNhHI1mCFklrol0tvj32y3vt0s/0Xkc5B+14+NGZMwtYxxchFGcE89cwMv0aS0 7v1eyE/RGJ3wiwOTxmj6DIIeTq7IJMe9dX/hAVNcmxGZcDezkBCpIeq2xVaa+39LMkXVY wU3locEUDCNMUITmqfpc3ovBlobnQ3QojfVjqOTuULHZjCDO91rvM5rp2ODXCnTXbkToy tvzRt2a/L98F85+FkoQS11Ut7knfFXoBlX6A2tHlJUhkwEcmOpvsc22w/OQtx6Awurw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380447; 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=uzBPVuXqXZPd35MabIGUEAr061Ja5YVtlIzc8rGWvaQ=; b=YlGx7uQ/dzWN5S+3+48eWMPuxKOxS2+IltJBFIGWGky/oMgbmUEOFj8P9LgN0Fr9WcMc KQCdrOKfePauN4P49nJ59NN08yd5SQBgqw4zVTGM0l5pMrRWrpvoYNbTN5ny1T76ud3vZ 3N8JDkHuI+KpVA8ghxLlvkiaIhQAHkONBLlAax7HtAM/hQ2jd/VPUMnxyFrDrlmIepLMs 4Td1T60kC0vYsk8Js/KNTH64vMVFgIVx2rCBaKkXxInWeFbYx7zkgxnVcw5ThbR1GS6al TlCrz88sazcTEil3hBlO8MbpRf02dcXHaLqyVFQ/AiSyN38abvABltsD946796/j8cw== 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=YKoehMgM; 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 71978606A32D; Fri, 4 Dec 2026 10:34:07 +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=YKoehMgM Received: by smtp.kernel.org (Postfix) with ESMTPSA id D9CC71F000C2; Fri, 4 Dec 2026 10:34:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380447; bh=uzBPVuXqXZPd35MabIGUEAr061Ja5YVtlIzc8rGWvaQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=YKoehMgMxyI+DybJO0Gus0WBlaNdoh4OkwWymC7fb56OtN281UdO57rEreFe4YbtM H9+F4J2TXr5hLe1Q4Z/3oUXmD1AoZPUGBypxFqtER/VVThZQI2wwDwLaHe6LsJApW7 qdq3mVfpKuKzrC0twVb5+Y45YBjDqQBqw++KPeeE= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Alexei Starovoitov , Sasha Levin Subject: [PATCH 7.3 278/742] bpf: Add the symbol of a prog before its id Date: Fri, 4 Dec 2026 19:02:22 +0900 Message-ID: <20261204100642.435176567@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@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 7.3-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 51b2fe61b1da9..152191a6de5b2 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -3162,6 +3162,9 @@ static int bpf_prog_load(union bpf_attr *attr, bpfptr_t uattr, struct bpf_log_at 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; @@ -3180,7 +3183,6 @@ static int bpf_prog_load(union bpf_attr *attr, bpfptr_t uattr, struct bpf_log_at * 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