Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tests: test for setns() EINVAL regression

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>

+17 -5
+5
tools/testing/selftests/pidfd/pidfd.h
··· 95 95 return syscall(__NR_pidfd_getfd, pidfd, fd, flags); 96 96 } 97 97 98 + static inline int sys_memfd_create(const char *name, unsigned int flags) 99 + { 100 + return syscall(__NR_memfd_create, name, flags); 101 + } 102 + 98 103 #endif /* __PIDFD_H */
-5
tools/testing/selftests/pidfd/pidfd_getfd_test.c
··· 34 34 return syscall(__NR_kcmp, pid1, pid2, type, idx1, idx2); 35 35 } 36 36 37 - static int sys_memfd_create(const char *name, unsigned int flags) 38 - { 39 - return syscall(__NR_memfd_create, name, flags); 40 - } 41 - 42 37 static int __child(int sk, int memfd) 43 38 { 44 39 int ret;
+12
tools/testing/selftests/pidfd/pidfd_setns_test.c
··· 470 470 } 471 471 } 472 472 473 + TEST(setns_einval) 474 + { 475 + int fd; 476 + 477 + fd = sys_memfd_create("rostock", 0); 478 + EXPECT_GT(fd, 0); 479 + 480 + ASSERT_NE(setns(fd, 0), 0); 481 + EXPECT_EQ(errno, EINVAL); 482 + close(fd); 483 + } 484 + 473 485 TEST_HARNESS_MAIN