hugemmap37: Migrate truncate_sigbus_versus_oom from libhugetlbfs
PATCH v6 1/1 hugemmap37: Migrate truncate_sigbus_versus_oom from libhugetlbfs
Some kernels have a bug in the positioning of the test against i_size. This bug means that attempting to instantiate a page beyond the end of a hugepage file can result in an OOM and SIGKILL instead of the correct SIGBUS.
This test verifies that accessing memory beyond a truncated hugepage file correctly triggers SIGBUS rather than causing an OOM condition.
---
v6:
1. Fixed description: Removed dangling comma and improved clarity
2. Added 'static' keyword to setup() and cleanup() functions
3. Fixed signal handler initialization:
- Zero-initialized struct sigaction with = {}
- Added sigemptyset(&sa.sa_mask)
- Removed SA_SIGINFO flag (using sa_handler, not sa_sigaction)
4. Removed dead code: Deleted unused totpages assignment from setup()
5. Fixed resource leaks in run_test():
- Added SAFE_MUNMAP() for both mapped regions (p and q)
- Added SAFE_CLOSE() for both file descriptors (fd and fdx)
- Reset fd and fdx to -1 after closing
6. Fixed cleanup() checks: Changed 'if (fd > 0)' to 'if (fd != -1)'
7. Initialized file descriptors to -1 at declaration
--- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap37.c | 106 ++++++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap37.c
runtest/hugetlb +1 -0
@@ -36,6 +36,7 @@ hugemmap30 hugemmap30 hugemmap31 hugemmap31 hugemmap32 hugemmap32 hugemmap34 hugemmap34 +hugemmap37 hugemmap37 hugemmap05_1 hugemmap05 -m hugemmap05_2 hugemmap05 -s hugemmap05_3 hugemmap05 -s -m
testcases/kernel/mem/.gitignore +1 -0
@@ -36,6 +36,7 @@ /hugetlb/hugemmap/hugemmap31 /hugetlb/hugemmap/hugemmap32 /hugetlb/hugemmap/hugemmap34 +/hugetlb/hugemmap/hugemmap37 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03
testcases/kernel/mem/hugetlb/hugemmap/hugemmap37.c new file +106 -0
106 lines not on this page · raw message
Signature · 5 lines
2.52.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Samir,
Quoted 3 lines
+/*
+ * Copyright (C) 2005-2006 David Gibson & Adam Litke, IBM Corporation.
+ */
New file; please add a 2026 copyright line for yourself as the migration author.
testcases/kernel/mem/hugetlb/hugemmap/hugemmap37.c line 53
Quoted 7 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap37.c new file +7
-0+ p =SAFE_MMAP (NULL , hpage_size,PROT_READ |PROT_WRITE ,MAP_SHARED , fd,0 ); +SAFE_FTRUNCATE (fd,0 ); + + fdx =tst_creat_unlinked (MNTPOINT ,0 ,0600 ); + totpages =SAFE_READ_MEMINFO (MEMINFO_HPAGE_FREE ); + q =SAFE_MMAP (NULL , totpages * hpage_size,PROT_READ |PROT_WRITE ,MAP_SHARED , + fdx,0 );
If the second SAFE_MMAP (or anything between the two) aborts, p is still mapped but cleanup() only handles fds. Move p and q to file scope and add SAFE_MUNMAP guards in cleanup().
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp