From mboxrd@z Thu Jan 1 00:00:00 1970 From: Yunlong Song Subject: [PATCH v4] f2fs: check segment type in __f2fs_replace_block Date: Thu, 4 Jan 2018 15:02:02 +0800 Message-ID: <1515049322-29555-1-git-send-email-yunlong.song@huawei.com> References: <1514619768-134531-1-git-send-email-yunlong.song@huawei.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from sfi-mx-1.v28.ch3.sourceforge.com ([172.29.28.191] helo=mx.sourceforge.net) by sfs-ml-1.v29.ch3.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1eWzXj-0002hb-Df for linux-f2fs-devel@lists.sourceforge.net; Thu, 04 Jan 2018 07:02:23 +0000 Received: from [45.249.212.35] (helo=huawei.com) by sfi-mx-1.v28.ch3.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) id 1eWzXh-0003tr-TA for linux-f2fs-devel@lists.sourceforge.net; Thu, 04 Jan 2018 07:02:23 +0000 In-Reply-To: <1514619768-134531-1-git-send-email-yunlong.song@huawei.com> List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net To: jaegeuk@kernel.org, chao@kernel.org, yuchao0@huawei.com, yunlong.song@icloud.com, yunlong.song@huawei.com Cc: shengyong1@huawei.com, linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, heyunlei@huawei.com, linux-fsdevel@vger.kernel.org, miaoxie@huawei.com In some case, the node blocks has wrong blkaddr whose segment type is NODE, e.g., recover inode has missing xattr flag and the blkaddr is in the xattr range. Since fsck.f2fs does not check the recovery nodes, this will cause __f2fs_replace_block change the curseg of node and do the update_sit_entry(sbi, new_blkaddr, 1) with no next_blkoff refresh, as a result, when recovery process write checkpoint and sync nodes, the next_blkoff of curseg is used in the segment bit map, then it will cause f2fs_bug_on. So let's check segment type in __f2fs_replace_block. Signed-off-by: Yunlong Song --- fs/f2fs/segment.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index 890d483..50575d5 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -2720,6 +2720,7 @@ void __f2fs_replace_block(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, type = se->type; down_write(&SM_I(sbi)->curseg_lock); + f2fs_bug_on(sbi, se->valid_blocks && !IS_DATASEG(type)); if (!recover_curseg) { /* for recovery flow */ -- 1.8.5.2 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot