| 1 | |
| 2 |
|
| 3 | #define _GNU_SOURCE
|
| 4 | #include <errno.h>
|
| 5 | #include <fcntl.h>
|
| 6 | #include <limits.h>
|
| 7 | #include <linux/types.h>
|
| 8 | #include <poll.h>
|
| 9 | #include <pthread.h>
|
| 10 | #include <sched.h>
|
| 11 | #include <signal.h>
|
| 12 | #include <stdio.h>
|
| 13 | #include <stdlib.h>
|
| 14 | #include <string.h>
|
| 15 | #include <syscall.h>
|
| 16 | #include <sys/prctl.h>
|
| 17 | #include <sys/wait.h>
|
| 18 | #include <unistd.h>
|
| 19 | #include <sys/socket.h>
|
| 20 | #include <linux/kcmp.h>
|
| 21 | #include <sys/stat.h>
|
| 22 | #include <sys/xattr.h>
|
| 23 |
|
| 24 | #include "pidfd.h"
|
| 25 | #include "kselftest_harness.h"
|
| 26 |
|
| 27 | FIXTURE(pidfs_setattr)
|
| 28 | {
|
| 29 | pid_t child_pid;
|
| 30 | int child_pidfd;
|
| 31 | };
|
| 32 |
|
| 33 | FIXTURE_SETUP(pidfs_setattr)
|
| 34 | {
|
| 35 | self->child_pid = create_child(&self->child_pidfd, CLONE_NEWUSER | CLONE_NEWPID);
|
| 36 | EXPECT_GE(self->child_pid, 0);
|
| 37 |
|
| 38 | if (self->child_pid == 0)
|
| 39 | _exit(EXIT_SUCCESS);
|
| 40 | }
|
| 41 |
|
| 42 | FIXTURE_TEARDOWN(pidfs_setattr)
|
| 43 | {
|
| 44 | sys_waitid(P_PID, self->child_pid, NULL, WEXITED);
|
| 45 | EXPECT_EQ(close(self->child_pidfd), 0);
|
| 46 | }
|
| 47 |
|
| 48 | TEST_F(pidfs_setattr, no_chown)
|
| 49 | {
|
| 50 | ASSERT_LT(fchown(self->child_pidfd, 1234, 5678), 0);
|
| 51 | ASSERT_EQ(errno, EOPNOTSUPP);
|
| 52 | }
|
| 53 |
|
| 54 | TEST_F(pidfs_setattr, no_chmod)
|
| 55 | {
|
| 56 | ASSERT_LT(fchmod(self->child_pidfd, 0777), 0);
|
| 57 | ASSERT_EQ(errno, EOPNOTSUPP);
|
| 58 | }
|
| 59 |
|
| 60 | TEST_F(pidfs_setattr, no_exec)
|
| 61 | {
|
| 62 | char *const argv[] = { NULL };
|
| 63 | char *const envp[] = { NULL };
|
| 64 |
|
| 65 | ASSERT_LT(execveat(self->child_pidfd, "", argv, envp, AT_EMPTY_PATH), 0);
|
| 66 | ASSERT_EQ(errno, EACCES);
|
| 67 | }
|
| 68 |
|
| 69 | TEST_HARNESS_MAIN
|