Commit fbb58011 authored by Linus Torvalds's avatar Linus Torvalds
Browse files
Pull thread fix from Christian Brauner:
 "This fixes a regression introduced with 303cc571 ("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
parents 26e122e9 86f56395
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -531,7 +531,7 @@ SYSCALL_DEFINE2(setns, int, fd, int, flags)
	} else if (!IS_ERR(pidfd_pid(file))) {
	} else if (!IS_ERR(pidfd_pid(file))) {
		err = check_setns_flags(flags);
		err = check_setns_flags(flags);
	} else {
	} else {
		err = -EBADF;
		err = -EINVAL;
	}
	}
	if (err)
	if (err)
		goto out;
		goto out;
+5 −0
Original line number Original line Diff line number Diff line
@@ -95,4 +95,9 @@ static inline int sys_pidfd_getfd(int pidfd, int fd, int flags)
	return syscall(__NR_pidfd_getfd, pidfd, fd, 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 */
#endif /* __PIDFD_H */
+0 −5
Original line number Original line Diff line number Diff line
@@ -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);
	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)
static int __child(int sk, int memfd)
{
{
	int ret;
	int ret;
+12 −0
Original line number Original line Diff line number Diff line
@@ -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
TEST_HARNESS_MAIN