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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1B0A2C4332F for ; Sun, 16 Oct 2022 13:21:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229608AbiJPNVQ (ORCPT ); Sun, 16 Oct 2022 09:21:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229600AbiJPNVP (ORCPT ); Sun, 16 Oct 2022 09:21:15 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 603DF32EC0 for ; Sun, 16 Oct 2022 06:21:14 -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 0E421B80CBE for ; Sun, 16 Oct 2022 13:21:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 80A90C433C1; Sun, 16 Oct 2022 13:21:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1665926471; bh=NNJogp2luAxWLD8VRYpWNsJPH7gF8tFD/CVVwL1r2DM=; h=Subject:To:Cc:From:Date:From; b=pruWGuqyXW40HWKlJfnXRbvKuWaGAXyjAAVAKLBSra2M+5Q8X1I+Wg7uhQLgeaSfP PIQz9wQQ2jSDTT3/rspph1y21K9C2PPvD47R4bQZj1J5XWqoE2sPezVXtKxLl2wzIn 0mkGvhvzWd6fSeT37MTCmZldAO9CBt7h3pKS/mx4= Subject: FAILED: patch "[PATCH] ext4: fix dir corruption when ext4_dx_add_entry() fails" failed to apply to 5.4-stable tree To: chengzhihao1@huawei.com, jack@suse.cz, tytso@mit.edu Cc: From: Date: Sun, 16 Oct 2022 15:21:57 +0200 Message-ID: <16659265172313@kroah.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ANSI_X3.4-1968 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org The patch below does not apply to the 5.4-stable tree. If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to . Possible dependencies: 7177dd009c7c ("ext4: fix dir corruption when ext4_dx_add_entry() fails") 188c299e2a26 ("ext4: Support for checksumming from journal triggers") c915fb80eaa6 ("ext4: fix bh ref count on error paths") a3f5cf14ff91 ("ext4: drop ext4_handle_dirty_super()") 05c2c00f3769 ("ext4: protect superblock modifications with a buffer lock") 4392fbc4bab5 ("ext4: drop sync argument of ext4_commit_super()") c92dc856848f ("ext4: defer saving error info from atomic context") 02a7780e4d2f ("ext4: simplify ext4 error translation") 4067662388f9 ("ext4: move functions in super.c") 014c9caa29d3 ("ext4: make ext4_abort() use __ext4_error()") b08070eca9e2 ("ext4: don't remount read-only with errors=continue on reboot") ca9b404ff137 ("ext4: print quota journalling mode on (re-)mount") 9b5f6c9b83d9 ("ext4: make s_mount_flags modifications atomic") ababea77bc50 ("ext4: use s_mount_flags instead of s_mount_state for fast commit state") 8016e29f4362 ("ext4: fast commit recovery path") 5b849b5f96b4 ("jbd2: fast commit recovery path") aa75f4d3daae ("ext4: main fast-commit commit path") ff780b91efe9 ("jbd2: add fast commit machinery") 6866d7b3f2bb ("ext4 / jbd2: add fast commit initialization") 995a3ed67fc8 ("ext4: add fast_commit feature and handling for extended mount options") thanks, greg k-h ------------------ original commit in Linus's tree ------------------ >From 7177dd009c7c04290891e9a534cd47d1b620bd04 Mon Sep 17 00:00:00 2001 From: Zhihao Cheng Date: Sun, 11 Sep 2022 12:52:04 +0800 Subject: [PATCH] ext4: fix dir corruption when ext4_dx_add_entry() fails Following process may lead to fs corruption: 1. ext4_create(dir/foo) ext4_add_nondir ext4_add_entry ext4_dx_add_entry a. add_dirent_to_buf ext4_mark_inode_dirty ext4_handle_dirty_metadata // dir inode bh is recorded into journal b. ext4_append // dx_get_count(entries) == dx_get_limit(entries) ext4_bread(EXT4_GET_BLOCKS_CREATE) ext4_getblk ext4_map_blocks ext4_ext_map_blocks ext4_mb_new_blocks dquot_alloc_block dquot_alloc_space_nodirty inode_add_bytes // update dir's i_blocks ext4_ext_insert_extent ext4_ext_dirty // record extent bh into journal ext4_handle_dirty_metadata(bh) // record new block into journal inode->i_size += inode->i_sb->s_blocksize // new size(in mem) c. ext4_handle_dirty_dx_node(bh2) // record dir's new block(dx_node) into journal d. ext4_handle_dirty_dx_node((frame - 1)->bh) e. ext4_handle_dirty_dx_node(frame->bh) f. do_split // ret err! g. add_dirent_to_buf ext4_mark_inode_dirty(dir) // update raw_inode on disk(skipped) 2. fsck -a /dev/sdb drop last block(dx_node) which beyonds dir's i_size. /dev/sdb: recovering journal /dev/sdb contains a file system with errors, check forced. /dev/sdb: Inode 12, end of extent exceeds allowed value (logical block 128, physical block 3938, len 1) 3. fsck -fn /dev/sdb dx_node->entry[i].blk > dir->i_size Pass 2: Checking directory structure Problem in HTREE directory inode 12 (/dir): bad block number 128. Clear HTree index? no Problem in HTREE directory inode 12: block #3 has invalid depth (2) Problem in HTREE directory inode 12: block #3 has bad max hash Problem in HTREE directory inode 12: block #3 not referenced Fix it by marking inode dirty directly inside ext4_append(). Fetch a reproducer in [Link]. Link: https://bugzilla.kernel.org/show_bug.cgi?id=216466 Cc: stable@vger.kernel.org Signed-off-by: Zhihao Cheng Reviewed-by: Jan Kara Link: https://lore.kernel.org/r/20220911045204.516460-1-chengzhihao1@huawei.com Signed-off-by: Theodore Ts'o diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index bc2e0612ec32..4183a4cb4a21 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -85,15 +85,20 @@ static struct buffer_head *ext4_append(handle_t *handle, return bh; inode->i_size += inode->i_sb->s_blocksize; EXT4_I(inode)->i_disksize = inode->i_size; + err = ext4_mark_inode_dirty(handle, inode); + if (err) + goto out; BUFFER_TRACE(bh, "get_write_access"); err = ext4_journal_get_write_access(handle, inode->i_sb, bh, EXT4_JTR_NONE); - if (err) { - brelse(bh); - ext4_std_error(inode->i_sb, err); - return ERR_PTR(err); - } + if (err) + goto out; return bh; + +out: + brelse(bh); + ext4_std_error(inode->i_sb, err); + return ERR_PTR(err); } static int ext4_dx_csum_verify(struct inode *inode,