mirror of
https://github.com/torvalds/linux.git
synced 2026-06-04 20:46:48 +02:00
selftests/bpf: Add uprobe context ip register change test
Adding test to check we can change the application execution through instruction pointer change through uprobe program. It's x86_64 specific test. Acked-by: Andrii Nakryiko <andrii@kernel.org> Signed-off-by: Jiri Olsa <jolsa@kernel.org> Link: https://lore.kernel.org/r/20250916215301.664963-5-jolsa@kernel.org Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
parent
7f8a05c5d3
commit
6a4ea0d1cb
|
|
@ -190,10 +190,52 @@ static void regs_common(void)
|
|||
test_uprobe__destroy(skel);
|
||||
}
|
||||
|
||||
static noinline unsigned long uprobe_regs_change_ip_1(void)
|
||||
{
|
||||
return 0xc0ffee;
|
||||
}
|
||||
|
||||
static noinline unsigned long uprobe_regs_change_ip_2(void)
|
||||
{
|
||||
return 0xdeadbeef;
|
||||
}
|
||||
|
||||
static void regs_ip(void)
|
||||
{
|
||||
LIBBPF_OPTS(bpf_uprobe_opts, uprobe_opts);
|
||||
struct test_uprobe *skel;
|
||||
unsigned long ret;
|
||||
|
||||
skel = test_uprobe__open_and_load();
|
||||
if (!ASSERT_OK_PTR(skel, "skel_open"))
|
||||
return;
|
||||
|
||||
skel->bss->my_pid = getpid();
|
||||
skel->bss->ip = (unsigned long) uprobe_regs_change_ip_2;
|
||||
|
||||
uprobe_opts.func_name = "uprobe_regs_change_ip_1";
|
||||
skel->links.test_regs_change_ip = bpf_program__attach_uprobe_opts(
|
||||
skel->progs.test_regs_change_ip,
|
||||
-1,
|
||||
"/proc/self/exe",
|
||||
0 /* offset */,
|
||||
&uprobe_opts);
|
||||
if (!ASSERT_OK_PTR(skel->links.test_regs_change_ip, "bpf_program__attach_uprobe_opts"))
|
||||
goto cleanup;
|
||||
|
||||
ret = uprobe_regs_change_ip_1();
|
||||
ASSERT_EQ(ret, 0xdeadbeef, "ret");
|
||||
|
||||
cleanup:
|
||||
test_uprobe__destroy(skel);
|
||||
}
|
||||
|
||||
static void test_uprobe_regs_change(void)
|
||||
{
|
||||
if (test__start_subtest("regs_change_common"))
|
||||
regs_common();
|
||||
if (test__start_subtest("regs_change_ip"))
|
||||
regs_ip();
|
||||
}
|
||||
#else
|
||||
static void test_uprobe_regs_change(void) { }
|
||||
|
|
|
|||
|
|
@ -82,4 +82,18 @@ int BPF_UPROBE(test_regs_change)
|
|||
ctx->si = regs.si;
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned long ip;
|
||||
|
||||
SEC("uprobe")
|
||||
int BPF_UPROBE(test_regs_change_ip)
|
||||
{
|
||||
pid_t pid = bpf_get_current_pid_tgid() >> 32;
|
||||
|
||||
if (pid != my_pid)
|
||||
return 0;
|
||||
|
||||
ctx->ip = ip;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user