File tree Expand file tree Collapse file tree 1 file changed +24
-4
lines changed Expand file tree Collapse file tree 1 file changed +24
-4
lines changed Original file line number Diff line number Diff line change @@ -2597,16 +2597,36 @@ static int cmp_subprogs(const void *a, const void *b)
2597
2597
((struct bpf_subprog_info *)b)->start;
2598
2598
}
2599
2599
2600
+ /* Find subprogram that contains instruction at 'off' */
2601
+ static struct bpf_subprog_info *find_containing_subprog(struct bpf_verifier_env *env, int off)
2602
+ {
2603
+ struct bpf_subprog_info *vals = env->subprog_info;
2604
+ int l, r, m;
2605
+
2606
+ if (off >= env->prog->len || off < 0 || env->subprog_cnt == 0)
2607
+ return NULL;
2608
+
2609
+ l = 0;
2610
+ r = env->subprog_cnt - 1;
2611
+ while (l < r) {
2612
+ m = l + (r - l + 1) / 2;
2613
+ if (vals[m].start <= off)
2614
+ l = m;
2615
+ else
2616
+ r = m - 1;
2617
+ }
2618
+ return &vals[l];
2619
+ }
2620
+
2621
+ /* Find subprogram that starts exactly at 'off' */
2600
2622
static int find_subprog(struct bpf_verifier_env *env, int off)
2601
2623
{
2602
2624
struct bpf_subprog_info *p;
2603
2625
2604
- p = bsearch(&off, env->subprog_info, env->subprog_cnt,
2605
- sizeof(env->subprog_info[0]), cmp_subprogs);
2606
- if (!p)
2626
+ p = find_containing_subprog(env, off);
2627
+ if (!p || p->start != off)
2607
2628
return -ENOENT;
2608
2629
return p - env->subprog_info;
2609
-
2610
2630
}
2611
2631
2612
2632
static int add_subprog(struct bpf_verifier_env *env, int off)
You can’t perform that action at this time.
0 commit comments