Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2225704yba; Mon, 22 Apr 2019 02:51:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqz7mzU5uIMnJBC7iXFY+0B0DxFvmEEUjwASjad/P2kknisiCQTBIsX0nn1v3wvd7pZRSxYy X-Received: by 2002:a62:388d:: with SMTP id f135mr19808141pfa.103.1555926704937; Mon, 22 Apr 2019 02:51:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555926704; cv=none; d=google.com; s=arc-20160816; b=RXfK/ACS+zmqubpoI5qOCwD24F/GHquRURUFcdk6Z+RXX8Hstc9PgwZC8OT1skZl03 oRu5gIIVX8UFORPWfJ1ayU7M/i9JFJWSgSOY2sCev3+UldWOrnBPkELlUUT87WbU0F6z qtATq/VKgbSqTwzsePO/3pET+ddM2uSwT+Z6HFHnMD5Y9lKqmMQo7wZMb0Z6Wzo5pLP6 i/LDrb+prA8CNFPqm8FmMpNMB8oaz6nE67uySkUf6WolQYsD7uJeYdgW+kjmUSu9H5XB 4E9DAvfVag2htzDaRtrV5G5s8XWUmdju4C3Xs+1Qr6DBOqvztbIUFHFqrZ6Pw4MzVw2x N6rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=Nnir9Y5txJ5CUX7NISS7zqp0MLFPmX53/e3jAqBqWFw=; b=LkEfxfUE3nJvRt9wGDOPdFzB5v/bblfq2WwL9C0T6ijqexyMqQibj9/xcB0+4XB37s aLsr7UHxv3j3R2PIGguu93HzBioo4W5AP1V19w6QrEW7R+nX1P5OPzkDGA4obIJeTV4j BZTXbq3dDX1RCfdHXLx+9eDMttI3Z5XpznR5R9Dt7Fzz2sU1O9jkvhq3gaVEN+yPJQ6I nqeh28fhCPZr84enTDmC5Ok22tkNw1s3uBRMs96ze23Iuc59F7XcZQgff+XiBCsniYdO W1b7BrosmKzjmwXeb4G3C4mkAW2farLdQFzXUwhHdKlWlqIZBmY+jWD4JAhjhKnNEIKA EDzg== ARC-Authentication-Results: i=1; mx.google.com; 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 v4si11860209pga.366.2019.04.22.02.51.29; Mon, 22 Apr 2019 02:51:44 -0700 (PDT) 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; 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 S1726790AbfDVJeG (ORCPT + 99 others); Mon, 22 Apr 2019 05:34:06 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:2936 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725817AbfDVJeG (ORCPT ); Mon, 22 Apr 2019 05:34:06 -0400 Received: from DGGEMM406-HUB.china.huawei.com (unknown [172.30.72.56]) by Forcepoint Email with ESMTP id 21ED496658962B49F2C8; Mon, 22 Apr 2019 17:33:59 +0800 (CST) Received: from dggeme763-chm.china.huawei.com (10.3.19.109) by DGGEMM406-HUB.china.huawei.com (10.3.20.214) with Microsoft SMTP Server (TLS) id 14.3.408.0; Mon, 22 Apr 2019 17:33:58 +0800 Received: from szvp000201624.huawei.com (10.120.216.130) by dggeme763-chm.china.huawei.com (10.3.19.109) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1591.10; Mon, 22 Apr 2019 17:33:58 +0800 From: Chao Yu To: CC: , , , Chao Yu Subject: [PATCH 2/2] f2fs: relocate chksum_offset for large_nat_bitmap feature Date: Mon, 22 Apr 2019 17:33:53 +0800 Message-ID: <20190422093353.61014-2-yuchao0@huawei.com> X-Mailer: git-send-email 2.18.0.rc1 In-Reply-To: <20190422093353.61014-1-yuchao0@huawei.com> References: <20190422093353.61014-1-yuchao0@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.120.216.130] X-ClientProxiedBy: dggeme701-chm.china.huawei.com (10.1.199.97) To dggeme763-chm.china.huawei.com (10.3.19.109) X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For large_nat_bitmap feature, there is a design flaw: Previous: struct f2fs_checkpoint layout: +--------------------------+ 0x0000 | checkpoint_ver | | ...... | | checksum_offset |------+ | ...... | | | sit_nat_version_bitmap[] |<-----|-------+ | ...... | | | | checksum_value |<-----+ | +--------------------------+ 0x1000 | | | nat_bitmap + sit_bitmap | payload blocks | | | | | +--------------------------|<-------------+ Obviously, if nat_bitmap size + sit_bitmap size is larger than MAX_BITMAP_SIZE_IN_CKPT, nat_bitmap or sit_bitmap may overlap checkpoint checksum's position, once checkpoint() is triggered from kernel, nat or sit bitmap will be damaged by checksum field. In order to fix this, let's relocate checksum_value's position to the head of sit_nat_version_bitmap as below, then nat/sit bitmap and chksum value update will become safe. After: struct f2fs_checkpoint layout: +--------------------------+ 0x0000 | checkpoint_ver | | ...... | | checksum_offset |------+ | ...... | | | sit_nat_version_bitmap[] |<-----+ | ...... |<-------------+ | | | +--------------------------+ 0x1000 | | | nat_bitmap + sit_bitmap | payload blocks | | | | | +--------------------------|<-------------+ Related report and discussion: https://sourceforge.net/p/linux-f2fs/mailman/message/36642346/ Reported-by: Park Ju Hyung Signed-off-by: Chao Yu --- fs/f2fs/checkpoint.c | 11 +++++++++++ fs/f2fs/f2fs.h | 6 +++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c index a25556aef8cc..081eee9e3d92 100644 --- a/fs/f2fs/checkpoint.c +++ b/fs/f2fs/checkpoint.c @@ -831,6 +831,17 @@ static int get_checkpoint_version(struct f2fs_sb_info *sbi, block_t cp_addr, return -EINVAL; } + if (__is_set_ckpt_flags(*cp_block, CP_LARGE_NAT_BITMAP_FLAG)) { + if (crc_offset != CP_MIN_CHKSUM_OFFSET) { + f2fs_put_page(*cp_page, 1); + f2fs_msg(sbi->sb, KERN_WARNING, + "layout of large_nat_bitmap is deprecated, " + "run fsck to repair, chksum_offset: %zu", + crc_offset); + return -EINVAL; + } + } + crc = f2fs_checkpoint_chksum(sbi, *cp_block); if (crc != cur_cp_crc(*cp_block)) { f2fs_put_page(*cp_page, 1); diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 31531711e148..f5ffc09705eb 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -1911,7 +1911,11 @@ static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag) if (is_set_ckpt_flags(sbi, CP_LARGE_NAT_BITMAP_FLAG)) { offset = (flag == SIT_BITMAP) ? le32_to_cpu(ckpt->nat_ver_bitmap_bytesize) : 0; - return &ckpt->sit_nat_version_bitmap + offset; + /* + * if large_nat_bitmap feature is enabled, leave checksum + * protection for all nat/sit bitmaps. + */ + return &ckpt->sit_nat_version_bitmap + offset + sizeof(__le32); } if (__cp_payload(sbi) > 0) { -- 2.18.0.rc1