[LTP] [PATCH v2] mprotect: Add mprotect05 testcase
Liam R. Howlett
Liam.Howlett@oracle.com
Wed Mar 1 20:33:32 CET 2023
Add a test that uses mprotect to split and combine VMAs. Created to
ensure the correctness of the VMA iterator after a bug report.
Link: https://bugzilla.kernel.org/show_bug.cgi?id=217061
Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
---
.../kernel/syscalls/mprotect/mprotect05.c | 69 +++++++++++++++++++
1 file changed, 69 insertions(+)
create mode 100644 testcases/kernel/syscalls/mprotect/mprotect05.c
diff --git a/testcases/kernel/syscalls/mprotect/mprotect05.c b/testcases/kernel/syscalls/mprotect/mprotect05.c
new file mode 100644
index 000000000..974e026ae
--- /dev/null
+++ b/testcases/kernel/syscalls/mprotect/mprotect05.c
@@ -0,0 +1,69 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2023 Oracle and/or its affiliates. All Rights Reserved.
+ * Author: Liam R. Howlett <liam.howlett@oracle.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Testcase to check the mprotect(2) system call split and merge
+ *
+ * Reference links:
+ * - https://bugzilla.kernel.org/show_bug.cgi?id=217061
+ *
+ */
+
+#include <errno.h>
+#include <stdio.h>
+
+#include "tst_test.h"
+
+#define TEST_FILE "mprotect05-testfile"
+
+static int fd;
+static char *addr = MAP_FAILED;
+static unsigned long pagesize;
+static unsigned long fullsize;
+
+static void setup(void)
+{
+ pagesize = getpagesize();
+ fullsize = 5 * pagesize;
+}
+
+static void run(void)
+{
+ fd = SAFE_OPEN(TEST_FILE, O_RDWR | O_CREAT, 0777);
+ addr = SAFE_MMAP(0, fullsize, PROT_READ, MAP_SHARED, fd, 0);
+
+ if (mprotect(addr + pagesize, pagesize, PROT_EXEC))
+ tst_res(TFAIL | TERRNO, "mprotect failed to exec");
+
+ if (mprotect(addr + 3 * pagesize, pagesize, PROT_WRITE))
+ tst_res(TFAIL | TERRNO, "mprotect failed to write");
+
+ if (mprotect(addr + pagesize, pagesize * 4, PROT_READ))
+ tst_res(TFAIL | TERRNO, "mprotect failed to read");
+
+ SAFE_MUNMAP(addr, fullsize);
+ SAFE_CLOSE(fd);
+ addr = MAP_FAILED;
+ SAFE_UNLINK(TEST_FILE);
+ tst_res(TPASS, "test successfull");
+}
+
+static void cleanup(void)
+{
+ if (addr != MAP_FAILED) {
+ SAFE_MUNMAP(addr, fullsize);
+ SAFE_CLOSE(fd);
+ }
+}
+
+static struct tst_test test = {
+ .test_all = run,
+ .setup = setup,
+ .cleanup = cleanup,
+ .needs_tmpdir = 1,
+};
--
2.39.2
More information about the ltp
mailing list