@@ -5877,7 +5877,7 @@ static int update_alu_sanitation_state(struct bpf_insn_aux_data *aux,
58775877 aux -> alu_limit != alu_limit ))
58785878 return - EACCES ;
58795879
5880- /* Corresponding fixup done in fixup_bpf_calls (). */
5880+ /* Corresponding fixup done in do_misc_fixups (). */
58815881 aux -> alu_state = alu_state ;
58825882 aux -> alu_limit = alu_limit ;
58835883 return 0 ;
@@ -11535,12 +11535,10 @@ static int fixup_call_args(struct bpf_verifier_env *env)
1153511535 return err ;
1153611536}
1153711537
11538- /* fixup insn->imm field of bpf_call instructions
11539- * and inline eligible helpers as explicit sequence of BPF instructions
11540- *
11541- * this function is called after eBPF program passed verification
11538+ /* Do various post-verification rewrites in a single program pass.
11539+ * These rewrites simplify JIT and interpreter implementations.
1154211540 */
11543- static int fixup_bpf_calls (struct bpf_verifier_env * env )
11541+ static int do_misc_fixups (struct bpf_verifier_env * env )
1154411542{
1154511543 struct bpf_prog * prog = env -> prog ;
1154611544 bool expect_blinding = bpf_jit_blinding_enabled (prog );
@@ -11555,6 +11553,7 @@ static int fixup_bpf_calls(struct bpf_verifier_env *env)
1155511553 int i , ret , cnt , delta = 0 ;
1155611554
1155711555 for (i = 0 ; i < insn_cnt ; i ++ , insn ++ ) {
11556+ /* Make divide-by-zero exceptions impossible. */
1155811557 if (insn -> code == (BPF_ALU64 | BPF_MOD | BPF_X ) ||
1155911558 insn -> code == (BPF_ALU64 | BPF_DIV | BPF_X ) ||
1156011559 insn -> code == (BPF_ALU | BPF_MOD | BPF_X ) ||
@@ -11595,6 +11594,7 @@ static int fixup_bpf_calls(struct bpf_verifier_env *env)
1159511594 continue ;
1159611595 }
1159711596
11597+ /* Implement LD_ABS and LD_IND with a rewrite, if supported by the program type. */
1159811598 if (BPF_CLASS (insn -> code ) == BPF_LD &&
1159911599 (BPF_MODE (insn -> code ) == BPF_ABS ||
1160011600 BPF_MODE (insn -> code ) == BPF_IND )) {
@@ -11614,6 +11614,7 @@ static int fixup_bpf_calls(struct bpf_verifier_env *env)
1161411614 continue ;
1161511615 }
1161611616
11617+ /* Rewrite pointer arithmetic to mitigate speculation attacks. */
1161711618 if (insn -> code == (BPF_ALU64 | BPF_ADD | BPF_X ) ||
1161811619 insn -> code == (BPF_ALU64 | BPF_SUB | BPF_X )) {
1161911620 const u8 code_add = BPF_ALU64 | BPF_ADD | BPF_X ;
@@ -11835,6 +11836,7 @@ static int fixup_bpf_calls(struct bpf_verifier_env *env)
1183511836 goto patch_call_imm ;
1183611837 }
1183711838
11839+ /* Implement bpf_jiffies64 inline. */
1183811840 if (prog -> jit_requested && BITS_PER_LONG == 64 &&
1183911841 insn -> imm == BPF_FUNC_jiffies64 ) {
1184011842 struct bpf_insn ld_jiffies_addr [2 ] = {
@@ -12645,7 +12647,7 @@ int bpf_check(struct bpf_prog **prog, union bpf_attr *attr,
1264512647 ret = convert_ctx_accesses (env );
1264612648
1264712649 if (ret == 0 )
12648- ret = fixup_bpf_calls (env );
12650+ ret = do_misc_fixups (env );
1264912651
1265012652 /* do 32-bit optimization after insn patching has done so those patched
1265112653 * insns could be handled correctly.
0 commit comments