Skip to content

Commit 86f5639

Browse files
author
Christian Brauner
committed
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 <[email protected]> Cc: Cyril Hrubis <[email protected]> Link: https://lore.kernel.org/lkml/20200615085836.GR12456@shao2-debian Signed-off-by: Christian Brauner <[email protected]>
1 parent e571d4e commit 86f5639

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

tools/testing/selftests/pidfd/pidfd.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,9 @@ static inline int sys_pidfd_getfd(int pidfd, int fd, int flags)
9595
return syscall(__NR_pidfd_getfd, pidfd, fd, flags);
9696
}
9797

98+
static inline int sys_memfd_create(const char *name, unsigned int flags)
99+
{
100+
return syscall(__NR_memfd_create, name, flags);
101+
}
102+
98103
#endif /* __PIDFD_H */

tools/testing/selftests/pidfd/pidfd_getfd_test.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@ static int sys_kcmp(pid_t pid1, pid_t pid2, int type, unsigned long idx1,
3434
return syscall(__NR_kcmp, pid1, pid2, type, idx1, idx2);
3535
}
3636

37-
static int sys_memfd_create(const char *name, unsigned int flags)
38-
{
39-
return syscall(__NR_memfd_create, name, flags);
40-
}
41-
4237
static int __child(int sk, int memfd)
4338
{
4439
int ret;

tools/testing/selftests/pidfd/pidfd_setns_test.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,4 +470,16 @@ TEST_F(current_nsset, no_foul_play)
470470
}
471471
}
472472

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+
473485
TEST_HARNESS_MAIN

0 commit comments

Comments
 (0)