OSDN Git Service

selftests/bpf: Add tests for _opts variants of bpf_*_get_fd_by_id()
authorRoberto Sassu <roberto.sassu@huawei.com>
Thu, 6 Oct 2022 11:07:36 +0000 (13:07 +0200)
committerAndrii Nakryiko <andrii@kernel.org>
Mon, 10 Oct 2022 23:49:43 +0000 (16:49 -0700)
commita9c7c18b57594c72a63fad749021b743c65a098b
treeac20de3e8053e3d82b65622bfe106d4243101fe4
parent97c8f9dd5db839f2387785ee936d0a5b257b31d3
selftests/bpf: Add tests for _opts variants of bpf_*_get_fd_by_id()

Introduce the data_input map, write-protected with a small eBPF program
implementing the lsm/bpf_map hook.

Then, ensure that bpf_map_get_fd_by_id() and bpf_map_get_fd_by_id_opts()
with NULL opts don't succeed due to requesting read-write access to the
write-protected map. Also, ensure that bpf_map_get_fd_by_id_opts() with
open_flags in opts set to BPF_F_RDONLY instead succeeds.

After obtaining a read-only fd, ensure that only map lookup succeeds and
not update. Ensure that update works only with the read-write fd obtained
at program loading time, when the write protection was not yet enabled.

Finally, ensure that the other _opts variants of bpf_*_get_fd_by_id() don't
work if the BPF_F_RDONLY flag is set in opts (due to the kernel not
handling the open_flags member of bpf_attr).

Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20221006110736.84253-7-roberto.sassu@huaweicloud.com
tools/testing/selftests/bpf/DENYLIST.s390x
tools/testing/selftests/bpf/prog_tests/libbpf_get_fd_by_id_opts.c [new file with mode: 0644]
tools/testing/selftests/bpf/progs/test_libbpf_get_fd_by_id_opts.c [new file with mode: 0644]