Skip to content

Commit c49db93

Browse files
pm215Michael Tokarev
authored andcommitted
linux-user: Use qemu_set_cloexec() to mark pidfd as FD_CLOEXEC
In the linux-user do_fork() function we try to set the FD_CLOEXEC flag on a pidfd like this: fcntl(pid_fd, F_SETFD, fcntl(pid_fd, F_GETFL) | FD_CLOEXEC); This has two problems: (1) it doesn't check errors, which Coverity complains about (2) we use F_GETFL when we mean F_GETFD Deal with both of these problems by using qemu_set_cloexec() instead. That function will assert() if the fcntls fail, which is fine (we are inside fork_start()/fork_end() so we know nothing can mess around with our file descriptors here, and we just got this one from pidfd_open()). (As we are touching the if() statement here, we correct the indentation.) Coverity: CID 1508111 Signed-off-by: Peter Maydell <[email protected]> Reviewed-by: Richard Henderson <[email protected]> Reviewed-by: Daniel P. Berrangé <[email protected]> Signed-off-by: Richard Henderson <[email protected]> Message-ID: <[email protected]> (cherry picked from commit d6390204c61e148488f034d1f79be35cd3318d93) Signed-off-by: Michael Tokarev <[email protected]>
1 parent b4ead90 commit c49db93

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

linux-user/syscall.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6746,10 +6746,9 @@ static int do_fork(CPUArchState *env, unsigned int flags, abi_ulong newsp,
67466746
int pid_child = ret;
67476747
pid_fd = pidfd_open(pid_child, 0);
67486748
if (pid_fd >= 0) {
6749-
fcntl(pid_fd, F_SETFD, fcntl(pid_fd, F_GETFL)
6750-
| FD_CLOEXEC);
6749+
qemu_set_cloexec(pid_fd);
67516750
} else {
6752-
pid_fd = 0;
6751+
pid_fd = 0;
67536752
}
67546753
#endif
67556754
put_user_u32(pid_fd, parent_tidptr);

0 commit comments

Comments
 (0)