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=1796379761; b=UaJHkBnGql6En8booUeA5/Qst9OPBd03a1P3ILVL7L9qU/l9oGjZ/AH4OPIoTSA0XsuK 7sw77KnvasBST7v9zrqkGKoq0xd3MLBqSH9emWdxlNekfsjr3R1jpgi31w/SgiOmD+WjG UN/OxsR+VYOI7uO+Del9NKvw8pwMaTNfxUuYd/ddiXcmhlBZ9I+ePdZCBoAgOCK7/EArN RPVcrYYIpoHSnGKgHYEBaxelg3bzwnNG8G+kqp/xOkc9rR4egnfNsUM91TKnZVFH/A6Ws xuUSz64cX/pces95IySmdBWf8sep6mCOIDj84dbmiz4OIvBS/AMBTMdcx7kWruhdOWw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796379761; 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=XVEHMZ2xAM3201qhsjmgodmGxnhR4dZrf8srZjWtt98=; b=wYLxJe63JyOqFXGdmU7gKM36RoLkkAYPE5JVDM1SKo2vYUFGEIdG+zokCGYJxBorkH+i f9dePtP/breUj0FYVIXi0m70xQsxP2mXgfcGJW2A1kzU8E+rItY7YkaSLjzSRfWhaVw1K R7S1sbxTtHC/dowiZN1UNrKSwc+MssXuqFEby5iTcQnjl6T/Ll/asjHcVNEHnY5wlyn2a 9RF0sSwuv4F7AhB3ZnWf3ik0hF1orKFnvYhtNUA5WhB0nvvD3ex4ZRzxruCprrsUyHC9k YAzMTWlkaHKZLmfQfW2enS3jgAt3JvCRM7EkP1lyBPoJ7x50VkZJdPwftEomPhMEklA== 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=yEoGl+la; 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 85476606A32C; Fri, 4 Dec 2026 10:22:41 +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=yEoGl+la Received: by smtp.kernel.org (Postfix) with ESMTPSA id F0F141F000CE; Fri, 4 Dec 2026 10:22:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796379761; bh=XVEHMZ2xAM3201qhsjmgodmGxnhR4dZrf8srZjWtt98=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=yEoGl+lamuFPVBi69qqenfXLnhr7SWqH90EWidAZ63FMoDaKhvhl8h7RBTCS3uWyw OXQ3sqk4WiyjlPwgH/W0KvWbFje/vEWU5XRlailTxvS8h1gXmNNL/jjteSVOWKN3ZG w+kkjxgxnABeHpqwO1vxSdnNxp+M4vDZzmTYjeGE= 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.12 041/555] bpf: Disallow interpreter fallback for BPF_ADDR_PERCPU insn Date: Fri, 4 Dec 2026 19:01:24 +0900 Message-ID: <20261204100607.524829269@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100603.988357525@linuxfoundation.org> References: <20261204100603.988357525@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.12-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.12.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.12.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 f2df5c47bef74..c8d8663b63915 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -3521,4 +3521,17 @@ static inline bool bpf_is_subprog(const struct bpf_prog *prog) return prog->aux->func_idx != 0; } +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 bcfc23ff3c57a..7ffd073c08423 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -21738,6 +21738,9 @@ static int do_misc_fixups(struct bpf_verifier_env *env) return -EINVAL; } + 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) @@ -21842,6 +21845,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_MOV32_IMM(BPF_REG_0, (u32)(unsigned long)&pcpu_hot.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