Skip to content

Commit

Permalink
selftests/seccomp: Don't call read() on TTY from background pgrp
Browse files Browse the repository at this point in the history
commit 2bfed7d upstream.

Since commit 92d2563 ("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: 92d2563 ("kselftest: signal all child processes")
Signed-off-by: Jann Horn <jannh@google.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20220319010011.1374622-1-jannh@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
thejh authored and gregkh committed May 12, 2022
1 parent 642e0de commit 6352eca
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions tools/testing/selftests/seccomp/seccomp_bpf.c
Expand Up @@ -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);
}

Expand All @@ -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));
}

/*
Expand All @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -2579,7 +2579,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;
}

Expand Down

0 comments on commit 6352eca

Please sign in to comment.