Skip to content

Commit

Permalink
selftests/bpf: Load struct_ops map in global_maps_resize test
Browse files Browse the repository at this point in the history
In prog_tests/test_global_maps_resize.c, we test various use cases for
resizing global maps. Commit 7244100 ("libbpf: Don't take direct
pointers into BTF data from st_ops") updated libbpf to not store pointers
to volatile BTF data, which for some users, was causing a UAF when resizing
a datasec array.

Let's ensure we have coverage for resizing datasec arrays with struct_ops
progs by also including a struct_ops map and struct_ops prog in the
test_global_map_resize skeleton. The map is automatically loaded, so we
don't need to do anything other than add it to the BPF prog being tested
to get the coverage.

Signed-off-by: David Vernet <[email protected]>
Signed-off-by: Andrii Nakryiko <[email protected]>
Link: https://lore.kernel.org/bpf/[email protected]
  • Loading branch information
Byte-Lab authored and anakryiko committed Jul 25, 2024
1 parent 6189fa6 commit 7d30b8a
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tools/testing/selftests/bpf/progs/test_global_map_resize.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "vmlinux.h"
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>

char _license[] SEC("license") = "GPL";

Expand Down Expand Up @@ -60,3 +61,18 @@ int data_array_sum(void *ctx)

return 0;
}

SEC("struct_ops/test_1")
int BPF_PROG(test_1)
{
return 0;
}

struct bpf_testmod_ops {
int (*test_1)(void);
};

SEC(".struct_ops.link")
struct bpf_testmod_ops st_ops_resize = {
.test_1 = (void *)test_1
};

0 comments on commit 7d30b8a

Please sign in to comment.