Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp10789103imu; Thu, 6 Dec 2018 06:51:37 -0800 (PST) X-Google-Smtp-Source: AFSGD/WxRNgzCg950DHJxiBk3sA7K+UEfOa62Nd9CqYm7GPHkDQDmu36zPqr+rgH+y+MMuGq1CrW X-Received: by 2002:a63:9712:: with SMTP id n18mr24060165pge.295.1544107897643; Thu, 06 Dec 2018 06:51:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544107897; cv=none; d=google.com; s=arc-20160816; b=K9mvsBpdnaFTRWHDMmox7AZN2PVI4miJj01h2w+VzTcXadwL+6D3jMgRcn9Z/6YaVu 0wKIGqVg8EBhBFT6Yoxmz3Wsq2LeASvZXYAxgKsuTpBOBqzj4Zt9RH9GcbudwzZZg+HJ mW+/nWqgJAhjuT0COmEvpzI1fGz4uOtxmpsKVBtWdlm5zNGkhI7JYXll5Ikg/9U8ttPD 3XYb/QndVBESbsvpEz23I6lv3JkwHHRw212HOkWodbyS798ilGVAHP7tqHw99OkF7Zxf vUj/X/hcNxqIk1syzLqmEoQWzoBgHtWZjmluopd46llnj5li3ZTjMN9hBsD9s/I1BeRu z+Sg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=AYHIYM9Ek9unk483YfQDGr7U3jwEV4WUG+KUfI0uW1o=; b=uOigPy0rgnyiDY0MOFWHTv/whDExD7nMcsYGvLjYi7IkjcS3PK9rTuHlRXQSsddT9F 9DbioHHCih997n9g0RENNdg+rpvWhJuKig29G0gocUuuhxcwPdvBuG1I+ouqyx+4soGs rWpPeWSVo67Gsnjn4hqJGC3MSLpr1CtGFY+evLLfKJ123mxTxKtW5033ALIDfnUF7RAv 2PCYAxMi9SseghIZyz1i1XeTOYI59ix0K32Tlc7Jt9WnYCZJ1bFxRb8Yr+QAAmwYFNPn YEpwHwAOgtQKMIgBDFNakNXXbRGI0NEj4WclSxRc5kjDBjcrR93EnJS563B0gltGgKj+ DBrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Jx6jrlF8; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x191si419300pfd.220.2018.12.06.06.51.21; Thu, 06 Dec 2018 06:51:37 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Jx6jrlF8; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731431AbeLFOrc (ORCPT + 99 others); Thu, 6 Dec 2018 09:47:32 -0500 Received: from mail.kernel.org ([198.145.29.99]:52458 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729752AbeLFOrZ (ORCPT ); Thu, 6 Dec 2018 09:47:25 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2077E214DE; Thu, 6 Dec 2018 14:47:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544107644; bh=ZyVUMUtMessVDXwLerp9tzthSEROM2RC4V3U7KX3WKg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Jx6jrlF8ugkXs8Ix9FAL89z31JiGHFtzT+YhwEK2wr68GhBFnINxae5343ROx2wg3 mWGappXfFQqKRSgoD+c761jVZ2RxAT3RXCTYKdfV/RnElGgCCtac3fcHWOEfCPEkpf SU4XovRCr4RgvlBcKHfU9oKzA4W+59/8Y9b7SRZA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jaegeuk Kim , Ben Hutchings Subject: [PATCH 4.9 085/101] f2fs: detect wrong layout Date: Thu, 6 Dec 2018 15:39:24 +0100 Message-Id: <20181206143017.598273794@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181206143011.174892052@linuxfoundation.org> References: <20181206143011.174892052@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jaegeuk Kim commit 2040fce83fe17763b07c97c1f691da2bb85e4135 upstream. Previous mkfs.f2fs allows small partition inappropriately, so f2fs should detect that as well. Refer this in f2fs-tools. mkfs.f2fs: detect small partition by overprovision ratio and # of segments Reported-and-Tested-by: Eric Biggers Signed-off-by: Jaegeuk Kim [bwh: Backported to 4.9: adjust context] Signed-off-by: Ben Hutchings Signed-off-by: Greg Kroah-Hartman --- fs/f2fs/segment.h | 2 ++ fs/f2fs/super.c | 11 +++++++++++ 2 files changed, 13 insertions(+) --- a/fs/f2fs/segment.h +++ b/fs/f2fs/segment.h @@ -18,6 +18,8 @@ #define DEF_RECLAIM_PREFREE_SEGMENTS 5 /* 5% over total segments */ #define DEF_MAX_RECLAIM_PREFREE_SEGMENTS 4096 /* 8GB in maximum */ +#define F2FS_MIN_SEGMENTS 9 /* SB + 2 (CP + SIT + NAT) + SSA + MAIN */ + /* L: Logical segment # in volume, R: Relative segment # in main area */ #define GET_L2R_SEGNO(free_i, segno) (segno - free_i->start_segno) #define GET_R2L_SEGNO(free_i, segno) (segno + free_i->start_segno) --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -1424,6 +1424,7 @@ int sanity_check_ckpt(struct f2fs_sb_inf unsigned int total, fsmeta; struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi); struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); + unsigned int ovp_segments, reserved_segments; unsigned int main_segs, blocks_per_seg; unsigned int sit_segs, nat_segs; unsigned int sit_bitmap_size, nat_bitmap_size; @@ -1442,6 +1443,16 @@ int sanity_check_ckpt(struct f2fs_sb_inf if (unlikely(fsmeta >= total)) return 1; + ovp_segments = le32_to_cpu(ckpt->overprov_segment_count); + reserved_segments = le32_to_cpu(ckpt->rsvd_segment_count); + + if (unlikely(fsmeta < F2FS_MIN_SEGMENTS || + ovp_segments == 0 || reserved_segments == 0)) { + f2fs_msg(sbi->sb, KERN_ERR, + "Wrong layout: check mkfs.f2fs version"); + return 1; + } + main_segs = le32_to_cpu(raw_super->segment_count_main); blocks_per_seg = sbi->blocks_per_seg;