Re: [PATCH 2/4] virNetSocket: Be more safe with fork() around virNetSocketDupFD()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Sep 21, 2018 at 11:29 AM +0200, Michal Privoznik <mprivozn@xxxxxxxxxx> wrote:
> If there was a caller which would dup the client FD without
> CLOEXEC flag and later decided to change the flag it wouldn't be
> safe to do because fork() might have had occurred meantime.
> Switch to the other pattern - always dup FD with the flag set and
> let callers clear the flag if they need to do so.
>
> Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
> ---

[…snip…]

>
>
> -int virNetSocketDupFD(virNetSocketPtr sock, bool cloexec)
> +int virNetSocketDupFD(virNetSocketPtr sock)

Might be useful to document this function.

>  {
>      int fd;
>
> -    if (cloexec)
> -        fd = fcntl(sock->fd, F_DUPFD_CLOEXEC, 0);
> -    else
> -        fd = dup(sock->fd);
> +    fd = fcntl(sock->fd, F_DUPFD_CLOEXEC, 0);
>      if (fd < 0) {
>          virReportSystemError(errno, "%s",
>                               _("Unable to copy socket file handle"));
> diff --git a/src/rpc/virnetsocket.h b/src/rpc/virnetsocket.h
> index de795af917..e6bac27566 100644
> --- a/src/rpc/virnetsocket.h
> +++ b/src/rpc/virnetsocket.h
> @@ -124,7 +124,7 @@ virNetSocketPtr virNetSocketNewPostExecRestart(virJSONValuePtr object);
>  virJSONValuePtr virNetSocketPreExecRestart(virNetSocketPtr sock);
>
>  int virNetSocketGetFD(virNetSocketPtr sock);
> -int virNetSocketDupFD(virNetSocketPtr sock, bool cloexec);
> +int virNetSocketDupFD(virNetSocketPtr sock);
>
>  bool virNetSocketIsLocal(virNetSocketPtr sock);
>
> --
> 2.16.4
>
> --
> libvir-list mailing list
> libvir-list@xxxxxxxxxx
> https://www.redhat.com/mailman/listinfo/libvir-list
>

Anyway, Reviewed-by: Marc Hartmayer <mhartmay@xxxxxxxxxxxxx>

--
Kind regards / Beste Grüße
   Marc Hartmayer

IBM Deutschland Research & Development GmbH
Vorsitzende des Aufsichtsrats: Martina Koederitz
Geschäftsführung: Dirk Wittkopp
Sitz der Gesellschaft: Böblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294


--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux