Skip to content

Commit 7058e3a

Browse files
Yonghong SongAlexei Starovoitov
Yonghong Song
authored and
Alexei Starovoitov
committed
bpf: Fix jit blinding with new sdiv/smov insns
Handle new insns properly in bpf_jit_blind_insn() function. Acked-by: Eduard Zingerman <[email protected]> Signed-off-by: Yonghong Song <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent ec0e2da commit 7058e3a

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

include/linux/filter.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,22 +93,28 @@ struct ctl_table_header;
9393

9494
/* ALU ops on registers, bpf_add|sub|...: dst_reg += src_reg */
9595

96-
#define BPF_ALU64_REG(OP, DST, SRC) \
96+
#define BPF_ALU64_REG_OFF(OP, DST, SRC, OFF) \
9797
((struct bpf_insn) { \
9898
.code = BPF_ALU64 | BPF_OP(OP) | BPF_X, \
9999
.dst_reg = DST, \
100100
.src_reg = SRC, \
101-
.off = 0, \
101+
.off = OFF, \
102102
.imm = 0 })
103103

104-
#define BPF_ALU32_REG(OP, DST, SRC) \
104+
#define BPF_ALU64_REG(OP, DST, SRC) \
105+
BPF_ALU64_REG_OFF(OP, DST, SRC, 0)
106+
107+
#define BPF_ALU32_REG_OFF(OP, DST, SRC, OFF) \
105108
((struct bpf_insn) { \
106109
.code = BPF_ALU | BPF_OP(OP) | BPF_X, \
107110
.dst_reg = DST, \
108111
.src_reg = SRC, \
109-
.off = 0, \
112+
.off = OFF, \
110113
.imm = 0 })
111114

115+
#define BPF_ALU32_REG(OP, DST, SRC) \
116+
BPF_ALU32_REG_OFF(OP, DST, SRC, 0)
117+
112118
/* ALU ops on immediates, bpf_add|sub|...: dst_reg += imm32 */
113119

114120
#define BPF_ALU64_IMM(OP, DST, IMM) \

kernel/bpf/core.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,7 +1272,7 @@ static int bpf_jit_blind_insn(const struct bpf_insn *from,
12721272
case BPF_ALU | BPF_MOD | BPF_K:
12731273
*to++ = BPF_ALU32_IMM(BPF_MOV, BPF_REG_AX, imm_rnd ^ from->imm);
12741274
*to++ = BPF_ALU32_IMM(BPF_XOR, BPF_REG_AX, imm_rnd);
1275-
*to++ = BPF_ALU32_REG(from->code, from->dst_reg, BPF_REG_AX);
1275+
*to++ = BPF_ALU32_REG_OFF(from->code, from->dst_reg, BPF_REG_AX, from->off);
12761276
break;
12771277

12781278
case BPF_ALU64 | BPF_ADD | BPF_K:
@@ -1286,7 +1286,7 @@ static int bpf_jit_blind_insn(const struct bpf_insn *from,
12861286
case BPF_ALU64 | BPF_MOD | BPF_K:
12871287
*to++ = BPF_ALU64_IMM(BPF_MOV, BPF_REG_AX, imm_rnd ^ from->imm);
12881288
*to++ = BPF_ALU64_IMM(BPF_XOR, BPF_REG_AX, imm_rnd);
1289-
*to++ = BPF_ALU64_REG(from->code, from->dst_reg, BPF_REG_AX);
1289+
*to++ = BPF_ALU64_REG_OFF(from->code, from->dst_reg, BPF_REG_AX, from->off);
12901290
break;
12911291

12921292
case BPF_JMP | BPF_JEQ | BPF_K:

0 commit comments

Comments
 (0)