futex: Add EFAULT error coverage tests
v17 cover futex: Add EFAULT error coverage tests
Hi Petr,
Thanks for the review. Here is v17 addressing your feedback.
futex_wait06 and futex_wait07 were already merged. This series contains the remaining two patches.
futex_cmp_requeue03:
Applied your nit — removed the exp_errno field from the testcase struct and used EFAULT directly in TST_EXP_FAIL().
futex_wake05:
Applied both nits (list comment format, EFAULT directly). For the kernel-space address case: you were right to question it. I couldn't confirm consistent EFAULT across kernels, so I looked for a better replacement.
I used AI assistance to research the kernel's get_user_pages() code paths and cross-referenced existing LTP mmap tests to verify the approach. The replacement I landed on is a shared file-backed mapping where the file is truncated to 0 after mmap().
The three cases now exercise genuinely different code paths:
- unmapped memory fails at find_vma() (no VMA exists)
- PROT_NONE memory fails at get_user_pages_fast() (VMA exists but page is inaccessible)
- the truncated file mapping triggers VM_FAULT_SIGBUS inside the page fault handler (filemap_fault() sees offset beyond EOF), which get_user_pages() propagates as EFAULT
The SIGBUS is never delivered to user space — get_user_pages() converts VM_FAULT_SIGBUS to -EFAULT internally. This behavior has been stable since before kernel 2.6 and works reliably on all architectures and both 32/64-bit. The test uses .needs_tmpdir = 1.
Changes since v16:
- futex_wake05: replace kernel-space address case with truncated file-backed mapping, fix comment to list format, use EFAULT directly in TST_EXP_FAIL(), add .needs_tmpdir
- futex_cmp_requeue03: use EFAULT directly in TST_EXP_FAIL()
Michael Menasherov (2):
futex_wake05: Add EFAULT error coverage test
futex_cmp_requeue03: Add EFAULT error coverage test
runtest/syscalls | 2 + testcases/kernel/syscalls/futex/.gitignore | 2 + .../syscalls/futex/futex_cmp_requeue03.c | 103 ++++++++++++++++ .../kernel/syscalls/futex/futex_wake05.c | 113 ++++++++++++++++++ 4 files changed, 220 insertions(+) create mode 100644 testcases/kernel/syscalls/futex/futex_cmp_requeue03.c create mode 100644 testcases/kernel/syscalls/futex/futex_wake05.c
Signature · 5 lines
2.55.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v17 1/2 futex_wake05: Add EFAULT error coverage test
futex(FUTEX_WAKE) has no existing test for EFAULT. Add coverage for unmapped, PROT_NONE, and truncated file-backed uaddr, each exercising a different code path in the kernel's address validation.
--- runtest/syscalls | 1 + testcases/kernel/syscalls/futex/.gitignore | 1 + .../kernel/syscalls/futex/futex_wake05.c | 113 ++++++++++++++++++ 3 files changed, 115 insertions(+) create mode 100644 testcases/kernel/syscalls/futex/futex_wake05.c
runtest/syscalls +1 -0
@@ -1878,6 +1878,7 @@ futex_wake01 futex_wake01 futex_wake02 futex_wake02 futex_wake03 futex_wake03 futex_wake04 futex_wake04 +futex_wake05 futex_wake05 futex_wait_bitset01 futex_wait_bitset01 memfd_create01 memfd_create01
testcases/kernel/syscalls/futex/.gitignore +1 -0
@@ -15,3 +15,4 @@ /futex_waitv03 /futex_wait06 /futex_wait07 +/futex_wake05
testcases/kernel/syscalls/futex/futex_wake05.c new file +113 -0
113 lines not on this page · raw message
Signature · 5 lines
2.55.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] futex_wake05: Add EFAULT error coverage test
Hi Michael,
Quoted 1 line · Michael Menasherov
futex_wake05: Add EFAULT error coverage test
--- [PATCH 1/2] ---
Quoted 2 lines
+/*\
+ * Check thatfutex(FUTEX_WAKE)returns EFAULT when uaddr points to
The doc block is rendered in the test catalog as reStructuredText. When referring to a raw syscall in a /*\ ... */ block, the :manpage: role is required (c-tests.md rule 19). Should this read:
Check that :manpage:futex(2) with ``FUTEX_WAKE`` returns EFAULT when uaddr points to ...
--- [PATCH 2/2] ---
Quoted 2 lines
+/*\
+ * Check thatfutex(FUTEX_CMP_REQUEUE)returns EFAULT when uaddr or
Same :manpage: issue: "futex(FUTEX_CMP_REQUEUE)" should be ":manpage:futex(2)" with "``FUTEX_CMP_REQUEUE``" for the operation.
Quoted 1 line
+/futex_cmp_requeue03
The git.md rule requires .gitignore entries to be kept sorted. The existing file already has /futex_cmp_requeue01 and /futex_cmp_requeue02 near the top. Appending /futex_cmp_requeue03 at the end leaves it out of order; it belongs immediately after /futex_cmp_requeue02.
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
Re: [LTP] futex_wake05: Add EFAULT error coverage test
Hi!
I've fixed the minor issues pointed out by the reviewer and pushed, thanks.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v17 2/2 futex_cmp_requeue03: Add EFAULT error coverage test
In reply to Michael Menasherov via ltpfutex(FUTEX_CMP_REQUEUE) has no existing test for EFAULT. Add coverage for the cases where uaddr or uaddr2 points to unmapped or inaccessible (PROT_NONE) memory.
--- runtest/syscalls | 1 + testcases/kernel/syscalls/futex/.gitignore | 1 + .../syscalls/futex/futex_cmp_requeue03.c | 103 ++++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 testcases/kernel/syscalls/futex/futex_cmp_requeue03.c
runtest/syscalls +1 -0
@@ -1864,6 +1864,7 @@ perf_event_open02 perf_event_open02 futex_cmp_requeue01 futex_cmp_requeue01 futex_cmp_requeue02 futex_cmp_requeue02 +futex_cmp_requeue03 futex_cmp_requeue03 futex_wait01 futex_wait01 futex_wait02 futex_wait02 futex_wait03 futex_wait03
testcases/kernel/syscalls/futex/.gitignore +1 -0
@@ -16,3 +16,4 @@ /futex_wait06 /futex_wait07 /futex_wake05 +/futex_cmp_requeue03
testcases/kernel/syscalls/futex/futex_cmp_requeue03.c new file +103 -0
103 lines not on this page · raw message
Signature · 5 lines
2.55.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp