diff options
author | Theodore Ts'o <tytso@mit.edu> | 2014-03-30 10:20:01 -0400 |
---|---|---|
committer | Qiming Wu <wuqm@marvell.com> | 2014-11-19 18:27:18 +0800 |
commit | 555de605570346d6abffc67980baf15c6dfd051e (patch) | |
tree | adafadf92a9d7ffed247468afe5f21d983012311 /fs/ext4 | |
parent | 512ef58d1cd6b37b1c1061e1ef8cf6364e5dd173 (diff) | |
download | pxa-v3.14-555de605570346d6abffc67980baf15c6dfd051e.tar.gz |
ext4: atomically set inode->i_flags in ext4_set_inode_flags()
Use cmpxchg() to atomically set i_flags instead of clearing out the
S_IMMUTABLE, S_APPEND, etc. flags and then setting them from the
EXT4_IMMUTABLE_FL, EXT4_APPEND_FL flags, since this opens up a race
where an immutable file has the immutable flag cleared for a brief
window of time.
Change-Id: I2b26d75508766caea17475bc858ae4adfb34ca10
Reported-by: John Sullivan <jsrhbz@kanargh.force9.co.uk>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Cc: stable@kernel.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Jialing Fu <jlfu@marvell.com>
Diffstat (limited to 'fs/ext4')
-rw-r--r-- | fs/ext4/inode.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 6e39895a91b..24bfd7ff304 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -38,6 +38,7 @@ #include <linux/slab.h> #include <linux/ratelimit.h> #include <linux/aio.h> +#include <linux/bitops.h> #include "ext4_jbd2.h" #include "xattr.h" @@ -3921,18 +3922,20 @@ int ext4_get_inode_loc(struct inode *inode, struct ext4_iloc *iloc) void ext4_set_inode_flags(struct inode *inode) { unsigned int flags = EXT4_I(inode)->i_flags; + unsigned int new_fl = 0; - inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC); if (flags & EXT4_SYNC_FL) - inode->i_flags |= S_SYNC; + new_fl |= S_SYNC; if (flags & EXT4_APPEND_FL) - inode->i_flags |= S_APPEND; + new_fl |= S_APPEND; if (flags & EXT4_IMMUTABLE_FL) - inode->i_flags |= S_IMMUTABLE; + new_fl |= S_IMMUTABLE; if (flags & EXT4_NOATIME_FL) - inode->i_flags |= S_NOATIME; + new_fl |= S_NOATIME; if (flags & EXT4_DIRSYNC_FL) - inode->i_flags |= S_DIRSYNC; + new_fl |= S_DIRSYNC; + set_mask_bits(&inode->i_flags, + S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC, new_fl); } /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */ |