Skip to content

Commit 7ebd35b

Browse files
Xu KuohaiKernel Patches Daemon
authored andcommitted
bpf, arm64: Emit BTI for indirect jump target
On CPUs that support BTI, the indirect jump selftest triggers a kernel panic because there is no BTI instructions at the indirect jump targets. Fix it by emitting a BTI instruction for each indirect jump target. For reference, below is a sample panic log. Internal error: Oops - BTI: 0000000036000003 [#1] SMP ... Call trace: bpf_prog_2e5f1c71c13ac3e0_big_jump_table+0x54/0xf8 (P) bpf_prog_run_pin_on_cpu+0x140/0x468 bpf_prog_test_run_syscall+0x280/0x3b8 bpf_prog_test_run+0x22c/0x2c0 Fixes: f4a66cf ("bpf: arm64: Add support for indirect jumps") Reviewed-by: Anton Protopopov <[email protected]> Signed-off-by: Xu Kuohai <[email protected]>
1 parent 4228152 commit 7ebd35b

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

arch/arm64/net/bpf_jit_comp.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,8 +1198,8 @@ static int add_exception_handler(const struct bpf_insn *insn,
11981198
* >0 - successfully JITed a 16-byte eBPF instruction.
11991199
* <0 - failed to JIT.
12001200
*/
1201-
static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx,
1202-
bool extra_pass)
1201+
static int build_insn(const struct bpf_verifier_env *env, const struct bpf_insn *insn,
1202+
struct jit_ctx *ctx, bool extra_pass)
12031203
{
12041204
const u8 code = insn->code;
12051205
u8 dst = bpf2a64[insn->dst_reg];
@@ -1224,6 +1224,9 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx,
12241224
int ret;
12251225
bool sign_extend;
12261226

1227+
if (bpf_insn_is_indirect_target(env, ctx->prog, i))
1228+
emit_bti(A64_BTI_J, ctx);
1229+
12271230
switch (code) {
12281231
/* dst = src */
12291232
case BPF_ALU | BPF_MOV | BPF_X:
@@ -1899,7 +1902,7 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx,
18991902
return 0;
19001903
}
19011904

1902-
static int build_body(struct jit_ctx *ctx, bool extra_pass)
1905+
static int build_body(struct bpf_verifier_env *env, struct jit_ctx *ctx, bool extra_pass)
19031906
{
19041907
const struct bpf_prog *prog = ctx->prog;
19051908
int i;
@@ -1918,7 +1921,7 @@ static int build_body(struct jit_ctx *ctx, bool extra_pass)
19181921
int ret;
19191922

19201923
ctx->offset[i] = ctx->idx;
1921-
ret = build_insn(insn, ctx, extra_pass);
1924+
ret = build_insn(env, insn, ctx, extra_pass);
19221925
if (ret > 0) {
19231926
i++;
19241927
ctx->offset[i] = ctx->idx;
@@ -2079,7 +2082,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_verifier_env *env, struct bpf_pr
20792082
if (build_prologue(&ctx, was_classic))
20802083
goto out_off;
20812084

2082-
if (build_body(&ctx, extra_pass))
2085+
if (build_body(env, &ctx, extra_pass))
20832086
goto out_off;
20842087

20852088
ctx.epilogue_offset = ctx.idx;
@@ -2127,7 +2130,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_verifier_env *env, struct bpf_pr
21272130
/* Dont write body instructions to memory for now */
21282131
ctx.write = false;
21292132

2130-
if (build_body(&ctx, extra_pass))
2133+
if (build_body(env, &ctx, extra_pass))
21312134
goto out_free_hdr;
21322135

21332136
ctx.epilogue_offset = ctx.idx;
@@ -2136,7 +2139,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_verifier_env *env, struct bpf_pr
21362139
ctx.write = true;
21372140

21382141
/* Pass 3: Adjust jump offset and write final image */
2139-
if (build_body(&ctx, extra_pass) ||
2142+
if (build_body(env, &ctx, extra_pass) ||
21402143
WARN_ON_ONCE(ctx.idx != ctx.epilogue_offset))
21412144
goto out_free_hdr;
21422145

0 commit comments

Comments
 (0)