From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from cn.fujitsu.com ([59.151.112.132]:19414 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1751510AbbAMMgD (ORCPT ); Tue, 13 Jan 2015 07:36:03 -0500 From: Zhaolei To: CC: Zhao Lei , Miao Xie Subject: [PATCH 01/15] Btrfs: fix a out-of-bound access of raid_map Date: Tue, 13 Jan 2015 20:34:34 +0800 Message-ID: <1421152488-30548-2-git-send-email-zhaolei@cn.fujitsu.com> In-Reply-To: <1421152488-30548-1-git-send-email-zhaolei@cn.fujitsu.com> References: <1421152488-30548-1-git-send-email-zhaolei@cn.fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-btrfs-owner@vger.kernel.org List-ID: From: Zhao Lei 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 Signed-off-by: Miao Xie --- fs/btrfs/scrub.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c index 9e1569f..9d19065 100644 --- a/fs/btrfs/scrub.c +++ b/fs/btrfs/scrub.c @@ -1291,7 +1291,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; @@ -1412,7 +1414,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); -- 1.8.5.1