]> git.hungrycats.org Git - linux/commitdiff
Btrfs: fix a out-of-bound access of raid_map
authorZhao Lei <zhaolei@cn.fujitsu.com>
Tue, 20 Jan 2015 07:11:31 +0000 (15:11 +0800)
committerZygo Blaxell <zblaxell@serenity.furryterror.org>
Tue, 14 Apr 2015 02:30:50 +0000 (22:30 -0400)
We add the number of stripes on target devices into bbio->num_stripes
if we are under device replacement, and we just sort the raid_map of
those stripes that not on the target devices, so if when we need
real raid_map, we need skip the stripes on the target devices.

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Chris Mason <clm@fb.com>
(cherry picked from commit e34c330d639177bbb345bf2bde16613b00cc6e6b)

fs/btrfs/scrub.c

index fba12aed6383444340437f53fa34633836dc65c5..9960bf0f5be549a23a4ef7857a0a5f5d30efb397 100644 (file)
@@ -1299,7 +1299,9 @@ out:
 static inline int scrub_nr_raid_mirrors(struct btrfs_bio *bbio, u64 *raid_map)
 {
        if (raid_map) {
-               if (raid_map[bbio->num_stripes - 1] == RAID6_Q_STRIPE)
+               int real_stripes = bbio->num_stripes - bbio->num_tgtdevs;
+
+               if (raid_map[real_stripes - 1] == RAID6_Q_STRIPE)
                        return 3;
                else
                        return 2;
@@ -1420,7 +1422,8 @@ leave_nomem:
 
                        scrub_stripe_index_and_offset(logical, raid_map,
                                                      mapped_length,
-                                                     bbio->num_stripes,
+                                                     bbio->num_stripes -
+                                                     bbio->num_tgtdevs,
                                                      mirror_index,
                                                      &stripe_index,
                                                      &stripe_offset);