On Sun, Sep 7, 2025, 19:35 Collin Funk <[email protected]> wrote:

> Grisha Levit <[email protected]> writes:
>
> > On Sun, Sep 7, 2025 at 6:26 PM Collin Funk <[email protected]>
> wrote:
> >>
> >> Interesting, thanks for the report. Can't we just do the following to
> >> avoid the extra umask() call?
> >>
> >
> >> -      mode_t umask_value = umask (~mode);
> >> +      mode_t umask_value = umask (~mode & (S_IRWXU | S_IRWXG |
> S_IRWXO));
> >
> > This seems likely fine, but after reading the POSIX description[1], I
> > was worried that in the case that the other bits do serve some
> > implementation-defined purpose it may not be correct to clear them, so
> > went the route of only clearing the bits we need to. I'm not aware of
> > any platform where that would actually matter though.
> >
> > [1]
> https://pubs.opengroup.org/onlinepubs/9799919799/functions/umask.html
>
> Lets see what others think. All of the BSDs [1][2][3], MacOS [4], and
> illumos (OpenSolaris fork) [5] mask it to only be the 0777 bits
> similarly to Linux.
>
> Collin
>
> [1]
> https://github.com/freebsd/freebsd-src/blob/14b61b2e931741281d0bfef426e9809f16006504/sys/kern/vfs_syscalls.c#L4399
> [2]
> https://github.com/NetBSD/src/blob/be853cde76b2ccea84a3374a21cbaebb52620ccf/sys/kern/vfs_syscalls.c#L4902
> [3]
> https://github.com/openbsd/src/blob/1c9950446e514b92a735ccfed45c91103981fa42/sys/kern/vfs_syscalls.c#L3209
> [4]
> https://github.com/apple-oss-distributions/xnu/blob/e3723e1f17661b24996789d8afc084c0c3303b26/bsd/vfs/vfs_syscalls.c#L10767
> [5]
> https://github.com/illumos/illumos-gate/blob/80040569a359c61120972d882d97428e80dcab90/usr/src/uts/common/syscall/umask.c#L48


FWIW, [1], [2] and [4] above all mask with ALLPERMS, which is 07777. [3]
and [5] use 0777.

Reply via email to