@@ -140,6 +140,22 @@ void test_mmap(void)
goto cleanup;
}
+ map_mmaped = mmap(NULL, map_sz, PROT_READ, MAP_SHARED, data_map_fd, 0);
+ if (CHECK(map_mmaped == MAP_FAILED, "data_mmap",
+ "data_map R/O mmap failed: %d\n", errno)) {
+ map_mmaped = NULL;
+ goto cleanup;
+ }
+ err = mprotect(map_mmaped, map_sz, PROT_WRITE);
+ if (CHECK(!err, "mprotect_wr", "mprotect() succeeded unexpectedly!\n"))
+ goto cleanup;
+ err = mprotect(map_mmaped, map_sz, PROT_EXEC);
+ if (CHECK(!err, "mprotect_ex", "mprotect() succeeded unexpectedly!\n"))
+ goto cleanup;
+ err = munmap(map_mmaped, map_sz);
+ CHECK_FAIL(err);
+ map_mmaped = NULL;
+
bss_data->in_val = 321;
usleep(1);
CHECK_FAIL(bss_data->in_val != 321);
Test that frozen and mmap()'ed BPF map can't be mprotect()'ed as writable or executable memory. Signed-off-by: Andrii Nakryiko <andriin@fb.com> --- tools/testing/selftests/bpf/prog_tests/mmap.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)