[LTP] [PATCH v2 0/2] Harden safe_sysconf() and add madvise13
Wenyuan Li
2063309626@qq.com
Wed Nov 4 12:00:19 CET 2026
This is v2 of the RFC that adds a madvise() test covering MADV_DONTNEED
across an unmapped hole.
I split this into two patches: the first tightens safe_sysconf() as
suggested, the second adds madvise13. I can squash them if you prefer a
single patch.
The library change affects every SAFE_SYSCONF() caller, so keeping it in
its own patch makes the blast radius visible and makes it easy to review,
bisect or revert independently. Patch 2/2 depends on 1/2.
Changes in v2 (addressing Cyril Hrubis' review):
- lib: move the page size validation into safe_sysconf(), reject values
below -1, and for _SC_PAGESIZE also reject -1 without errno, zero and
non-power-of-two values; leave the generic -1 && !errno path unchanged
- split the check helpers into page_mapped()/page_first_mismatch() and
keep TPASS/TFAIL in run()
- drop the MADV_NOHUGEPAGE call
- rename the local range macros to RANGE_FIRST/RANGE_LAST/RANGE_PAGES to
avoid confusion with MADV_* advice constants
- rebase on current master (d9add0a9a)
Verified on x86_64, 4096-byte pages, kernel 6.18.54.1 (WSL2): lib and
madvise13 build cleanly, madvise13 reports 18 TPASS / 0 failed and 36
TPASS with -i 2. git diff --check passes.
Link: https://lore.kernel.org/ltp/tencent_B786C5458553D16AB70F62E3AAC3C5C9B306@qq.com
Wenyuan Li (2):
lib: Validate sysconf() return values in the safe wrapper
syscalls/madvise13: Check MADV_DONTNEED across an unmapped hole
lib/safe_macros.c | 20 +++
runtest/syscalls | 1 +
testcases/kernel/syscalls/madvise/.gitignore | 1 +
testcases/kernel/syscalls/madvise/madvise13.c | 154 ++++++++++++++++++
4 files changed, 176 insertions(+)
create mode 100644 testcases/kernel/syscalls/madvise/madvise13.c
--
2.43.0
More information about the ltp
mailing list