Skip to content

Commit 469fb2c

Browse files
Pu LehuiAlexei Starovoitov
authored andcommitted
riscv, bpf: Fix missing exception handling and redundant zext for LDX_B/H/W
For LDX_B/H/W, when zext has been inserted by verifier, it'll return 1, and no exception handling will continue. Also, when the offset is 12-bit value, the redundant zext inserted by the verifier is not removed. Fix both scenarios by moving down the removal of redundant zext. Signed-off-by: Pu Lehui <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 1b580c9 commit 469fb2c

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

arch/riscv/net/bpf_jit_comp64.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,8 +1512,6 @@ int bpf_jit_emit_insn(const struct bpf_insn *insn, struct rv_jit_context *ctx,
15121512
insns_start = ctx->ninsns;
15131513
emit(rv_lbu(rd, 0, RV_REG_T1), ctx);
15141514
insn_len = ctx->ninsns - insns_start;
1515-
if (insn_is_zext(&insn[1]))
1516-
return 1;
15171515
break;
15181516
case BPF_H:
15191517
if (is_12b_int(off)) {
@@ -1528,8 +1526,6 @@ int bpf_jit_emit_insn(const struct bpf_insn *insn, struct rv_jit_context *ctx,
15281526
insns_start = ctx->ninsns;
15291527
emit(rv_lhu(rd, 0, RV_REG_T1), ctx);
15301528
insn_len = ctx->ninsns - insns_start;
1531-
if (insn_is_zext(&insn[1]))
1532-
return 1;
15331529
break;
15341530
case BPF_W:
15351531
if (is_12b_int(off)) {
@@ -1544,8 +1540,6 @@ int bpf_jit_emit_insn(const struct bpf_insn *insn, struct rv_jit_context *ctx,
15441540
insns_start = ctx->ninsns;
15451541
emit(rv_lwu(rd, 0, RV_REG_T1), ctx);
15461542
insn_len = ctx->ninsns - insns_start;
1547-
if (insn_is_zext(&insn[1]))
1548-
return 1;
15491543
break;
15501544
case BPF_DW:
15511545
if (is_12b_int(off)) {
@@ -1566,6 +1560,9 @@ int bpf_jit_emit_insn(const struct bpf_insn *insn, struct rv_jit_context *ctx,
15661560
ret = add_exception_handler(insn, ctx, rd, insn_len);
15671561
if (ret)
15681562
return ret;
1563+
1564+
if (BPF_SIZE(code) != BPF_DW && insn_is_zext(&insn[1]))
1565+
return 1;
15691566
break;
15701567
}
15711568
/* speculation barrier */

0 commit comments

Comments
 (0)