bpf: Don't trigger __bpf_prog_ret0_warn() for -ENOMEM.
Subsystems (25)
cover bpf: Don't trigger __bpf_prog_ret0_warn() for -ENOMEM.
syzkaller reported a splat in __bpf_prog_ret0_warn() with a sane bpf prog, which was triggered by fault injection.
This series suppresses the warning in such a case.
Kuniyuki Iwashima (2):
bpf: Allow bpf_int_jit_compile() to set errno.
bpf: Set -ENOMEM to err in bpf_int_jit_compile().
arch/arc/net/bpf_jit_core.c | 21 +++++++++++++-------- arch/arm/net/bpf_jit_32.c | 10 ++++++++-- arch/arm64/net/bpf_jit_comp.c | 10 ++++++++-- arch/loongarch/net/bpf_jit.c | 10 ++++++++-- arch/mips/net/bpf_jit_comp.c | 15 +++++++++++---- arch/parisc/net/bpf_jit_core.c | 10 ++++++++-- arch/powerpc/net/bpf_jit_comp.c | 10 ++++++++-- arch/riscv/net/bpf_jit_core.c | 10 ++++++++-- arch/s390/net/bpf_jit_comp.c | 9 +++++++-- arch/sparc/net/bpf_jit_comp_64.c | 10 ++++++++-- arch/x86/net/bpf_jit_comp.c | 11 +++++++++-- arch/x86/net/bpf_jit_comp32.c | 9 +++++++-- include/linux/filter.h | 2 +- kernel/bpf/core.c | 6 ++++-- kernel/bpf/verifier.c | 21 +++++++++++++++------ 15 files changed, 123 insertions(+), 41 deletions(-)
Signature · 1 line
2.49.0
PATCH 1/2 bpf: Allow bpf_int_jit_compile() to set errno.
There are some failure paths in bpf_int_jit_compile() that are not worth triggering a warning in __bpf_prog_ret0_warn().
For example, if we fail to allocate memory in bpf_int_jit_compile(), we should propagate -ENOMEM to userspace instead of attaching __bpf_prog_ret0_warn().
Let's pass &err to bpf_int_jit_compile() to propagate errno.
--- arch/arc/net/bpf_jit_core.c | 2 +- arch/arm/net/bpf_jit_32.c | 2 +- arch/arm64/net/bpf_jit_comp.c | 2 +- arch/loongarch/net/bpf_jit.c | 2 +- arch/mips/net/bpf_jit_comp.c | 2 +- arch/parisc/net/bpf_jit_core.c | 2 +- arch/powerpc/net/bpf_jit_comp.c | 2 +- arch/riscv/net/bpf_jit_core.c | 2 +- arch/s390/net/bpf_jit_comp.c | 2 +- arch/sparc/net/bpf_jit_comp_64.c | 2 +- arch/x86/net/bpf_jit_comp.c | 2 +- arch/x86/net/bpf_jit_comp32.c | 2 +- include/linux/filter.h | 2 +- kernel/bpf/core.c | 6 ++++-- kernel/bpf/verifier.c | 21 +++++++++++++++------ 15 files changed, 32 insertions(+), 21 deletions(-)
arch/arc/net/bpf_jit_core.c +1 -1
@@ -1411,7 +1411,7 @@ static struct bpf_prog *do_extra_pass(struct bpf_prog *prog)* (re)locations involved that their addresses are not known * during the first run. */ -struct bpf_prog *bpf_int_jit_compile (struct bpf_prog *prog) +struct bpf_prog *bpf_int_jit_compile (struct bpf_prog *prog,int *err) {vm_dump (prog);
arch/arm/net/bpf_jit_32.c +1 -1
@@ -2142,7 +2142,7 @@ bool bpf_jit_needs_zext(void)return true; } -struct bpf_prog *bpf_int_jit_compile (struct bpf_prog *prog) +struct bpf_prog *bpf_int_jit_compile (struct bpf_prog *prog,int *err) {struct bpf_prog *tmp, *orig_prog = prog;struct bpf_binary_header *header;
arch/arm64/net/bpf_jit_comp.c +1 -1
@@ -1820,7 +1820,7 @@ struct arm64_jit_data {struct jit_ctx ctx; }; -struct bpf_prog *bpf_int_jit_compile (struct bpf_prog *prog) +struct bpf_prog *bpf_int_jit_compile (struct bpf_prog *prog,int *err) {int image_size, prog_size, extable_size, extable_align, extable_offset;struct bpf_prog *tmp, *orig_prog = prog;
arch/loongarch/net/bpf_jit.c +1 -1
@@ -1186,7 +1186,7 @@ static int validate_code(struct jit_ctx *ctx)return 0 ; } -struct bpf_prog *bpf_int_jit_compile (struct bpf_prog *prog) +struct bpf_prog *bpf_int_jit_compile (struct bpf_prog *prog,int *err) {bool tmp_blinded = false, extra_pass = false;u8 *image_ptr;
arch/mips/net/bpf_jit_comp.c +1 -1
@@ -909,7 +909,7 @@ bool bpf_jit_needs_zext(void)return true; } -struct bpf_prog *bpf_int_jit_compile (struct bpf_prog *prog) +struct bpf_prog *bpf_int_jit_compile (struct bpf_prog *prog,int *err) {struct bpf_prog *tmp, *orig_prog = prog;struct bpf_binary_header *header =NULL ;
arch/parisc/net/bpf_jit_core.c +1 -1
@@ -41,7 +41,7 @@ bool bpf_jit_needs_zext(void)return true; } -struct bpf_prog *bpf_int_jit_compile (struct bpf_prog *prog) +struct bpf_prog *bpf_int_jit_compile (struct bpf_prog *prog,int *err) {unsigned int prog_size =0 , extable_size =0 ;bool tmp_blinded = false, extra_pass = false;
arch/powerpc/net/bpf_jit_comp.c +1 -1
@@ -129,7 +129,7 @@ bool bpf_jit_needs_zext(void)return true; } -struct bpf_prog *bpf_int_jit_compile (struct bpf_prog *fp) +struct bpf_prog *bpf_int_jit_compile (struct bpf_prog *fp,int *err) {u32 proglen;u32 alloclen;
arch/riscv/net/bpf_jit_core.c +1 -1
@@ -42,7 +42,7 @@ bool bpf_jit_needs_zext(void)return true; } -struct bpf_prog *bpf_int_jit_compile (struct bpf_prog *prog) +struct bpf_prog *bpf_int_jit_compile (struct bpf_prog *prog,int *err) {unsigned int prog_size =0 , extable_size =0 ;bool tmp_blinded = false, extra_pass = false;
arch/s390/net/bpf_jit_comp.c +1 -1
@@ -2255,7 +2255,7 @@ static struct bpf_binary_header *bpf_jit_alloc(struct bpf_jit *jit,/* * Compile eBPF program "fp" */ -struct bpf_prog *bpf_int_jit_compile (struct bpf_prog *fp) +struct bpf_prog *bpf_int_jit_compile (struct bpf_prog *fp,int *err) {u32 stack_depth =round_up (fp->aux->stack_depth,8 );struct bpf_prog *tmp, *orig_fp = fp;
arch/sparc/net/bpf_jit_comp_64.c +1 -1
@@ -1477,7 +1477,7 @@ struct sparc64_jit_data {struct jit_ctx ctx; }; -struct bpf_prog *bpf_int_jit_compile (struct bpf_prog *prog) +struct bpf_prog *bpf_int_jit_compile (struct bpf_prog *prog,int *err) {struct bpf_prog *tmp, *orig_prog = prog;struct sparc64_jit_data *jit_data;
arch/x86/net/bpf_jit_comp.c +1 -1
@@ -3495,7 +3495,7 @@ struct x64_jit_data {#define MAX_PASSES 20#define PADDING_PASSES (MAX_PASSES - 5) -struct bpf_prog *bpf_int_jit_compile (struct bpf_prog *prog) +struct bpf_prog *bpf_int_jit_compile (struct bpf_prog *prog,int *err) {struct bpf_binary_header *rw_header =NULL ;struct bpf_binary_header *header =NULL ;
arch/x86/net/bpf_jit_comp32.c +1 -1
@@ -2518,7 +2518,7 @@ bool bpf_jit_needs_zext(void)return true; } -struct bpf_prog *bpf_int_jit_compile (struct bpf_prog *prog) +struct bpf_prog *bpf_int_jit_compile (struct bpf_prog *prog,int *err) {struct bpf_binary_header *header =NULL ;struct bpf_prog *tmp, *orig_prog = prog;
include/linux/filter.h +1 -1
@@ -1124,7 +1124,7 @@ u64 __bpf_call_base(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5); ((u64 (*)(u64 ,u64 ,u64 ,u64 ,u64 ,const struct bpf_insn *)) \ (void *)__bpf_call_base) -struct bpf_prog *bpf_int_jit_compile (struct bpf_prog *prog); +struct bpf_prog *bpf_int_jit_compile (struct bpf_prog *prog,int *err);void bpf_jit_compile (struct bpf_prog *prog);bool bpf_jit_needs_zext (void );bool bpf_jit_inlines_helper_call (s32 imm);
kernel/bpf/core.c +4 -2
@@ -2491,8 +2491,10 @@ struct bpf_prog *bpf_prog_select_runtime(struct bpf_prog *fp, int *err)if (*err)return fp; - fp =bpf_int_jit_compile (fp); + fp =bpf_int_jit_compile (fp, err);bpf_prog_jit_attempt_done (fp); +if (*err) +return fp;if (!fp->jited && jit_needed) { *err = -ENOTSUPP ;return fp;
@@ -2999,7 +3001,7 @@ const struct bpf_func_proto bpf_tail_call_proto = {* It is encouraged to implement bpf_int_jit_compile() instead, so that * eBPF and implicitly also cBPF can get JITed! */ -struct bpf_prog *__weak bpf_int_jit_compile (struct bpf_prog *prog) +struct bpf_prog *__weak bpf_int_jit_compile (struct bpf_prog *prog,int *err) {return prog; }
kernel/bpf/verifier.c +15 -6
@@ -21074,10 +21074,11 @@ static int jit_subprogs(struct bpf_verifier_env *env)if (err) goto out_undo_insn; - err = -ENOMEM ; func =kcalloc (env->subprog_cnt,sizeof (prog),GFP_KERNEL ); -if (!func) +if (!func) { + err = -ENOMEM ; goto out_undo_insn; + }for (i =0 ; i < env->subprog_cnt; i++) { subprog_start = subprog_end;
@@ -21090,14 +21091,18 @@ static int jit_subprogs(struct bpf_verifier_env *env)* func[i]->stats will never be accessed and stays NULL */ func[i] =bpf_prog_alloc_no_stats (bpf_prog_size (len),GFP_USER ); -if (!func[i]) +if (!func[i]) { + err = -ENOMEM ; goto out_free; + }memcpy (func[i]->insnsi, &prog->insnsi[subprog_start], len *sizeof (struct bpf_insn )); func[i]->type = prog->type; func[i]->len = len; -if (bpf_prog_calc_tag (func[i])) +if (bpf_prog_calc_tag (func[i])) { + err = -ENOMEM ; goto out_free; + } func[i]->is_func =1 ; func[i]->sleepable = prog->sleepable; func[i]->aux->func_idx = i;
@@ -21154,7 +21159,9 @@ static int jit_subprogs(struct bpf_verifier_env *env) func[i]->aux->might_sleep = env->subprog_info[i].might_sleep;if (!i) func[i]->aux->exception_boundary = env->seen_exception; - func[i] =bpf_int_jit_compile (func[i]); + func[i] =bpf_int_jit_compile (func[i], &err); +if (err) + goto out_free;if (!func[i]->jited) { err = -ENOTSUPP ; goto out_free;
@@ -21198,7 +21205,9 @@ static int jit_subprogs(struct bpf_verifier_env *env) }for (i =0 ; i < env->subprog_cnt; i++) { old_bpf_func = func[i]->bpf_func; - tmp =bpf_int_jit_compile (func[i]); + tmp =bpf_int_jit_compile (func[i], &err); +if (err) + goto out_free;if (tmp != func[i] || func[i]->bpf_func != old_bpf_func) {verbose (env,"JIT doesn't support bpf-to-bpf calls\n" ); err = -ENOTSUPP ;
Signature · 1 line
2.49.0
Re: [PATCH v1 bpf 1/2] bpf: Allow bpf_int_jit_compile() to set errno.
Quoted 9 lines · Kuniyuki Iwashima
There are some failure paths in
bpf_int_jit_compile()that are not worth triggering a warning in__bpf_prog_ret0_warn().For example, if we fail to allocate memory in
bpf_int_jit_compile(), we should propagate-ENOMEMto userspace instead of attaching__bpf_prog_ret0_warn().Let's pass &err to
bpf_int_jit_compile()to propagate errno.
Is there any reason we are not just returning ERR_PTR() instead of the approach in this patch? That seems more canonical within BPF subsystem, if we need to return error for pointer-returning functions?
Quoted 20 lines
Signed-off-by Kuniyuki Iwashima <[email protected]>--- arch/arc/net/bpf_jit_core.c | 2 +- arch/arm/net/bpf_jit_32.c | 2 +- arch/arm64/net/bpf_jit_comp.c | 2 +- arch/loongarch/net/bpf_jit.c | 2 +- arch/mips/net/bpf_jit_comp.c | 2 +- arch/parisc/net/bpf_jit_core.c | 2 +- arch/powerpc/net/bpf_jit_comp.c | 2 +- arch/riscv/net/bpf_jit_core.c | 2 +- arch/s390/net/bpf_jit_comp.c | 2 +- arch/sparc/net/bpf_jit_comp_64.c | 2 +- arch/x86/net/bpf_jit_comp.c | 2 +- arch/x86/net/bpf_jit_comp32.c | 2 +- include/linux/filter.h | 2 +- kernel/bpf/core.c | 6 ++++-- kernel/bpf/verifier.c | 21 +++++++++++++++------ 15 files changed, 32 insertions(+), 21 deletions(-)
[...]
Re: [PATCH v1 bpf 1/2] bpf: Allow bpf_int_jit_compile() to set errno.
From: Andrii Nakryiko <[email protected]>
Date: Tue, 15 Apr 2025 16:10:42 -0700
Quoted 9 lines · Kuniyuki Iwashima
Quoted 8 lines
There are some failure paths in
bpf_int_jit_compile()that are not worth triggering a warning in__bpf_prog_ret0_warn().For example, if we fail to allocate memory in
bpf_int_jit_compile(), we should propagate-ENOMEMto userspace instead of attaching__bpf_prog_ret0_warn().
Quoted 5 lines
Quoted 1 line
Let's pass &err to
bpf_int_jit_compile()to propagate errno.Is there any reason we are not just returning
ERR_PTR()instead of the approach in this patch? That seems more canonical within BPF subsystem, if we need to return error for pointer-returning functions?
From the comment in __bpf_prog_ret0_warn(), I thought BPF folks wanted to catch any JIT failure as a warning for syzbot etc, instead of returning an error to user. Even it can be done by adding WARN_ON() to the caller of bpf_int_jit_compile() though.
That's why I only set error in the -ENOMEM paths in patch 2, which is not a BPF problem at least.
With Alexei's suggestion, we can suppress that case, but as -ENOTSUPP.
What do you think ?
Re: [PATCH v1 bpf 1/2] bpf: Allow bpf_int_jit_compile() to set errno.
Quoted 23 lines · Kuniyuki Iwashima
From: Andrii Nakryiko <[email protected]>
Date: Tue, 15 Apr 2025 16:10:42 -0700Quoted 9 lines · Kuniyuki Iwashima
Quoted 8 lines
There are some failure paths in
bpf_int_jit_compile()that are not worth triggering a warning in__bpf_prog_ret0_warn().For example, if we fail to allocate memory in
bpf_int_jit_compile(), we should propagate-ENOMEMto userspace instead of attaching__bpf_prog_ret0_warn().Quoted 5 lines
Quoted 1 line
Let's pass &err to
bpf_int_jit_compile()to propagate errno.Is there any reason we are not just returning
ERR_PTR()instead of the approach in this patch? That seems more canonical within BPF subsystem, if we need to return error for pointer-returning functions?From the comment in
__bpf_prog_ret0_warn(), I thought BPF folks wanted to catch any JIT failure as a warning for syzbot etc, instead of returning an error to user. Even it can be done by addingWARN_ON()to the caller ofbpf_int_jit_compile()though.
Quoted 6 lines
That's why I only set error in the
-ENOMEMpaths in patch 2, which is not a BPF problem at least.With Alexei's suggestion, we can suppress that case, but as
-ENOTSUPP.What do you think ?
I'm not sure I follow this completely. My only suggestion is the *mechanics* of delivering error code. Instead of setting error by pointer, we can just return it as ERR_PTR(). The callers of bpf_int_jit_compile() (verifier and core.c) can still swallow any errors, if necessary and revert to original pointer. E.g., in verifier, instead of:
func[i] = bpf_int_jit_compile(func[i]);
if (!func[i]->jited) {
err = -ENOTSUPP;
goto out_free;
}you'd do:
struct bpf_prog *jit_prog = bpf_int_jit_compile(func[i]);
if (IS_ERR(jit_prog) || !jit_prog->jited) {
err = -ENOTSUPP;
goto out_free;
}func[i] = jit_prog;
Again, it's just weird to pass error as an extra out parameter, that's all.
But I don't feel strongly about this, was just trying to suggest a cleaner alternative.
PATCH 2/2 bpf: Set -ENOMEM to err in bpf_int_jit_compile().
In reply to Kuniyuki Iwashimasyzkaller reported a splat below. [0]
It always followed another splat by fault injection in bpf_int_jit_compile(). [1]
Instead of proceeding with __bpf_prog_ret0_warn() and seeing a splat later, let's return -ENOMEM to userspace.
[0]:
WARNING: CPU: 1 PID: 36 at kernel/bpf/core.c:2357 __bpf_prog_ret0_warn+0xa/0x10 kernel/bpf/core.c:2357 Modules linked in: CPU: 1 UID: 0 PID: 36 Comm: kworker/1:1 Not tainted 6.14.0-13344-ga9843689e2de #28 PREEMPT(voluntary) 167b7ecb8f281ed56016416cdf1d8bb342db88fc Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.3-0-ga6ed6b701f0a-prebuilt.qemu.org 04/01/2014 Workqueue: mld mld_ifc_work RIP: 0010:__bpf_prog_ret0_warn+0xa/0x10 kernel/bpf/core.c:2357 Code: ff eb 84 e8 b8 cf ee ff e9 7a ff ff ff e8 ae cf ee ff e9 70 ff ff ff 66 0f 1f 84 00 00 00 00 00 f3 0f 1e fa e8 97 cf ee ff 90 <0f> 0b 90 31 c0 c3 f3 0f 1e fa 55 48 89 e5 41 57 41 56 41 55 41 54 RSP: 0000:ffa0000000267050 EFLAGS: 00010293 RAX: ffffffff81881569 RBX: ffa0000000393030 RCX: ff11000100dc4500 RDX: 0000000000000000 RSI: ffa0000000393048 RDI: ff1100010b812a00 RBP: 0000000000000000 R08: 0000000000000002 R09: 0000000000000000 R10: dffffc0000000000 R11: fffffbfff0e5ef77 R12: 0000000000000000 R13: dffffc0000000000 R14: ff1100010b812a00 R15: ffa0000000393048 FS: 0000000000000000(0000) GS:ff11000192213000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007ff451d686ec CR3: 00000001037eb004 CR4: 0000000000771ef0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe07f0 DR7: 0000000000000600 PKRU: 55555554 Call Trace: <TASK> bpf_dispatcher_nop_func include/linux/bpf.h:1316 [inline] __bpf_prog_run include/linux/filter.h:718 [inline] bpf_prog_run include/linux/filter.h:725 [inline] bpf_prog_run_pin_on_cpu include/linux/filter.h:742 [inline] bpf_prog_run_clear_cb+0x7f/0x140 include/linux/filter.h:983 run_filter+0x156/0x260 net/packet/af_packet.c:2135 packet_rcv+0x491/0x15b0 net/packet/af_packet.c:2208 dev_queue_xmit_nit+0xc27/0xcb0 net/core/dev.c:2592 xmit_one net/core/dev.c:3831 [inline] dev_hard_start_xmit+0x1d5/0x720 net/core/dev.c:3851 sch_direct_xmit+0x242/0x4a0 net/sched/sch_generic.c:343 __dev_xmit_skb net/core/dev.c:4127 [inline] __dev_queue_xmit+0x186d/0x37a0 net/core/dev.c:4654 dev_queue_xmit include/linux/netdevice.h:3355 [inline] neigh_hh_output include/net/neighbour.h:523 [inline] neigh_output include/net/neighbour.h:537 [inline] ip6_finish_output2+0x11f3/0x16e0 net/ipv6/ip6_output.c:141 dst_output include/net/dst.h:459 [inline] NF_HOOK+0x160/0x470 include/linux/netfilter.h:314 mld_sendpack+0x7f7/0xd70 net/ipv6/mcast.c:1868 mld_send_cr net/ipv6/mcast.c:2169 [inline] mld_ifc_work+0x835/0xde0 net/ipv6/mcast.c:2702 process_one_work kernel/workqueue.c:3238 [inline] process_scheduled_works+0xa77/0x16a0 kernel/workqueue.c:3319 worker_thread+0x8b6/0xd50 kernel/workqueue.c:3400 kthread+0x413/0x870 kernel/kthread.c:464 ret_from_fork+0x48/0x80 arch/x86/kernel/process.c:153 ret_from_fork_asm+0x11/0x20 arch/x86/entry/entry_64.S:245 </TASK>
[1]:FAULT_INJECTION: forcing a failure.
name failslab, interval 1, probability 0, space 0, times 1
CPU: 1 UID: 0 PID: 4562 Comm: syz.4.1225 Not tainted 6.14.0-13344-ga9843689e2de #28 PREEMPT(voluntary) 167b7ecb8f281ed56016416cdf1d8bb342db88fc Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.3-0-ga6ed6b701f0a-prebuilt.qemu.org 04/01/2014 Call Trace: <TASK> dump_stack_lvl+0xfa/0x120 should_fail_ex+0x501/0x610 should_failslab+0xba/0x120 __kmalloc_cache_noprof+0x5d/0x310 bpf_int_jit_compile+0x1292/0x18b0 bpf_prog_select_runtime+0x439/0x780
--- arch/arc/net/bpf_jit_core.c | 19 ++++++++++++------- arch/arm/net/bpf_jit_32.c | 8 +++++++- arch/arm64/net/bpf_jit_comp.c | 8 +++++++- arch/loongarch/net/bpf_jit.c | 8 +++++++- arch/mips/net/bpf_jit_comp.c | 13 ++++++++++--- arch/parisc/net/bpf_jit_core.c | 8 +++++++- arch/powerpc/net/bpf_jit_comp.c | 8 +++++++- arch/riscv/net/bpf_jit_core.c | 8 +++++++- arch/s390/net/bpf_jit_comp.c | 7 ++++++- arch/sparc/net/bpf_jit_comp_64.c | 8 +++++++- arch/x86/net/bpf_jit_comp.c | 9 ++++++++- arch/x86/net/bpf_jit_comp32.c | 7 ++++++- 12 files changed, 91 insertions(+), 20 deletions(-)
arch/arc/net/bpf_jit_core.c +12 -7
@@ -1335,7 +1335,7 @@ static int jit_patch_relocations(struct jit_context *ctx)* to get the necessary data for the real compilation phase, * jit_compile(). */ -static struct bpf_prog *do_normal_pass (struct bpf_prog *prog) +static struct bpf_prog *do_normal_pass (struct bpf_prog *prog,int *err) {struct jit_context ctx;
@@ -1343,13 +1343,17 @@ static struct bpf_prog *do_normal_pass(struct bpf_prog *prog)if (!prog->jit_requested)return prog; -if (jit_ctx_init (&ctx, prog)) { + *err =jit_ctx_init (&ctx, prog); +if (*err) {jit_ctx_cleanup (&ctx);return prog; }/* Get the lengths and allocate buffer. */ -if (jit_prepare (&ctx)) { + *err =jit_prepare (&ctx); +if (*err) { +if (*err != -ENOMEM ) + *err =0 ;jit_ctx_cleanup (&ctx);return prog; }
@@ -1374,7 +1378,7 @@ static struct bpf_prog *do_normal_pass(struct bpf_prog *prog)* again to get the newly translated addresses in order to resolve * the "call"s. */ -static struct bpf_prog *do_extra_pass (struct bpf_prog *prog) +static struct bpf_prog *do_extra_pass (struct bpf_prog *prog,int *err) {struct jit_context ctx;
@@ -1382,7 +1386,8 @@ static struct bpf_prog *do_extra_pass(struct bpf_prog *prog)if (check_jit_context (prog))return prog; -if (jit_ctx_init (&ctx, prog)) { + *err =jit_ctx_init (&ctx, prog); +if (*err) {jit_ctx_cleanup (&ctx);return prog; }
@@ -1417,9 +1422,9 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog, int *err)/* Was this program already translated? */ if (!prog->jited) -return do_normal_pass (prog); +return do_normal_pass (prog, err);else -return do_extra_pass (prog); +return do_extra_pass (prog, err);return prog; }
arch/arm/net/bpf_jit_32.c +7 -1
@@ -2164,8 +2164,11 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog, int *err)*/ tmp =bpf_jit_blind_constants (prog); -if (IS_ERR (tmp)) +if (IS_ERR (tmp)) { +if (PTR_ERR (tmp) == -ENOMEM ) + *err = -ENOMEM ;return orig_prog; + }if (tmp != prog) { tmp_blinded = true; prog = tmp;
@@ -2180,6 +2183,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog, int *err)*/ ctx.offsets =kcalloc (prog->len,sizeof (int ),GFP_KERNEL );if (ctx.offsets ==NULL ) { + *err = -ENOMEM ; prog = orig_prog; goto out; }
@@ -2214,6 +2218,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog, int *err)if (ctx.imm_count) { ctx.imms =kcalloc (ctx.imm_count,sizeof (u32),GFP_KERNEL );if (ctx.imms ==NULL ) { + *err = -ENOMEM ; prog = orig_prog; goto out_off; }
@@ -2239,6 +2244,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog, int *err)* we must fall back to the interpretation */ if (header ==NULL ) { + *err = -ENOMEM ; prog = orig_prog; goto out_imms; }
arch/arm64/net/bpf_jit_comp.c +7 -1
@@ -1843,8 +1843,11 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog, int *err)/* If blinding was requested and we failed during blinding, * we must fall back to the interpreter. */ -if (IS_ERR (tmp)) +if (IS_ERR (tmp)) { +if (PTR_ERR (tmp) == -ENOMEM ) + *err = -ENOMEM ;return orig_prog; + }if (tmp != prog) { tmp_blinded = true; prog = tmp;
@@ -1854,6 +1857,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog, int *err)if (!jit_data) { jit_data =kzalloc (sizeof (*jit_data),GFP_KERNEL );if (!jit_data) { + *err = -ENOMEM ; prog = orig_prog; goto out; }
@@ -1875,6 +1879,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog, int *err) ctx.offset =kvcalloc (prog->len +1 ,sizeof (int ),GFP_KERNEL );if (ctx.offset ==NULL ) { + *err = -ENOMEM ; prog = orig_prog; goto out_off; }
@@ -1914,6 +1919,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog, int *err)sizeof (u32), &header, &image_ptr, jit_fill_hole);if (!ro_header) { + *err = -ENOMEM ; prog = orig_prog; goto out_off; }
arch/loongarch/net/bpf_jit.c +7 -1
@@ -1209,8 +1209,11 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog, int *err)* we must fall back to the interpreter. Otherwise, we save * the new JITed code. */ -if (IS_ERR (tmp)) +if (IS_ERR (tmp)) { +if (PTR_ERR (tmp) == -ENOMEM ) + *err = -ENOMEM ;return orig_prog; + }if (tmp != prog) { tmp_blinded = true;
@@ -1221,6 +1224,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog, int *err)if (!jit_data) { jit_data =kzalloc (sizeof (*jit_data),GFP_KERNEL );if (!jit_data) { + *err = -ENOMEM ; prog = orig_prog; goto out; }
@@ -1240,6 +1244,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog, int *err) ctx.offset =kvcalloc (prog->len +1 ,sizeof (u32),GFP_KERNEL );if (ctx.offset ==NULL ) { + *err = -ENOMEM ; prog = orig_prog; goto out_offset; }
@@ -1266,6 +1271,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog, int *err) header =bpf_jit_binary_alloc (image_size, &image_ptr,sizeof (u32), jit_fill_hole);if (header ==NULL ) { + *err = -ENOMEM ; prog = orig_prog; goto out_offset; }
arch/mips/net/bpf_jit_comp.c +10 -3
@@ -932,8 +932,11 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog, int *err)* the new JITed code. */ tmp =bpf_jit_blind_constants (prog); -if (IS_ERR (tmp)) +if (IS_ERR (tmp)) { +if (PTR_ERR (tmp) == -ENOMEM ) + *err = -ENOMEM ;return orig_prog; + }if (tmp != prog) { tmp_blinded = true; prog = tmp;
@@ -948,8 +951,10 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog, int *err)*/ ctx.descriptors =kcalloc (prog->len +1 ,sizeof (*ctx.descriptors),GFP_KERNEL ); -if (ctx.descriptors ==NULL ) +if (ctx.descriptors ==NULL ) { + *err = -ENOMEM ; goto out_err; + }/* First pass discovers used resources */ if (build_body (&ctx) <0 )
@@ -991,8 +996,10 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog, int *err)* Not able to allocate memory for the structure then * we must fall back to the interpretation */ -if (header ==NULL ) +if (header ==NULL ) { + *err = -ENOMEM ; goto out_err; + }/* Actual pass to generate final JIT code */ ctx.target = (u32 *)image_ptr;
arch/parisc/net/bpf_jit_core.c +7 -1
@@ -54,8 +54,11 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog, int *err)return orig_prog; tmp =bpf_jit_blind_constants (prog); -if (IS_ERR (tmp)) +if (IS_ERR (tmp)) { +if (PTR_ERR (tmp) == -ENOMEM ) + *err = -ENOMEM ;return orig_prog; + }if (tmp != prog) { tmp_blinded = true; prog = tmp;
@@ -65,6 +68,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog, int *err)if (!jit_data) { jit_data =kzalloc (sizeof (*jit_data),GFP_KERNEL );if (!jit_data) { + *err = -ENOMEM ; prog = orig_prog; goto out; }
@@ -82,6 +86,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog, int *err) ctx->prog = prog; ctx->offset =kcalloc (prog->len,sizeof (int ),GFP_KERNEL );if (!ctx->offset) { + *err = -ENOMEM ; prog = orig_prog; goto out_offset; }
@@ -117,6 +122,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog, int *err)sizeof (long ), bpf_fill_ill_insns);if (!jit_data->header) { + *err = -ENOMEM ; prog = orig_prog; goto out_offset; }
arch/powerpc/net/bpf_jit_comp.c +7 -1
@@ -155,8 +155,11 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp, int *err)return org_fp; tmp_fp =bpf_jit_blind_constants (org_fp); -if (IS_ERR (tmp_fp)) +if (IS_ERR (tmp_fp)) { +if (PTR_ERR (tmp_fp) == -ENOMEM ) + *err = -ENOMEM ;return org_fp; + }if (tmp_fp != org_fp) { bpf_blinded = true;
@@ -167,6 +170,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp, int *err)if (!jit_data) { jit_data =kzalloc (sizeof (*jit_data),GFP_KERNEL );if (!jit_data) { + *err = -ENOMEM ; fp = org_fp; goto out; }
@@ -195,6 +199,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp, int *err) addrs =kcalloc (flen +1 ,sizeof (*addrs),GFP_KERNEL );if (addrs ==NULL ) { + *err = -ENOMEM ; fp = org_fp; goto out_addrs; }
@@ -246,6 +251,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp, int *err) fhdr =bpf_jit_binary_pack_alloc (alloclen, &fimage,4 , &hdr, &image, bpf_jit_fill_ill_insns);if (!fhdr) { + *err = -ENOMEM ; fp = org_fp; goto out_addrs; }
arch/riscv/net/bpf_jit_core.c +7 -1
@@ -55,8 +55,11 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog, int *err)return orig_prog; tmp =bpf_jit_blind_constants (prog); -if (IS_ERR (tmp)) +if (IS_ERR (tmp)) { +if (PTR_ERR (tmp) == -ENOMEM ) + *err = -ENOMEM ;return orig_prog; + }if (tmp != prog) { tmp_blinded = true; prog = tmp;
@@ -66,6 +69,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog, int *err)if (!jit_data) { jit_data =kzalloc (sizeof (*jit_data),GFP_KERNEL );if (!jit_data) { + *err = -ENOMEM ; prog = orig_prog; goto out; }
@@ -85,6 +89,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog, int *err) ctx->prog = prog; ctx->offset =kcalloc (prog->len,sizeof (int ),GFP_KERNEL );if (!ctx->offset) { + *err = -ENOMEM ; prog = orig_prog; goto out_offset; }
@@ -128,6 +133,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog, int *err) &jit_data->header, &jit_data->image, bpf_fill_ill_insns);if (!jit_data->ro_header) { + *err = -ENOMEM ; prog = orig_prog; goto out_offset; }
arch/s390/net/bpf_jit_comp.c +6 -1
@@ -2274,8 +2274,11 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp, int *err)* If blinding was requested and we failed during blinding, * we must fall back to the interpreter. */ -if (IS_ERR (tmp)) +if (IS_ERR (tmp)) { +if (PTR_ERR (tmp) == -ENOMEM ) + *err = -ENOMEM ;return orig_fp; + }if (tmp != fp) { tmp_blinded = true; fp = tmp;
@@ -2285,6 +2288,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp, int *err)if (!jit_data) { jit_data =kzalloc (sizeof (*jit_data),GFP_KERNEL );if (!jit_data) { + *err = -ENOMEM ; fp = orig_fp; goto out; }
@@ -2301,6 +2305,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp, int *err)memset (&jit,0 ,sizeof (jit)); jit.addrs =kvcalloc (fp->len +1 ,sizeof (*jit.addrs),GFP_KERNEL );if (jit.addrs ==NULL ) { + *err = -ENOMEM ; fp = orig_fp; goto free_addrs; }
arch/sparc/net/bpf_jit_comp_64.c +7 -1
@@ -1496,8 +1496,11 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog, int *err)/* If blinding was requested and we failed during blinding, * we must fall back to the interpreter. */ -if (IS_ERR (tmp)) +if (IS_ERR (tmp)) { +if (PTR_ERR (tmp) == -ENOMEM ) + *err = -ENOMEM ;return orig_prog; + }if (tmp != prog) { tmp_blinded = true; prog = tmp;
@@ -1507,6 +1510,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog, int *err)if (!jit_data) { jit_data =kzalloc (sizeof (*jit_data),GFP_KERNEL );if (!jit_data) { + *err = -ENOMEM ; prog = orig_prog; goto out; }
@@ -1528,6 +1532,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog, int *err) ctx.offset =kmalloc_array (prog->len,sizeof (unsigned int ),GFP_KERNEL );if (ctx.offset ==NULL ) { + *err = -ENOMEM ; prog = orig_prog; goto out_off; }
@@ -1570,6 +1575,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog, int *err) header =bpf_jit_binary_alloc (image_size, &image_ptr,sizeof (u32), jit_fill_hole);if (header ==NULL ) { + *err = -ENOMEM ; prog = orig_prog; goto out_off; }
arch/x86/net/bpf_jit_comp.c +8 -1
@@ -3522,8 +3522,11 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog, int *err)* If blinding was requested and we failed during blinding, * we must fall back to the interpreter. */ -if (IS_ERR (tmp)) +if (IS_ERR (tmp)) { +if (PTR_ERR (tmp) == -ENOMEM ) + *err = -ENOMEM ;return orig_prog; + }if (tmp != prog) { tmp_blinded = true; prog = tmp;
@@ -3533,6 +3536,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog, int *err)if (!jit_data) { jit_data =kzalloc (sizeof (*jit_data),GFP_KERNEL );if (!jit_data) { + *err = -ENOMEM ; prog = orig_prog; goto out; }
@@ -3548,6 +3552,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog, int *err)2 *PRIV_STACK_GUARD_SZ ; priv_stack_ptr =__alloc_percpu_gfp (priv_stack_alloc_sz,8 ,GFP_KERNEL );if (!priv_stack_ptr) { + *err = -ENOMEM ; prog = orig_prog; goto out_priv_stack; }
@@ -3569,6 +3574,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog, int *err) } addrs =kvmalloc_array (prog->len +1 ,sizeof (*addrs),GFP_KERNEL );if (!addrs) { + *err = -ENOMEM ; prog = orig_prog; goto out_addrs; }
@@ -3635,6 +3641,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog, int *err) &image, align, &rw_header, &rw_image, jit_fill_hole);if (!header) { + *err = -ENOMEM ; prog = orig_prog; goto out_addrs; }
arch/x86/net/bpf_jit_comp32.c +6 -1
@@ -2538,8 +2538,11 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog, int *err)* If blinding was requested and we failed during blinding, * we must fall back to the interpreter. */ -if (IS_ERR (tmp)) +if (IS_ERR (tmp)) { +if (PTR_ERR (tmp) == -ENOMEM ) + *err = -ENOMEM ;return orig_prog; + }if (tmp != prog) { tmp_blinded = true; prog = tmp;
@@ -2547,6 +2550,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog, int *err) addrs =kmalloc_array (prog->len,sizeof (*addrs),GFP_KERNEL );if (!addrs) { + *err = -ENOMEM ; prog = orig_prog; goto out; }
@@ -2589,6 +2593,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog, int *err) header =bpf_jit_binary_alloc (proglen, &image,1 , jit_fill_hole);if (!header) { + *err = -ENOMEM ; prog = orig_prog; goto out_addrs; }
Signature · 1 line
2.49.0
Re: [PATCH v1 bpf 2/2] bpf: Set -ENOMEM to err in bpf_int_jit_compile().
Quoted 75 lines · Kuniyuki Iwashima
syzkaller reported a splat below. [0]
It always followed another splat by fault injection in
bpf_int_jit_compile(). [1]Instead of proceeding with
__bpf_prog_ret0_warn()and seeing a splat later, let's return-ENOMEMto userspace.[0]:
WARNING: CPU: 1 PID: 36 at kernel/bpf/core.c:2357 __bpf_prog_ret0_warn+0xa/0x10 kernel/bpf/core.c:2357 Modules linked in: CPU: 1 UID: 0 PID: 36 Comm: kworker/1:1 Not tainted 6.14.0-13344-ga9843689e2de #28 PREEMPT(voluntary) 167b7ecb8f281ed56016416cdf1d8bb342db88fc Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.3-0-ga6ed6b701f0a-prebuilt.qemu.org 04/01/2014 Workqueue: mld mld_ifc_work RIP: 0010:__bpf_prog_ret0_warn+0xa/0x10 kernel/bpf/core.c:2357 Code: ff eb 84 e8 b8 cf ee ff e9 7a ff ff ff e8 ae cf ee ff e9 70 ff ff ff 66 0f 1f 84 00 00 00 00 00 f3 0f 1e fa e8 97 cf ee ff 90 <0f> 0b 90 31 c0 c3 f3 0f 1e fa 55 48 89 e5 41 57 41 56 41 55 41 54 RSP: 0000:ffa0000000267050 EFLAGS: 00010293 RAX: ffffffff81881569 RBX: ffa0000000393030 RCX: ff11000100dc4500 RDX: 0000000000000000 RSI: ffa0000000393048 RDI: ff1100010b812a00 RBP: 0000000000000000 R08: 0000000000000002 R09: 0000000000000000 R10: dffffc0000000000 R11: fffffbfff0e5ef77 R12: 0000000000000000 R13: dffffc0000000000 R14: ff1100010b812a00 R15: ffa0000000393048 FS: 0000000000000000(0000) GS:ff11000192213000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007ff451d686ec CR3: 00000001037eb004 CR4: 0000000000771ef0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe07f0 DR7: 0000000000000600 PKRU: 55555554 Call Trace: <TASK> bpf_dispatcher_nop_func include/linux/bpf.h:1316 [inline] __bpf_prog_run include/linux/filter.h:718 [inline] bpf_prog_run include/linux/filter.h:725 [inline] bpf_prog_run_pin_on_cpu include/linux/filter.h:742 [inline] bpf_prog_run_clear_cb+0x7f/0x140 include/linux/filter.h:983 run_filter+0x156/0x260 net/packet/af_packet.c:2135 packet_rcv+0x491/0x15b0 net/packet/af_packet.c:2208 dev_queue_xmit_nit+0xc27/0xcb0 net/core/dev.c:2592 xmit_one net/core/dev.c:3831 [inline] dev_hard_start_xmit+0x1d5/0x720 net/core/dev.c:3851 sch_direct_xmit+0x242/0x4a0 net/sched/sch_generic.c:343 __dev_xmit_skb net/core/dev.c:4127 [inline] __dev_queue_xmit+0x186d/0x37a0 net/core/dev.c:4654 dev_queue_xmit include/linux/netdevice.h:3355 [inline] neigh_hh_output include/net/neighbour.h:523 [inline] neigh_output include/net/neighbour.h:537 [inline] ip6_finish_output2+0x11f3/0x16e0 net/ipv6/ip6_output.c:141 dst_output include/net/dst.h:459 [inline] NF_HOOK+0x160/0x470 include/linux/netfilter.h:314 mld_sendpack+0x7f7/0xd70 net/ipv6/mcast.c:1868 mld_send_cr net/ipv6/mcast.c:2169 [inline] mld_ifc_work+0x835/0xde0 net/ipv6/mcast.c:2702 process_one_work kernel/workqueue.c:3238 [inline] process_scheduled_works+0xa77/0x16a0 kernel/workqueue.c:3319 worker_thread+0x8b6/0xd50 kernel/workqueue.c:3400 kthread+0x413/0x870 kernel/kthread.c:464 ret_from_fork+0x48/0x80 arch/x86/kernel/process.c:153 ret_from_fork_asm+0x11/0x20 arch/x86/entry/entry_64.S:245 </TASK>[1]:
FAULT_INJECTION: forcing a failure.
name failslab, interval 1, probability 0, space 0, times 1CPU: 1 UID: 0 PID: 4562 Comm: syz.4.1225 Not tainted 6.14.0-13344-ga9843689e2de #28 PREEMPT(voluntary) 167b7ecb8f281ed56016416cdf1d8bb342db88fc Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.3-0-ga6ed6b701f0a-prebuilt.qemu.org 04/01/2014 Call Trace: <TASK> dump_stack_lvl+0xfa/0x120 should_fail_ex+0x501/0x610 should_failslab+0xba/0x120 __kmalloc_cache_noprof+0x5d/0x310 bpf_int_jit_compile+0x1292/0x18b0 bpf_prog_select_runtime+0x439/0x780
Quoted 1 line
Fixes fa9dd599b4da ("bpf: get rid of pure_initcall dependency to enable jits")
The Fixes tag looks wrong and I suspect you root caused it incorrectly and the "fix" adds a ton of churn for no good reason.
If CONFIG_BPF_JIT_ALWAYS_ON=y and JIT fails for whatever reason the following should have executed:
fp = bpf_int_jit_compile(fp);
bpf_prog_jit_attempt_done(fp);
if (!fp->jited && jit_needed) {
*err = -ENOTSUPP;
return fp;
}so the prog won't load and won't execute.
jit_needed will be false if CONFIG_BPF_JIT_ALWAYS_ON=n and if fp->jit_requested == true then ret0_warn may indeed stay.
Then the fix is probably just this hunk:
kernel/bpf/core.c +0 -0
@@ -2493,7 +2493,7 @@ struct bpf_prog *bpf_prog_select_runtime(struct
bpf_prog *fp, int *err)
fp = bpf_int_jit_compile(fp);
bpf_prog_jit_attempt_done(fp);- if (!fp->jited && jit_needed) {
+ if (!fp->jited && (fp->jit_requested || jit_needed)) {
or maybe this instead:
- bool jit_needed = false;
+ bool jit_needed = fp->jit_requested;
pw-bot: cr
Re: [PATCH v1 bpf 2/2] bpf: Set -ENOMEM to err in bpf_int_jit_compile().
From: Alexei Starovoitov <[email protected]>
Date: Mon, 14 Apr 2025 15:32:21 -0700
[...]
Quoted 6 lines
Quoted 4 lines
bpf_int_jit_compile+0x1292/0x18b0 bpf_prog_select_runtime+0x439/0x780Fixes fa9dd599b4da ("bpf: get rid of pure_initcall dependency to enable jits")The Fixes tag looks wrong and I suspect you root caused it incorrectly
I chose this one as it added WARN_ON_ONCE(), but if we go back to the first invocation of bpf_int_jit_compile(), the tag will be
?
FWIW, syzkaller reported the same splat in the seccomp path too.
Quoted 30 lines
and the "fix" adds a ton of churn for no good reason.
If
CONFIG_BPF_JIT_ALWAYS_ON=yand JIT fails for whatever reason the following should have executed:fp = bpf_int_jit_compile(fp); bpf_prog_jit_attempt_done(fp); if (!fp->jited && jit_needed) { *err = -ENOTSUPP; return fp; }so the prog won't load and won't execute.
jit_neededwill be false ifCONFIG_BPF_JIT_ALWAYS_ON=nand iffp->jit_requested== true thenret0_warnmay indeed stay.Then the fix is probably just this hunk:
kernel/bpf/core.c +1
-1@@ -2493,7 +2493,7 @@ struct bpf_prog *bpf_prog_select_runtime(struct bpf_prog *fp, int *err) fp =bpf_int_jit_compile (fp);bpf_prog_jit_attempt_done (fp); -if (!fp->jited && jit_needed) { +if (!fp->jited && (fp->jit_requested || jit_needed)) {or maybe this instead:
kernel/bpf/core.c
Quoted 2 lines
kernel/bpf/core.c +1
-1-bool jit_needed = false; +bool jit_needed = fp->jit_requested;
This looks much cleaner, will use this in v2.
Thanks!
Re: [PATCH v1 bpf 2/2] bpf: Set -ENOMEM to err in bpf_int_jit_compile().
Quoted 9 lines · Kuniyuki Iwashima
From: Alexei Starovoitov <[email protected]>
Date: Mon, 14 Apr 2025 15:32:21 -0700
[...]Quoted 5 lines
Quoted 4 lines
bpf_int_jit_compile+0x1292/0x18b0 bpf_prog_select_runtime+0x439/0x780Fixes fa9dd599b4da ("bpf: get rid of pure_initcall dependency to enable jits")
Quoted 8 lines
Quoted 1 line
The Fixes tag looks wrong and I suspect you root caused it incorrectly
I chose this one as it added
WARN_ON_ONCE(), but if we go back to the first invocation ofbpf_int_jit_compile(), the tag will beFixes 8f577cadf718 ("seccomp: JIT compile seccomp filter")Fixes 622582786c9e ("net: filter: x86: internal BPF JIT")
That would be wrong as well. There are no issues in the above two commits.
Let's keep Fixes: fa9dd599b4da
though it's not accurate, no one will be backporting that far anyway.
Quoted 41 lines
?
FWIW, syzkaller reported the same splat in the seccomp path too.
Quoted 30 lines
and the "fix" adds a ton of churn for no good reason.
If
CONFIG_BPF_JIT_ALWAYS_ON=yand JIT fails for whatever reason the following should have executed:fp = bpf_int_jit_compile(fp); bpf_prog_jit_attempt_done(fp); if (!fp->jited && jit_needed) { *err = -ENOTSUPP; return fp; }so the prog won't load and won't execute.
jit_neededwill be false ifCONFIG_BPF_JIT_ALWAYS_ON=nand iffp->jit_requested== true thenret0_warnmay indeed stay.Then the fix is probably just this hunk:
kernel/bpf/core.c +1
-1@@ -2493,7 +2493,7 @@ struct bpf_prog *bpf_prog_select_runtime(struct bpf_prog *fp, int *err) fp =bpf_int_jit_compile (fp);bpf_prog_jit_attempt_done (fp); -if (!fp->jited && jit_needed) { +if (!fp->jited && (fp->jit_requested || jit_needed)) {or maybe this instead:
kernel/bpf/core.c
Quoted 2 lines
kernel/bpf/core.c +1
-1-bool jit_needed = false; +bool jit_needed = fp->jit_requested;This looks much cleaner, will use this in v2.
Thanks!