Skip to contentSkip to conversation

selftests/seccomp: Accept any valid fd in user_notification_addfd

PATCH In review Seth Forshee 3 participants 4 messages Jan 28, 2021 – Feb 10, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests/seccomp: Accept any valid fd in user_notification_addfd

This test expects fds to have specific values, which works fine when the test is run standalone. However, the kselftest runner consumes a couple of extra fds for redirection when running tests, so the test fails when run via kselftest.

Change the test to pass on any valid fd number.

---
 tools/testing/selftests/seccomp/seccomp_bpf.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
tools/testing/selftests/seccomp/seccomp_bpf.c +2 -6
index 26c72f2b61b1..9338df6f4ca8 100644
@@ -4019,18 +4019,14 @@ TEST(user_notification_addfd)
 
 	/* Verify we can set an arbitrary remote fd */
 	fd = ioctl(listener, SECCOMP_IOCTL_NOTIF_ADDFD, &addfd);
-	/*
-	 * The child has fds 0(stdin), 1(stdout), 2(stderr), 3(memfd),
-	 * 4(listener), so the newly allocated fd should be 5.
-	 */
-	EXPECT_EQ(fd, 5);
+	EXPECT_GE(fd, 0);
 	EXPECT_EQ(filecmp(getpid(), pid, memfd, fd), 0);
 
 	/* Verify we can set an arbitrary remote fd with large size */
 	memset(&big, 0x0, sizeof(big));
 	big.addfd = addfd;
 	fd = ioctl(listener, SECCOMP_IOCTL_NOTIF_ADDFD_BIG, &big);
-	EXPECT_EQ(fd, 6);
+	EXPECT_GE(fd, 0);
 
 	/* Verify we can set a specific remote fd */
 	addfd.newfd = 42;
Signature · 1 line
2.29.2
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 28 lines · Seth Forshee

This test expects fds to have specific values, which works fine when the test is run standalone. However, the kselftest runner consumes a couple of extra fds for redirection when running tests, so the test fails when run via kselftest.

Change the test to pass on any valid fd number.

---
  tools/testing/selftests/seccomp/seccomp_bpf.c | 8 ++------
  1 file changed, 2 insertions(+), 6 deletions(-)
tools/testing/selftests/seccomp/seccomp_bpf.c +1 -5
index 26c72f2b61b1..9338df6f4ca8 100644
@@ -4019,18 +4019,14 @@ TEST(user_notification_addfd)
 
  	/* Verify we can set an arbitrary remote fd */
  	fd = ioctl(listener, SECCOMP_IOCTL_NOTIF_ADDFD, &addfd);
-	/*
-	 * The child has fds 0(stdin), 1(stdout), 2(stderr), 3(memfd),
-	 * 4(listener), so the newly allocated fd should be 5.
-	 */
-	EXPECT_EQ(fd, 5);
+	EXPECT_GE(fd, 0);
  	EXPECT_EQ(filecmp(getpid(), pid, memfd, fd), 0);

tools/testing/selftests/seccomp/seccomp_bpf.c TEST(user_notification_addfd) · line 4032

Quoted 10 lines
tools/testing/selftests/seccomp/seccomp_bpf.c +1 -1
 
  	/* Verify we can set an arbitrary remote fd with large size */
  	memset(&big, 0x0, sizeof(big));
  	big.addfd = addfd;
  	fd = ioctl(listener, SECCOMP_IOCTL_NOTIF_ADDFD_BIG, &big);
-	EXPECT_EQ(fd, 6);
+	EXPECT_GE(fd, 0);
 
  	/* Verify we can set a specific remote fd */
  	addfd.newfd = 42;

Here is my Ack if Kees wants to take it through seccomp.

thanks,
-- Shuah

Acked-by on v1 1/1
#2 lore raw
In reply to Seth Forshee
Quoted 8 lines · Seth Forshee

This test expects fds to have specific values, which works fine when the test is run standalone. However, the kselftest runner consumes a couple of extra fds for redirection when running tests, so the test fails when run via kselftest.

Change the test to pass on any valid fd number.

Thanks!

I'll snag this if Shuah doesn't first. :)

-Kees

Quoted 32 lines
---
 tools/testing/selftests/seccomp/seccomp_bpf.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
tools/testing/selftests/seccomp/seccomp_bpf.c +2 -6
index 26c72f2b61b1..9338df6f4ca8 100644
@@ -4019,18 +4019,14 @@ TEST(user_notification_addfd)
 
 	/* Verify we can set an arbitrary remote fd */
 	fd = ioctl(listener, SECCOMP_IOCTL_NOTIF_ADDFD, &addfd);
-	/*
-	 * The child has fds 0(stdin), 1(stdout), 2(stderr), 3(memfd),
-	 * 4(listener), so the newly allocated fd should be 5.
-	 */
-	EXPECT_EQ(fd, 5);
+	EXPECT_GE(fd, 0);
 	EXPECT_EQ(filecmp(getpid(), pid, memfd, fd), 0);
 
 	/* Verify we can set an arbitrary remote fd with large size */
 	memset(&big, 0x0, sizeof(big));
 	big.addfd = addfd;
 	fd = ioctl(listener, SECCOMP_IOCTL_NOTIF_ADDFD_BIG, &big);
-	EXPECT_EQ(fd, 6);
+	EXPECT_GE(fd, 0);
 
 	/* Verify we can set a specific remote fd */
 	addfd.newfd = 42;
Signature · 1 line
2.29.2
Signature · 1 line
Kees Cook
maintainer
#3 lore raw
Quoted 8 lines · Kees Cook
Quoted 7 lines · Seth Forshee

This test expects fds to have specific values, which works fine when the test is run standalone. However, the kselftest runner consumes a couple of extra fds for redirection when running tests, so the test fails when run via kselftest.

Change the test to pass on any valid fd number.

Quoted 8 lines
Quoted 1 line

Thanks!

I'll snag this if Shuah doesn't first. :)

I will apply this. I have several queued for 5.12-rc1 anyway.

thanks,
-- Shuah