Message ID | 20241127-bpf-const-ops-v1-0-a698b8d58680@weissschuh.net |
---|---|
Headers | show |
Series | bpf: Constify BPF ops | expand |
On Wed, Nov 27, 2024 at 11:20 AM Thomas Weißschuh <linux@weissschuh.net> wrote: > > --- a/net/bpf/bpf_dummy_struct_ops.c > +++ b/net/bpf/bpf_dummy_struct_ops.c > @@ -129,7 +129,7 @@ extern const struct bpf_link_ops bpf_struct_ops_link_lops; > int bpf_struct_ops_test_run(struct bpf_prog *prog, const union bpf_attr *kattr, > union bpf_attr __user *uattr) > { > - const struct bpf_struct_ops *st_ops = &bpf_bpf_dummy_ops; > + static typeof_member(struct bpf_struct_ops_desc, func_models) func_models; > const struct btf_type *func_proto; > struct bpf_dummy_ops_test_args *args; > struct bpf_tramp_links *tlinks = NULL; > @@ -175,7 +175,7 @@ int bpf_struct_ops_test_run(struct bpf_prog *prog, const union bpf_attr *kattr, > > op_idx = prog->expected_attach_type; > err = bpf_struct_ops_prepare_trampoline(tlinks, link, > - &st_ops->func_models[op_idx], > + &func_models[op_idx], This is sad. You didn't bother running the tests. Above is producing garbage. That's why so many BPF CI tests are failing. Overall I think it's a minimal positive value to constify struct_ops. Unless other bpf developers see a huge value I'd prefer to keep the code as-is. pw-bot: cr
Move struct bpf_struct_ops into read-only memory to protect against accidental and malicious modifications. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> --- Thomas Weißschuh (9): bpf: tcp: Remove inaccurate comment about extern bpf: Move func_models from bpf_struct_ops to bpf_struct_ops_desc bpf: Allow registration of const struct bpf_struct_ops const_structs.checkpatch: add bpf_struct_ops bpf: Allow registration of const cfi_stubs bpf, net: tcp: Constify BPF ops bpf, net: dummy_ops: Constify BPF ops HID: bpf: constify BPF ops sched_ext: Constify BPF ops drivers/hid/bpf/hid_bpf_struct_ops.c | 4 ++-- include/linux/bpf.h | 8 ++++---- include/linux/btf.h | 2 +- kernel/bpf/bpf_struct_ops.c | 8 ++++---- kernel/bpf/btf.c | 4 ++-- kernel/sched/ext.c | 4 ++-- net/bpf/bpf_dummy_struct_ops.c | 10 +++++----- net/ipv4/bpf_tcp_ca.c | 7 +++---- scripts/const_structs.checkpatch | 1 + 9 files changed, 24 insertions(+), 24 deletions(-) --- base-commit: fc39fb56917bb3cb53e99560ca3612a84456ada2 change-id: 20241127-bpf-const-ops-add2866b3157 Best regards,