]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Mark returned descriptor as valid when CLONE_PIDFD is used
authorTom Hughes <tom@compton.nu>
Thu, 20 Feb 2020 09:18:17 +0000 (09:18 +0000)
committerTom Hughes <tom@compton.nu>
Thu, 20 Feb 2020 09:25:08 +0000 (09:25 +0000)
When CLONE_PIDFD is set the descriptor is returned via the
argument otherwise used for the parent thread id.

coregrind/m_syswrap/syswrap-linux.c

index a4c106f684a5504ed5cb83f748a06fbc38ddac5c..87334c9cad0ea4550915300230639dd67c4f54f7 100644 (file)
@@ -852,7 +852,7 @@ PRE(sys_clone)
       PRA_CHILD_STACK("clone",  void *, child_stack);
    }
 
-   if (ARG_FLAGS & VKI_CLONE_PARENT_SETTID) {
+   if (ARG_FLAGS & (VKI_CLONE_PARENT_SETTID | VKI_CLONE_PIDFD)) {
       if (VG_(tdict).track_pre_reg_read) {
          PRA3("clone", int *, parent_tidptr);
       }
@@ -941,10 +941,20 @@ PRE(sys_clone)
    }
 
    if (SUCCESS) {
-      if (ARG_FLAGS & VKI_CLONE_PARENT_SETTID)
+      if (ARG_FLAGS & (VKI_CLONE_PARENT_SETTID | VKI_CLONE_PIDFD))
          POST_MEM_WRITE(ARG3, sizeof(Int));
       if (ARG_FLAGS & (VKI_CLONE_CHILD_SETTID | VKI_CLONE_CHILD_CLEARTID))
          POST_MEM_WRITE(ARG_CHILD_TIDPTR, sizeof(Int));
+      if (ARG_FLAGS & VKI_CLONE_PIDFD) {
+         Int fd = *(Int*)(Addr)ARG3;
+         if (!ML_(fd_allowed)(fd, "clone", tid, True)) {
+            VG_(close)(fd);
+            SET_STATUS_Failure( VKI_EMFILE );
+         } else {
+            if (VG_(clo_track_fds))
+               ML_(record_fd_open_nameless) (tid, fd);
+         }
+      }
 
       /* Thread creation was successful; let the child have the chance
          to run */