diff mbox

nfs: override uid and gid for exclusive creates in nfs3_proc_create

Message ID 20170922201551.15222-1-smayhew@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Scott Mayhew Sept. 22, 2017, 8:15 p.m. UTC
RFC 1813 section 3.3.8 states

      Once the client has performed a successful exclusive
      create, it must issue a SETATTR to set the correct file
      attributes.  Until it does so, it should not rely upon any
      of the file attributes, since the server implementation
      may need to overload file metadata to store the verifier.

HP-UX expects the client to send the uid and gid in the post-create
setattr for exclusive creates.  Customers are sometimes seeing bogus
values because the Linux NFS client is only updating the atime and
mtime.

Signed-off-by: Scott Mayhew <smayhew@redhat.com>
---
 fs/nfs/nfs3proc.c | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Trond Myklebust Sept. 22, 2017, 9:18 p.m. UTC | #1
On Fri, 2017-09-22 at 16:15 -0400, Scott Mayhew wrote:
> RFC 1813 section 3.3.8 states

> 

>       Once the client has performed a successful exclusive

>       create, it must issue a SETATTR to set the correct file

>       attributes.  Until it does so, it should not rely upon any

>       of the file attributes, since the server implementation

>       may need to overload file metadata to store the verifier.

> 

> HP-UX expects the client to send the uid and gid in the post-create

> setattr for exclusive creates.  Customers are sometimes seeing bogus

> values because the Linux NFS client is only updating the atime and

> mtime.


I'm sorry, but that is just insanely stupid server behaviour. How do
you guarantee that a second client won't hijack the file by sending
their own SETATTR call before your client has an opportunity to set the
owner?

-- 
Trond Myklebust
Linux NFS client maintainer, PrimaryData
trond.myklebust@primarydata.com
diff mbox

Patch

diff --git a/fs/nfs/nfs3proc.c b/fs/nfs/nfs3proc.c
index d1e87ec..4d77d2d 100644
--- a/fs/nfs/nfs3proc.c
+++ b/fs/nfs/nfs3proc.c
@@ -370,6 +370,13 @@  nfs3_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
 	if (data->arg.create.createmode == NFS3_CREATE_EXCLUSIVE) {
 		dprintk("NFS call  setattr (post-create)\n");
 
+		sattr->ia_uid = current_fsuid();
+		sattr->ia_valid |= ATTR_UID;
+		if (dir->i_mode & S_ISGID)
+			sattr->ia_gid = dir->i_gid;
+		else
+			sattr->ia_gid = current_fsgid();
+		sattr->ia_valid |= ATTR_GID;
 		if (!(sattr->ia_valid & ATTR_ATIME_SET))
 			sattr->ia_valid |= ATTR_ATIME;
 		if (!(sattr->ia_valid & ATTR_MTIME_SET))