|
From: Tom H. <tom...@so...> - 2020-02-20 09:25:36
|
https://sourceware.org/git/gitweb.cgi?p=valgrind.git;h=22aa8640e6c44c78c228ffa726cfacf918455343 commit 22aa8640e6c44c78c228ffa726cfacf918455343 Author: Tom Hughes <to...@co...> Date: Thu Feb 20 09:18:17 2020 +0000 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: --- coregrind/m_syswrap/syswrap-linux.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/coregrind/m_syswrap/syswrap-linux.c b/coregrind/m_syswrap/syswrap-linux.c index a4c106f..87334c9 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 */ |