* [PATCH] selftests/seccomp: report errno and add hints on failure
@ 2025-05-17 12:27 Sameeksha Sankpal
2025-05-19 15:19 ` Kees Cook
0 siblings, 1 reply; 5+ messages in thread
From: Sameeksha Sankpal @ 2025-05-17 12:27 UTC (permalink / raw)
To: skhan, kees, luto, wad, shuah
Cc: linux-kselftest, linux-kernel, Sameeksha Sankpal
Signed-off-by: Sameeksha Sankpal <sameekshasankpal@gmail.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);
status = *line;
free(line);
@@ -4518,6 +4522,7 @@ static char get_proc_stat(struct __test_metadata *_metadata, pid_t pid)
TEST(user_notification_fifo)
{
struct seccomp_notif_resp resp = {};
+ ksft_print_msg("[INFO] Starting FIFO notification test\n");
struct seccomp_notif req = {};
int i, status, listener;
pid_t pid, pids[3];
@@ -4535,6 +4540,7 @@ TEST(user_notification_fifo)
listener = user_notif_syscall(__NR_getppid,
SECCOMP_FILTER_FLAG_NEW_LISTENER);
ASSERT_GE(listener, 0);
+ ksft_print_msg("[INFO] user_notification_fifo: listener PID is %d\n", listener);
pid = fork();
ASSERT_GE(pid, 0);
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] selftests/seccomp: report errno and add hints on failure
2025-05-17 12:27 [PATCH] selftests/seccomp: report errno and add hints on failure Sameeksha Sankpal
@ 2025-05-19 15:19 ` Kees Cook
2025-05-28 1:08 ` [PATCH v2] selftests/seccomp: Improve error logging in get_proc_stat() Sameeksha Sankpal
0 siblings, 1 reply; 5+ messages in thread
From: Kees Cook @ 2025-05-19 15:19 UTC (permalink / raw)
To: Sameeksha Sankpal; +Cc: skhan, luto, wad, shuah, linux-kselftest, linux-kernel
On Sat, May 17, 2025 at 05:57:40PM +0530, Sameeksha Sankpal wrote:
> Signed-off-by: Sameeksha Sankpal <sameekshasankpal@gmail.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
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2] selftests/seccomp: Improve error logging in get_proc_stat()
2025-05-19 15:19 ` Kees Cook
@ 2025-05-28 1:08 ` Sameeksha Sankpal
2025-05-28 16:36 ` Kees Cook
0 siblings, 1 reply; 5+ messages in thread
From: Sameeksha Sankpal @ 2025-05-28 1:08 UTC (permalink / raw)
To: skhan, kees, luto, wad, shuah
Cc: linux-kselftest, linux-kernel, Sameeksha Sankpal
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@kernel.org>
Signed-off-by: Sameeksha Sankpal <sameekshasankpal@gmail.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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2] selftests/seccomp: Improve error logging in get_proc_stat()
2025-05-28 1:08 ` [PATCH v2] selftests/seccomp: Improve error logging in get_proc_stat() Sameeksha Sankpal
@ 2025-05-28 16:36 ` Kees Cook
2025-05-29 22:55 ` [PATCH v3] selftests/seccomp: Fix indentation and rebase error logging patch Sameeksha Sankpal
0 siblings, 1 reply; 5+ messages in thread
From: Kees Cook @ 2025-05-28 16:36 UTC (permalink / raw)
To: Sameeksha Sankpal; +Cc: skhan, luto, wad, shuah, linux-kselftest, linux-kernel
On Wed, May 28, 2025 at 06:38:39AM +0530, Sameeksha Sankpal wrote:
> 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.
printf wasn't used previous, that was in your v1. :)
>
> Suggested-by: Kees Cook <kees@kernel.org>
>
No blank line here -- other tags should all be together with the S-o-b
line.
> Signed-off-by: Sameeksha Sankpal <sameekshasankpal@gmail.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);
This patch is against your v1 patch -- it doesn't apply to the seccomp
tree as-is. Please rebase your v2 off of the upstream tree rather than
your v1.
> + rc = get_nth(_metadata, proc_path, 3, &line);
> + ASSERT_EQ(rc, 1) {
Indenting looks wrong here, double-check you're using tabs. (And please
use scripts/checkpatch.pl to check your patch for common errors.)
> + TH_LOG("user_notification_fifo: failed to read stat for PID %d (rc=%d)", pid, rc);
> + }
> status = *line;
> free(line);
Code-wise, it looks good. Please respin for a v3 and this change should
be good to land.
-Kees
--
Kees Cook
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v3] selftests/seccomp: Fix indentation and rebase error logging patch
2025-05-28 16:36 ` Kees Cook
@ 2025-05-29 22:55 ` Sameeksha Sankpal
0 siblings, 0 replies; 5+ messages in thread
From: Sameeksha Sankpal @ 2025-05-29 22:55 UTC (permalink / raw)
To: skhan, kees, luto, wad, shuah
Cc: linux-kselftest, linux-kernel, Sameeksha Sankpal
Rebase the error logging enhancement for get_proc_stat() against the upstream seccomp tree with proper indentation formatting.
Suggested-by: Kees Cook <kees@kernel.org>
Signed-off-by: Sameeksha Sankpal <sameekshasankpal@gmail.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
v2 -> v3:
- Rebased against upstream seccomp tree (was previously against v1)
- Fixed indentation to use tabs instead of spaces
- Used scripts/checkpatch.pl to check the patch for common errors
- Removed the blank line beforeS S-o-b added in v2
tools/testing/selftests/seccomp/seccomp_bpf.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/tools/testing/selftests/seccomp/seccomp_bpf.c b/tools/testing/selftests/seccomp/seccomp_bpf.c
index 61acbd45ffaa..dbd7e705a2af 100644
--- a/tools/testing/selftests/seccomp/seccomp_bpf.c
+++ b/tools/testing/selftests/seccomp/seccomp_bpf.c
@@ -4508,9 +4508,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);
+ 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
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-05-29 22:55 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-17 12:27 [PATCH] selftests/seccomp: report errno and add hints on failure Sameeksha Sankpal
2025-05-19 15:19 ` Kees Cook
2025-05-28 1:08 ` [PATCH v2] selftests/seccomp: Improve error logging in get_proc_stat() Sameeksha Sankpal
2025-05-28 16:36 ` Kees Cook
2025-05-29 22:55 ` [PATCH v3] selftests/seccomp: Fix indentation and rebase error logging patch Sameeksha Sankpal
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).