From: George Guo The JIT does not implement atomics on arena pointers (BPF_PROBE_ATOMIC) nor sign-extending loads from the arena (BPF_PROBE_MEM32SX). Without a bpf_jit_supports_insn() callback the verifier assumes both are available, so such programs are accepted only to fail later in the JIT with a confusing -EINVAL 'unknown opcode'. Implement bpf_jit_supports_insn() to reject these instructions in the arena case. The verifier then rejects the program early with a clear message ('BPF_ATOMIC stores into R ... is not allowed' / 'sign extending loads from arena are not supported yet'). Regular arena accesses (BPF_PROBE_MEM32 loads/stores of all sizes) remain supported. Signed-off-by: George Guo --- arch/loongarch/net/bpf_jit.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/arch/loongarch/net/bpf_jit.c b/arch/loongarch/net/bpf_jit.c index 24913dc7f4e8..3f9ffdde2491 100644 --- a/arch/loongarch/net/bpf_jit.c +++ b/arch/loongarch/net/bpf_jit.c @@ -2357,6 +2357,26 @@ bool bpf_jit_supports_arena(void) return true; } +bool bpf_jit_supports_insn(struct bpf_insn *insn, bool in_arena) +{ + if (!in_arena) + return true; + + switch (insn->code) { + case BPF_STX | BPF_ATOMIC | BPF_W: + case BPF_STX | BPF_ATOMIC | BPF_DW: + /* Atomics on arena pointers are not implemented yet. */ + return false; + case BPF_LDX | BPF_MEMSX | BPF_B: + case BPF_LDX | BPF_MEMSX | BPF_H: + case BPF_LDX | BPF_MEMSX | BPF_W: + /* Sign-extending loads from arena are not implemented yet. */ + return false; + } + + return true; +} + bool bpf_jit_supports_fsession(void) { return true; -- 2.25.1