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=1796379334; b=n0mi0jlGwqThuilwRduE4ipWsVye/nOGdYIw3A/zp2/Q6o/016eW+Tlkd+29tzDw109G rzz2fBS0+Q/ngV/JodKXUxKZb/HVQOzg9H+shNGEkaQCnWMaCITBHCbps06Y+gUT9Cogt 3991eMaD+XvCfrSBPjobJ1lggsSFlNaPutAVexUIHfblux8GKDxMkjpFyAE2FbR/YRxcL 0tsFmeqyCntzyxpYyE0+pmUZMmoYXJhgDB1ATl6hCsCf5xgeGc45W/MA5Fru1N9CIe8FZ MR3GwX1WxKkc4PL+XY/JingZH0PuQdYarjHW2lm0HVSuUpiuHRiIdePlG4lAVBZDxDQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796379334; 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=xhMsuDBiGU0Obe1ta7YdeDYmN63qSt7g/PQANntlpvw=; b=KyIPRn+WoQeo/CS9R2maMLcin7BifJozFY+7EWZx9lorgKcIEz8v9plxtZ3zo6i47HAG rv+F3kjeFb0yYILhS25HHhqWup7bMqvWmhJliArtxOCMrqkDSJ5lwTV3H4To96BBqZzAO Ug9lxR+Wlq9p+aveMV6NIHtIYEfAmqYUH44aDaE2XvZJjKzHciidxP/N4LWbPVyl/m3M1 c7hY0pDrJJjdsJ9SGhV8qdi3CPXs/XC5W88dLe2lw1XvQY/BBE7uk7lA3US4kVV8NLpMZ sJb8BvRfEj4Z2dldStNiZifoGEVGdDZnnkeMqbmCUv5rpgTH90WfiiKAnHCs61JGNyw== 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="g/N4M/7X"; 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 C6223606A32C; Fri, 4 Dec 2026 10:15:34 +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=g/N4M/7X Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4176E1F000CE; Fri, 4 Dec 2026 10:15:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796379334; bh=xhMsuDBiGU0Obe1ta7YdeDYmN63qSt7g/PQANntlpvw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=g/N4M/7XdL6n4RcXH3YdlqnYpaZwm20SV6qoPPYo19dVFU/x/glmkuN268DEgHVF+ zAR9LDeT4lwnOX9sgDqz6AT+1zkln8FwsESUZ1WyWMvfxfk+88xUQEHpXZH6KhY5si I5hoLlc9l4k+jl6BV9LPm9gA6A1uYjXtYxW3gjjs= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Leon Hwang , Kumar Kartikeya Dwivedi , Sasha Levin Subject: [PATCH 6.18 017/703] bpf: Disallow interpreter fallback for BPF_ADDR_PERCPU insn Date: Fri, 4 Dec 2026 18:58:36 +0900 Message-ID: <20261204100628.010842106@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: 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.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Leon Hwang [ Upstream commit 7a0855e73757ee9cf25ba635a1c735018ecba742 ] The BPF_MOV64_PERCPU_REG insn requires JIT to emit native code to for 'dst_reg = src_reg + '. However, the interpreter ignores the 'off' at its ALU64_MOV_X label. The 'off' indicates the insn is BPF_MOV64_PERCPU_REG insn. Then, when the interpreter loads memory from the register, it will hit a page fault. [ 2.545572] BUG: unable to handle page fault for address: ffffffffacaaf034 [ 2.546485] #PF: supervisor read access in kernel mode [ 2.547167] #PF: error_code(0x0000) - not-present page [ 2.547850] PGD 134e63067 P4D 134e63067 PUD 134e64063 PMD 10021c063 PTE 800ffffeca550062 [ 2.548912] Oops: Oops: 0000 [#1] SMP PTI Set jit_required as true in order to disallow interpreter fallback in core.c::__bpf_prog_select_runtime(), if any BPF_ADDR_PERCPU insn is patched to the prog. BTW, rename the helper bpf_map_supports_cpu_flags() to bpf_map_is_percpu_map(). Fixes: 7bdbf7446305 ("bpf: add special internal-only MOV instruction to resolve per-CPU addrs") Signed-off-by: Leon Hwang Link: https://lore.kernel.org/bpf/20260715141122.15783-4-leon.hwang@linux.dev Signed-off-by: Kumar Kartikeya Dwivedi [edit] Add bpf_map_is_percpu_map() directly because 6.18.y lacks bpf_map_supports_cpu_flags(). Apply the map lookup and bpf_get_smp_processor_id() changes to do_misc_fixups() in kernel/bpf/verifier.c. Omit the current-task helper hunk because 6.18.y lacks the verifier inlining introduced by commit eaedea154eb9 ("bpf, x86: inline bpf_get_current_task() for x86_64"). Signed-off-by: Leon Hwang Signed-off-by: Sasha Levin --- include/linux/bpf.h | 13 +++++++++++++ kernel/bpf/verifier.c | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index cc9c58ea53b10..74110a8c800d9 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -3784,4 +3784,17 @@ int bpf_prog_get_file_line(struct bpf_prog *prog, unsigned long ip, const char * const char **linep, int *nump); struct bpf_prog *bpf_prog_find_from_stack(void); +static inline bool bpf_map_is_percpu_map(enum bpf_map_type map_type) +{ + switch (map_type) { + case BPF_MAP_TYPE_PERCPU_ARRAY: + case BPF_MAP_TYPE_PERCPU_HASH: + case BPF_MAP_TYPE_LRU_PERCPU_HASH: + case BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE: + return true; + default: + return false; + } +} + #endif /* _LINUX_BPF_H */ diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index ec862cd11942b..40265041cc056 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -23346,6 +23346,9 @@ static int do_misc_fixups(struct bpf_verifier_env *env) return -EFAULT; } + if (bpf_map_is_percpu_map(map_ptr->map_type)) + prog->jit_required = true; + new_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt); if (!new_prog) @@ -23450,6 +23453,7 @@ static int do_misc_fixups(struct bpf_verifier_env *env) * way, it's fine to back out this inlining logic */ #ifdef CONFIG_SMP + prog->jit_required = true; insn_buf[0] = BPF_MOV64_IMM(BPF_REG_0, (u32)(unsigned long)&cpu_number); insn_buf[1] = BPF_MOV64_PERCPU_REG(BPF_REG_0, BPF_REG_0); insn_buf[2] = BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_0, 0); -- 2.53.0