Skip to content

Commit db78b87

Browse files
Christoph HellwigAl Viro
authored andcommitted
always call inode_change_ok early in ->setattr
Make sure we call inode_change_ok before doing any changes in ->setattr, and make sure to call it even if our fs wants to ignore normal UNIX permissions, but use the ATTR_FORCE to skip those. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 1025774 commit db78b87

6 files changed

Lines changed: 48 additions & 48 deletions

File tree

‎fs/cifs/inode.c‎

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1796,14 +1796,12 @@ cifs_setattr_unix(struct dentry *direntry, struct iattr *attrs)
17961796

17971797
xid = GetXid();
17981798

1799-
if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM) == 0) {
1800-
/* check if we have permission to change attrs */
1801-
rc = inode_change_ok(inode, attrs);
1802-
if (rc < 0)
1803-
goto out;
1804-
else
1805-
rc = 0;
1806-
}
1799+
if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM)
1800+
attrs->ia_valid |= ATTR_FORCE;
1801+
1802+
rc = inode_change_ok(inode, attrs);
1803+
if (rc < 0)
1804+
goto out;
18071805

18081806
full_path = build_path_from_dentry(direntry);
18091807
if (full_path == NULL) {
@@ -1934,14 +1932,13 @@ cifs_setattr_nounix(struct dentry *direntry, struct iattr *attrs)
19341932
cFYI(1, "setattr on file %s attrs->iavalid 0x%x",
19351933
direntry->d_name.name, attrs->ia_valid);
19361934

1937-
if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM) == 0) {
1938-
/* check if we have permission to change attrs */
1939-
rc = inode_change_ok(inode, attrs);
1940-
if (rc < 0) {
1941-
FreeXid(xid);
1942-
return rc;
1943-
} else
1944-
rc = 0;
1935+
if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM)
1936+
attrs->ia_valid |= ATTR_FORCE;
1937+
1938+
rc = inode_change_ok(inode, attrs);
1939+
if (rc < 0) {
1940+
FreeXid(xid);
1941+
return rc;
19451942
}
19461943

19471944
full_path = build_path_from_dentry(direntry);

‎fs/fat/file.c‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -387,21 +387,6 @@ int fat_setattr(struct dentry *dentry, struct iattr *attr)
387387
unsigned int ia_valid;
388388
int error;
389389

390-
/*
391-
* Expand the file. Since inode_setattr() updates ->i_size
392-
* before calling the ->truncate(), but FAT needs to fill the
393-
* hole before it. XXX: this is no longer true with new truncate
394-
* sequence.
395-
*/
396-
if (attr->ia_valid & ATTR_SIZE) {
397-
if (attr->ia_size > inode->i_size) {
398-
error = fat_cont_expand(inode, attr->ia_size);
399-
if (error || attr->ia_valid == ATTR_SIZE)
400-
goto out;
401-
attr->ia_valid &= ~ATTR_SIZE;
402-
}
403-
}
404-
405390
/* Check for setting the inode time. */
406391
ia_valid = attr->ia_valid;
407392
if (ia_valid & TIMES_SET_FLAGS) {
@@ -417,6 +402,21 @@ int fat_setattr(struct dentry *dentry, struct iattr *attr)
417402
goto out;
418403
}
419404

405+
/*
406+
* Expand the file. Since inode_setattr() updates ->i_size
407+
* before calling the ->truncate(), but FAT needs to fill the
408+
* hole before it. XXX: this is no longer true with new truncate
409+
* sequence.
410+
*/
411+
if (attr->ia_valid & ATTR_SIZE) {
412+
if (attr->ia_size > inode->i_size) {
413+
error = fat_cont_expand(inode, attr->ia_size);
414+
if (error || attr->ia_valid == ATTR_SIZE)
415+
goto out;
416+
attr->ia_valid &= ~ATTR_SIZE;
417+
}
418+
}
419+
420420
if (((attr->ia_valid & ATTR_UID) &&
421421
(attr->ia_uid != sbi->options.fs_uid)) ||
422422
((attr->ia_valid & ATTR_GID) &&

‎fs/fuse/dir.c‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,11 +1270,12 @@ static int fuse_do_setattr(struct dentry *entry, struct iattr *attr,
12701270
if (!fuse_allow_task(fc, current))
12711271
return -EACCES;
12721272

1273-
if (fc->flags & FUSE_DEFAULT_PERMISSIONS) {
1274-
err = inode_change_ok(inode, attr);
1275-
if (err)
1276-
return err;
1277-
}
1273+
if (!(fc->flags & FUSE_DEFAULT_PERMISSIONS))
1274+
attr->ia_valid |= ATTR_FORCE;
1275+
1276+
err = inode_change_ok(inode, attr);
1277+
if (err)
1278+
return err;
12781279

12791280
if ((attr->ia_valid & ATTR_OPEN) && fc->atomic_o_trunc)
12801281
return 0;

‎fs/logfs/file.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,16 +232,16 @@ static int logfs_setattr(struct dentry *dentry, struct iattr *attr)
232232
struct inode *inode = dentry->d_inode;
233233
int err = 0;
234234

235+
err = inode_change_ok(inode, attr);
236+
if (err)
237+
return err;
238+
235239
if (attr->ia_valid & ATTR_SIZE) {
236240
err = logfs_truncate(inode, attr->ia_size);
237241
if (err)
238242
return err;
239243
}
240244

241-
err = inode_change_ok(inode, attr);
242-
if (err)
243-
return err;
244-
245245
setattr_copy(inode, attr);
246246
mark_inode_dirty(inode);
247247
return 0;

‎fs/reiserfs/inode.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3084,6 +3084,10 @@ int reiserfs_setattr(struct dentry *dentry, struct iattr *attr)
30843084
int depth;
30853085
int error;
30863086

3087+
error = inode_change_ok(inode, attr);
3088+
if (error)
3089+
return error;
3090+
30873091
/* must be turned off for recursive notify_change calls */
30883092
ia_valid = attr->ia_valid &= ~(ATTR_KILL_SUID|ATTR_KILL_SGID);
30893093

@@ -3133,10 +3137,6 @@ int reiserfs_setattr(struct dentry *dentry, struct iattr *attr)
31333137
goto out;
31343138
}
31353139

3136-
error = inode_change_ok(inode, attr);
3137-
if (error)
3138-
goto out;
3139-
31403140
if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
31413141
(ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
31423142
struct reiserfs_transaction_handle th;

‎mm/shmem.c‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,10 @@ static int shmem_notify_change(struct dentry *dentry, struct iattr *attr)
767767
loff_t newsize = attr->ia_size;
768768
int error;
769769

770+
error = inode_change_ok(inode, attr);
771+
if (error)
772+
return error;
773+
770774
if (S_ISREG(inode->i_mode) && (attr->ia_valid & ATTR_SIZE)
771775
&& newsize != inode->i_size) {
772776
struct page *page = NULL;
@@ -809,11 +813,9 @@ static int shmem_notify_change(struct dentry *dentry, struct iattr *attr)
809813
shmem_truncate_range(inode, newsize, (loff_t)-1);
810814
}
811815

812-
error = inode_change_ok(inode, attr);
813-
if (!error)
814-
setattr_copy(inode, attr);
816+
setattr_copy(inode, attr);
815817
#ifdef CONFIG_TMPFS_POSIX_ACL
816-
if (!error && (attr->ia_valid & ATTR_MODE))
818+
if (attr->ia_valid & ATTR_MODE)
817819
error = generic_acl_chmod(inode);
818820
#endif
819821
return error;

0 commit comments

Comments
 (0)