Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2189784iof; Tue, 7 Jun 2022 22:39:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwXjUCqe0d3OKtPmFNAH33FJcXHcFDc/1c61XibzSuTJu8cXEvTCijnZHF9RfpYHdbnPBhA X-Received: by 2002:a63:5a58:0:b0:3fb:b455:ed15 with SMTP id k24-20020a635a58000000b003fbb455ed15mr28470463pgm.228.1654666770445; Tue, 07 Jun 2022 22:39:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654666770; cv=none; d=google.com; s=arc-20160816; b=PV42ClVrlly+USxljlsYwEJekSDs0eHAX5+i2uxN3yCayLkH49Xge3NP+Z+5fRZEMp hlDK/L4iNNiAAg3SuJoxUTx7ErhRQ/HrdzHFXC5uQx5hUPHJyE/LqMfmVNFpJ+Kh3wFd //n92JH0zVMMGDDjWf2QVvls9U90T3Uim/mlMB+dm6YYMqWWUGrQd1CP3zCtqc0fHDyN btKwP3ZCcfAmAbfB/Ri8qw3dHD5YdKFihWJ+2L+pK5UJ492bmWz9ItYJgQ8AJFt4rs4e gx1bZ2xAxTSKTSzwuacW0Wzs/Qlip1jb0nNIo8d5SQyUPoz7kcYPwogPXmNK6rdNezBh Lj8Q== 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=i21o8ZVhNSu6YF1DR9HJiFji4UJ3ZVxDhMD4vC8If+c=; b=Z1TuUHYHPLk55huu7SmBy0g04NwIJAa6fJSeD7Z7BdqzLGzozcdsM1TnWis746kuQH JBUum61LnfiZuF6KbRo4oQtfwaTZOnqkoxd8CY/v28ve4eD1gU3TWtxxdwq7SliJGaUk LGwpNkESsEWsMtJRD04u2d13HwQqAq1qxH6QmesIglALwLaXITz9hpcZVmqEoVws0VrG ND2juKN9x6WcT+OoryIi3kZ1tBafFO2f3Q70SB6YseFc3bniykdm1fBECXZyTDsNzWa2 e0UdlgDEbB78x07ICBSa6TYJ/RQER+j1/w3JaW3QYNX192MwYJlmb2ajep3s7Lbm0An4 KWCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=v2vUKRhy; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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. [23.128.96.19]) by mx.google.com with ESMTPS id bj11-20020a056a02018b00b003fd74779846si14194885pgb.826.2022.06.07.22.39.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 22:39:30 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=v2vUKRhy; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 328E54944CB; Tue, 7 Jun 2022 22:05:37 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358375AbiFGUA7 (ORCPT + 99 others); Tue, 7 Jun 2022 16:00:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354266AbiFGSz7 (ORCPT ); Tue, 7 Jun 2022 14:55:59 -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 C2F3D14B671; Tue, 7 Jun 2022 11:04:02 -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 2741F617B4; Tue, 7 Jun 2022 18:04:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 375DFC385A5; Tue, 7 Jun 2022 18:04:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654625041; bh=SnhfKEe0MKs7yReaOKbjYZ3mwtheNlwZ3SANedtDVI4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=v2vUKRhyNxEZywLu5KRkv1Sp7rXj9BLH9k1PJtu8OdZMEqUJwrBgvmnhtwRSyzsAR nVAw8Epj9frxFpVeveIXaPcSmC1oxK5MN4bCUFO/PjaHgFNmsdmUskTwLF5lawshDD zw4zuGF/NB1iOXSXU2U92a7vvfRiWVY6rq8R6Cjs= 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.15 545/667] ext4: filter out EXT4_FC_REPLAY from on-disk superblock field s_state Date: Tue, 7 Jun 2022 19:03:30 +0200 Message-Id: <20220607164951.045941234@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607164934.766888869@linuxfoundation.org> References: <20220607164934.766888869@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 @@ -4391,7 +4391,7 @@ static int ext4_fill_super(struct super_ 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)); @@ -5937,7 +5937,8 @@ static int ext4_remount(struct super_blo 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)