]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
UBUNTU: SAUCE: selftests/seccomp: fix check of fds being assigned
authorAndrea Righi <andrea.righi@canonical.com>
Mon, 15 Nov 2021 16:52:27 +0000 (17:52 +0100)
committerAndrea Righi <andrea.righi@canonical.com>
Thu, 9 Mar 2023 14:57:29 +0000 (15:57 +0100)
There might be an arbitrary free open fd slot when we run the addfd
sub-test, so checking for progressive numbers of file descriptors
starting from memfd is not always a reliable check and we could get the
following failure:

  #  RUN           global.user_notification_addfd ...
  # seccomp_bpf.c:3989:user_notification_addfd:Expected listener (18) == nextfd++ (9)
  # user_notification_addfd: Test terminated by assertion

Simply check if memfd and listener are valid file descriptors and start
counting for progressive file checking with the listener fd.

Fixes: 93e720d710df ("selftests/seccomp: More closely track fds being assigned")
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
Acked-by: Christian Brauner <christian.brauner@ubuntu.com>
(cherry picked from https://lore.kernel.org/all/20211115165227.101124-1-andrea.righi@canonical.com/)
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
tools/testing/selftests/seccomp/seccomp_bpf.c

index 9c2f448bb3a9d3a51024329ea94affe9f0f2aa76..aa9e60365a907722fb5114979dbcc5bfc2cefaa4 100644 (file)
@@ -4031,18 +4031,17 @@ TEST(user_notification_addfd)
        /* There may be arbitrary already-open fds at test start. */
        memfd = memfd_create("test", 0);
        ASSERT_GE(memfd, 0);
-       nextfd = memfd + 1;
 
        ret = prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0);
        ASSERT_EQ(0, ret) {
                TH_LOG("Kernel does not support PR_SET_NO_NEW_PRIVS!");
        }
 
-       /* fd: 4 */
        /* Check that the basic notification machinery works */
        listener = user_notif_syscall(__NR_getppid,
                                      SECCOMP_FILTER_FLAG_NEW_LISTENER);
-       ASSERT_EQ(listener, nextfd++);
+       ASSERT_GE(listener, 0);
+       nextfd = listener + 1;
 
        pid = fork();
        ASSERT_GE(pid, 0);