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: <20250528010839.11594-1-sameekshasankpal@gmail.com>
Date: Wed, 28 May 2025 06:38:39 +0530
From: Sameeksha Sankpal <sameekshasankpal@...il.com>
To: skhan@...uxfoundation.org,
	kees@...nel.org,
	luto@...capital.net,
	wad@...omium.org,
	shuah@...nel.org
Cc: linux-kselftest@...r.kernel.org,
	linux-kernel@...r.kernel.org,
	Sameeksha Sankpal <sameekshasankpal@...il.com>
Subject: [PATCH v2] selftests/seccomp: Improve error logging in get_proc_stat()

Use TH_LOG to report failure when reading /proc/<pid>/stat in
get_proc_stat(), following kernel test framework conventions.

Previously, printf() was used which is discouraged.

Suggested-by: Kees Cook <kees@...nel.org>

Signed-off-by: Sameeksha Sankpal <sameekshasankpal@...il.com>
---
v1 -> v2:
- Used TH_LOG instead of printf for error logging
- Moved variable declaration to the top of the function
- Applied review suggestion by Kees Cook

 tools/testing/selftests/seccomp/seccomp_bpf.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/tools/testing/selftests/seccomp/seccomp_bpf.c b/tools/testing/selftests/seccomp/seccomp_bpf.c
index d6a85d7b26da..0f12052ef1c7 100644
--- a/tools/testing/selftests/seccomp/seccomp_bpf.c
+++ b/tools/testing/selftests/seccomp/seccomp_bpf.c
@@ -4505,14 +4505,14 @@ static char get_proc_stat(struct __test_metadata *_metadata, pid_t pid)
 	char proc_path[100] = {0};
 	char status;
 	char *line;
+	int rc;
 
 	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);
+	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);
+	}
 	status = *line;
 	free(line);
 
-- 
2.43.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ