diff options
| author | Eduard Zingerman <[email protected]> | 2024-03-06 12:45:20 +0200 | 
|---|---|---|
| committer | Andrii Nakryiko <[email protected]> | 2024-03-06 15:18:15 -0800 | 
| commit | c1b93c07b3ac3204c6a42a7f7b6217e36f44df4f (patch) | |
| tree | bc5013bfc1d6b5f26f1a7cf9796c0f11b7639022 /tools/testing/selftests/bpf/prog_tests | |
| parent | c8617e8bcf8d1ef357fadf5c96bd86b9952fb93f (diff) | |
selftests/bpf: Bad_struct_ops test
When loading struct_ops programs kernel requires BTF id of the
struct_ops type and member index for attachment point inside that
type. This makes impossible to use same BPF program in several
struct_ops maps that have different struct_ops type.
Check if libbpf rejects such BPF objects files.
Signed-off-by: Eduard Zingerman <[email protected]>
Signed-off-by: Andrii Nakryiko <[email protected]>
Acked-by: Andrii Nakryiko <[email protected]>
Link: https://lore.kernel.org/bpf/[email protected]
Diffstat (limited to 'tools/testing/selftests/bpf/prog_tests')
| -rw-r--r-- | tools/testing/selftests/bpf/prog_tests/bad_struct_ops.c | 35 | 
1 files changed, 35 insertions, 0 deletions
| diff --git a/tools/testing/selftests/bpf/prog_tests/bad_struct_ops.c b/tools/testing/selftests/bpf/prog_tests/bad_struct_ops.c new file mode 100644 index 000000000000..9f5dbefa0dd9 --- /dev/null +++ b/tools/testing/selftests/bpf/prog_tests/bad_struct_ops.c @@ -0,0 +1,35 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include <test_progs.h> +#include "bad_struct_ops.skel.h" + +static void invalid_prog_reuse(void) +{ +	struct bad_struct_ops *skel; +	char *log = NULL; +	int err; + +	skel = bad_struct_ops__open(); +	if (!ASSERT_OK_PTR(skel, "bad_struct_ops__open")) +		return; + +	if (start_libbpf_log_capture()) +		goto cleanup; + +	err = bad_struct_ops__load(skel); +	log = stop_libbpf_log_capture(); +	ASSERT_ERR(err, "bad_struct_ops__load should fail"); +	ASSERT_HAS_SUBSTR(log, +		"struct_ops init_kern testmod_2 func ptr test_1: invalid reuse of prog test_1", +		"expected init_kern message"); + +cleanup: +	free(log); +	bad_struct_ops__destroy(skel); +} + +void test_bad_struct_ops(void) +{ +	if (test__start_subtest("invalid_prog_reuse")) +		invalid_prog_reuse(); +} |