Skip to content

Commit b17cd82

Browse files
olsajiriKernel Patches Daemon
authored andcommitted
selftests/bpf: Add kprobe multi write ctx attach test
Adding test to check we can't attach kprobe multi program that writes to the context. It's x86_64 specific test. Acked-by: Andrii Nakryiko <[email protected]> Signed-off-by: Jiri Olsa <[email protected]>
1 parent a718892 commit b17cd82

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "kprobe_multi_session.skel.h"
88
#include "kprobe_multi_session_cookie.skel.h"
99
#include "kprobe_multi_verifier.skel.h"
10+
#include "kprobe_write_ctx.skel.h"
1011
#include "bpf/libbpf_internal.h"
1112
#include "bpf/hashmap.h"
1213

@@ -539,6 +540,30 @@ static void test_attach_override(void)
539540
kprobe_multi_override__destroy(skel);
540541
}
541542

543+
#ifdef __x86_64__
544+
static void test_attach_write_ctx(void)
545+
{
546+
struct kprobe_write_ctx *skel = NULL;
547+
struct bpf_link *link = NULL;
548+
549+
skel = kprobe_write_ctx__open_and_load();
550+
if (!ASSERT_OK_PTR(skel, "kprobe_write_ctx__open_and_load"))
551+
return;
552+
553+
link = bpf_program__attach_kprobe_opts(skel->progs.kprobe_multi_write_ctx,
554+
"bpf_fentry_test1", NULL);
555+
if (!ASSERT_ERR_PTR(link, "bpf_program__attach_kprobe_opts"))
556+
bpf_link__destroy(link);
557+
558+
kprobe_write_ctx__destroy(skel);
559+
}
560+
#else
561+
static void test_attach_write_ctx(void)
562+
{
563+
test__skip();
564+
}
565+
#endif
566+
542567
void serial_test_kprobe_multi_bench_attach(void)
543568
{
544569
if (test__start_subtest("kernel"))
@@ -578,5 +603,7 @@ void test_kprobe_multi_test(void)
578603
test_session_cookie_skel_api();
579604
if (test__start_subtest("unique_match"))
580605
test_unique_match();
606+
if (test__start_subtest("attach_write_ctx"))
607+
test_attach_write_ctx();
581608
RUN_TESTS(kprobe_multi_verifier);
582609
}

tools/testing/selftests/bpf/progs/kprobe_write_ctx.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,11 @@ int kprobe_write_ctx(struct pt_regs *ctx)
1212
ctx->ax = 0;
1313
return 0;
1414
}
15+
16+
SEC("kprobe.multi")
17+
int kprobe_multi_write_ctx(struct pt_regs *ctx)
18+
{
19+
ctx->ax = 0;
20+
return 0;
21+
}
1522
#endif

0 commit comments

Comments
 (0)