From: Tom Hughes Date: Thu, 20 Feb 2020 09:18:17 +0000 (+0000) Subject: Mark returned descriptor as valid when CLONE_PIDFD is used X-Git-Tag: VALGRIND_3_16_0~98 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=22aa8640e6c44c78c228ffa726cfacf918455343;p=thirdparty%2Fvalgrind.git Mark returned descriptor as valid when CLONE_PIDFD is used When CLONE_PIDFD is set the descriptor is returned via the argument otherwise used for the parent thread id. --- diff --git a/coregrind/m_syswrap/syswrap-linux.c b/coregrind/m_syswrap/syswrap-linux.c index a4c106f684..87334c9cad 100644 --- a/coregrind/m_syswrap/syswrap-linux.c +++ b/coregrind/m_syswrap/syswrap-linux.c @@ -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 */