From nobody Sat Jul 25 17:33:35 2026 Received: from out-170.mta1.migadu.com (out-170.mta1.migadu.com [95.215.58.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B8E3437C92F for ; Wed, 15 Jul 2026 14:12:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784124724; cv=none; b=rEObbUuTZrgHP1Jzr9d7zRZMmGn/09s0/ZvE8+jinLDI/hYZ2riLIV+283V3fIv4Hq6oj32gTxzi5rB44SXh9f4vUzwQIQ+SQytAj8mxaIINHvR2fJWrVA1jy8YlVOYyfPbk030N8J5KYSri6FRtnfJUvkdpojwWEhs9UfG2XXw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784124724; c=relaxed/simple; bh=ndIKSrxKmnZE3dqZBVKJ4gJkM4iILtOVd8tk7yAm7Bo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VpHsMHhwxAJ96ZW6/wQkn+a3M7tyXqR3PB/eL0sUiNrhRNAk786nAQNzzlWAd/5mbteydx/QRDv2LCAqdykOZcAYmhxyb8IUZ1H2uDz0Lbf/nM3G4l+OUwVloOGjqfmAqIUwfEX5u1p618Z4jZix6fOBFjhGtWLj+W9KDi+ZirU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=DPSNM8JO; arc=none smtp.client-ip=95.215.58.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="DPSNM8JO" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1784124720; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=F4+xmeri9B7yuLUBZttyuZ0Ke5OCWdR2oNJkXqmaxfk=; b=DPSNM8JOVEdpxg0EF4Tq11QjLxM5d/2/uVeFOpNT9ZYfLNsobbfDndEtQUId18Qwo4aYJ0 Tle3VH6+jqBI9URw+OPE3XkUegM5E3VYfzbri3+whCjuuA9TMP6BeMacK3aI6mSeIJyuvb ru1z70D1zwaCl/zH/EDJYjbYLDbmpZQ= From: Leon Hwang To: bpf@vger.kernel.org Cc: Alexei Starovoitov , Daniel Borkmann , John Fastabend , Andrii Nakryiko , Eduard Zingerman , Kumar Kartikeya Dwivedi , Martin KaFai Lau , Song Liu , Yonghong Song , Jiri Olsa , Emil Tsalapatis , Andrew Morton , Shuah Khan , Puranjay Mohan , Anton Protopopov , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Leon Hwang Subject: [PATCH bpf-next v2 1/3] bpf: Disallow interpreter fallback for arena-related insns Date: Wed, 15 Jul 2026 22:11:20 +0800 Message-ID: <20260715141122.15783-2-leon.hwang@linux.dev> In-Reply-To: <20260715141122.15783-1-leon.hwang@linux.dev> References: <20260715141122.15783-1-leon.hwang@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" Since the interpreter does not support the arena-related insns, interpreter fallback should not be allowed for these insns in core.c::__bpf_prog_select_runtime(). Currently, when the interpreter executes the arena ST/LDX/STX insns, it would hit the BUG_ON() in ___bpf_prog_run() at run time. [ 2.579196] BPF interpreter: unknown opcode a2 (imm: 0x0) [ 2.579998] ------------[ cut here ]------------ [ 2.580652] kernel BUG at kernel/bpf/core.c:2349! [ 2.581314] Oops: invalid opcode: 0000 [#1] SMP PTI Set jit_required as true when arena map is used in the prog to disallow interpreter fallback for arena-related insns. Fixes: 6082b6c328b5 ("bpf: Recognize addr_space_cast instruction in the ver= ifier.") Signed-off-by: Leon Hwang --- kernel/bpf/verifier.c | 1 + 1 file changed, 1 insertion(+) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index de816063ae63..3849d3d00e15 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -17873,6 +17873,7 @@ static int check_map_prog_compatibility(struct bpf_= verifier_env *env, return -EOPNOTSUPP; } env->prog->aux->arena =3D (void *)map; + env->prog->jit_required =3D true; if (!bpf_arena_get_user_vm_start(env->prog->aux->arena)) { verbose(env, "arena's user address must be set via map_extra or mmap()\= n"); return -EINVAL; --=20 2.55.0 From nobody Sat Jul 25 17:33:35 2026 Received: from out-179.mta1.migadu.com (out-179.mta1.migadu.com [95.215.58.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A910E36F8EA for ; Wed, 15 Jul 2026 14:12:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784124730; cv=none; b=lvVLaZFhaRb1QGwruu7JH1V0rbB3bxdLepg7B+1Aw+XZVxrUvPkKZXdc97DaktxMbLo/Og7H4nnUxulsXSQ7KlZnmog5K7k4fxOlk4iPK044WSWZL3AQpIdu6gxUtO8TTj0Dnk1EOnOBbjDetr5Rv2O3+kEoEHypcj32mmcjuFU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784124730; c=relaxed/simple; bh=IUpRML8hO2gj9vmCZMANV/jz26mRY1zTafZXxC6Gh5A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cy/CeQuohU3wgnDZVAtUshlbK/6xIooA3sgKHAMolbcElsbPVre7FXdLQu2HhHgBwl09Nm8ccRXbVgOpRPqKf3OAk3cCt25vZk404Joy2nl9ybhlgDprUWmRYCf/Aumn2qhDH8F4Sc/+nOZGZbQKvbD7zsmrwFs3ylWy0hjE34s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=eDbRsCO8; arc=none smtp.client-ip=95.215.58.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="eDbRsCO8" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1784124725; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qlDYeaOEO6DzxNGHrEZRQDIYtYqdYOgqvzgHbc9tT1o=; b=eDbRsCO8vDaNbi4whUE62g/5CJhbpU1+kF3HthUif5iQW1ENWb38zVktrR9hVSPjqYaUgS SJregPcSec/hp9nvUUAw5fcCHZbGTIwAsmorocOJP2oYm3/wkJ0qLXVX2rO7bZ4SvuNoH2 tjRDTA//UIo5NxoSXh88uNaeFiUlm68= From: Leon Hwang To: bpf@vger.kernel.org Cc: Alexei Starovoitov , Daniel Borkmann , John Fastabend , Andrii Nakryiko , Eduard Zingerman , Kumar Kartikeya Dwivedi , Martin KaFai Lau , Song Liu , Yonghong Song , Jiri Olsa , Emil Tsalapatis , Andrew Morton , Shuah Khan , Puranjay Mohan , Anton Protopopov , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Leon Hwang Subject: [PATCH bpf-next v2 2/3] bpf: Disallow interpreter fallback for gotox insn Date: Wed, 15 Jul 2026 22:11:21 +0800 Message-ID: <20260715141122.15783-3-leon.hwang@linux.dev> In-Reply-To: <20260715141122.15783-1-leon.hwang@linux.dev> References: <20260715141122.15783-1-leon.hwang@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" The interpreter does not recognize the BPF_JMP|BPF_JA|BPF_X insn, which is used for insn_array map. Thereafter, it would hit the BUG_ON() in ___bpf_prog_run() at run time. [ 2.563726] BPF interpreter: unknown opcode 0d (imm: 0x0) [ 2.564557] ------------[ cut here ]------------ [ 2.565206] kernel BUG at kernel/bpf/core.c:2349! [ 2.565882] Oops: invalid opcode: 0000 [#1] SMP PTI Set jit_required as true when insn_array map is used in the prog in order to disallow interpreter fallback for gotox insn in core.c::__bpf_prog_select_runtime(). Fixes: 493d9e0d6083 ("bpf, x86: add support for indirect jumps") Signed-off-by: Leon Hwang --- kernel/bpf/verifier.c | 1 + 1 file changed, 1 insertion(+) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 3849d3d00e15..e2ef7836b7b5 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -17927,6 +17927,7 @@ static int __add_used_map(struct bpf_verifier_env *= env, struct bpf_map *map) return err; } env->insn_array_maps[env->insn_array_map_cnt++] =3D map; + env->prog->jit_required =3D true; } =20 return env->used_map_cnt - 1; --=20 2.55.0 From nobody Sat Jul 25 17:33:35 2026 Received: from out-173.mta1.migadu.com (out-173.mta1.migadu.com [95.215.58.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7F1D547B410 for ; Wed, 15 Jul 2026 14:12:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784124734; cv=none; b=hu0MSaaX81buKziMhamyvW8ET6nzr8P6/luLB6mF0QkYQ/rIy4td7gzcZ1rokPLxcuF6hk/+E8GPu3Lz22yu1C75OuvTSRhzbZzvkl7nEWVGVMhCEZuJZX6rqOCo9fYf5v7SPahqhMOFFNqZg19K73zIKq/r4ftq9sHpO7b9YfU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784124734; c=relaxed/simple; bh=afs5fLgT8Qx3Rxr22x1O8wwdXCqlwGq87d0SiIZw1Vg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VYUU3Xf7Ua3o9+E8hSXY9w0IOj1qYOp91KlDI79oacSLb+vmHII/bPgawJg98NGT31Xq/nISv/2eZWm9INlcNwAkIj3+sVtYzxlBpLHobXaRbalbjhexCpLhQrSWR/7qETtQC1S7ZvTIJ+fPtexg7Sc79m/0xaV1XVt5iFafb1Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=Vee2idHR; arc=none smtp.client-ip=95.215.58.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="Vee2idHR" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1784124730; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iva0H+8uYUGc12Hzh0ksizDRG/UQtCa60DRk1jyvB3c=; b=Vee2idHR5IyO4YqpuEuKl/3i0VeAy0U36lbJqVzMaHkjSHjN7lLAxZOCzYNi/RLq65V+3u weIAgZvj74PZsJqvoGU6l4XhifcR/q8UrYR+HzzWzisXVm2LQnT6m6H8J/d3myOGHA9/vX fQF7OUPbu6aKAAjw/Z6cPuyE//mwo3g= From: Leon Hwang To: bpf@vger.kernel.org Cc: Alexei Starovoitov , Daniel Borkmann , John Fastabend , Andrii Nakryiko , Eduard Zingerman , Kumar Kartikeya Dwivedi , Martin KaFai Lau , Song Liu , Yonghong Song , Jiri Olsa , Emil Tsalapatis , Andrew Morton , Shuah Khan , Puranjay Mohan , Anton Protopopov , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Leon Hwang Subject: [PATCH bpf-next v2 3/3] bpf: Disallow interpreter fallback for BPF_ADDR_PERCPU insn Date: Wed, 15 Jul 2026 22:11:22 +0800 Message-ID: <20260715141122.15783-4-leon.hwang@linux.dev> In-Reply-To: <20260715141122.15783-1-leon.hwang@linux.dev> References: <20260715141122.15783-1-leon.hwang@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" The BPF_MOV64_PERCPU_REG insn requires JIT to emit native code to for 'dst_reg =3D 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: ffffffffacaaf0= 34 [ 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 res= olve per-CPU addrs") Signed-off-by: Leon Hwang --- include/linux/bpf.h | 4 ++-- kernel/bpf/fixups.c | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 31181e0c2b80..d9542127dfdf 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -4163,7 +4163,7 @@ bpf_prog_update_insn_ptrs(struct bpf_prog *prog, u32 = *offsets, void *image) } #endif =20 -static inline bool bpf_map_supports_cpu_flags(enum bpf_map_type map_type) +static inline bool bpf_map_is_percpu_map(enum bpf_map_type map_type) { switch (map_type) { case BPF_MAP_TYPE_PERCPU_ARRAY: @@ -4190,7 +4190,7 @@ static inline int bpf_map_check_op_flags(struct bpf_m= ap *map, u64 flags, u64 all return -EINVAL; =20 if (flags & (BPF_F_CPU | BPF_F_ALL_CPUS)) { - if (!bpf_map_supports_cpu_flags(map->map_type)) + if (!bpf_map_is_percpu_map(map->map_type)) return -EINVAL; if ((flags & BPF_F_CPU) && (flags & BPF_F_ALL_CPUS)) return -EINVAL; diff --git a/kernel/bpf/fixups.c b/kernel/bpf/fixups.c index d3be972714b2..a0bddada7964 100644 --- a/kernel/bpf/fixups.c +++ b/kernel/bpf/fixups.c @@ -2008,6 +2008,9 @@ int bpf_do_misc_fixups(struct bpf_verifier_env *env) return -EFAULT; } =20 + if (bpf_map_is_percpu_map(map_ptr->map_type)) + prog->jit_required =3D true; + new_prog =3D bpf_patch_insn_data(env, i + delta, insn_buf, cnt); if (!new_prog) @@ -2112,6 +2115,7 @@ int bpf_do_misc_fixups(struct bpf_verifier_env *env) * way, it's fine to back out this inlining logic */ #ifdef CONFIG_SMP + prog->jit_required =3D true; insn_buf[0] =3D BPF_MOV64_IMM(BPF_REG_0, (u32)(unsigned long)&cpu_numbe= r); insn_buf[1] =3D BPF_MOV64_PERCPU_REG(BPF_REG_0, BPF_REG_0); insn_buf[2] =3D BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_0, 0); @@ -2133,6 +2137,7 @@ int bpf_do_misc_fixups(struct bpf_verifier_env *env) /* Implement bpf_get_current_task() and bpf_get_current_task_btf() inlin= e. */ if ((insn->imm =3D=3D BPF_FUNC_get_current_task || insn->imm =3D=3D BPF_= FUNC_get_current_task_btf) && bpf_verifier_inlines_helper_call(env, insn->imm)) { + prog->jit_required =3D true; insn_buf[0] =3D BPF_MOV64_IMM(BPF_REG_0, (u32)(unsigned long)¤t_t= ask); insn_buf[1] =3D BPF_MOV64_PERCPU_REG(BPF_REG_0, BPF_REG_0); insn_buf[2] =3D BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_0, 0); --=20 2.55.0