All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: Jiri Olsa <jolsa@kernel.org>
Cc: "Alexei Starovoitov" <ast@kernel.org>,
	"Daniel Borkmann" <daniel@iogearbox.net>,
	"Andrii Nakryiko" <andriin@fb.com>,
	Networking <netdev@vger.kernel.org>, bpf <bpf@vger.kernel.org>,
	"Martin KaFai Lau" <kafai@fb.com>,
	"Song Liu" <songliubraving@fb.com>, "Yonghong Song" <yhs@fb.com>,
	"John Fastabend" <john.fastabend@gmail.com>,
	"KP Singh" <kpsingh@chromium.org>,
	"Toke Høiland-Jørgensen" <toke@redhat.com>
Subject: Re: [PATCHv2 bpf-next 5/5] selftests/bpf: Test that module can't be unloaded with attached trampoline
Date: Wed, 7 Apr 2021 16:04:48 -0700	[thread overview]
Message-ID: <CAEf4BzYnr=r-+iYaZ9yoTgRCs7h0mNo=rjg6S2OAYRkDdPniJA@mail.gmail.com> (raw)
In-Reply-To: <20210406212913.970917-6-jolsa@kernel.org>

On Wed, Apr 7, 2021 at 4:22 AM Jiri Olsa <jolsa@kernel.org> wrote:
>
> Adding test to verify that once we attach module's trampoline,
> the module can't be unloaded.
>
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> ---

To be fair, to test that you are actually testing what you think you
are testing, you'd have to prove that you *can* detach when no program
is attached to bpf_testmod ;) You'd also need kern_sync_rcu() to wait
for all the async clean up to complete inside the kernel. But that
doesn't interact with other tests well, so I think it's fine.

grumpily due to CHECK() usage (please do consider updating to ASSERT):

Acked-by: Andrii Nakryiko <andrii@kernel.org>

>  .../selftests/bpf/prog_tests/module_attach.c  | 23 +++++++++++++++++++
>  1 file changed, 23 insertions(+)
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/module_attach.c b/tools/testing/selftests/bpf/prog_tests/module_attach.c
> index 5bc53d53d86e..d180b8c28287 100644
> --- a/tools/testing/selftests/bpf/prog_tests/module_attach.c
> +++ b/tools/testing/selftests/bpf/prog_tests/module_attach.c
> @@ -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();
> @@ -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 (CHECK(IS_ERR(link), "attach_fentry", "err: %ld\n", PTR_ERR(link)))
> +               goto cleanup;
> +
> +       ASSERT_ERR(delete_module("bpf_testmod", 0), "delete_module");
> +       bpf_link__destroy(link);
> +
> +       link = bpf_program__attach(skel->progs.handle_fexit);
> +       if (CHECK(IS_ERR(link), "attach_fexit", "err: %ld\n", PTR_ERR(link)))
> +               goto cleanup;
> +
> +       ASSERT_ERR(delete_module("bpf_testmod", 0), "delete_module");
> +       bpf_link__destroy(link);
> +
>  cleanup:
>         test_module_attach__destroy(skel);
>  }
> --
> 2.30.2
>

  reply	other threads:[~2021-04-07 23:05 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-06 21:29 [PATCHv2 bpf-next 0/5] bpf: Tracing and lsm programs re-attach Jiri Olsa
2021-04-06 21:29 ` [PATCHv2 bpf-next 1/5] bpf: Allow trampoline re-attach for tracing and lsm programs Jiri Olsa
2021-04-06 21:35   ` Toke Høiland-Jørgensen
2021-04-06 21:29 ` [PATCHv2 bpf-next 2/5] selftests/bpf: Add re-attach test to fentry_test Jiri Olsa
2021-04-07 22:47   ` Andrii Nakryiko
2021-04-08 11:52     ` Jiri Olsa
2021-04-06 21:29 ` [PATCHv2 bpf-next 3/5] selftests/bpf: Add re-attach test to fexit_test Jiri Olsa
2021-04-07 22:51   ` Andrii Nakryiko
2021-04-08 11:51     ` Jiri Olsa
2021-04-06 21:29 ` [PATCHv2 bpf-next 4/5] selftests/bpf: Add re-attach test to lsm test Jiri Olsa
2021-04-06 21:29 ` [PATCHv2 bpf-next 5/5] selftests/bpf: Test that module can't be unloaded with attached trampoline Jiri Olsa
2021-04-07 23:04   ` Andrii Nakryiko [this message]
2021-04-08 11:59     ` Jiri Olsa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAEf4BzYnr=r-+iYaZ9yoTgRCs7h0mNo=rjg6S2OAYRkDdPniJA@mail.gmail.com' \
    --to=andrii.nakryiko@gmail.com \
    --cc=andriin@fb.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kafai@fb.com \
    --cc=kpsingh@chromium.org \
    --cc=netdev@vger.kernel.org \
    --cc=songliubraving@fb.com \
    --cc=toke@redhat.com \
    --cc=yhs@fb.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.