Skip to content

Commit

Permalink
Btrfs: fix a out-of-bound access of raid_map
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
zhaoleidd authored and masoncl committed Jan 22, 2015
1 parent df8d116 commit e34c330
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions fs/btrfs/scrub.c
Original file line number Diff line number Diff line change
Expand Up @@ -1299,7 +1299,9 @@ static int scrub_handle_errored_block(struct scrub_block *sblock_to_check)
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;
Expand Down Expand Up @@ -1420,7 +1422,8 @@ static int scrub_setup_recheck_block(struct scrub_ctx *sctx,

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);
Expand Down

0 comments on commit e34c330

Please sign in to comment.