Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2152193iof; Tue, 7 Jun 2022 21:30:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxpUJ6dQCoMYYTuVSrtulVeo/2ZtCMOuVdRGEP1MfkEIWXioCJgrjQk7E8VCTVAiaKkpzCD X-Received: by 2002:a17:902:f607:b0:161:5f47:b213 with SMTP id n7-20020a170902f60700b001615f47b213mr32668324plg.4.1654662619523; Tue, 07 Jun 2022 21:30:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654662619; cv=none; d=google.com; s=arc-20160816; b=FfP3CeLuPHHLnBCx7/+blTKA+jq94y0BWmDKFzugLSROt4oM6hKfE4pxin+GjdPO1b E+yrbf28hyGD5oBytnUzGhYEVb7sh3sb4thwhsEJfHeNdCtc+Js+cL34wIpI4fYZAtwT LFbj8OR+3Eybg3760cC1aCP1d5VDMMmLT3/STpXNCiNDVAjy/iuxjT1V1V+4G0c/5DcB Bn6k4Muhqe9vfh04ikX+QzCai52+FVxWTEdBRX44NwXkTlHgXS6nGFp8gDLCwAl4r2ne FJtut0Xp8uiOmBKn55rviB7zRFwqljOGPu616UfOL8IS4C/V0qKujtMEXyZMXI7321uS p+VQ== 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=Ks4FFKHAELmgPctzhXKIh1A34V5MeIrSr5kmjbcXZ38=; b=kp0/1gMAnotd19WA6cV+BmEYrJpOxXTTDfJnmNx0lLrpKeHNdgnOcc2NUzQX6Cabld 6g9oOyuqF+uLs5QXz6Chx7EbeUoMVZ5wkVNI9foKi4IqQjffyyXdZpSIrTsmz0E+F3O+ GhsiPQot15kfg/2C6Yleos5poN98CkoK1PAkzRtTOtFkZXJW24yF6ybG5QZpiIctk9s6 QxLg8RhWyUnGYPwOomloiEurUVAa1utc0OTNIb8czJoUZAgGlk9cFr3Si5t2ux13dc0E 5DyKv/wA60BByuc9MvEnhlkH/4IJyJpDxMXBqyD/xWQsmuDdClibcnSH8rv5cDahRiZX mleQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=f8c8HqkX; 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 bt14-20020a17090af00e00b001e2d70eb5bcsi28128238pjb.48.2022.06.07.21.30.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 21:30:19 -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=f8c8HqkX; 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 5601F2509D3; Tue, 7 Jun 2022 20:58:55 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351069AbiFGSPg (ORCPT + 99 others); Tue, 7 Jun 2022 14:15:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348698AbiFGRy2 (ORCPT ); Tue, 7 Jun 2022 13:54:28 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B639144FFD; Tue, 7 Jun 2022 10:39:54 -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 ams.source.kernel.org (Postfix) with ESMTPS id ACCB0B822CE; Tue, 7 Jun 2022 17:34:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 247B3C34115; Tue, 7 Jun 2022 17:34:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654623288; bh=IeaTqaLEzPlaM4RkSnKLeBGciH+Iz0ykpPXh8d68FCc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f8c8HqkXqWWjW1zQGh7PO3xQawNcJu+91v5vwaz3xBxkuqFOQeTBxwf9l/uEmViSA iA7hlpfbl27KmIwmdquA2u+liS3TwoBSENuPkXYYTFx0ptO/ZmobBEC2xcgIQoacHv NWcdgnSvds1Ni15MPMqnj/Fzxio1yo129+PMK5ek= 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.10 362/452] ext4: filter out EXT4_FC_REPLAY from on-disk superblock field s_state Date: Tue, 7 Jun 2022 19:03:39 +0200 Message-Id: <20220607164919.351649050@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607164908.521895282@linuxfoundation.org> References: <20220607164908.521895282@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 @@ -4538,7 +4538,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)); @@ -5998,7 +5998,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)