Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2205587iof; Tue, 7 Jun 2022 23:10:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwkal9g8uVwVh/qu2kMbLzJDmw1oAoINRDporul5RRhIrBL4RnlO+S1UDt4+392V10EZY1e X-Received: by 2002:a17:90b:1101:b0:1e8:5df5:b2ac with SMTP id gi1-20020a17090b110100b001e85df5b2acmr21719218pjb.239.1654668609178; Tue, 07 Jun 2022 23:10:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654668609; cv=none; d=google.com; s=arc-20160816; b=NYIDKJWxwLiB6aAJ9zWQ22SybwrFWXsQw7nVQ8wx7qpZ7RyDIvTDmpe41xH+ZrEkXq gyxsAuxLyf4VNNKzv7fNeV4dxRhaaS/6CCiQeLnEWhFljTUJdjWIIK/pH2htlnTXk33v Z7DqSigFNRAPP2ZEfzc/tMESLCRYKGmDzBkDLp/agpZt2U+SR0RRSCHtA6LGzVLIWtO/ MpLpM4vjNItVyHXf1SuxIUvkcau9nHy8a8fAtlgxD9xbUMFqeIYv9gKT5A0QQ1I1rEZr Ng6IbsXN5/PGoXaAgC1/BhO2kf2hcQ/D5SJtMecyZxoFS8toMnRpqH3hoM2KYDEFPICu J2rA== 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=VrqbnfRNRgVs50uZmIWAvek+MGOPSE2Hp1k/brcgTsQ=; b=JEUwgoUSJis3YLbuHlDTSUISiKtT6SfAWFSo7wrBieyIEkVDm0G4wZ62DaqrK6EGNV ejF+bBZc4cL1XeHajDSk0n/MVeTcc4KOS2rjhHngCT1DusPbmZo1AVS9CqEFpvgwzOdw eVBBKByGaYUwbsSJqatvdCdKDj4WP3ywqJzE37RTBKQ8qtwJ0yzvOrnSq8iE8Q+SV5VH 3RmwO/HvsEFRyvbqwF2mFndYSiwvWEZi5y4bcnR3K33R1TtdZEHPj5mp41YqGbHoLeUg boEqORYNKLjd3NcT4mNgFwAcGhhmv6KU66dxD77o0ke4eCz0ukpbUseBncVspQn4GhQd OpPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="Obit/vaF"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id ob4-20020a17090b390400b001e0728a2a5csi21556713pjb.99.2022.06.07.23.10.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 23:10:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="Obit/vaF"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 09E64495046; Tue, 7 Jun 2022 22:32:27 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381474AbiFHBfg (ORCPT + 99 others); Tue, 7 Jun 2022 21:35:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1384760AbiFGWQM (ORCPT ); Tue, 7 Jun 2022 18:16:12 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F5BD26129E; Tue, 7 Jun 2022 12:20:01 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3C2916194A; Tue, 7 Jun 2022 19:19:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1EB68C385A2; Tue, 7 Jun 2022 19:19:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654629582; bh=ctuS+qzsxtX+EZZEbj4SB3xQ5P63NIKytgvwWabwSBk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Obit/vaFHkPFuYffuoQiGkHnCZZI/Hb+A8qfZSRj6Nz1x+gOsGbCHpI5M/5yBRBp+ 9vcNmdfwi4HvIgnyi9I593YLD2mQDzPtfi+TSWI1uosHcpyWzPOZkoMAMDffgJTpfy UsgUuRYMlAkDrepDmOXwsUvbyFhwVpMsL/e8+Nfg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, stable@kernel.org, Theodore Tso , syzbot+c7358a3cd05ee786eb31@syzkaller.appspotmail.com Subject: [PATCH 5.18 743/879] ext4: filter out EXT4_FC_REPLAY from on-disk superblock field s_state Date: Tue, 7 Jun 2022 19:04:21 +0200 Message-Id: <20220607165024.425163916@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607165002.659942637@linuxfoundation.org> References: <20220607165002.659942637@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Theodore Ts'o commit c878bea3c9d724ddfa05a813f30de3d25a0ba83f upstream. The EXT4_FC_REPLAY bit in sbi->s_mount_state is used to indicate that we are in the middle of replay the fast commit journal. This was actually a mistake, since the sbi->s_mount_info is initialized from es->s_state. Arguably s_mount_state is misleadingly named, but the name is historical --- s_mount_state and s_state dates back to ext2. What should have been used is the ext4_{set,clear,test}_mount_flag() inline functions, which sets EXT4_MF_* bits in sbi->s_mount_flags. The problem with using EXT4_FC_REPLAY is that a maliciously corrupted superblock could result in EXT4_FC_REPLAY getting set in s_mount_state. This bypasses some sanity checks, and this can trigger a BUG() in ext4_es_cache_extent(). As a easy-to-backport-fix, filter out the EXT4_FC_REPLAY bit for now. We should eventually transition away from EXT4_FC_REPLAY to something like EXT4_MF_REPLAY. Cc: stable@kernel.org Signed-off-by: Theodore Ts'o Link: https://lore.kernel.org/r/20220420192312.1655305-1-phind.uet@gmail.com Link: https://lore.kernel.org/r/20220517174028.942119-1-tytso@mit.edu Reported-by: syzbot+c7358a3cd05ee786eb31@syzkaller.appspotmail.com Signed-off-by: Greg Kroah-Hartman --- fs/ext4/super.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -4890,7 +4890,7 @@ static int __ext4_fill_super(struct fs_c sbi->s_inodes_per_block; sbi->s_desc_per_block = blocksize / EXT4_DESC_SIZE(sb); sbi->s_sbh = bh; - sbi->s_mount_state = le16_to_cpu(es->s_state); + sbi->s_mount_state = le16_to_cpu(es->s_state) & ~EXT4_FC_REPLAY; sbi->s_addr_per_block_bits = ilog2(EXT4_ADDR_PER_BLOCK(sb)); sbi->s_desc_per_block_bits = ilog2(EXT4_DESC_PER_BLOCK(sb)); @@ -6453,7 +6453,8 @@ static int __ext4_remount(struct fs_cont if (err) goto restore_opts; } - sbi->s_mount_state = le16_to_cpu(es->s_state); + sbi->s_mount_state = (le16_to_cpu(es->s_state) & + ~EXT4_FC_REPLAY); err = ext4_setup_super(sb, es, 0); if (err)