Message ID | 20230328004738.381898-2-eddyz87@gmail.com (mailing list archive) |
---|---|
State | Changes Requested |
Delegated to: | BPF |
Headers | show |
Series | Fix double-free when linker processes empty sections | expand |
On Mon, Mar 27, 2023 at 5:47 PM Eduard Zingerman <eddyz87@gmail.com> wrote: > > Adds two empty functions to linked_funcs[12].c. The functions are > annotated as "naked" and go to a separate section. This section ends > up having size 0. bpftool linker merges content for sections with > identical names. This tests if it can handle empty sections. > > Signed-off-by: Eduard Zingerman <eddyz87@gmail.com> > --- > tools/testing/selftests/bpf/progs/linked_funcs1.c | 3 +++ > tools/testing/selftests/bpf/progs/linked_funcs2.c | 3 +++ > 2 files changed, 6 insertions(+) > > diff --git a/tools/testing/selftests/bpf/progs/linked_funcs1.c b/tools/testing/selftests/bpf/progs/linked_funcs1.c > index c4b49ceea967..029bb5022ba2 100644 > --- a/tools/testing/selftests/bpf/progs/linked_funcs1.c > +++ b/tools/testing/selftests/bpf/progs/linked_funcs1.c > @@ -86,4 +86,7 @@ int BPF_PROG(handler1, struct pt_regs *regs, long id) > return 0; > } > > +SEC(".empty_section") > +__naked void empty_function1(void) {} > + > char LICENSE[] SEC("license") = "GPL"; > diff --git a/tools/testing/selftests/bpf/progs/linked_funcs2.c b/tools/testing/selftests/bpf/progs/linked_funcs2.c > index 013ff0645f0c..4547c8dfc689 100644 > --- a/tools/testing/selftests/bpf/progs/linked_funcs2.c > +++ b/tools/testing/selftests/bpf/progs/linked_funcs2.c > @@ -86,4 +86,7 @@ int BPF_PROG(handler2, struct pt_regs *regs, long id) > return 0; > } > > +SEC(".empty_section") > +__naked void empty_function2(void) {} These empty section functions make this whole BPF object file invalid from libbpf's standpoint. It didn't feel worth it to add this confusion just to test this edge case in realloc() handling. So I dropped this patch and only applied libbpf fix. Pushed to bpf-next, thanks! > + > char LICENSE[] SEC("license") = "GPL"; > -- > 2.40.0 >
diff --git a/tools/testing/selftests/bpf/progs/linked_funcs1.c b/tools/testing/selftests/bpf/progs/linked_funcs1.c index c4b49ceea967..029bb5022ba2 100644 --- a/tools/testing/selftests/bpf/progs/linked_funcs1.c +++ b/tools/testing/selftests/bpf/progs/linked_funcs1.c @@ -86,4 +86,7 @@ int BPF_PROG(handler1, struct pt_regs *regs, long id) return 0; } +SEC(".empty_section") +__naked void empty_function1(void) {} + char LICENSE[] SEC("license") = "GPL"; diff --git a/tools/testing/selftests/bpf/progs/linked_funcs2.c b/tools/testing/selftests/bpf/progs/linked_funcs2.c index 013ff0645f0c..4547c8dfc689 100644 --- a/tools/testing/selftests/bpf/progs/linked_funcs2.c +++ b/tools/testing/selftests/bpf/progs/linked_funcs2.c @@ -86,4 +86,7 @@ int BPF_PROG(handler2, struct pt_regs *regs, long id) return 0; } +SEC(".empty_section") +__naked void empty_function2(void) {} + char LICENSE[] SEC("license") = "GPL";
Adds two empty functions to linked_funcs[12].c. The functions are annotated as "naked" and go to a separate section. This section ends up having size 0. bpftool linker merges content for sections with identical names. This tests if it can handle empty sections. Signed-off-by: Eduard Zingerman <eddyz87@gmail.com> --- tools/testing/selftests/bpf/progs/linked_funcs1.c | 3 +++ tools/testing/selftests/bpf/progs/linked_funcs2.c | 3 +++ 2 files changed, 6 insertions(+)