Re: [PATCH v2 bpf-next 2/2] selftests/bpf: add tests verifying unprivileged bpf disabled behaviour

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, May 17, 2022 at 5:00 AM Alan Maguire <alan.maguire@xxxxxxxxxx> wrote:
>
> tests load/attach bpf prog with maps, perfbuf and ringbuf, pinning
> them.  Then effective caps are dropped and we verify we can
>
> - pick up the pin
> - create ringbuf/perfbuf
> - get ringbuf/perfbuf events, carry out map update, lookup and delete
> - create a link
>
> Negative testing also ensures
>
> - BPF prog load fails
> - BPF map create fails
> - get fd by id fails
> - get next id fails
> - query fails
> - BTF load fails
>
> Signed-off-by: Alan Maguire <alan.maguire@xxxxxxxxxx>
> ---
>  .../bpf/prog_tests/unpriv_bpf_disabled.c      | 308 ++++++++++++++++++
>  .../bpf/progs/test_unpriv_bpf_disabled.c      |  83 +++++
>  2 files changed, 391 insertions(+)
>  create mode 100644 tools/testing/selftests/bpf/prog_tests/unpriv_bpf_disabled.c
>  create mode 100644 tools/testing/selftests/bpf/progs/test_unpriv_bpf_disabled.c
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/unpriv_bpf_disabled.c b/tools/testing/selftests/bpf/prog_tests/unpriv_bpf_disabled.c
> new file mode 100644
> index 000000000000..7c58c4f7ecc7
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/prog_tests/unpriv_bpf_disabled.c
> @@ -0,0 +1,308 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/* Copyright (c) 2022, Oracle and/or its affiliates. */
> +
> +#include <test_progs.h>
> +#include <bpf/btf.h>
> +
> +#include "test_unpriv_bpf_disabled.skel.h"
> +
> +#include "cap_helpers.h"
> +
> +#define ADMIN_CAPS (1ULL << CAP_SYS_ADMIN |    \
> +                   1ULL << CAP_NET_ADMIN |     \
> +                   1ULL << CAP_PERFMON |       \
> +                   1ULL << CAP_BPF)
> +
> +#define PINPATH                "/sys/fs/bpf/unpriv_bpf_disabled_"
> +
> +struct test_unpriv_bpf_disabled *skel;
> +__u32 prog_id;
> +int prog_fd;
> +int perf_fd;
> +char *map_paths[7] =   { PINPATH "array",
> +                         PINPATH "percpu_array",
> +                         PINPATH "hash",
> +                         PINPATH "percpu_hash",
> +                         PINPATH "perfbuf",
> +                         PINPATH "ringbuf",
> +                         PINPATH "prog_array" };
> +int map_fds[7];

just very briefly skimming, all these variables should be static

but at least for skel why not passing it as input argument to
respective subtest functions?

> +
> +static __u32 got_perfbuf_val;
> +static __u32 got_ringbuf_val;
> +

[...]



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux