Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1524137pxb; Thu, 16 Sep 2021 09:12:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzVt6fVwXUBsCBT00OOl66GYBN8Mlb59gep3YECa6kbIWpKnczX8Bl8aWMS+pzU01CLpBLG X-Received: by 2002:a17:906:368e:: with SMTP id a14mr7026417ejc.60.1631808746919; Thu, 16 Sep 2021 09:12:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631808746; cv=none; d=google.com; s=arc-20160816; b=XC6AfpZn5ApvHcISg82tOlL3i0Z4hSf5xVlOCaq16pUqXEXTX0k+KUu+NYZx9KnFw4 tXBeJJebq2CRRhrzRd2ZYBKZK3aXkjV1H9YkEABWVcbP6ERJ2WfO5QV+kXvbq29AtAlr 4WRcGhP2r8G7bx5swVisVW8ri3V9GEqOVP6uD2r1kp3Xs6I7QJHQIp49OroSs06jjdQ6 3rP5O+vy+m5q3aLwyRa8qNX7wCAMiv+uNiPAi6tTq73fpbvw1wxivCXwRoJO5b5rBnkj D6mXsXgqlJuMJVjH4Su8csL1mHr5TMnCMgc9BE5MwecLFniYgWARDtH4NApCWa7lZipl QWDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=qerz8ADAw7RJp1qWlEGaICcBhZh2WLACNj6xEBQ03G0=; b=rq8+TW/SACR7si40dR0Ha1mIrGu5i750s2NYsH6B0EdDZN8bwgvoL1ET9Apv3nGF8s viyITxPndbhHE7FSI1gJjc4RASjyJvD25Wt0jLGl3A1Yvc1jVNYNs6jRZ7KD9rd+Hyo3 4vgInLsZATAwH+yU6KfoGdG1TrsUldJr87G90Ae7nm2yIBWsuEcMigur/IngiQAVQpsc HcwFECxvg7U991cBHPXwXZgAi6gnfsVhxlq4dzhDLEsGVoD6GuN4DSwIoFwMNo/jp+Ph zHed/+a+yCkFmkwXIXW1FCRuAI1Z30MF4USa0ReCPT+D8gt7Xm0tOaMbHUD5bx1WNPXX rVYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ap25Syop; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hb44si3402278ejc.174.2021.09.16.09.12.01; Thu, 16 Sep 2021 09:12:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ap25Syop; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235481AbhIPQJH (ORCPT + 99 others); Thu, 16 Sep 2021 12:09:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:45176 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233448AbhIPQGj (ORCPT ); Thu, 16 Sep 2021 12:06:39 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7896560232; Thu, 16 Sep 2021 16:05:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631808319; bh=+FpmXXRpAh8PROdVCzv6jtM4wORXri1JVm+4ZnrgLCU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ap25SyopGkr57TEx/CB2xYf2Oqd/T59iiPpZlGu5JkHso9ZmQcqte1ltDJcgaYWAG YAQBeh7ogeDZxc4ir3d5OhefEY9wj4fk4hhLpa9VNCmagQ0VciUEhqfKudedMT+i+c 9YWXbkcHMswPOlMrIT4UzV0+PvS3PbkEt7LZFGPE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, stable@kernel.org, Chao Yu , Jaegeuk Kim Subject: [PATCH 5.10 045/306] f2fs: fix to do sanity check for sb/cp fields correctly Date: Thu, 16 Sep 2021 17:56:30 +0200 Message-Id: <20210916155755.480312003@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210916155753.903069397@linuxfoundation.org> References: <20210916155753.903069397@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Chao Yu commit 65ddf6564843890a58ee3b18bb46ce67d96333fb upstream. This patch fixes below problems of sb/cp sanity check: - in sanity_check_raw_superi(), it missed to consider log header blocks while cp_payload check. - in f2fs_sanity_check_ckpt(), it missed to check nat_bits_blocks. Cc: Signed-off-by: Chao Yu Signed-off-by: Jaegeuk Kim Signed-off-by: Greg Kroah-Hartman --- fs/f2fs/super.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -2898,11 +2898,13 @@ static int sanity_check_raw_super(struct return -EFSCORRUPTED; } - if (le32_to_cpu(raw_super->cp_payload) > - (blocks_per_seg - F2FS_CP_PACKS)) { - f2fs_info(sbi, "Insane cp_payload (%u > %u)", + if (le32_to_cpu(raw_super->cp_payload) >= + (blocks_per_seg - F2FS_CP_PACKS - + NR_CURSEG_PERSIST_TYPE)) { + f2fs_info(sbi, "Insane cp_payload (%u >= %u)", le32_to_cpu(raw_super->cp_payload), - blocks_per_seg - F2FS_CP_PACKS); + blocks_per_seg - F2FS_CP_PACKS - + NR_CURSEG_PERSIST_TYPE); return -EFSCORRUPTED; } @@ -2938,6 +2940,7 @@ int f2fs_sanity_check_ckpt(struct f2fs_s unsigned int cp_pack_start_sum, cp_payload; block_t user_block_count, valid_user_blocks; block_t avail_node_count, valid_node_count; + unsigned int nat_blocks, nat_bits_bytes, nat_bits_blocks; int i, j; total = le32_to_cpu(raw_super->segment_count); @@ -3058,6 +3061,17 @@ int f2fs_sanity_check_ckpt(struct f2fs_s return 1; } + nat_blocks = nat_segs << log_blocks_per_seg; + nat_bits_bytes = nat_blocks / BITS_PER_BYTE; + nat_bits_blocks = F2FS_BLK_ALIGN((nat_bits_bytes << 1) + 8); + if (__is_set_ckpt_flags(ckpt, CP_NAT_BITS_FLAG) && + (cp_payload + F2FS_CP_PACKS + + NR_CURSEG_PERSIST_TYPE + nat_bits_blocks >= blocks_per_seg)) { + f2fs_warn(sbi, "Insane cp_payload: %u, nat_bits_blocks: %u)", + cp_payload, nat_bits_blocks); + return -EFSCORRUPTED; + } + if (unlikely(f2fs_cp_error(sbi))) { f2fs_err(sbi, "A bug case: need to run fsck"); return 1;