From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0E650C433EF for ; Mon, 6 Sep 2021 12:58:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EE1F061052 for ; Mon, 6 Sep 2021 12:58:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243427AbhIFM7e (ORCPT ); Mon, 6 Sep 2021 08:59:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:36364 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242971AbhIFM7A (ORCPT ); Mon, 6 Sep 2021 08:59:00 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C483960238; Mon, 6 Sep 2021 12:57:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1630933075; bh=PccPhp9/jPxlR4OvAeMVMDKSr0uu4kaq5JhbYerJlf0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mPxeXRUiaFhK+kchdaV1PhEKbxmEw0/g16jXTdHpuFG378X3kLctojvm5Rpcib6Pr KkDCbqv6yoS0Iu/2GxaBIVr9Ww8ClY3oQflbYNO3dEBAnXMQQh1YW74QtrppYVr/kq +Zp51Cd5z5K4ZF2AmsbCOtw0ZHf2Pf0J7W62xUTQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, stable@kernel.org, Boyang Xue , Jan Kara , Theodore Tso Subject: [PATCH 5.13 02/24] ext4: fix e2fsprogs checksum failure for mounted filesystem Date: Mon, 6 Sep 2021 14:55:31 +0200 Message-Id: <20210906125449.193516869@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210906125449.112564040@linuxfoundation.org> References: <20210906125449.112564040@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jan Kara commit b2bbb92f7042e8075fb036bf97043339576330c3 upstream. Commit 81414b4dd48 ("ext4: remove redundant sb checksum recomputation") removed checksum recalculation after updating superblock free space / inode counters in ext4_fill_super() based on the fact that we will recalculate the checksum on superblock writeout. That is correct assumption but until the writeout happens (which can take a long time) the checksum is incorrect in the buffer cache and if programs such as tune2fs or resize2fs is called shortly after a file system is mounted can fail. So return back the checksum recalculation and add a comment explaining why. Fixes: 81414b4dd48f ("ext4: remove redundant sb checksum recomputation") Cc: stable@kernel.org Reported-by: Boyang Xue Signed-off-by: Jan Kara Signed-off-by: Theodore Ts'o Link: https://lore.kernel.org/r/20210812124737.21981-1-jack@suse.cz Signed-off-by: Greg Kroah-Hartman --- fs/ext4/super.c | 8 ++++++++ 1 file changed, 8 insertions(+) --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -5051,6 +5051,14 @@ no_journal: err = percpu_counter_init(&sbi->s_freeinodes_counter, freei, GFP_KERNEL); } + /* + * Update the checksum after updating free space/inode + * counters. Otherwise the superblock can have an incorrect + * checksum in the buffer cache until it is written out and + * e2fsprogs programs trying to open a file system immediately + * after it is mounted can fail. + */ + ext4_superblock_csum_set(sb); if (!err) err = percpu_counter_init(&sbi->s_dirs_counter, ext4_count_dirs(sb), GFP_KERNEL);