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: <202505190816.2A78B3153@keescook>
Date: Mon, 19 May 2025 08:19:57 -0700
From: Kees Cook <kees@...nel.org>
To: Sameeksha Sankpal <sameekshasankpal@...il.com>
Cc: skhan@...uxfoundation.org, luto@...capital.net, wad@...omium.org,
	shuah@...nel.org, linux-kselftest@...r.kernel.org,
	linux-kernel@...r.kernel.org
Subject: Re: [PATCH] selftests/seccomp: report errno and add hints on failure

On Sat, May 17, 2025 at 05:57:40PM +0530, Sameeksha Sankpal wrote:
> Signed-off-by: Sameeksha Sankpal <sameekshasankpal@...il.com>
> ---
>  tools/testing/selftests/seccomp/seccomp_bpf.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/seccomp/seccomp_bpf.c b/tools/testing/selftests/seccomp/seccomp_bpf.c
> index 14ba51b52095..d6a85d7b26da 100644
> --- a/tools/testing/selftests/seccomp/seccomp_bpf.c
> +++ b/tools/testing/selftests/seccomp/seccomp_bpf.c
> @@ -4508,7 +4508,11 @@ static char get_proc_stat(struct __test_metadata *_metadata, pid_t pid)
>  
>  	snprintf(proc_path, sizeof(proc_path), "/proc/%d/stat", pid);
>  	ASSERT_EQ(get_nth(_metadata, proc_path, 3, &line), 1);
> -
> +	int rc = get_nth(_metadata, proc_path, 3, &line);
> +    	if (rc != 1) {
> +        	printf("[ERROR] user_notification_fifo: failed to read stat for PID %d (rc=%d)\n", pid, rc);
> +    	}
> +    	ASSERT_EQ(rc, 1);

An ASSERT will stop execution, so if it fails, you'll never reach the
printf. And a "printf" shouldn't be used. What you want to use is TH_LOG,
probably like this:


	rc = get_nth(_metadata, proc_path, 3, &line);
  	ASSERT_EQ(rc, 1) {
		TH_LOG("user_notification_fifo: failed to read stat for PID %d (rc=%d)", pid, rc);
	}

And please don't introduce new variables in the middle -- they need to
be declared at the top of the function.

-Kees

-- 
Kees Cook

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ