summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/pidfd/pidfd.h
AgeCommit message (Collapse)Author
2023-06-12selftest: pidfd: Omit long and repeating outputsZiqi Zhao
An output message: > # # waitpid WEXITSTATUS=0 will be printed for 30,000+ times in the `pidfd_test` selftest, which does not seem ideal. This patch removes the print logic in the `wait_for_pid` function, so each call to this function does not output a line by default. Any existing call sites where the extra line might be beneficial have been modified to include extra print statements outside of the function calls. Signed-off-by: Ziqi Zhao <astrajoan@yahoo.com> Reviewed-by: Christian Brauner <brauner@kernel.org> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
2022-02-04pidfd: fix test failure due to stack overflow on some archesAxel Rasmussen
When running the pidfd_fdinfo_test on arm64, it fails for me. After some digging, the reason is that the child exits due to SIGBUS, because it overflows the 1024 byte stack we've reserved for it. To fix the issue, increase the stack size to 8192 bytes (this number is somewhat arbitrary, and was arrived at through experimentation -- I kept doubling until the failure no longer occurred). Also, let's make the issue easier to debug. wait_for_pid() returns an ambiguous value: it may return -1 in all of these cases: 1. waitpid() itself returned -1 2. waitpid() returned success, but we found !WIFEXITED(status). 3. The child process exited, but it did so with a -1 exit code. There's no way for the caller to tell the difference. So, at least log which occurred, so the test runner can debug things. While debugging this, I found that we had !WIFEXITED(), because the child exited due to a signal. This seems like a reasonably common case, so also print out whether or not we have WIFSIGNALED(), and the associated WTERMSIG() (if any). This lets us see the SIGBUS I'm fixing clearly when it occurs. Finally, I'm suspicious of allocating the child's stack on our stack. man clone(2) suggests that the correct way to do this is with mmap(), and in particular by setting MAP_STACK. So, switch to doing it that way instead. Signed-off-by: Axel Rasmussen <axelrasmussen@google.com> Acked-by: Christian Brauner <brauner@kernel.org> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
2020-09-04tests: add waitid() tests for non-blocking pidfdsChristian Brauner
Verify that the PIDFD_NONBLOCK flag works with pidfd_open() and that waitid() with a non-blocking pidfd returns EAGAIN: TAP version 13 1..3 # Starting 3 tests from 1 test cases. # RUN global.wait_simple ... # OK global.wait_simple ok 1 global.wait_simple # RUN global.wait_states ... # OK global.wait_states ok 2 global.wait_states # RUN global.wait_nonblock ... # OK global.wait_nonblock ok 3 global.wait_nonblock # PASSED: 3 / 3 tests passed. # Totals: pass:3 fail:0 xfail:0 xpass:0 skip:0 error:0 Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com> Reviewed-by: Josh Triplett <josh@joshtriplett.org> Cc: Shuah Khan <shuah@kernel.org> Cc: linux-kselftest@vger.kernel.org Link: https://lore.kernel.org/r/20200902102130.147672-5-christian.brauner@ubuntu.com
2020-07-08tests: add CLONE_NEWTIME setns testsChristian Brauner
Now that pidfds support CLONE_NEWTIME as well enable testing them in the setns() testuite. Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com> Cc: Serge Hallyn <serge@hallyn.com> Cc: Michael Kerrisk <mtk.manpages@gmail.com> Cc: Dmitry Safonov <dima@arista.com> Cc: Andrei Vagin <avagin@gmail.com> Link: https://lore.kernel.org/r/20200706154912.3248030-5-christian.brauner@ubuntu.com
2020-06-17tests: test for setns() EINVAL regressionChristian Brauner
Verify that setns() reports EINVAL when an fd is passed that refers to an open file but the file is not a file descriptor useable to interact with namespaces. Cc: Jan Stancek <jstancek@redhat.com> Cc: Cyril Hrubis <chrubis@suse.cz> Link: https://lore.kernel.org/lkml/20200615085836.GR12456@shao2-debian Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2020-03-25selftests: add pid namespace ENOMEM regression testChristian Brauner
We recently regressed (cf. [1] and its corresponding fix in [2]) returning ENOMEM when trying to create a process in a pid namespace whose init process/child subreaper has already died. This has caused confusion at least once before that (cf. [3]). Let's add a simple regression test to catch this in the future. [1]: 49cb2fc42ce4 ("fork: extend clone3() to support setting a PID") [2]: b26ebfe12f34 ("pid: Fix error return value in some cases") [3]: 35f71bc0a09a ("fork: report pid reservation failure properly") Cc: Corey Minyard <cminyard@mvista.com> Cc: Oleg Nesterov <oleg@redhat.com> Cc: Adrian Reber <areber@redhat.com> Cc: Dmitry Safonov <0x7f454c46@gmail.com> Cc: Andrei Vagin <avagin@gmail.com> Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2020-01-13test: Add test for pidfd getfdSargun Dhillon
The following tests: * Fetch FD, and then compare via kcmp * Make sure getfd can be blocked by blocking ptrace_may_access * Making sure fetching bad FDs fails * Make sure trying to set flags to non-zero results in an EINVAL Signed-off-by: Sargun Dhillon <sargun@sargun.me> Acked-by: Christian Brauner <christian.brauner@ubuntu.com> Link: https://lore.kernel.org/r/20200107175927.4558-5-sargun@sargun.me Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-08-06tests: move common definitions and functions into pidfd.hSuren Baghdasaryan
Move definitions and functions used across different pidfd tests into pidfd.h header. Signed-off-by: Suren Baghdasaryan <surenb@google.com> Reviewed-by: Christian Brauner <christian@brauner.io> Link: https://lore.kernel.org/r/20190726162226.252750-1-surenb@google.com Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-08-06pidfd: add pidfd_wait testsChristian Brauner
Add tests for pidfd_wait() and CLONE_WAIT_PID: - test that waitid(P_PIDFD) fails on /proc/<pid> - test that waitid(P_PIDFD) fails on /dev/null - test that waitid(P_PIDFD) can wait on a pidfd - test that waitid(P_PIDFD) can wait on a pidfd and return siginfo_t - test that waitid(P_PIDFD) works with WEXITED - test that waitid(P_PIDFD) works with WSTOPPED - test that waitid(P_PIDFD) works with WUNTRACED - test that waitid(P_PIDFD) works with WCONTINUED - test that waitid(P_PIDFD) works with WNOWAIT - test that waitid(P_PIDFD)works with WNOHANG Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com> Reviewed-by: Kees Cook <keescook@chromium.org> Cc: Arnd Bergmann <arnd@arndb.de> Cc: "Eric W. Biederman" <ebiederm@xmission.com> Cc: Joel Fernandes (Google) <joel@joelfernandes.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: David Howells <dhowells@redhat.com> Cc: Jann Horn <jannh@google.com> Cc: Andy Lutomirsky <luto@kernel.org> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Oleg Nesterov <oleg@redhat.com> Cc: Aleksa Sarai <cyphar@cyphar.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Al Viro <viro@zeniv.linux.org.uk> Link: https://lore.kernel.org/r/20190727222229.6516-3-christian@brauner.io
2019-06-28tests: add pidfd_open() testsChristian Brauner
This adds testing for the new pidfd_open() syscalls. Specifically, we test: - that no invalid flags can be passed to pidfd_open() - that no invalid pid can be passed to pidfd_open() - that a pidfd can be retrieved with pidfd_open() - that the retrieved pidfd references the correct pid Signed-off-by: Christian Brauner <christian@brauner.io> Cc: Arnd Bergmann <arnd@arndb.de> Cc: "Eric W. Biederman" <ebiederm@xmission.com> Cc: Kees Cook <keescook@chromium.org> Cc: Joel Fernandes (Google) <joel@joelfernandes.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Jann Horn <jannh@google.com> Cc: David Howells <dhowells@redhat.com> Cc: "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com> Cc: Andy Lutomirsky <luto@kernel.org> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Oleg Nesterov <oleg@redhat.com> Cc: Aleksa Sarai <cyphar@cyphar.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: linux-api@vger.kernel.org