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] [day] [month] [year] [list]
Message-ID: <20250807140508-d3df8cab-249a-47ed-b92a-d33e43de0aee@linutronix.de>
Date: Thu, 7 Aug 2025 14:14:09 +0200
From: Thomas Weißschuh <thomas.weissschuh@...utronix.de>
To: Wake Liu <wakel@...gle.com>
Cc: tglx@...utronix.de, mingo@...hat.com, shuah@...nel.org, 
	linux-kernel@...r.kernel.org, linux-kselftest@...r.kernel.org, peterz@...radead.org, 
	dvhart@...radead.org, dave@...olabs.net, andrealmeid@...lia.com
Subject: Re: [PATCH v2 1/1] selftests/futex: Check for shmget support at
 runtime

On Thu, Aug 07, 2025 at 08:00:42PM +0800, Wake Liu wrote:
> The futex tests `futex_wait.c` and `futex_waitv.c` rely on the `shmget()`
> syscall, which may not be available if the kernel is built without
> System V IPC support (CONFIG_SYSVIPC=n). This can lead to test
> failures on such systems.
> 
> This patch modifies the tests to check for `shmget()` support at
> runtime by calling it and checking for an `ENOSYS` error. If `shmget()`
> is not supported, the tests are skipped with a clear message,
> improving the user experience and preventing false negatives.
> 
> This approach is more robust than relying on compile-time checks and
> ensures that the tests run only when the required kernel features are
> present.
> 
> Signed-off-by: Wake Liu <wakel@...gle.com>
> ---
>  .../selftests/futex/functional/futex_wait.c   | 49 +++++++------
>  .../selftests/futex/functional/futex_waitv.c  | 73 ++++++++++++-------
>  2 files changed, 73 insertions(+), 49 deletions(-)
> 
> diff --git a/tools/testing/selftests/futex/functional/futex_wait.c b/tools/testing/selftests/futex/functional/futex_wait.c
> index 685140d9b93d..17a465313a59 100644
> --- a/tools/testing/selftests/futex/functional/futex_wait.c
> +++ b/tools/testing/selftests/futex/functional/futex_wait.c
> @@ -48,7 +48,7 @@ static void *waiterfn(void *arg)
>  int main(int argc, char *argv[])
>  {
>  	int res, ret = RET_PASS, fd, c, shm_id;
> -	u_int32_t f_private = 0, *shared_data;
> +	u_int32_t f_private = 0, *shared_data = NULL;
>  	unsigned int flags = FUTEX_PRIVATE_FLAG;
>  	pthread_t waiter;
>  	void *shm;
> @@ -96,32 +96,35 @@ int main(int argc, char *argv[])
>  	/* Testing an anon page shared memory */
>  	shm_id = shmget(IPC_PRIVATE, 4096, IPC_CREAT | 0666);
>  	if (shm_id < 0) {
> -		perror("shmget");
> -		exit(1);
> -	}
> -
> -	shared_data = shmat(shm_id, NULL, 0);
> +		if (errno == ENOSYS) {
> +			ksft_test_result_skip("Kernel does not support System V shared memory\n");
> +		} else {
> +			ksft_test_result_fail("shmget() failed with error: %s\n", strerror(errno));
> +			ret = RET_FAIL;

kselftest.h is already keeping track of the failure status.
Just call ksft_finished() at the end.
Also the whole perror()/exit(1) pattern doesn't really make sense in a kselftest.

> +		}
> +	} else {
> +		shared_data = shmat(shm_id, NULL, 0);

(...)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ