Skip to content

Commit c78f8bd

Browse files
borkmanndavem330
authored andcommitted
bpf: mark all registered map/prog types as __ro_after_init
All map types and prog types are registered to the BPF core through bpf_register_map_type() and bpf_register_prog_type() during init and remain unchanged thereafter. As by design we don't (and never will) have any pluggable code that can register to that at any later point in time, lets mark all the existing bpf_{map,prog}_type_list objects in the tree as __ro_after_init, so they can be moved to read-only section from then onwards. Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: Alexei Starovoitov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent afcb50b commit c78f8bd

File tree

6 files changed

+23
-23
lines changed

6 files changed

+23
-23
lines changed

kernel/bpf/arraymap.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ static const struct bpf_map_ops array_ops = {
269269
.map_delete_elem = array_map_delete_elem,
270270
};
271271

272-
static struct bpf_map_type_list array_type __read_mostly = {
272+
static struct bpf_map_type_list array_type __ro_after_init = {
273273
.ops = &array_ops,
274274
.type = BPF_MAP_TYPE_ARRAY,
275275
};
@@ -283,7 +283,7 @@ static const struct bpf_map_ops percpu_array_ops = {
283283
.map_delete_elem = array_map_delete_elem,
284284
};
285285

286-
static struct bpf_map_type_list percpu_array_type __read_mostly = {
286+
static struct bpf_map_type_list percpu_array_type __ro_after_init = {
287287
.ops = &percpu_array_ops,
288288
.type = BPF_MAP_TYPE_PERCPU_ARRAY,
289289
};
@@ -409,7 +409,7 @@ static const struct bpf_map_ops prog_array_ops = {
409409
.map_fd_put_ptr = prog_fd_array_put_ptr,
410410
};
411411

412-
static struct bpf_map_type_list prog_array_type __read_mostly = {
412+
static struct bpf_map_type_list prog_array_type __ro_after_init = {
413413
.ops = &prog_array_ops,
414414
.type = BPF_MAP_TYPE_PROG_ARRAY,
415415
};
@@ -522,7 +522,7 @@ static const struct bpf_map_ops perf_event_array_ops = {
522522
.map_release = perf_event_fd_array_release,
523523
};
524524

525-
static struct bpf_map_type_list perf_event_array_type __read_mostly = {
525+
static struct bpf_map_type_list perf_event_array_type __ro_after_init = {
526526
.ops = &perf_event_array_ops,
527527
.type = BPF_MAP_TYPE_PERF_EVENT_ARRAY,
528528
};
@@ -564,7 +564,7 @@ static const struct bpf_map_ops cgroup_array_ops = {
564564
.map_fd_put_ptr = cgroup_fd_array_put_ptr,
565565
};
566566

567-
static struct bpf_map_type_list cgroup_array_type __read_mostly = {
567+
static struct bpf_map_type_list cgroup_array_type __ro_after_init = {
568568
.ops = &cgroup_array_ops,
569569
.type = BPF_MAP_TYPE_CGROUP_ARRAY,
570570
};

kernel/bpf/hashtab.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,7 @@ static const struct bpf_map_ops htab_ops = {
10231023
.map_delete_elem = htab_map_delete_elem,
10241024
};
10251025

1026-
static struct bpf_map_type_list htab_type __read_mostly = {
1026+
static struct bpf_map_type_list htab_type __ro_after_init = {
10271027
.ops = &htab_ops,
10281028
.type = BPF_MAP_TYPE_HASH,
10291029
};
@@ -1037,7 +1037,7 @@ static const struct bpf_map_ops htab_lru_ops = {
10371037
.map_delete_elem = htab_lru_map_delete_elem,
10381038
};
10391039

1040-
static struct bpf_map_type_list htab_lru_type __read_mostly = {
1040+
static struct bpf_map_type_list htab_lru_type __ro_after_init = {
10411041
.ops = &htab_lru_ops,
10421042
.type = BPF_MAP_TYPE_LRU_HASH,
10431043
};
@@ -1124,7 +1124,7 @@ static const struct bpf_map_ops htab_percpu_ops = {
11241124
.map_delete_elem = htab_map_delete_elem,
11251125
};
11261126

1127-
static struct bpf_map_type_list htab_percpu_type __read_mostly = {
1127+
static struct bpf_map_type_list htab_percpu_type __ro_after_init = {
11281128
.ops = &htab_percpu_ops,
11291129
.type = BPF_MAP_TYPE_PERCPU_HASH,
11301130
};
@@ -1138,7 +1138,7 @@ static const struct bpf_map_ops htab_lru_percpu_ops = {
11381138
.map_delete_elem = htab_lru_map_delete_elem,
11391139
};
11401140

1141-
static struct bpf_map_type_list htab_lru_percpu_type __read_mostly = {
1141+
static struct bpf_map_type_list htab_lru_percpu_type __ro_after_init = {
11421142
.ops = &htab_lru_percpu_ops,
11431143
.type = BPF_MAP_TYPE_LRU_PERCPU_HASH,
11441144
};

kernel/bpf/lpm_trie.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ static const struct bpf_map_ops trie_ops = {
508508
.map_delete_elem = trie_delete_elem,
509509
};
510510

511-
static struct bpf_map_type_list trie_type __read_mostly = {
511+
static struct bpf_map_type_list trie_type __ro_after_init = {
512512
.ops = &trie_ops,
513513
.type = BPF_MAP_TYPE_LPM_TRIE,
514514
};

kernel/bpf/stackmap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ static const struct bpf_map_ops stack_map_ops = {
273273
.map_delete_elem = stack_map_delete_elem,
274274
};
275275

276-
static struct bpf_map_type_list stack_map_type __read_mostly = {
276+
static struct bpf_map_type_list stack_map_type __ro_after_init = {
277277
.ops = &stack_map_ops,
278278
.type = BPF_MAP_TYPE_STACK_TRACE,
279279
};

kernel/trace/bpf_trace.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ static const struct bpf_verifier_ops kprobe_prog_ops = {
506506
.is_valid_access = kprobe_prog_is_valid_access,
507507
};
508508

509-
static struct bpf_prog_type_list kprobe_tl = {
509+
static struct bpf_prog_type_list kprobe_tl __ro_after_init = {
510510
.ops = &kprobe_prog_ops,
511511
.type = BPF_PROG_TYPE_KPROBE,
512512
};
@@ -589,7 +589,7 @@ static const struct bpf_verifier_ops tracepoint_prog_ops = {
589589
.is_valid_access = tp_prog_is_valid_access,
590590
};
591591

592-
static struct bpf_prog_type_list tracepoint_tl = {
592+
static struct bpf_prog_type_list tracepoint_tl __ro_after_init = {
593593
.ops = &tracepoint_prog_ops,
594594
.type = BPF_PROG_TYPE_TRACEPOINT,
595595
};
@@ -648,7 +648,7 @@ static const struct bpf_verifier_ops perf_event_prog_ops = {
648648
.convert_ctx_access = pe_prog_convert_ctx_access,
649649
};
650650

651-
static struct bpf_prog_type_list perf_event_tl = {
651+
static struct bpf_prog_type_list perf_event_tl __ro_after_init = {
652652
.ops = &perf_event_prog_ops,
653653
.type = BPF_PROG_TYPE_PERF_EVENT,
654654
};

net/core/filter.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3296,47 +3296,47 @@ static const struct bpf_verifier_ops cg_sock_ops = {
32963296
.convert_ctx_access = sock_filter_convert_ctx_access,
32973297
};
32983298

3299-
static struct bpf_prog_type_list sk_filter_type __read_mostly = {
3299+
static struct bpf_prog_type_list sk_filter_type __ro_after_init = {
33003300
.ops = &sk_filter_ops,
33013301
.type = BPF_PROG_TYPE_SOCKET_FILTER,
33023302
};
33033303

3304-
static struct bpf_prog_type_list sched_cls_type __read_mostly = {
3304+
static struct bpf_prog_type_list sched_cls_type __ro_after_init = {
33053305
.ops = &tc_cls_act_ops,
33063306
.type = BPF_PROG_TYPE_SCHED_CLS,
33073307
};
33083308

3309-
static struct bpf_prog_type_list sched_act_type __read_mostly = {
3309+
static struct bpf_prog_type_list sched_act_type __ro_after_init = {
33103310
.ops = &tc_cls_act_ops,
33113311
.type = BPF_PROG_TYPE_SCHED_ACT,
33123312
};
33133313

3314-
static struct bpf_prog_type_list xdp_type __read_mostly = {
3314+
static struct bpf_prog_type_list xdp_type __ro_after_init = {
33153315
.ops = &xdp_ops,
33163316
.type = BPF_PROG_TYPE_XDP,
33173317
};
33183318

3319-
static struct bpf_prog_type_list cg_skb_type __read_mostly = {
3319+
static struct bpf_prog_type_list cg_skb_type __ro_after_init = {
33203320
.ops = &cg_skb_ops,
33213321
.type = BPF_PROG_TYPE_CGROUP_SKB,
33223322
};
33233323

3324-
static struct bpf_prog_type_list lwt_in_type __read_mostly = {
3324+
static struct bpf_prog_type_list lwt_in_type __ro_after_init = {
33253325
.ops = &lwt_inout_ops,
33263326
.type = BPF_PROG_TYPE_LWT_IN,
33273327
};
33283328

3329-
static struct bpf_prog_type_list lwt_out_type __read_mostly = {
3329+
static struct bpf_prog_type_list lwt_out_type __ro_after_init = {
33303330
.ops = &lwt_inout_ops,
33313331
.type = BPF_PROG_TYPE_LWT_OUT,
33323332
};
33333333

3334-
static struct bpf_prog_type_list lwt_xmit_type __read_mostly = {
3334+
static struct bpf_prog_type_list lwt_xmit_type __ro_after_init = {
33353335
.ops = &lwt_xmit_ops,
33363336
.type = BPF_PROG_TYPE_LWT_XMIT,
33373337
};
33383338

3339-
static struct bpf_prog_type_list cg_sock_type __read_mostly = {
3339+
static struct bpf_prog_type_list cg_sock_type __ro_after_init = {
33403340
.ops = &cg_sock_ops,
33413341
.type = BPF_PROG_TYPE_CGROUP_SOCK
33423342
};

0 commit comments

Comments
 (0)