Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2143503iof; Tue, 7 Jun 2022 21:12:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzEMt7PJY3MY8tRqx8pgg4wNrJvGpYjtlXBu1gbpOHCtot4mCi1FKag/Jdh52b7ZSO+elN5 X-Received: by 2002:a17:90b:1d8c:b0:1e6:8032:a8dc with SMTP id pf12-20020a17090b1d8c00b001e68032a8dcmr34889564pjb.99.1654661532769; Tue, 07 Jun 2022 21:12:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654661532; cv=none; d=google.com; s=arc-20160816; b=gMheOjb0ni1Rm+gT3o/XLqSI+ALeiRMsPOB43rAbHucUNbYftWoYY3ZL8nzV6Vhf3x WxuN58iMJporYOk05wmK08UignPDfdKswfFhdxqOFbqE4/3qU6y6kCfAOtFym1tn4i0A FJIXksTzYTz9eJa59b6Opzd7g+CHnDL4g0auzqZUu0z6hgC9T4aivicBMJtLMy0rcFtM pMOxS5JvTe5hgo1FQpx+5lGEay8D+gV9EWvywcqSDkxehgxz6pcxUxFhGZ8lGDLsMqzc fr5ye7d973J2vItzBFtgtvKyX7OOQo4gA2k6vbkvO8FWrNDkNn+9B8U+yGgWITuCjVPS b9+Q== 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=E2+W2t7UF08aJTX4M2A7izeiAmq5lVoHOcv/h9Uwqlo=; b=kLCh7KzxQq9Q8A7Zr4EazEdQyz+wOks80veUdJtdnMTxkQ+qCAECta0JXSe8mcMeWR HjrAy7UKRhAHBvd0xN7DfkxzWBdjsOdiyJ1iVxyaoeOHxOduYP3DHopbRoW1OkSNK+je znhgx+53VZSitDaGccjKQAGCZHOSprKz4+fHPZUUJZqPz+PDupKnjvbXnRqyDbBETNVM Ula+gNO+9N3CTafsYI8elaw5ejQUZ+IPH5UlINwy5jUXTU35ExhUyXTPm6eUX6tr76UJ bYy8oCR2fM3AvbTe9Mxt4PdZkAieMC8gkFu6Bu3SSr2QZRDDRm/z265KFbWACsPf94lX 6dIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=nThiGnTL; 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 z24-20020a63d018000000b003c144fa99d2si26750067pgf.635.2022.06.07.21.12.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 21:12:12 -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=nThiGnTL; 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 B56F12A306D; Tue, 7 Jun 2022 20:43:38 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381069AbiFGVj1 (ORCPT + 99 others); Tue, 7 Jun 2022 17:39:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376912AbiFGUtD (ORCPT ); Tue, 7 Jun 2022 16:49:03 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07E3E1F77C3; Tue, 7 Jun 2022 11:39:53 -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 160F7612F2; Tue, 7 Jun 2022 18:39:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 23CE6C385A2; Tue, 7 Jun 2022 18:39:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654627176; bh=CE9fNNcldNDuuD0Cqy824P8Phcg5NsT9JARyufuV3vQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nThiGnTLpVK1M5ClnjXONw0v4YaZhP6fBwsNdBLzY+sxnI8BFlbUAV8UTYvWBPUAc LOMapejBwme0URouPZyjd1YBKtghw1AJNeLPNQyiX4VzxDrf7MfLz/DzYZa0bc8VXQ vtxuatt3ec6ufPlsgBGMpLvRsVedDO/A0D+U4x1M= 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.17 643/772] ext4: filter out EXT4_FC_REPLAY from on-disk superblock field s_state Date: Tue, 7 Jun 2022 19:03:55 +0200 Message-Id: <20220607165008.014707886@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607164948.980838585@linuxfoundation.org> References: <20220607164948.980838585@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 @@ -4874,7 +4874,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)); @@ -6437,7 +6437,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)