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: <CAEf4BzZPd0-unT7ChKNFCYRVU2NHfdp8kKuEFSZgaDxm9ndC8w@mail.gmail.com>
Date:   Sat, 28 Mar 2020 13:06:18 -0700
From:   Andrii Nakryiko <andrii.nakryiko@...il.com>
To:     Toke Høiland-Jørgensen <toke@...hat.com>
Cc:     Daniel Borkmann <daniel@...earbox.net>,
        Alexei Starovoitov <ast@...com>, bpf <bpf@...r.kernel.org>,
        Networking <netdev@...r.kernel.org>
Subject: Re: [PATCH v3 2/2] selftests: Add test for overriding global data
 value before load

On Sat, Mar 28, 2020 at 11:29 AM Toke Høiland-Jørgensen <toke@...hat.com> wrote:
>
> This extends the global_data test to also exercise the new
> bpf_map__set_initial_value() function. The test simply overrides the global
> data section with all zeroes, and checks that the new value makes it into
> the kernel map on load.
>
> Signed-off-by: Toke Høiland-Jørgensen <toke@...hat.com>
> ---
>  .../selftests/bpf/prog_tests/global_data.c    | 61 +++++++++++++++++++
>  1 file changed, 61 insertions(+)
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/global_data.c b/tools/testing/selftests/bpf/prog_tests/global_data.c
> index c680926fce73..f018ce53a8d1 100644
> --- a/tools/testing/selftests/bpf/prog_tests/global_data.c
> +++ b/tools/testing/selftests/bpf/prog_tests/global_data.c
> @@ -121,6 +121,65 @@ static void test_global_data_rdonly(struct bpf_object *obj, __u32 duration)
>               "err %d errno %d\n", err, errno);
>  }
>
> +static void test_global_data_set_rdonly(__u32 duration)
> +{
> +       const char *file = "./test_global_data.o";
> +       int err = -ENOMEM, map_fd, zero = 0;
> +       __u8 *buff = NULL, *newval = NULL;
> +       struct bpf_program *prog;
> +       struct bpf_object *obj;
> +       struct bpf_map *map;
> +       size_t sz;
> +
> +       obj = bpf_object__open_file(file, NULL);

Try using skeleton open and load .o file, it will cut this code almost in half.

> +       if (CHECK_FAIL(!obj))
> +               return;
> +       prog = bpf_program__next(NULL, obj);
> +       if (CHECK_FAIL(!prog))
> +               goto out;
> +       err = bpf_program__set_sched_cls(prog);

Please fix SEC() name for that program instead of setting type explicitly.

> +       if (CHECK_FAIL(err))
> +               goto out;
> +
> +       map = bpf_object__find_map_by_name(obj, "test_glo.rodata");
> +       if (CHECK_FAIL(!map || !bpf_map__is_internal(map)))
> +               goto out;
> +
> +       sz = bpf_map__def(map)->value_size;
> +       newval = malloc(sz);
> +       if (CHECK_FAIL(!newval))
> +               goto out;
> +       memset(newval, 0, sz);
> +
> +       /* wrong size, should fail */
> +       err = bpf_map__set_initial_value(map, newval, sz - 1);
> +       if (CHECK(!err, "reject set initial value wrong size", "err %d\n", err))
> +               goto out;
> +
> +       err = bpf_map__set_initial_value(map, newval, sz);
> +       if (CHECK_FAIL(err))
> +               goto out;
> +
> +       err = bpf_object__load(obj);
> +       if (CHECK_FAIL(err))
> +               goto out;
> +
> +       map_fd = bpf_map__fd(map);
> +       if (CHECK_FAIL(map_fd < 0))
> +               goto out;
> +
> +       buff = malloc(sz);
> +       if (buff)
> +               err = bpf_map_lookup_elem(map_fd, &zero, buff);
> +       CHECK(!buff || err || memcmp(buff, newval, sz),
> +             "compare .rodata map data override",
> +             "err %d errno %d\n", err, errno);
> +out:
> +       free(buff);
> +       free(newval);
> +       bpf_object__close(obj);
> +}
> +
>  void test_global_data(void)
>  {
>         const char *file = "./test_global_data.o";
> @@ -144,4 +203,6 @@ void test_global_data(void)
>         test_global_data_rdonly(obj, duration);
>
>         bpf_object__close(obj);
> +
> +       test_global_data_set_rdonly(duration);

This should either be a sub-test or better yet a separate test altogether.

>  }
> --
> 2.26.0
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ