Skip to content

Commit

Permalink
ext4: fix overflow when counting used blocks on 32-bit architectures
Browse files Browse the repository at this point in the history
The arithmetics adding delalloc blocks to the number of used blocks in
ext4_getattr() can easily overflow on 32-bit archs as we first multiply
number of blocks by blocksize and then divide back by 512. Make the
arithmetics more clever and also use proper type (unsigned long long
instead of unsigned long).

Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
  • Loading branch information
Jan Kara authored and Theodore Ts'o committed May 31, 2013
1 parent a60697f commit 8af8eec
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions fs/ext4/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -4702,7 +4702,7 @@ int ext4_getattr(struct vfsmount *mnt, struct dentry *dentry,
struct kstat *stat)
{
struct inode *inode;
unsigned long delalloc_blocks;
unsigned long long delalloc_blocks;

inode = dentry->d_inode;
generic_fillattr(inode, stat);
Expand All @@ -4720,7 +4720,7 @@ int ext4_getattr(struct vfsmount *mnt, struct dentry *dentry,
delalloc_blocks = EXT4_C2B(EXT4_SB(inode->i_sb),
EXT4_I(inode)->i_reserved_data_blocks);

stat->blocks += (delalloc_blocks << inode->i_sb->s_blocksize_bits)>>9;
stat->blocks += delalloc_blocks << (inode->i_sb->s_blocksize_bits-9);
return 0;
}

Expand Down

0 comments on commit 8af8eec

Please sign in to comment.