[ovs-dev] [PATCH] socket-util-unix: Fix umask race in bind_unix_socket().

Ben Pfaff blp at nicira.com
Thu Aug 7 23:25:42 UTC 2014


On Thu, Aug 07, 2014 at 02:31:24PM -0300, Flavio Leitner wrote:
> On Thu, Jul 24, 2014 at 12:53:30PM -0700, Ben Pfaff wrote:
> > The umask is a process-wide value, so bind_unix_socket() races with file
> > creation in other Open vSwitch threads.  This fixes the race.
> > 
> > The workaround for non-Linux systems is not ideal, but I do not know any
> > other general solution.  I tested the workaround only on Linux.
> 
> The Linux part looks good. Although my style preference for
> readability is like:
> 
> if (LINUX) {
>    /* On Linux, the fd's permissions become the file's permissions.
>       fchmod() does not affect other files, like umask() does. */
>    if (fchmod(fd, mode)) {
>        return errno;
>    }
> 
>    /* must be after fchmod */
>    if (bind(fd, sun, sun_len))
>        return errno;
>    }
> 
>    return 0;
> }
> 
> I can't tell about the specifics of FreeBSD and NetBSD though
> the work around looks sane too.
> 
> Acked-by: Flavio Leitner <fbl at redhat.com>

Fair enough.  I adopted your suggested style and applied this to
master.



More information about the dev mailing list