[Devel] [PATCH hci-8.1 1/2] selftests/futex: run futex_waitv argument checks with a valid waitv
Eva Kurchatova
eva.kurchatova at virtuozzo.com
Mon Nov 2 23:04:37 MSK 2026
The argument checks reuse the waitv[] the shared subtest leaves behind,
whose entries point into detached memory, and the invalid clockid
check passes NULL waiters. So the kernel can reject a call for a
reason other than the one tested. This goes unnoticed while the checks
accept any result.
Reset waitv[] to valid private futexes before the checks and pass it to
the clockid check.
Fixes: 5e59c1d1c78c ("selftests: futex: Add sys_futex_waitv() test")
https://virtuozzo.atlassian.net/browse/VSTOR-152660
Feature: fix selftests
Signed-off-by: Eva Kurchatova <eva.kurchatova at virtuozzo.com>
---
.../selftests/futex/functional/futex_waitv.c | 26 ++++++++++++++-----
1 file changed, 19 insertions(+), 7 deletions(-)
diff --git a/tools/testing/selftests/futex/functional/futex_waitv.c b/tools/testing/selftests/futex/functional/futex_waitv.c
index 3706a32102c6..98edb25690d9 100644
--- a/tools/testing/selftests/futex/functional/futex_waitv.c
+++ b/tools/testing/selftests/futex/functional/futex_waitv.c
@@ -69,6 +69,18 @@ static int join_waiter(pthread_t waiter)
return failed != NULL;
}
+static void set_private_waitv(void)
+{
+ int i;
+
+ for (i = 0; i < NR_FUTEXES; i++) {
+ waitv[i].uaddr = (uintptr_t)&futexes[i];
+ waitv[i].flags = FUTEX_32 | FUTEX_PRIVATE_FLAG;
+ waitv[i].val = 0;
+ waitv[i].__reserved = 0;
+ }
+}
+
int main(int argc, char *argv[])
{
pthread_t waiter;
@@ -98,12 +110,7 @@ int main(int argc, char *argv[])
ksft_print_msg("%s: Test FUTEX_WAITV\n",
basename(argv[0]));
- for (i = 0; i < NR_FUTEXES; i++) {
- waitv[i].uaddr = (uintptr_t)&futexes[i];
- waitv[i].flags = FUTEX_32 | FUTEX_PRIVATE_FLAG;
- waitv[i].val = 0;
- waitv[i].__reserved = 0;
- }
+ set_private_waitv();
/* Private waitv */
if (pthread_create(&waiter, NULL, waiterfn, NULL))
@@ -165,6 +172,9 @@ int main(int argc, char *argv[])
for (i = 0; i < NR_FUTEXES; i++)
shmdt(u64_to_ptr(waitv[i].uaddr));
+ /* Each check below breaks one argument of an otherwise valid call */
+ set_private_waitv();
+
/* Testing a waiter without FUTEX_32 flag */
waitv[0].flags = FUTEX_PRIVATE_FLAG;
@@ -237,12 +247,14 @@ int main(int argc, char *argv[])
}
/* Testing an invalid clockid */
+ waitv[0].uaddr = (uintptr_t)&futexes[0];
+
if (clock_gettime(CLOCK_MONOTONIC, &to))
error("gettime64 failed\n", errno);
to.tv_sec++;
- res = futex_waitv(NULL, NR_FUTEXES, 0, &to, CLOCK_TAI);
+ res = futex_waitv(waitv, NR_FUTEXES, 0, &to, CLOCK_TAI);
if (res == EINVAL) {
ksft_test_result_fail("futex_waitv private returned: %d %s\n",
res ? errno : res,
--
2.56.0
More information about the Devel
mailing list