]> git.karo-electronics.de Git - linux-beck.git/commitdiff
Btrfs: fix divide error upon chunk's stripe_len
authorLiu Bo <bo.li.liu@oracle.com>
Wed, 27 Apr 2016 00:53:31 +0000 (17:53 -0700)
committerDavid Sterba <dsterba@suse.com>
Fri, 6 May 2016 13:22:49 +0000 (15:22 +0200)
The struct 'map_lookup' uses type int for @stripe_len, while
btrfs_chunk_stripe_len() can return a u64 value, and it may end up with
@stripe_len being undefined value and it can lead to 'divide error' in
 __btrfs_map_block().

This changes 'map_lookup' to use type u64 for stripe_len, also right now
we only use BTRFS_STRIPE_LEN for stripe_len, so this adds a valid checker for
BTRFS_STRIPE_LEN.

Reported-by: Vegard Nossum <vegard.nossum@oracle.com>
Reported-by: Quentin Casasnovas <quentin.casasnovas@oracle.com>
Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
Reviewed-by: David Sterba <dsterba@suse.com>
[ folded division fix to scrub_raid56_parity ]
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/scrub.c
fs/btrfs/volumes.c
fs/btrfs/volumes.h

index 2ff2876656babdfd208a778b44bd84d86a2e9fad..96d2a0de35a8b5f2446ed9fe05fb3ac71a08b4f0 100644 (file)
@@ -2860,7 +2860,7 @@ static noinline_for_stack int scrub_raid56_parity(struct scrub_ctx *sctx,
        int extent_mirror_num;
        int stop_loop = 0;
 
-       nsectors = map->stripe_len / root->sectorsize;
+       nsectors = div_u64(map->stripe_len, root->sectorsize);
        bitmap_len = scrub_calc_parity_bitmap_len(nsectors);
        sparity = kzalloc(sizeof(struct scrub_parity) + 2 * bitmap_len,
                          GFP_NOFS);
index 7bd553d42e0df2488112f456ad977a156e23d6f7..f13e2bcc1398860f19b306eecedb0ec35c86001a 100644 (file)
@@ -6254,7 +6254,7 @@ static int read_one_chunk(struct btrfs_root *root, struct btrfs_key *key,
                        "invalid chunk length %llu", length);
                return -EIO;
        }
-       if (!is_power_of_2(stripe_len)) {
+       if (!is_power_of_2(stripe_len) || stripe_len != BTRFS_STRIPE_LEN) {
                btrfs_err(root->fs_info, "invalid chunk stripe length: %llu",
                          stripe_len);
                return -EIO;
index 1939ebde63dff6c0500151bfa9bc106bb2267838..7507be74f7daa90183c073e997f493f42bc2be75 100644 (file)
@@ -347,7 +347,7 @@ struct map_lookup {
        u64 type;
        int io_align;
        int io_width;
-       int stripe_len;
+       u64 stripe_len;
        int sector_size;
        int num_stripes;
        int sub_stripes;