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

Merge tag 'for-linus-2020-06-24' of git://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux

Pull thread fix from Christian Brauner:
"This fixes a regression introduced with 303cc571d107 ("nsproxy: attach
to namespaces via pidfds").

The LTP testsuite reported a regression where users would now see
EBADF returned instead of EINVAL when an fd was passed that referred
to an open file but the file was not a namespace file.

Fix this by continuing to report EINVAL and add a regression test"

* tag 'for-linus-2020-06-24' of git://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux:
tests: test for setns() EINVAL regression
nsproxy: restore EINVAL for non-namespace file descriptor

+18 -6
+1 -1
kernel/nsproxy.c
··· 531 531 } else if (!IS_ERR(pidfd_pid(file))) { 532 532 err = check_setns_flags(flags); 533 533 } else { 534 - err = -EBADF; 534 + err = -EINVAL; 535 535 } 536 536 if (err) 537 537 goto out;
+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