mirror of
https://github.com/torvalds/linux.git
synced 2026-11-07 06:17:02 +01:00
selftests/bpf: Test the length and the address of an arena mmap()
libbpf maps all max_entries pages of an arena and never maps it at address 0. No test maps an arena differently. Thus the checks from "bpf: Refuse an arena mmap() longer than max_entries pages" and "bpf: Refuse to map an arena at address 0" have no test. Test that a longer mmap() fails with E2BIG, and that an mmap() at address 0 fails with EINVAL. Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261101190535.1454146-8-alexei.starovoitov@gmail.com
This commit is contained in:
parent
15dedd4b25
commit
14d3e5bf9f
37
tools/testing/selftests/bpf/prog_tests/arena_mmap.c
Normal file
37
tools/testing/selftests/bpf/prog_tests/arena_mmap.c
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
// SPDX-License-Identifier: GPL-2.0
|
||||||
|
|
||||||
|
#include <test_progs.h>
|
||||||
|
#include <sys/mman.h>
|
||||||
|
|
||||||
|
#define ARENA_PAGES 8
|
||||||
|
|
||||||
|
static void test_refused(int pages, int flags, int err)
|
||||||
|
{
|
||||||
|
LIBBPF_OPTS(bpf_map_create_opts, opts, .map_flags = BPF_F_MMAPABLE);
|
||||||
|
void *area;
|
||||||
|
int fd;
|
||||||
|
|
||||||
|
fd = bpf_map_create(BPF_MAP_TYPE_ARENA, "arena", 0, 0, ARENA_PAGES, &opts);
|
||||||
|
if (fd == -EOPNOTSUPP) {
|
||||||
|
test__skip();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!ASSERT_GE(fd, 0, "bpf_map_create"))
|
||||||
|
return;
|
||||||
|
|
||||||
|
area = mmap(NULL, pages * getpagesize(), PROT_READ | PROT_WRITE,
|
||||||
|
MAP_SHARED | flags, fd, 0);
|
||||||
|
if (ASSERT_EQ(area, MAP_FAILED, "mmap"))
|
||||||
|
ASSERT_EQ(errno, err, "errno");
|
||||||
|
else
|
||||||
|
munmap(area, pages * getpagesize());
|
||||||
|
close(fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_arena_mmap(void)
|
||||||
|
{
|
||||||
|
if (test__start_subtest("long"))
|
||||||
|
test_refused(ARENA_PAGES + 1, 0, E2BIG);
|
||||||
|
if (test__start_subtest("address_0"))
|
||||||
|
test_refused(ARENA_PAGES, MAP_FIXED, EINVAL);
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user