The interpreter does not recognize the BPF_PROBE_ATOMIC insn.
Thereafter, it would hit the BUG_ON() in ___bpf_prog_run() at run time.

[    2.617849] BPF interpreter: unknown opcode e3 (imm: 0x110)
[    2.618643] ------------[ cut here ]------------
[    2.619277] kernel BUG at kernel/bpf/core.c:2349!
[    2.619928] Oops: invalid opcode: 0000 [#1] SMP PTI

On the fallback path from JIT in __bpf_prog_select_runtime(), reject
the BPF_PROBE_ATOMIC insn to avoid the BUG.

Fixes: d503a04f8bc0 ("bpf: Add support for certain atomics in bpf_arena to x86 
JIT")
Signed-off-by: Leon Hwang <[email protected]>
---
 kernel/bpf/core.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index 900ba10e1de9..778ae565ebbe 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -2627,6 +2627,9 @@ static bool bpf_insn_requires_jit(struct bpf_insn *insn)
                    BPF_CLASS(insn->code) == BPF_LDX &&
                    BPF_SIZE(insn->code) != BPF_DW)
                        return true;
+               /* BPF_LOAD_ACQ, BPF_STORE_REL insns */
+               if (BPF_MODE(insn->code) == BPF_PROBE_ATOMIC)
+                       return true;
                break;
        default:
                return false;
-- 
2.54.0


Reply via email to