Skip to content

Commit

Permalink
Merge tag 'for-linus-2020-06-24' of git://git.kernel.org/pub/scm/linu…
Browse files Browse the repository at this point in the history
…x/kernel/git/brauner/linux

Pull thread fix from Christian Brauner:
 "This fixes a regression introduced with 303cc57 ("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
  • Loading branch information
Linus Torvalds committed Jun 24, 2020
2 parents 26e122e + 86f5639 commit fbb5801
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion kernel/nsproxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ SYSCALL_DEFINE2(setns, int, fd, int, flags)
} else if (!IS_ERR(pidfd_pid(file))) {
err = check_setns_flags(flags);
} else {
err = -EBADF;
err = -EINVAL;
}
if (err)
goto out;
Expand Down
5 changes: 5 additions & 0 deletions tools/testing/selftests/pidfd/pidfd.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,9 @@ static inline int sys_pidfd_getfd(int pidfd, int fd, int flags)
return syscall(__NR_pidfd_getfd, pidfd, fd, flags);
}

static inline int sys_memfd_create(const char *name, unsigned int flags)
{
return syscall(__NR_memfd_create, name, flags);
}

#endif /* __PIDFD_H */
5 changes: 0 additions & 5 deletions tools/testing/selftests/pidfd/pidfd_getfd_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ static int sys_kcmp(pid_t pid1, pid_t pid2, int type, unsigned long idx1,
return syscall(__NR_kcmp, pid1, pid2, type, idx1, idx2);
}

static int sys_memfd_create(const char *name, unsigned int flags)
{
return syscall(__NR_memfd_create, name, flags);
}

static int __child(int sk, int memfd)
{
int ret;
Expand Down
12 changes: 12 additions & 0 deletions tools/testing/selftests/pidfd/pidfd_setns_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -470,4 +470,16 @@ TEST_F(current_nsset, no_foul_play)
}
}

TEST(setns_einval)
{
int fd;

fd = sys_memfd_create("rostock", 0);
EXPECT_GT(fd, 0);

ASSERT_NE(setns(fd, 0), 0);
EXPECT_EQ(errno, EINVAL);
close(fd);
}

TEST_HARNESS_MAIN

0 comments on commit fbb5801

Please sign in to comment.