Commit 2f4c9a2d authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] NFS: fix bogus setattr calls

From: Trond Myklebust <trond.myklebust@fys.uio.no>

If users set the execute bit on a file, and then write to it,
remove_suid() causes a flood of SETATTR calls (one per write() syscall)
with no arguments to be sent down the wire.

The server will in any case clear the suid bit itself without any
prompting from us, so the following patch simply filters away all
SETATTR requests with empty or unsupported ia_valid fields.
parent 06fbe36f
......@@ -791,6 +791,8 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr)
goto out;
}
#define NFS_VALID_ATTRS (ATTR_MODE|ATTR_UID|ATTR_GID|ATTR_SIZE|ATTR_ATIME|ATTR_ATIME_SET|ATTR_MTIME|ATTR_MTIME_SET)
int
nfs_setattr(struct dentry *dentry, struct iattr *attr)
{
......@@ -798,6 +800,11 @@ nfs_setattr(struct dentry *dentry, struct iattr *attr)
struct nfs_fattr fattr;
int error;
/* Optimization: if the end result is no change, don't RPC */
attr->ia_valid &= NFS_VALID_ATTRS;
if (attr->ia_valid == 0)
return 0;
lock_kernel();
/*
......@@ -813,6 +820,8 @@ printk("nfs_setattr: revalidate failed, error=%d\n", error);
if (!S_ISREG(inode->i_mode)) {
attr->ia_valid &= ~ATTR_SIZE;
if (attr->ia_valid == 0)
goto out;
} else {
filemap_fdatawrite(inode->i_mapping);
error = nfs_wb_all(inode);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment