mprotect: Add mprotect05 testcase
PATCH 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 | 118 ++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 testcases/kernel/syscalls/mprotect/mprotect05.c
testcases/kernel/syscalls/mprotect/mprotect05.c new file +118 -0
@@ -0,0 +1,118 @@ +/* +* Copyright (c) International Business Machines Corp., 2001 +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +* the GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +/* +* DESCRIPTION +* Testcase to check the mprotect(2) system call split/merge +* +* ALGORITHM +* Create a mapped region using mmap with READ permission. +* Create different VMAs in stripes with mprotect (exec & write) +* mprotect over middle & write area, causing vma_merge of prev & next +* before hitting the limnits. +* +*/ + +#include <sys/mman.h> +#include <sys/wait.h> +#include <errno.h> +#include <fcntl.h> +#include <limits.h> +#include <stdlib.h> +#include "test.h" + +#include "safe_macros.h" + +static void sighandler (int sig); +static void cleanup (void ); +static void setup (void ); + +char *TCID ="mprotect05" ; +int TST_TOTAL =1 ; +static int fd; +static char file1[BUFSIZ ]; + +static char *addr =MAP_FAILED ; +static unsigned long fullsize; + +int main (int ac,char **av) +{ +int lc; +int fd; +unsigned long pagesize; + +tst_parse_opts (ac, av,NULL ,NULL ); + +setup (); + + pagesize =getpagesize (); + fullsize =5 * pagesize; + +for (lc =0 ;TEST_LOOPING (lc); lc++) { + fd =SAFE_OPEN (cleanup, file1,O_RDWR |O_CREAT ,0777 ); + + addr =SAFE_MMAP (cleanup,0 , fullsize,PROT_READ , +MAP_SHARED , fd,0 ); + +TEST (mprotect (addr + pagesize, pagesize*1 ,PROT_EXEC )); +if (TEST_RETURN ) +tst_resm (TFAIL |TERRNO ,"mprotect failed to write" ); + +TEST (mprotect (addr +3 *pagesize, pagesize,PROT_WRITE )); +if (TEST_RETURN ) +tst_resm (TFAIL |TERRNO ,"mprotect failed to write" ); + +TEST (mprotect (addr + pagesize, pagesize*4 ,PROT_READ )); +if (TEST_RETURN ) +tst_resm (TFAIL |TERRNO ,"mprotect failed to write" ); + +SAFE_MUNMAP (cleanup, addr, fullsize); + addr =MAP_FAILED ; +SAFE_CLOSE (cleanup, fd); +SAFE_UNLINK (cleanup, file1); + } + +cleanup (); +tst_exit (); +} + +static void sighandler (int sig) +{ +_exit ((sig ==SIGSEGV ) ?0 : sig); +} + +static void setup (void ) +{ +tst_sig (FORK , sighandler, cleanup); + +TEST_PAUSE ; + +tst_tmpdir (); + +sprintf (file1,"mprotect05.tmp.%d" ,getpid ()); +} + +static void cleanup (void ) +{ +if (addr !=MAP_FAILED ) { +SAFE_MUNMAP (NULL , addr, fullsize); +SAFE_CLOSE (NULL , fd); + } + +tst_rmdir (); +}
Signature · 5 lines
2.39.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Quoted 23 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.
Signed-off-by Liam R. Howlett <[email protected]>--- .../kernel/syscalls/mprotect/mprotect05.c | 118 ++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 testcases/kernel/syscalls/mprotect/mprotect05.ctestcases/kernel/syscalls/mprotect/mprotect05.c new file +7
-0@@ -0,0 +1,118 @@ +/* +* Copyright (c) International Business Machines Corp., 2001 +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version.
testcases/kernel/syscalls/mprotect/mprotect05.c line 17
Quoted 10 lines
testcases/kernel/syscalls/mprotect/mprotect05.c new file +10
-0+* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +* the GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/
We switched to SPDX long time ago, please use that instead.
testcases/kernel/syscalls/mprotect/mprotect05.c line 29
Quoted 11 lines
testcases/kernel/syscalls/mprotect/mprotect05.c new file +11
-0+/* +* DESCRIPTION +* Testcase to check the mprotect(2) system call split/merge +* +* ALGORITHM +* Create a mapped region using mmap with READ permission. +* Create different VMAs in stripes with mprotect (exec & write) +* mprotect over middle & write area, causing vma_merge of prev & next +* before hitting the limnits. +* +*/
This should be asciidoc formatted comment that starts with a special header:
/*\
* [Description]
*
Quoted 52 lines
testcases/kernel/syscalls/mprotect/mprotect05.c new file +52
-0+#include <sys/mman.h> +#include <sys/wait.h> +#include <errno.h> +#include <fcntl.h> +#include <limits.h> +#include <stdlib.h> +#include "test.h" + +#include "safe_macros.h" + +static void sighandler (int sig); +static void cleanup (void ); +static void setup (void ); + +char *TCID ="mprotect05" ; +int TST_TOTAL =1 ; +static int fd; +static char file1[BUFSIZ ]; + +static char *addr =MAP_FAILED ; +static unsigned long fullsize; + +int main (int ac,char **av) +{ +int lc; +int fd; +unsigned long pagesize; + +tst_parse_opts (ac, av,NULL ,NULL ); + +setup (); + + pagesize =getpagesize (); + fullsize =5 * pagesize; + +for (lc =0 ;TEST_LOOPING (lc); lc++) { + fd =SAFE_OPEN (cleanup, file1,O_RDWR |O_CREAT ,0777 ); + + addr =SAFE_MMAP (cleanup,0 , fullsize,PROT_READ , +MAP_SHARED , fd,0 ); + +TEST (mprotect (addr + pagesize, pagesize*1 ,PROT_EXEC )); +if (TEST_RETURN ) +tst_resm (TFAIL |TERRNO ,"mprotect failed to write" ); + +TEST (mprotect (addr +3 *pagesize, pagesize,PROT_WRITE )); +if (TEST_RETURN ) +tst_resm (TFAIL |TERRNO ,"mprotect failed to write" ); + +TEST (mprotect (addr + pagesize, pagesize*4 ,PROT_READ )); +if (TEST_RETURN ) +tst_resm (TFAIL |TERRNO ,"mprotect failed to write" );
testcases/kernel/syscalls/mprotect/mprotect05.c line 92
Quoted 10 lines
testcases/kernel/syscalls/mprotect/mprotect05.c new file +10
-0+ +SAFE_MUNMAP (cleanup, addr, fullsize); + addr =MAP_FAILED ; +SAFE_CLOSE (cleanup, fd); +SAFE_UNLINK (cleanup, file1); + } + +cleanup (); +tst_exit (); +}
Please use the new test library, the old test library is deprecated and will be removed. See include/tst_test.h.
Quoted 31 lines
testcases/kernel/syscalls/mprotect/mprotect05.c new file +25
-0+static void sighandler (int sig) +{ +_exit ((sig ==SIGSEGV ) ?0 : sig); +} + +static void setup (void ) +{ +tst_sig (FORK , sighandler, cleanup); + +TEST_PAUSE ; + +tst_tmpdir (); + +sprintf (file1,"mprotect05.tmp.%d" ,getpid ()); +} + +static void cleanup (void ) +{ +if (addr !=MAP_FAILED ) { +SAFE_MUNMAP (NULL , addr, fullsize); +SAFE_CLOSE (NULL , fd); + } + +tst_rmdir (); +}Signature · 5 lines
2.39.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 28 lines · Cyril Hrubis
Hi!
Quoted 27 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.
Signed-off-by Liam R. Howlett <[email protected]>--- .../kernel/syscalls/mprotect/mprotect05.c | 118 ++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 testcases/kernel/syscalls/mprotect/mprotect05.ctestcases/kernel/syscalls/mprotect/mprotect05.c new file +11
-0@@ -0,0 +1,118 @@ +/* +* Copyright (c) International Business Machines Corp., 2001 +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
Quoted 8 lines
testcases/kernel/syscalls/mprotect/mprotect05.c line 17
Quoted 6 lines
testcases/kernel/syscalls/mprotect/mprotect05.c new file +6
-0+* the GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ We switched to SPDX long time ago, please use that instead.
Thanks, this seems to be the wrong file anyways. I've messed up this patch. I'll move to SPDX from the right file.
Quoted 13 lines
testcases/kernel/syscalls/mprotect/mprotect05.c line 29
Quoted 12 lines
testcases/kernel/syscalls/mprotect/mprotect05.c new file +11
-0+/* +* DESCRIPTION +* Testcase to check the mprotect(2) system call split/merge +* +* ALGORITHM +* Create a mapped region using mmap with READ permission. +* Create different VMAs in stripes with mprotect (exec & write) +* mprotect over middle & write area, causing vma_merge of prev & next +* before hitting the limnits. +* +*/
Quoted 6 lines
This should be asciidoc formatted comment that starts with a special header:
/*\
* [Description]
*
Thanks.
Quoted 58 lines
Quoted 58 lines
testcases/kernel/syscalls/mprotect/mprotect05.c new file +57
-0+#include <sys/mman.h> +#include <sys/wait.h> +#include <errno.h> +#include <fcntl.h> +#include <limits.h> +#include <stdlib.h> +#include "test.h" + +#include "safe_macros.h" + +static void sighandler (int sig); +static void cleanup (void ); +static void setup (void ); + +char *TCID ="mprotect05" ; +int TST_TOTAL =1 ; +static int fd; +static char file1[BUFSIZ ]; + +static char *addr =MAP_FAILED ; +static unsigned long fullsize; + +int main (int ac,char **av) +{ +int lc; +int fd; +unsigned long pagesize; + +tst_parse_opts (ac, av,NULL ,NULL ); + +setup (); + + pagesize =getpagesize (); + fullsize =5 * pagesize; + +for (lc =0 ;TEST_LOOPING (lc); lc++) { + fd =SAFE_OPEN (cleanup, file1,O_RDWR |O_CREAT ,0777 ); + + addr =SAFE_MMAP (cleanup,0 , fullsize,PROT_READ , +MAP_SHARED , fd,0 ); + +TEST (mprotect (addr + pagesize, pagesize*1 ,PROT_EXEC )); +if (TEST_RETURN ) +tst_resm (TFAIL |TERRNO ,"mprotect failed to write" ); + +TEST (mprotect (addr +3 *pagesize, pagesize,PROT_WRITE )); +if (TEST_RETURN ) +tst_resm (TFAIL |TERRNO ,"mprotect failed to write" ); + +TEST (mprotect (addr + pagesize, pagesize*4 ,PROT_READ )); +if (TEST_RETURN ) +tst_resm (TFAIL |TERRNO ,"mprotect failed to write" ); + +SAFE_MUNMAP (cleanup, addr, fullsize); + addr =MAP_FAILED ; +SAFE_CLOSE (cleanup, fd); +SAFE_UNLINK (cleanup, file1);
Quoted 8 lines
testcases/kernel/syscalls/mprotect/mprotect05.c line 92
Quoted 5 lines
testcases/kernel/syscalls/mprotect/mprotect05.c new file +5
-0+ } + +cleanup (); +tst_exit (); +}Please use the new test library, the old test library is deprecated and will be removed. See
include/tst_test.h.
Thanks. I'll do that.
Quoted 36 lines
Quoted 32 lines
testcases/kernel/syscalls/mprotect/mprotect05.c new file +25
-0+static void sighandler (int sig) +{ +_exit ((sig ==SIGSEGV ) ?0 : sig); +} + +static void setup (void ) +{ +tst_sig (FORK , sighandler, cleanup); + +TEST_PAUSE ; + +tst_tmpdir (); + +sprintf (file1,"mprotect05.tmp.%d" ,getpid ()); +} + +static void cleanup (void ) +{ +if (addr !=MAP_FAILED ) { +SAFE_MUNMAP (NULL , addr, fullsize); +SAFE_CLOSE (NULL , fd); + } + +tst_rmdir (); +}Signature · 5 lines
2.39.0 -- Mailing list info: https://lists.linux.it/listinfo/ltpSignature · 2 lines
Cyril Hrubis [email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp