lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250704-tonyk-robust_test_cleanup-v1-13-c0ff4f24c4e1@igalia.com>
Date: Fri, 04 Jul 2025 12:05:17 -0300
From: André Almeida <andrealmeid@...lia.com>
To: Shuah Khan <shuah@...nel.org>, Thomas Gleixner <tglx@...utronix.de>, 
 Ingo Molnar <mingo@...hat.com>, Peter Zijlstra <peterz@...radead.org>, 
 Darren Hart <dvhart@...radead.org>, Davidlohr Bueso <dave@...olabs.net>, 
 Sebastian Andrzej Siewior <bigeasy@...utronix.de>
Cc: linux-kselftest@...r.kernel.org, linux-kernel@...r.kernel.org, 
 kernel-dev@...lia.com, 
 André Almeida <andrealmeid@...lia.com>
Subject: [PATCH 13/15] selftests/futex: Refactor futex_numa_mpol with
 kselftest_harness.h

To reduce the boilerplate code, refactor futex_numa_mpol test to use
kselftest_harness header instead of futex's logging header.

Using kselftest_harness produces a side effect of having two adjacents
buffers, because test_harness_run() calls mmap() before this test
calling mmap(). This makes the "Memory out of range" subtest fail,
because the test address falls inside the first mmap() region, thus
being a valid address. Create a "buffer zone" with mmap(PROT_NONE) to
make sure there's invalid memory between the two mmaps and munmap() them
by the end of the test.

Signed-off-by: André Almeida <andrealmeid@...lia.com>
---
 .../selftests/futex/functional/futex_numa_mpol.c   | 57 ++++++++--------------
 tools/testing/selftests/futex/functional/run.sh    | 15 +-----
 2 files changed, 21 insertions(+), 51 deletions(-)

diff --git a/tools/testing/selftests/futex/functional/futex_numa_mpol.c b/tools/testing/selftests/futex/functional/futex_numa_mpol.c
index a9ecfb2d3932add7e560d885dc2088313fbb63bb..8d8d117b095f267af08fddcf13337f4674c44863 100644
--- a/tools/testing/selftests/futex/functional/futex_numa_mpol.c
+++ b/tools/testing/selftests/futex/functional/futex_numa_mpol.c
@@ -16,9 +16,9 @@
 #include <linux/futex.h>
 #include <sys/mman.h>
 
-#include "logging.h"
 #include "futextest.h"
 #include "futex2test.h"
+#include "../../kselftest_harness.h"
 
 #define MAX_THREADS	64
 
@@ -130,44 +130,25 @@ static void test_futex_mpol(void *futex_ptr, int must_fail)
 	__test_futex(futex_ptr, must_fail, FUTEX2_SIZE_U32 | FUTEX_PRIVATE_FLAG | FUTEX2_NUMA | FUTEX2_MPOL);
 }
 
-static void usage(char *prog)
-{
-	printf("Usage: %s\n", prog);
-	printf("  -c    Use color\n");
-	printf("  -h    Display this help message\n");
-	printf("  -v L  Verbosity level: %d=QUIET %d=CRITICAL %d=INFO\n",
-	       VQUIET, VCRITICAL, VINFO);
-}
-
-int main(int argc, char *argv[])
+TEST(futex_numa_mpol)
 {
 	struct futex32_numa *futex_numa;
 	int mem_size, i;
-	void *futex_ptr;
-	int c;
-
-	while ((c = getopt(argc, argv, "chv:")) != -1) {
-		switch (c) {
-		case 'c':
-			log_color(1);
-			break;
-		case 'h':
-			usage(basename(argv[0]));
-			exit(0);
-			break;
-		case 'v':
-			log_verbosity(atoi(optarg));
-			break;
-		default:
-			usage(basename(argv[0]));
-			exit(1);
-		}
-	}
-
-	ksft_print_header();
-	ksft_set_plan(1);
+	void *futex_ptr, *buffer_zone;
 
 	mem_size = sysconf(_SC_PAGE_SIZE);
+
+	/*
+	 * test_harness_run() calls mmap(..., MAP_SHARED, ...), which can create
+	 * a valid access memory region just bellow the mmap() issue here. Then,
+	 * the test for "Memory out of range" will fail because it will succeed
+	 * accessing the memory address after the range. To avoid this we create
+	 * a "Buffer zone" with PROT_NONE between the two mmap's.
+	 */
+	buffer_zone = mmap(NULL, mem_size, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
+	if (buffer_zone == MAP_FAILED)
+		ksft_exit_fail_msg("mmap() for %d bytes failed\n", mem_size);
+
 	futex_ptr = mmap(NULL, mem_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
 	if (futex_ptr == MAP_FAILED)
 		ksft_exit_fail_msg("mmap() for %d bytes failed\n", mem_size);
@@ -229,7 +210,9 @@ int main(int argc, char *argv[])
 			}
 		}
 	}
-	ksft_test_result_pass("NUMA MPOL tests passed\n");
-	ksft_finished();
-	return 0;
+
+	munmap(buffer_zone, mem_size);
+	munmap(futex_ptr, mem_size);
 }
+
+TEST_HARNESS_MAIN
diff --git a/tools/testing/selftests/futex/functional/run.sh b/tools/testing/selftests/futex/functional/run.sh
index f725531f06c4a88e6d3ebbabb628a5d5009eaa3b..e88545c06d57a7b202e9a65a66d129996b4ebd27 100755
--- a/tools/testing/selftests/futex/functional/run.sh
+++ b/tools/testing/selftests/futex/functional/run.sh
@@ -18,19 +18,6 @@
 #
 ###############################################################################
 
-# Test for a color capable console
-if [ -z "$USE_COLOR" ]; then
-    tput setf 7 || tput setaf 7
-    if [ $? -eq 0 ]; then
-        USE_COLOR=1
-        tput sgr0
-    fi
-fi
-if [ "$USE_COLOR" -eq 1 ]; then
-    COLOR="-c"
-fi
-
-
 echo
 ./futex_requeue_pi
 
@@ -63,4 +50,4 @@ echo
 ./futex_priv_hash
 
 echo
-./futex_numa_mpol $COLOR
+./futex_numa_mpol

-- 
2.49.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ