Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 17CB0C7618A for ; Tue, 14 Mar 2023 14:12:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230209AbjCNOMP (ORCPT ); Tue, 14 Mar 2023 10:12:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230358AbjCNOMB (ORCPT ); Tue, 14 Mar 2023 10:12:01 -0400 Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9853A72B8 for ; Tue, 14 Mar 2023 07:11:38 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4Pbb6P1BPCz4f3mJk for ; Tue, 14 Mar 2023 22:11:09 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.170]) by APP4 (Coremail) with SMTP id gCh0CgD3X7NygBBkPBlyFQ--.57348S7; Tue, 14 Mar 2023 22:11:11 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, yukuai3@huawei.com Subject: [PATCH 3/4] debugfs/e2fsck: check bad s_head block number Date: Tue, 14 Mar 2023 22:10:57 +0800 Message-Id: <20230314141058.3267404-4-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230314141058.3267404-1-yi.zhang@huaweicloud.com> References: <20230314141058.3267404-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: gCh0CgD3X7NygBBkPB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DU0xZFpf9x0JULtxhUUUUU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Zhang Yi Check s_head in the journal superblock and fix it if this value is out of bounds. Signed-off-by: Zhang Yi --- debugfs/journal.c | 5 +++++ e2fsck/journal.c | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/debugfs/journal.c b/debugfs/journal.c index 5bc7552d..1eef3bca 100644 --- a/debugfs/journal.c +++ b/debugfs/journal.c @@ -631,6 +631,11 @@ static errcode_t ext2fs_journal_load(journal_t *journal) else if (ntohl(jsb->s_maxlen) > journal->j_total_len) return EXT2_ET_CORRUPT_JOURNAL_SB; + if (jsb->s_head != 0 && + (ntohl(jsb->s_head) < ntohl(jsb->s_first) || + ntohl(jsb->s_head) >= journal->j_total_len)) + return EXT2_ET_CORRUPT_JOURNAL_SB; + journal->j_tail_sequence = ntohl(jsb->s_sequence); journal->j_transaction_sequence = journal->j_tail_sequence; journal->j_tail = ntohl(jsb->s_start); diff --git a/e2fsck/journal.c b/e2fsck/journal.c index 8950446f..4b9f00ce 100644 --- a/e2fsck/journal.c +++ b/e2fsck/journal.c @@ -1374,6 +1374,15 @@ static errcode_t e2fsck_journal_load(journal_t *journal) return EXT2_ET_CORRUPT_JOURNAL_SB; } + if (jsb->s_head != 0 && + (ntohl(jsb->s_head) < ntohl(jsb->s_first) || + ntohl(jsb->s_head) >= journal->j_total_len)) { + com_err(ctx->program_name, EXT2_ET_CORRUPT_JOURNAL_SB, + _("%s, journal head out of bounds\n"), + ctx->device_name); + return EXT2_ET_CORRUPT_JOURNAL_SB; + } + journal->j_tail_sequence = ntohl(jsb->s_sequence); journal->j_transaction_sequence = journal->j_tail_sequence; journal->j_tail = ntohl(jsb->s_start); -- 2.31.1