Appended is a small program to reproduce the issue:

#include <sys/types.h>
#include <sys/stat.h>
#include <err.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

/*
 * Demonstrate file creation bug on NFS v4 and linux kernel 4.4+
 *
 * mktemp() is used on purpose.
 */
int
main(int argc, char *argv[])
{
        const char *name = argv[1];
        char tmp[] = "./tmpXXXXXXXXXX";
        struct stat buf;
        mode_t expected;
        int fd, i, n = 40;

        umask(S_IWGRP | S_IWOTH);
        expected = 0666 & ~(S_IWGRP | S_IWOTH);
        if (argv[1] == NULL)
                name = mktemp(tmp);
        for (i = 0; i < n; i++) {
                fd = open(name, O_RDWR|O_CREAT|O_EXCL, 0666);
                if (fd < 0)
                        err(1, "open %s", name);
                memset(&buf, 0, sizeof(buf));
                if (stat(name, &buf) < 0)
                        err(1, "stat %s", name);
                if ((buf.st_mode & (S_IRWXU|S_IRWXG|S_IRWXO)) != expected)
                        printf("%s: %o\n", name, 
                            (int)buf.st_mode & (S_IRWXU|S_IRWXG|S_IRWXO));
                else
                        printf("%s: ok\n", name);
                unlink(name);
        }
        exit(0);
}

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/1654288

Title:
  NFSv4 open(O_CREAT|O_EXCL) creates file with bad mode

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/linux-meta-lts-xenial/+bug/1654288/+subscriptions

-- 
ubuntu-bugs mailing list
ubuntu-bugs@lists.ubuntu.com
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to