mprotect: Add mprotect05 testcase
PATCH v2 1/1 mprotect: Add mprotect05 testcase
Add a test that uses mprotect to split and combine VMAs. Created to ensure the correctness of the VMA iterator after a bug report.
--- .../kernel/syscalls/mprotect/mprotect05.c | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 testcases/kernel/syscalls/mprotect/mprotect05.c
testcases/kernel/syscalls/mprotect/mprotect05.c new file +69 -0
@@ -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 <[email protected]> +*/ + +/*\ +* [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 , +};
Signature · 5 lines
2.39.2 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Liam,
Quoted 2 lines
Add a test that uses mprotect to split and combine VMAs. Created to ensure the correctness of the VMA iterator after a bug report.
LGTM, thank you.
...
Quoted 7 lines
+/*\
+ * [Description]
+ *
+ * Testcase to check the mprotect(2) system call split and merge
+ *
+ * Reference links:
+ * - https://bugzilla.kernel.org/show_bug.cgi?id=217061
This would be formatted as inline in our docs.
testcases/kernel/syscalls/mprotect/mprotect05.c line 18
Quoted 5 lines
+ *
+ */testcases/kernel/syscalls/mprotect/mprotect05.c new file +3
-0+ +#include <errno.h> +#include <stdio.h>
These aren't needed.
Waiting little longer for any feedback before merging with the diff below.
Kind regards,
Petr
+++ testcases/kernel/syscalls/mprotect/mprotect05.c @@ -9,14 +9,10 @@
*
* Testcase to check the mprotect(2) system call split and merge
*
- * Reference links:
- * - https://bugzilla.kernel.org/show_bug.cgi?id=217061
+ * https://bugzilla.kernel.org/show_bug.cgi?id=217061
*
*/
-#include <errno.h>
-#include <stdio.h>
-
#include "tst_test.h"
#define TEST_FILE "mprotect05-testfile"
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Quoted 16 lines
Quoted 2 lines
Add a test that uses mprotect to split and combine VMAs. Created to ensure the correctness of the VMA iterator after a bug report.
LGTM, thank you.
Reviewed-by Petr Vorel <[email protected]>...
Quoted 7 lines
+/*\
+ * [Description]
+ *
+ * Testcase to check the mprotect(2) system call split and merge
+ *
+ * Reference links:
+ * - https://bugzilla.kernel.org/show_bug.cgi?id=217061This would be formatted as inline in our docs.
Quoted 8 lines
testcases/kernel/syscalls/mprotect/mprotect05.c line 18
Quoted 5 lines
+ *
+ */testcases/kernel/syscalls/mprotect/mprotect05.c new file +3
-0+ +#include <errno.h> +#include <stdio.h> These aren't needed.
Waiting little longer for any feedback before merging with the diff below.
Can we also add a git tag to the test? It looks like fix is in mainline in:
commit 2fcd07b7ccd5fd10b2120d298363e4e6c53ccf9c
Author: Liam R. Howlett <[email protected]> Date: Fri Feb 24 16:20:55 2023 -0500
mm/mprotect: Fix successful vma_merge() of next in do_mprotect_pkey()
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Cyril, Liam,
Quoted 8 lines
Can we also add a git tag to the test? It looks like fix is in mainline in:
commit
2fcd07b7ccd5fd10b2120d298363e4e6c53ccf9cAuthor: Liam R. Howlett <[email protected]> Date: Fri Feb 24 16:20:55 2023 -0500mm/mprotect: Fix successful
vma_merge()of next indo_mprotect_pkey()
Good catch, thanks!
Merged with git tag + added .gitignore and runtest/syscalls entry.
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp