Merge branch 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4

* 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4:
  ext4: Fix remaining racy updates of EXT4_I(inode)->i_flags
  ext4: Make sure the MOVE_EXT ioctl can't overwrite append-only files
This commit is contained in:
Linus Torvalds 2010-06-05 10:07:25 -07:00
commit 78b36558b7
2 changed files with 25 additions and 16 deletions

View File

@ -4942,20 +4942,26 @@ void ext4_set_inode_flags(struct inode *inode)
/* Propagate flags from i_flags to EXT4_I(inode)->i_flags */ /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
void ext4_get_inode_flags(struct ext4_inode_info *ei) void ext4_get_inode_flags(struct ext4_inode_info *ei)
{ {
unsigned int flags = ei->vfs_inode.i_flags; unsigned int vfs_fl;
unsigned long old_fl, new_fl;
ei->i_flags &= ~(EXT4_SYNC_FL|EXT4_APPEND_FL| do {
EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|EXT4_DIRSYNC_FL); vfs_fl = ei->vfs_inode.i_flags;
if (flags & S_SYNC) old_fl = ei->i_flags;
ei->i_flags |= EXT4_SYNC_FL; new_fl = old_fl & ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
if (flags & S_APPEND) EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|
ei->i_flags |= EXT4_APPEND_FL; EXT4_DIRSYNC_FL);
if (flags & S_IMMUTABLE) if (vfs_fl & S_SYNC)
ei->i_flags |= EXT4_IMMUTABLE_FL; new_fl |= EXT4_SYNC_FL;
if (flags & S_NOATIME) if (vfs_fl & S_APPEND)
ei->i_flags |= EXT4_NOATIME_FL; new_fl |= EXT4_APPEND_FL;
if (flags & S_DIRSYNC) if (vfs_fl & S_IMMUTABLE)
ei->i_flags |= EXT4_DIRSYNC_FL; new_fl |= EXT4_IMMUTABLE_FL;
if (vfs_fl & S_NOATIME)
new_fl |= EXT4_NOATIME_FL;
if (vfs_fl & S_DIRSYNC)
new_fl |= EXT4_DIRSYNC_FL;
} while (cmpxchg(&ei->i_flags, old_fl, new_fl) != old_fl);
} }
static blkcnt_t ext4_inode_blocks(struct ext4_inode *raw_inode, static blkcnt_t ext4_inode_blocks(struct ext4_inode *raw_inode,
@ -5191,7 +5197,7 @@ static int ext4_inode_blocks_set(handle_t *handle,
*/ */
raw_inode->i_blocks_lo = cpu_to_le32(i_blocks); raw_inode->i_blocks_lo = cpu_to_le32(i_blocks);
raw_inode->i_blocks_high = 0; raw_inode->i_blocks_high = 0;
ei->i_flags &= ~EXT4_HUGE_FILE_FL; ext4_clear_inode_flag(inode, EXT4_INODE_HUGE_FILE);
return 0; return 0;
} }
if (!EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_HUGE_FILE)) if (!EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_HUGE_FILE))
@ -5204,9 +5210,9 @@ static int ext4_inode_blocks_set(handle_t *handle,
*/ */
raw_inode->i_blocks_lo = cpu_to_le32(i_blocks); raw_inode->i_blocks_lo = cpu_to_le32(i_blocks);
raw_inode->i_blocks_high = cpu_to_le16(i_blocks >> 32); raw_inode->i_blocks_high = cpu_to_le16(i_blocks >> 32);
ei->i_flags &= ~EXT4_HUGE_FILE_FL; ext4_clear_inode_flag(inode, EXT4_INODE_HUGE_FILE);
} else { } else {
ei->i_flags |= EXT4_HUGE_FILE_FL; ext4_set_inode_flag(inode, EXT4_INODE_HUGE_FILE);
/* i_block is stored in file system block size */ /* i_block is stored in file system block size */
i_blocks = i_blocks >> (inode->i_blkbits - 9); i_blocks = i_blocks >> (inode->i_blkbits - 9);
raw_inode->i_blocks_lo = cpu_to_le32(i_blocks); raw_inode->i_blocks_lo = cpu_to_le32(i_blocks);

View File

@ -960,6 +960,9 @@ mext_check_arguments(struct inode *orig_inode,
return -EINVAL; return -EINVAL;
} }
if (IS_IMMUTABLE(donor_inode) || IS_APPEND(donor_inode))
return -EPERM;
/* Ext4 move extent does not support swapfile */ /* Ext4 move extent does not support swapfile */
if (IS_SWAPFILE(orig_inode) || IS_SWAPFILE(donor_inode)) { if (IS_SWAPFILE(orig_inode) || IS_SWAPFILE(donor_inode)) {
ext4_debug("ext4 move extent: The argument files should " ext4_debug("ext4 move extent: The argument files should "