All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] selftests/seccomp: Don't call read() on TTY from background pgrp
@ 2022-03-19  1:00 Jann Horn
  2022-03-24 23:21 ` Kees Cook
  0 siblings, 1 reply; 2+ messages in thread
From: Jann Horn @ 2022-03-19  1:00 UTC (permalink / raw)
  To: Kees Cook; +Cc: Andy Lutomirski, Will Drewry, linux-kernel, Jann Horn

Since commit 92d25637a3a4 ("kselftest: signal all child processes"), tests
are executed in background process groups. This means that trying to read
from stdin now throws SIGTTIN when stdin is a TTY, which breaks some
seccomp selftests that try to use read(0, NULL, 0) as a dummy syscall.

The simplest way to fix that is probably to just use -1 instead of 0 as
the dummy read()'s FD.

Fixes: 92d25637a3a4 ("kselftest: signal all child processes")
Signed-off-by: Jann Horn <jannh@google.com>
---
 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 9d126d7fabdb..313bb0cbfb1e 100644
--- a/tools/testing/selftests/seccomp/seccomp_bpf.c
+++ b/tools/testing/selftests/seccomp/seccomp_bpf.c
@@ -955,7 +955,7 @@ TEST(ERRNO_valid)
 	ASSERT_EQ(0, ret);
 
 	EXPECT_EQ(parent, syscall(__NR_getppid));
-	EXPECT_EQ(-1, read(0, NULL, 0));
+	EXPECT_EQ(-1, read(-1, NULL, 0));
 	EXPECT_EQ(E2BIG, errno);
 }
 
@@ -974,7 +974,7 @@ TEST(ERRNO_zero)
 
 	EXPECT_EQ(parent, syscall(__NR_getppid));
 	/* "errno" of 0 is ok. */
-	EXPECT_EQ(0, read(0, NULL, 0));
+	EXPECT_EQ(0, read(-1, NULL, 0));
 }
 
 /*
@@ -995,7 +995,7 @@ TEST(ERRNO_capped)
 	ASSERT_EQ(0, ret);
 
 	EXPECT_EQ(parent, syscall(__NR_getppid));
-	EXPECT_EQ(-1, read(0, NULL, 0));
+	EXPECT_EQ(-1, read(-1, NULL, 0));
 	EXPECT_EQ(4095, errno);
 }
 
@@ -1026,7 +1026,7 @@ TEST(ERRNO_order)
 	ASSERT_EQ(0, ret);
 
 	EXPECT_EQ(parent, syscall(__NR_getppid));
-	EXPECT_EQ(-1, read(0, NULL, 0));
+	EXPECT_EQ(-1, read(-1, NULL, 0));
 	EXPECT_EQ(12, errno);
 }
 
@@ -2623,7 +2623,7 @@ void *tsync_sibling(void *data)
 	ret = prctl(PR_GET_NO_NEW_PRIVS, 0, 0, 0, 0);
 	if (!ret)
 		return (void *)SIBLING_EXIT_NEWPRIVS;
-	read(0, NULL, 0);
+	read(-1, NULL, 0);
 	return (void *)SIBLING_EXIT_UNKILLED;
 }
 

base-commit: 34e047aa16c0123bbae8e2f6df33e5ecc1f56601
-- 
2.35.1.894.gb6a874cedc-goog


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] selftests/seccomp: Don't call read() on TTY from background pgrp
  2022-03-19  1:00 [PATCH] selftests/seccomp: Don't call read() on TTY from background pgrp Jann Horn
@ 2022-03-24 23:21 ` Kees Cook
  0 siblings, 0 replies; 2+ messages in thread
From: Kees Cook @ 2022-03-24 23:21 UTC (permalink / raw)
  To: Jann Horn; +Cc: Kees Cook, linux-kernel, Will Drewry, Andy Lutomirski

On Sat, 19 Mar 2022 02:00:11 +0100, Jann Horn wrote:
> Since commit 92d25637a3a4 ("kselftest: signal all child processes"), tests
> are executed in background process groups. This means that trying to read
> from stdin now throws SIGTTIN when stdin is a TTY, which breaks some
> seccomp selftests that try to use read(0, NULL, 0) as a dummy syscall.
> 
> The simplest way to fix that is probably to just use -1 instead of 0 as
> the dummy read()'s FD.
> 
> [...]

Applied to for-next/seccomp, thanks!

[1/1] selftests/seccomp: Don't call read() on TTY from background pgrp
      https://git.kernel.org/kees/c/1d27adee48cf

-- 
Kees Cook


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-03-24 23:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-19  1:00 [PATCH] selftests/seccomp: Don't call read() on TTY from background pgrp Jann Horn
2022-03-24 23:21 ` Kees Cook

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.