ocfs2: fix shift left operations overflow
authorJoseph Qi <joseph.qi@huawei.com>
Thu, 9 Oct 2014 22:24:56 +0000 (15:24 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 10 Oct 2014 02:25:47 +0000 (22:25 -0400)
ocfs2_inode_info->ip_clusters and ocfs2_dinode->id1.bitmap1.i_total are
defined as type u32, so the shift left operations may overflow if volume
size is large, for example, 2TB and cluster size is 1MB.

Signed-off-by: Joseph Qi <joseph.qi@huawei.com>
Reviewed-by: Alex Chen <alex.chen@huawei.com>
Cc: Mark Fasheh <mfasheh@suse.com>
Cc: Joel Becker <jlbec@evilplan.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
fs/ocfs2/inode.h
fs/ocfs2/move_extents.c

index a6c991c0fc98cf413a846ff75c1edf62c1348fcd..a9b76de46047d02f754aa8d9fbdcd96ff74b853c 100644 (file)
@@ -162,7 +162,7 @@ static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
 {
        int c_to_s_bits = OCFS2_SB(inode->i_sb)->s_clustersize_bits - 9;
 
-       return (blkcnt_t)(OCFS2_I(inode)->ip_clusters << c_to_s_bits);
+       return (blkcnt_t)OCFS2_I(inode)->ip_clusters << c_to_s_bits;
 }
 
 /* Validate that a bh contains a valid inode */
index 6219aaadeb08dadeb44ebdacb2b2559edfc52d7c..74caffeeee1d5453a2ec7126b11dd9a9676d9b08 100644 (file)
@@ -404,7 +404,7 @@ static int ocfs2_find_victim_alloc_group(struct inode *inode,
         * 'vict_blkno' was out of the valid range.
         */
        if ((vict_blkno < le64_to_cpu(rec->c_blkno)) ||
-           (vict_blkno >= (le32_to_cpu(ac_dinode->id1.bitmap1.i_total) <<
+           (vict_blkno >= ((u64)le32_to_cpu(ac_dinode->id1.bitmap1.i_total) <<
                                bits_per_unit))) {
                ret = -EINVAL;
                goto out;