Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bpf: Constify struct btf_kind_operations

struct btf_kind_operations are not modified in BTF.

Constifying this structures moves some data to a read-only section,
so increase overall security, especially when the structure holds
some function pointers.

On a x86_64, with allmodconfig:

Before:
======
text data bss dec hex filename
184320 7091 548 191959 2edd7 kernel/bpf/btf.o

After:
=====
text data bss dec hex filename
184896 6515 548 191959 2edd7 kernel/bpf/btf.o

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/r/9192ab72b2e9c66aefd6520f359a20297186327f.1726417289.git.christophe.jaillet@wanadoo.fr
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Christophe JAILLET and committed by
Alexei Starovoitov
7bae563c 58dbb369

+9 -9
+9 -9
kernel/bpf/btf.c
··· 2808 2808 btf_verifier_log(env, "type_id=%u", t->type); 2809 2809 } 2810 2810 2811 - static struct btf_kind_operations modifier_ops = { 2811 + static const struct btf_kind_operations modifier_ops = { 2812 2812 .check_meta = btf_ref_type_check_meta, 2813 2813 .resolve = btf_modifier_resolve, 2814 2814 .check_member = btf_modifier_check_member, ··· 2817 2817 .show = btf_modifier_show, 2818 2818 }; 2819 2819 2820 - static struct btf_kind_operations ptr_ops = { 2820 + static const struct btf_kind_operations ptr_ops = { 2821 2821 .check_meta = btf_ref_type_check_meta, 2822 2822 .resolve = btf_ptr_resolve, 2823 2823 .check_member = btf_ptr_check_member, ··· 2858 2858 btf_verifier_log(env, "%s", btf_type_kflag(t) ? "union" : "struct"); 2859 2859 } 2860 2860 2861 - static struct btf_kind_operations fwd_ops = { 2861 + static const struct btf_kind_operations fwd_ops = { 2862 2862 .check_meta = btf_fwd_check_meta, 2863 2863 .resolve = btf_df_resolve, 2864 2864 .check_member = btf_df_check_member, ··· 3109 3109 __btf_array_show(btf, t, type_id, data, bits_offset, show); 3110 3110 } 3111 3111 3112 - static struct btf_kind_operations array_ops = { 3112 + static const struct btf_kind_operations array_ops = { 3113 3113 .check_meta = btf_array_check_meta, 3114 3114 .resolve = btf_array_resolve, 3115 3115 .check_member = btf_array_check_member, ··· 4185 4185 __btf_struct_show(btf, t, type_id, data, bits_offset, show); 4186 4186 } 4187 4187 4188 - static struct btf_kind_operations struct_ops = { 4188 + static const struct btf_kind_operations struct_ops = { 4189 4189 .check_meta = btf_struct_check_meta, 4190 4190 .resolve = btf_struct_resolve, 4191 4191 .check_member = btf_struct_check_member, ··· 4353 4353 btf_show_end_type(show); 4354 4354 } 4355 4355 4356 - static struct btf_kind_operations enum_ops = { 4356 + static const struct btf_kind_operations enum_ops = { 4357 4357 .check_meta = btf_enum_check_meta, 4358 4358 .resolve = btf_df_resolve, 4359 4359 .check_member = btf_enum_check_member, ··· 4456 4456 btf_show_end_type(show); 4457 4457 } 4458 4458 4459 - static struct btf_kind_operations enum64_ops = { 4459 + static const struct btf_kind_operations enum64_ops = { 4460 4460 .check_meta = btf_enum64_check_meta, 4461 4461 .resolve = btf_df_resolve, 4462 4462 .check_member = btf_enum_check_member, ··· 4534 4534 btf_verifier_log(env, ")"); 4535 4535 } 4536 4536 4537 - static struct btf_kind_operations func_proto_ops = { 4537 + static const struct btf_kind_operations func_proto_ops = { 4538 4538 .check_meta = btf_func_proto_check_meta, 4539 4539 .resolve = btf_df_resolve, 4540 4540 /* ··· 4592 4592 return 0; 4593 4593 } 4594 4594 4595 - static struct btf_kind_operations func_ops = { 4595 + static const struct btf_kind_operations func_ops = { 4596 4596 .check_meta = btf_func_check_meta, 4597 4597 .resolve = btf_func_resolve, 4598 4598 .check_member = btf_df_check_member,