File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -1450,6 +1450,23 @@ void bpf_jit_prog_release_other(struct bpf_prog *fp, struct bpf_prog *fp_other)
14501450 bpf_prog_clone_free (fp_other );
14511451}
14521452
1453+ static void adjust_insn_arrays (struct bpf_prog * prog , u32 off , u32 len )
1454+ {
1455+ #ifdef CONFIG_BPF_SYSCALL
1456+ struct bpf_map * map ;
1457+ int i ;
1458+
1459+ if (len <= 1 )
1460+ return ;
1461+
1462+ for (i = 0 ; i < prog -> aux -> used_map_cnt ; i ++ ) {
1463+ map = prog -> aux -> used_maps [i ];
1464+ if (map -> map_type == BPF_MAP_TYPE_INSN_ARRAY )
1465+ bpf_insn_array_adjust (map , off , len );
1466+ }
1467+ #endif
1468+ }
1469+
14531470struct bpf_prog * bpf_jit_blind_constants (struct bpf_prog * prog )
14541471{
14551472 struct bpf_insn insn_buff [16 ], aux [2 ];
@@ -1505,6 +1522,9 @@ struct bpf_prog *bpf_jit_blind_constants(struct bpf_prog *prog)
15051522 clone = tmp ;
15061523 insn_delta = rewritten - 1 ;
15071524
1525+ /* Instructions arrays must be updated using absolute xlated offsets */
1526+ adjust_insn_arrays (clone , prog -> aux -> subprog_start + i , rewritten );
1527+
15081528 /* Walk new program and skip insns we just inserted. */
15091529 insn = clone -> insnsi + i + insn_delta ;
15101530 insn_cnt += insn_delta ;
Original file line number Diff line number Diff line change @@ -21632,6 +21632,7 @@ static int jit_subprogs(struct bpf_verifier_env *env)
2163221632 struct bpf_insn *insn;
2163321633 void *old_bpf_func;
2163421634 int err, num_exentries;
21635+ int old_len, subprog_start_adjustment = 0;
2163521636
2163621637 if (env->subprog_cnt <= 1)
2163721638 return 0;
@@ -21706,7 +21707,7 @@ static int jit_subprogs(struct bpf_verifier_env *env)
2170621707 func[i]->aux->func_idx = i;
2170721708 /* Below members will be freed only at prog->aux */
2170821709 func[i]->aux->btf = prog->aux->btf;
21709- func[i]->aux->subprog_start = subprog_start;
21710+ func[i]->aux->subprog_start = subprog_start + subprog_start_adjustment ;
2171021711 func[i]->aux->func_info = prog->aux->func_info;
2171121712 func[i]->aux->func_info_cnt = prog->aux->func_info_cnt;
2171221713 func[i]->aux->poke_tab = prog->aux->poke_tab;
@@ -21762,7 +21763,15 @@ static int jit_subprogs(struct bpf_verifier_env *env)
2176221763 func[i]->aux->might_sleep = env->subprog_info[i].might_sleep;
2176321764 if (!i)
2176421765 func[i]->aux->exception_boundary = env->seen_exception;
21766+
21767+ /*
21768+ * To properly pass the absolute subprog start to jit
21769+ * all instruction adjustments should be accumulated
21770+ */
21771+ old_len = func[i]->len;
2176521772 func[i] = bpf_int_jit_compile(func[i]);
21773+ subprog_start_adjustment += func[i]->len - old_len;
21774+
2176621775 if (!func[i]->jited) {
2176721776 err = -ENOTSUPP;
2176821777 goto out_free;
You can’t perform that action at this time.
0 commit comments