Skip to content

Commit

Permalink
fat: fat_setattr() fix
Browse files Browse the repository at this point in the history
Fix fat_setattr() on the case of showexec option. If user specified
showexec option, inode->i_mode may not have S_IXUGO. This just use
inode->i_mode to fix it.

And with this patch, we don't allow chmod() on memory inode, it's just
bad behaviour. IOW, we allow changing S_IWUGO only which can be stored
to disk.

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
OGAWA Hirofumi authored and Linus Torvalds committed Apr 28, 2008
1 parent 1278fdd commit e97e8de
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions fs/fat/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@ int fat_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
}
EXPORT_SYMBOL_GPL(fat_getattr);

static int fat_check_mode(const struct msdos_sb_info *sbi, mode_t mode)
static int fat_check_mode(const struct msdos_sb_info *sbi, struct inode *inode,
mode_t mode)
{
mode_t mask, req = mode & ~S_IFMT;

Expand All @@ -271,7 +272,7 @@ static int fat_check_mode(const struct msdos_sb_info *sbi, mode_t mode)
* w bits, either all (subject to umask) or none must be present.
*/
req &= ~mask;
if ((req & (S_IRUGO | S_IXUGO)) != ((S_IRUGO | S_IXUGO) & ~mask))
if ((req & (S_IRUGO | S_IXUGO)) != (inode->i_mode & (S_IRUGO|S_IXUGO)))
return -EPERM;
if ((req & S_IWUGO) && ((req & S_IWUGO) != (S_IWUGO & ~mask)))
return -EPERM;
Expand Down Expand Up @@ -310,7 +311,9 @@ int fat_setattr(struct dentry *dentry, struct iattr *attr)
if (((attr->ia_valid & ATTR_UID) &&
(attr->ia_uid != sbi->options.fs_uid)) ||
((attr->ia_valid & ATTR_GID) &&
(attr->ia_gid != sbi->options.fs_gid)))
(attr->ia_gid != sbi->options.fs_gid)) ||
((attr->ia_valid & ATTR_MODE) &&
fat_check_mode(sbi, inode, attr->ia_mode) < 0))
error = -EPERM;

if (error) {
Expand All @@ -319,12 +322,6 @@ int fat_setattr(struct dentry *dentry, struct iattr *attr)
goto out;
}

if (attr->ia_valid & ATTR_MODE) {
error = fat_check_mode(sbi, attr->ia_mode);
if (error != 0 && !sbi->options.quiet)
goto out;
}

error = inode_setattr(inode, attr);
if (error)
goto out;
Expand Down

0 comments on commit e97e8de

Please sign in to comment.