summaryrefslogtreecommitdiffstats
path: root/fs/nfsd/vfs.c
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2017-02-20 01:21:33 -0500
committerJ. Bruce Fields <bfields@redhat.com>2017-02-21 10:13:37 -0500
commit783112f7401ff449d979530209b3f6c2594fdb4e (patch)
tree82ecfc2b095ecd229746b57100bc789bd403a009 /fs/nfsd/vfs.c
parent758e99fefe1d9230111296956335cd35995c0eaf (diff)
nfsd: special case truncates some more
Both the NFS protocols and the Linux VFS use a setattr operation with a bitmap of attributes to set to set various file attributes including the file size and the uid/gid. The Linux syscalls never mix size updates with unrelated updates like the uid/gid, and some file systems like XFS and GFS2 rely on the fact that truncates don't update random other attributes, and many other file systems handle the case but do not update the other attributes in the same transaction. NFSD on the other hand passes the attributes it gets on the wire more or less directly through to the VFS, leading to updates the file systems don't expect. XFS at least has an assert on the allowed attributes, which caught an unusual NFS client setting the size and group at the same time. To handle this issue properly this splits the notify_change call in nfsd_setattr into two separate ones. Signed-off-by: Christoph Hellwig <hch@lst.de> Cc: stable@vger.kernel.org Tested-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: J. Bruce Fields <bfields@redhat.com>
Diffstat (limited to 'fs/nfsd/vfs.c')
-rw-r--r--fs/nfsd/vfs.c32
1 files changed, 26 insertions, 6 deletions
diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
index 1c1b1d71b82b..19d50f600e8d 100644
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -414,13 +414,19 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp, struct iattr *iap,
414 414
415 /* 415 /*
416 * The size case is special, it changes the file in addition to the 416 * The size case is special, it changes the file in addition to the
417 * attributes. 417 * attributes, and file systems don't expect it to be mixed with
418 * "random" attribute changes. We thus split out the size change
419 * into a separate call to ->setattr, and do the rest as a separate
420 * setattr call.
418 */ 421 */
419 if (size_change) { 422 if (size_change) {
420 err = nfsd_get_write_access(rqstp, fhp, iap); 423 err = nfsd_get_write_access(rqstp, fhp, iap);
421 if (err) 424 if (err)
422 return err; 425 return err;
426 }
423 427
428 fh_lock(fhp);
429 if (size_change) {
424 /* 430 /*
425 * RFC5661, Section 18.30.4: 431 * RFC5661, Section 18.30.4:
426 * Changing the size of a file with SETATTR indirectly 432 * Changing the size of a file with SETATTR indirectly
@@ -428,16 +434,30 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp, struct iattr *iap,
428 * 434 *
429 * (and similar for the older RFCs) 435 * (and similar for the older RFCs)
430 */ 436 */
431 if (iap->ia_size != i_size_read(inode)) 437 struct iattr size_attr = {
432 iap->ia_valid |= ATTR_MTIME; 438 .ia_valid = ATTR_SIZE | ATTR_CTIME | ATTR_MTIME,
439 .ia_size = iap->ia_size,
440 };
441
442 host_err = notify_change(dentry, &size_attr, NULL);
443 if (host_err)
444 goto out_unlock;
445 iap->ia_valid &= ~ATTR_SIZE;
446
447 /*
448 * Avoid the additional setattr call below if the only other
449 * attribute that the client sends is the mtime, as we update
450 * it as part of the size change above.
451 */
452 if ((iap->ia_valid & ~ATTR_MTIME) == 0)
453 goto out_unlock;
433 } 454 }
434 455
435 iap->ia_valid |= ATTR_CTIME; 456 iap->ia_valid |= ATTR_CTIME;
436
437 fh_lock(fhp);
438 host_err = notify_change(dentry, iap, NULL); 457 host_err = notify_change(dentry, iap, NULL);
439 fh_unlock(fhp);
440 458
459out_unlock:
460 fh_unlock(fhp);
441 if (size_change) 461 if (size_change)
442 put_write_access(inode); 462 put_write_access(inode);
443out: 463out: