Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

f2fs: add READ_ONCE() for i_blocks in f2fs_update_inode()

f2fs_update_inode() reads inode->i_blocks without holding i_lock to
serialize it to the on-disk inode, while concurrent truncate or
allocation paths may modify i_blocks under i_lock. Since blkcnt_t is
u64, this risks torn reads on 32-bit architectures.

Following the approach in ext4_inode_blocks_set(), add READ_ONCE() to prevent
potential compiler-induced tearing.

Fixes: 19f99cee206c ("f2fs: add core inode operations")
Cc: stable@vger.kernel.org
Signed-off-by: Cen Zhang <zzzccc427@gmail.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>

authored by

Cen Zhang and committed by
Jaegeuk Kim
5471834a 1e134c33

+1 -1
+1 -1
fs/f2fs/inode.c
··· 687 687 ri->i_uid = cpu_to_le32(i_uid_read(inode)); 688 688 ri->i_gid = cpu_to_le32(i_gid_read(inode)); 689 689 ri->i_links = cpu_to_le32(inode->i_nlink); 690 - ri->i_blocks = cpu_to_le64(SECTOR_TO_BLOCK(inode->i_blocks) + 1); 690 + ri->i_blocks = cpu_to_le64(SECTOR_TO_BLOCK(READ_ONCE(inode->i_blocks)) + 1); 691 691 692 692 if (!f2fs_is_atomic_file(inode) || 693 693 is_inode_flag_set(inode, FI_ATOMIC_COMMITTED))