Skip to content

Commit

Permalink
selftests/bpf: Test that module can't be unloaded with attached tramp…
Browse files Browse the repository at this point in the history
…oline

Adding test to verify that once we attach module's trampoline,
the module can't be unloaded.

Signed-off-by: Jiri Olsa <[email protected]>
Signed-off-by: Alexei Starovoitov <[email protected]>
Acked-by: Andrii Nakryiko <[email protected]>
Link: https://lore.kernel.org/bpf/[email protected]
  • Loading branch information
olsajiri authored and Alexei Starovoitov committed Apr 26, 2021
1 parent cede72a commit a1c05c3
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tools/testing/selftests/bpf/prog_tests/module_attach.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,18 @@ static int trigger_module_test_write(int write_sz)
return 0;
}

static int delete_module(const char *name, int flags)
{
return syscall(__NR_delete_module, name, flags);
}

void test_module_attach(void)
{
const int READ_SZ = 456;
const int WRITE_SZ = 457;
struct test_module_attach* skel;
struct test_module_attach__bss *bss;
struct bpf_link *link;
int err;

skel = test_module_attach__open();
Expand Down Expand Up @@ -84,6 +90,23 @@ void test_module_attach(void)
ASSERT_EQ(bss->fexit_ret, -EIO, "fexit_tet");
ASSERT_EQ(bss->fmod_ret_read_sz, READ_SZ, "fmod_ret");

test_module_attach__detach(skel);

/* attach fentry/fexit and make sure it get's module reference */
link = bpf_program__attach(skel->progs.handle_fentry);
if (!ASSERT_OK_PTR(link, "attach_fentry"))
goto cleanup;

ASSERT_ERR(delete_module("bpf_testmod", 0), "delete_module");
bpf_link__destroy(link);

link = bpf_program__attach(skel->progs.handle_fexit);
if (!ASSERT_OK_PTR(link, "attach_fexit"))
goto cleanup;

ASSERT_ERR(delete_module("bpf_testmod", 0), "delete_module");
bpf_link__destroy(link);

cleanup:
test_module_attach__destroy(skel);
}

0 comments on commit a1c05c3

Please sign in to comment.