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

Bug #1654288 reported by Matthieu Herrb
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
linux (Ubuntu)
Fix Released
Medium
Unassigned
Xenial
Fix Released
Medium
Unassigned
Yakkety
Won't Fix
Medium
Unassigned

Bug Description

After upgrading my machine to Ubuntu 16.04, I noticed that 'git clone'
started creating files with wrong mode (0700 instead of 0644
typically) on NFSv4 partitions mounted from our NetApp servers.

I've first tracked this down to the fact that git uses

 open(name, O_RDWR|O_CREAT|O_EXCL, 0666);

to create files. If O_EXCL is not present, the files are created
normally.

I've tried various kernels from Ubuntu and the problems appeared
between their 4.2.0-42-generic kernel-image (as found on willy) and
the 4.4.0 kernels found on xenial. I tried building 4.9 from
kernel.org and the problem is also there.

I've then bisected the kernel to figure out that this is caused by the
following commit:

https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=5334c5bdac926c5f8d89729beccb46fe88eda9e7

ie NFS: Send attributes in OPEN request for NFS4_CREATE_EXCLUSIVE4_1

Our NetApp filers are running:

NetApp Release 8.2.3P3 7-Mode: Tue Apr 28 14:48:22 PDT 2015

Revision history for this message
Matthieu Herrb (matthieu-herrb) wrote :

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);
}

Revision history for this message
Matthieu Herrb (matthieu-herrb) wrote :
Revision history for this message
Matthieu Herrb (matthieu-herrb) wrote :
description: updated
tags: added: patch
affects: linux-meta-lts-xenial (Ubuntu) → linux (Ubuntu)
Changed in linux (Ubuntu):
importance: Undecided → Medium
status: New → Triaged
tags: added: kernel-da-key
Changed in linux (Ubuntu Xenial):
status: New → In Progress
Changed in linux (Ubuntu):
status: Triaged → In Progress
Changed in linux (Ubuntu Xenial):
importance: Undecided → Medium
Changed in linux (Ubuntu Yakkety):
status: New → In Progress
importance: Undecided → Medium
Changed in linux (Ubuntu):
assignee: nobody → Joseph Salisbury (jsalisbury)
Changed in linux (Ubuntu Xenial):
assignee: nobody → Joseph Salisbury (jsalisbury)
Changed in linux (Ubuntu Yakkety):
assignee: nobody → Joseph Salisbury (jsalisbury)
Revision history for this message
Joseph Salisbury (jsalisbury) wrote :

I built a Xenial test kernel with the patch mentioned in comment #3. The test kernel can be downloaded from:

http://kernel.ubuntu.com/~jsalisbury/lp1654288/

Can you test this kernel and see if it resolves this bug? You would need to install both the linux-image and linux-image-extra .deb packages.

Changed in linux (Ubuntu Xenial):
status: In Progress → Fix Released
Changed in linux (Ubuntu):
status: In Progress → Fix Released
Changed in linux (Ubuntu Yakkety):
status: In Progress → Incomplete
Revision history for this message
Andy Whitcroft (apw) wrote : Closing unsupported series nomination.

This bug was nominated against a series that is no longer supported, ie yakkety. The bug task representing the yakkety nomination is being closed as Won't Fix.

This change has been made by an automated script, maintained by the Ubuntu Kernel Team.

Changed in linux (Ubuntu Yakkety):
status: Incomplete → Won't Fix
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Bug attachments

Remote bug watches

Bug watches keep track of this bug in other bug trackers.