Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zfs ignores umask for files created with O_TMPFILE unless acltype=posixacl #8997

Closed
gyakovlev opened this issue Jul 6, 2019 · 2 comments
Closed

Comments

@gyakovlev
Copy link
Contributor

gyakovlev commented Jul 6, 2019

System information

Type Version/Name
Distribution Name gentoo
Distribution Version current
Linux Kernel 5.1.14-gentoo
Architecture amd64
ZFS Version 0.8.1-r0-gentoo
SPL Version 0.8.1-r0-gentoo

Describe the problem you're observing

zfs seems to be ignoring umask if files created with O_TMPFILE unless acltype=posixacl

detailed explanation here https://bugs.gentoo.org/686142

Describe how to reproduce the problem

minimal reproducer (credits: @trofi)

// $ gcc a.c -o a && ./a

#define _GNU_SOURCE /* for O_TMPFILE */

#include <fcntl.h>
#include <unistd.h>

#include <sys/types.h>
#include <sys/stat.h>

#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include <string.h>

static char probe_name[] = "file-for-b686142";

static void probe_umask(void) {
    mode_t current_umask = umask(0);
    umask(current_umask);

    printf("current umask = %#o\n", (unsigned)current_umask);
}

static void probe_open(void) {
    struct stat fs;
    struct stat s;
    int fd;
    int e;
    char path[PATH_MAX];
    mode_t mode = 0777;

    memset(&fs, 0, sizeof(fs));
    memset(&s, 0, sizeof(s));

    // create target file
    fd = open(".", O_TMPFILE | O_RDWR, mode);
    fstat(fd, &fs);
    snprintf(path, PATH_MAX,  "/proc/self/fd/%d", fd);
    linkat(AT_FDCWD, path, AT_FDCWD, probe_name, AT_SYMLINK_FOLLOW);
    close (fd);

    stat(probe_name, &s);
    unlink(probe_name);

    printf("fstat(): in_mode=%#o, resulting_mode=%#o\n", (unsigned)mode, (unsigned)fs.st_mode);
    printf("stat():  in_mode=%#o, resulting_mode=%#o\n", (unsigned)mode, (unsigned)s.st_mode);
}

static void probe_open_modes(void) {
    probe_umask();
    probe_open();
}

int main() {
    // test defaults
    probe_open_modes();

    // test restricted masks
    umask(0077);
    probe_open_modes();
}
localhost /zp # zfs set acltype=posixacl zp
localhost /zp # gcc a.c -o a && ./a
current umask = 022
fstat(): in_mode=0777, resulting_mode=0100755
stat():  in_mode=0777, resulting_mode=0100755
current umask = 077
fstat(): in_mode=0777, resulting_mode=0100700
stat():  in_mode=0777, resulting_mode=0100700
localhost /zp # zfs set acltype=noacl zp
localhost /zp # gcc a.c -o a && ./a
current umask = 022
fstat(): in_mode=0777, resulting_mode=0100777
stat():  in_mode=0777, resulting_mode=0100777
current umask = 077
fstat(): in_mode=0777, resulting_mode=0100777
stat():  in_mode=0777, resulting_mode=0100777

as you can see with posixacl it honors umask and does not with noacl

Include any warning/errors/backtraces from the system logs

@gyakovlev
Copy link
Contributor Author

sorry pressed open too soon

@gyakovlev gyakovlev reopened this Jul 6, 2019
@gyakovlev gyakovlev changed the title tmpfile zfs ignores umask for files created with O_TMPFILE unless acltype=posixacl Jul 6, 2019
@trofi
Copy link

trofi commented Jul 6, 2019

Extra note: proximate cause is lack of umask application for noacl case. MusicPlayerDaemon/MPD#558 (comment) has example fixes for other filesystems (don't know if it's a correct approach or generic vfs layer would be better place to enforce umask handling).

tonyhutter pushed a commit to tonyhutter/zfs that referenced this issue Dec 26, 2019
Apply umask to `mode` which will eventually be applied to inode.
This is needed since VFS doesn't apply umask for O_TMPFILE files.

(Note that zpl_init_acl() applies `ip->i_mode &= ~current_umask();`
only when POSIX ACL is used.)

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Signed-off-by: Tomohiro Kusumi <kusumi.tomohiro@gmail.com>
Closes openzfs#8997
Closes openzfs#8998
tonyhutter pushed a commit to tonyhutter/zfs that referenced this issue Dec 27, 2019
Apply umask to `mode` which will eventually be applied to inode.
This is needed since VFS doesn't apply umask for O_TMPFILE files.

(Note that zpl_init_acl() applies `ip->i_mode &= ~current_umask();`
only when POSIX ACL is used.)

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Signed-off-by: Tomohiro Kusumi <kusumi.tomohiro@gmail.com>
Closes openzfs#8997
Closes openzfs#8998
tonyhutter pushed a commit that referenced this issue Jan 23, 2020
Apply umask to `mode` which will eventually be applied to inode.
This is needed since VFS doesn't apply umask for O_TMPFILE files.

(Note that zpl_init_acl() applies `ip->i_mode &= ~current_umask();`
only when POSIX ACL is used.)

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Signed-off-by: Tomohiro Kusumi <kusumi.tomohiro@gmail.com>
Closes #8997
Closes #8998
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants