lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAEf4BzbrDu_GWWURnf4U=ji_8r6Cnqp-y8ye89xYuV4rTwzz9A@mail.gmail.com>
Date:   Thu, 16 Mar 2023 13:34:12 -0700
From:   Andrii Nakryiko <andrii.nakryiko@...il.com>
To:     Alexei Starovoitov <alexei.starovoitov@...il.com>
Cc:     davem@...emloft.net, daniel@...earbox.net, andrii@...nel.org,
        martin.lau@...nel.org, void@...ifault.com, davemarchevsky@...a.com,
        tj@...nel.org, memxor@...il.com, netdev@...r.kernel.org,
        bpf@...r.kernel.org, kernel-team@...com
Subject: Re: [PATCH bpf-next 2/2] selftests/bpf: Add test for bpf_kfunc_exists().

On Wed, Mar 15, 2023 at 3:36 PM Alexei Starovoitov
<alexei.starovoitov@...il.com> wrote:
>
> From: Alexei Starovoitov <ast@...nel.org>
>
> Add load and run time test for bpf_kfunc_exists() and check that the verifier
> performs dead code elimination for non-existing kfunc.
>
> Signed-off-by: Alexei Starovoitov <ast@...nel.org>
> ---

we have prog_tests/ksyms_btf.c and progs/test_ksyms_weak.c which do
these kind of tests for variable ksyms, let's just add kfunc ksyms
there (user-space part has also checking that captured pointer value
is correct and stuff like that, we probably want that for kfuncs as
well)


>  .../selftests/bpf/progs/task_kfunc_success.c       | 14 +++++++++++++-
>  1 file changed, 13 insertions(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/bpf/progs/task_kfunc_success.c b/tools/testing/selftests/bpf/progs/task_kfunc_success.c
> index 4f61596b0242..c0a7774e0c79 100644
> --- a/tools/testing/selftests/bpf/progs/task_kfunc_success.c
> +++ b/tools/testing/selftests/bpf/progs/task_kfunc_success.c
> @@ -17,6 +17,8 @@ int err, pid;
>   *         TP_PROTO(struct task_struct *p, u64 clone_flags)
>   */
>
> +void invalid_kfunc(void) __ksym __weak;
> +
>  static bool is_test_kfunc_task(void)
>  {
>         int cur_pid = bpf_get_current_pid_tgid() >> 32;
> @@ -26,7 +28,17 @@ static bool is_test_kfunc_task(void)
>
>  static int test_acquire_release(struct task_struct *task)
>  {
> -       struct task_struct *acquired;
> +       struct task_struct *acquired = NULL;
> +
> +       if (!bpf_kfunc_exists(bpf_task_acquire)) {
> +               err = 3;
> +               return 0;
> +       }
> +       if (bpf_kfunc_exists(invalid_kfunc)) {
> +               /* the verifier's dead code elimination should remove this */
> +               err = 4;
> +               asm volatile ("goto -1"); /* for (;;); */
> +       }
>
>         acquired = bpf_task_acquire(task);
>         bpf_task_release(acquired);
> --
> 2.34.1
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ