bpf: Fix bug in mmap() implementation for BPF array map
mmap() subsystem allows user-space application to memory-map region with
initial page offset. This wasn't taken into account in initial implementation
of BPF array memory-mapping. This would result in wrong pages, not taking into
account requested page shift, being memory-mmaped into user-space. This patch
fixes this gap and adds a test for such scenario.
Fixes: fc9702273e ("bpf: Add mmap() support for BPF_MAP_TYPE_ARRAY")
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Yonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/bpf/20200512235925.3817805-1-andriin@fb.com
This commit is contained in:
committed by
Alexei Starovoitov
parent
23ad04669f
commit
333291ce50
@@ -217,6 +217,14 @@ void test_mmap(void)
|
||||
|
||||
munmap(tmp2, 4 * page_size);
|
||||
|
||||
/* map all 4 pages, but with pg_off=1 page, should fail */
|
||||
tmp1 = mmap(NULL, 4 * page_size, PROT_READ, MAP_SHARED | MAP_FIXED,
|
||||
data_map_fd, page_size /* initial page shift */);
|
||||
if (CHECK(tmp1 != MAP_FAILED, "adv_mmap7", "unexpected success")) {
|
||||
munmap(tmp1, 4 * page_size);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
tmp1 = mmap(NULL, map_sz, PROT_READ, MAP_SHARED, data_map_fd, 0);
|
||||
if (CHECK(tmp1 == MAP_FAILED, "last_mmap", "failed %d\n", errno))
|
||||
goto cleanup;
|
||||
|
||||
Reference in New Issue
Block a user