Skip to content

Commit 7182e56

Browse files
olsajirianakryiko
authored andcommitted
selftests/bpf: Add kprobe_multi override test
Adding test that tries to attach program with bpf_override_return helper to function not within error injection list. Signed-off-by: Jiri Olsa <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 41bc46c commit 7182e56

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c

+37
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "kprobe_multi.skel.h"
44
#include "trace_helpers.h"
55
#include "kprobe_multi_empty.skel.h"
6+
#include "kprobe_multi_override.skel.h"
67
#include "bpf/libbpf_internal.h"
78
#include "bpf/hashmap.h"
89

@@ -453,6 +454,40 @@ static void test_kprobe_multi_bench_attach(bool kernel)
453454
}
454455
}
455456

457+
void test_attach_override(void)
458+
{
459+
struct kprobe_multi_override *skel = NULL;
460+
struct bpf_link *link = NULL;
461+
462+
skel = kprobe_multi_override__open_and_load();
463+
if (!ASSERT_OK_PTR(skel, "kprobe_multi_empty__open_and_load"))
464+
goto cleanup;
465+
466+
/* The test_override calls bpf_override_return so it should fail
467+
* to attach to bpf_fentry_test1 function, which is not on error
468+
* injection list.
469+
*/
470+
link = bpf_program__attach_kprobe_multi_opts(skel->progs.test_override,
471+
"bpf_fentry_test1", NULL);
472+
if (!ASSERT_ERR_PTR(link, "override_attached_bpf_fentry_test1")) {
473+
bpf_link__destroy(link);
474+
goto cleanup;
475+
}
476+
477+
/* The should_fail_bio function is on error injection list,
478+
* attach should succeed.
479+
*/
480+
link = bpf_program__attach_kprobe_multi_opts(skel->progs.test_override,
481+
"should_fail_bio", NULL);
482+
if (!ASSERT_OK_PTR(link, "override_attached_should_fail_bio"))
483+
goto cleanup;
484+
485+
bpf_link__destroy(link);
486+
487+
cleanup:
488+
kprobe_multi_override__destroy(skel);
489+
}
490+
456491
void serial_test_kprobe_multi_bench_attach(void)
457492
{
458493
if (test__start_subtest("kernel"))
@@ -480,4 +515,6 @@ void test_kprobe_multi_test(void)
480515
test_attach_api_syms();
481516
if (test__start_subtest("attach_api_fails"))
482517
test_attach_api_fails();
518+
if (test__start_subtest("attach_override"))
519+
test_attach_override();
483520
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
#include <linux/bpf.h>
3+
#include <bpf/bpf_helpers.h>
4+
#include <bpf/bpf_tracing.h>
5+
6+
char _license[] SEC("license") = "GPL";
7+
8+
SEC("kprobe.multi")
9+
int test_override(struct pt_regs *ctx)
10+
{
11+
bpf_override_return(ctx, 123);
12+
return 0;
13+
}

0 commit comments

Comments
 (0)