[PATCH bpf 2/2] selftests/bpf: validate frozen map contents stays frozen

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

 



Test that frozen and mmap()'ed BPF map can't be mprotect()'ed as writable or
executable memory.

Signed-off-by: Andrii Nakryiko <andriin@xxxxxx>
---
 tools/testing/selftests/bpf/prog_tests/mmap.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/tools/testing/selftests/bpf/prog_tests/mmap.c b/tools/testing/selftests/bpf/prog_tests/mmap.c
index 16a814eb4d64..1cdb738346a5 100644
--- a/tools/testing/selftests/bpf/prog_tests/mmap.c
+++ b/tools/testing/selftests/bpf/prog_tests/mmap.c
@@ -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);
-- 
2.24.1





[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