hugemmap/hugemmap37: migrated task-size-overrun.c from libhugetlbfs
PATCH 1/1 hugemmap/hugemmap37: migrated task-size-overrun.c from libhugetlbfs
This test verifies that the kernel correctly prevents mmap operations from creating mappings that straddle the TASK_SIZE boundary when using hugepages.
Signed-off-by Pavithra <[email protected]>
--- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap37.c | 173 ++++++++++++++++++ 3 files changed, 175 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap37.c
runtest/hugetlb +1 -0
@@ -37,6 +37,7 @@ hugemmap31 hugemmap31 hugemmap32 hugemmap32 hugemmap34 hugemmap34 hugemmap35 hugemmap35 +hugemmap37 hugemmap37 hugemmap05_1 hugemmap05 -m hugemmap05_2 hugemmap05 -s hugemmap05_3 hugemmap05 -s -m
testcases/kernel/mem/.gitignore +1 -0
@@ -37,6 +37,7 @@ /hugetlb/hugemmap/hugemmap32 /hugetlb/hugemmap/hugemmap34 /hugetlb/hugemmap/hugemmap35 +/hugetlb/hugemmap/hugemmap37 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03
testcases/kernel/mem/hugetlb/hugemmap/hugemmap37.c new file +173 -0
173 lines not on this page · raw message
Signature · 5 lines
2.55.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Pushed with following diff, thanks.
Changes:
- use TDEBUG for the verbose messages
- use TST_EXP_* macros, on Linux mmap() without MAP_FIXED ignores the address hint and always succeeds
- moved the code that locates task_size into the test setup() so that it's called exactly once on test with -i 10
testcases/kernel/mem/hugetlb/hugemmap/hugemmap37.c +19 -28
@@ -34,6 +34,7 @@#define MNTPOINT "hugetlbfs/"static long hpage_size; +static unsigned long task_size;static int fd =-1 ;static unsigned long find_last_mapped (void )
@@ -100,10 +101,10 @@ static unsigned long find_task_size(void) p =mmap ((void *)addr, page_size,PROT_READ ,MAP_PRIVATE |MAP_ANONYMOUS |MAP_FIXED ,-1 ,0 );if (p ==MAP_FAILED ) { -tst_res (TINFO |TERRNO ,"Map failed at 0x%lx" , addr); +tst_res (TDEBUG |TERRNO ,"Map failed at 0x%lx" , addr); high = pfn; }else { -tst_res (TINFO ,"Map succeeded at 0x%lx" , addr); +tst_res (TDEBUG ,"Map succeeded at 0x%lx" , addr);SAFE_MUNMAP (p, page_size); low = pfn; }
@@ -114,45 +115,35 @@ static unsigned long find_task_size(void)static void run_test (void ) { -void *p; -unsigned long task_size;unsigned long straddle_addr; - task_size =find_task_size (); -tst_res (TINFO ,"TASK_SIZE = 0x%lx" , task_size); - straddle_addr = task_size - hpage_size; straddle_addr =LTP_ALIGN (straddle_addr, hpage_size);tst_res (TINFO ,"Mapping without MAP_FIXED at %lx..." , straddle_addr); - errno =0 ; - p =mmap ((void *)straddle_addr,2 *hpage_size,PROT_READ |PROT_WRITE , -MAP_SHARED , fd,0 ); -if (p == (void *)straddle_addr) { -tst_res (TFAIL ,"Apparently succeeded in mapping across TASK_SIZE boundary" ); -SAFE_MUNMAP (p,2 *hpage_size); - }else if (p !=MAP_FAILED ) { -tst_res (TPASS ,"mmap without MAP_FIXED correctly avoided TASK_SIZE boundary" ); -SAFE_MUNMAP (p,2 *hpage_size); - }else { -tst_res (TPASS ,"mmap without MAP_FIXED correctly failed" ); - } + +TST_EXP_PASS_PTR_VOID (mmap ((void *)straddle_addr,2 *hpage_size, +PROT_READ |PROT_WRITE ,MAP_SHARED , fd,0 )); + +if (TST_RET_PTR !=MAP_FAILED ) +SAFE_MUNMAP (TST_RET_PTR ,2 *hpage_size);tst_res (TINFO ,"Mapping with MAP_FIXED at %lx..." , straddle_addr); - errno =0 ; - p =mmap ((void *)straddle_addr,2 *hpage_size,PROT_READ |PROT_WRITE , -MAP_SHARED |MAP_FIXED , fd,0 ); -if (p !=MAP_FAILED ) { -tst_res (TFAIL ,"Apparently succeeded in mapping across TASK_SIZE boundary" ); -SAFE_MUNMAP (p,2 *hpage_size); - }else { -tst_res (TPASS ,"mmap with MAP_FIXED correctly failed" ); - } + +TST_EXP_FAIL_PTR_VOID (mmap ((void *)straddle_addr,2 *hpage_size, +PROT_READ |PROT_WRITE ,MAP_SHARED |MAP_FIXED , fd,0 ),ENOMEM ); + +if (TST_RET_PTR !=MAP_FAILED ) +SAFE_MUNMAP (TST_RET_PTR ,2 *hpage_size); }static void setup (void ) { hpage_size =tst_get_hugepage_size (); + + task_size =find_task_size (); +tst_res (TINFO ,"TASK_SIZE = 0x%lx" , task_size); + fd =tst_creat_unlinked (MNTPOINT ,0 ,0600 ); }
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp