hugemmap37: migrated task-size-overrun.c from libhugetlbfs v4
PATCH 1/1 hugemmap37: migrated task-size-overrun.c from libhugetlbfs v4
This test verifies that the kernel correctly prevents mmap operations from creating mappings that straddle the TASK_SIZE boundary when using hugepages. Such mappings could lead to undefined behavior or security issues if allowed.
--- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap37.c | 164 ++++++++++++++++++ 3 files changed, 166 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 +164 -0
164 lines not on this page · raw message
Signature · 5 lines
2.53.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Pavithra,
Quoted 8 lines · Pavithra
hugemmap37: migrated
task-size-overrun.cfrom libhugetlbfs v4testcases/kernel/mem/hugetlb/hugemmap/hugemmap37.c new file +6
-0+static unsigned long find_last_mapped (void ) +{ +char line[MAPS_BUF_SZ ]; + ... +/* Read all lines and keep the last non-special mapping */ +while (fgets (line,MAPS_BUF_SZ , f)) {
testcases/kernel/mem/hugetlb/hugemmap/hugemmap37.c line 58
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap37.c new file +10
-0+/* Skip special mappings like [vsyscall], [vdso], [vvar] */ +if (strstr (line,"[vsyscall]" ) ||strstr (line,"[vdso]" ) || +strstr (line,"[vvar]" )) +continue ; + + found =1 ; + } + ... +tst_res (TINFO ,"Last map: %s" , line); +if (sscanf (line,"%lx-%lx %*s %lx %*s %ld" , &start, &end, &off, &ino) !=4 )
The comment says "keep the last non-special mapping" but the code does not do that. fgets() overwrites line on every iteration, including iterations that immediately hit the continue. After the loop, line holds the last line read overall, not the last non-special line.
On x86_64 with vsyscall support, [vsyscall] appears as the final entry in /proc/self/maps at address 0xffffffffff600000. In that case sscanf parses that address and find_last_mapped() returns 0xffffffffff601000. find_task_size() then starts its binary search with a low-PFN value already above TASK_SIZE, all probe mmaps fail, and an incorrect TASK_SIZE is returned -- making straddle_addr wrong and the test results unreliable.
The fix is to copy line into a separate buffer when a non-special line is encountered, and use that saved buffer after the loop.
Quoted 1 line
+// SPDX-License-Identifier: LGPL-2.1-or-later
Other tests in this directory that were migrated from the same libhugetlbfs upstream (e.g. hugemmap34.c, which credits the same original authors) carry GPL-2.0-or-later. LTP relicenses migrated code under GPL-2.0-or-later for consistency.
Quoted 4 lines
+/*
+ * Origin: https://github.com/libhugetlbfs/...
+ *
+ * This test verifies the behavior of mmap across theTASK_SIZEboundary.
The high-level description block must open with /*\ (backslash after the slash-star) so that the LTP documentation build recognises it as an RST-formatted block and includes it in the test catalog. A plain /* comment is silently ignored by the doc toolchain.
Verdict - Needs revision
---
Note:
The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.
Regards,
LTP AI Reviewer
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp