From patchwork Mon Feb 14 13:38:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Gardner X-Patchwork-Id: 1592543 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=DZLbASFp; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Jy51835zyz9s8s for ; Tue, 15 Feb 2022 00:39:24 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1nJbZU-00064G-VX; Mon, 14 Feb 2022 13:39:16 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1nJbZR-000636-IX for kernel-team@lists.ubuntu.com; Mon, 14 Feb 2022 13:39:13 +0000 Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 693843F1AE for ; Mon, 14 Feb 2022 13:39:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1644845953; bh=SRJEKKZoHcUzDY4uXyd4yrHqKV3E4Yx0ZF5YRJLggIY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=DZLbASFpYtUUy41rl9ndZz0gnCBDZRtkCe9A6KJYSehuLVAa8gUxRgn39ombbyfq9 vzztdJMCxA6kr8FDXm+JO5z4GAlrhWHCpPnIo30mQyQ21K30ll7VFyyqsrkRTzi3SR PkMGXEURFXrjmgmwry8gCQakSrSvu1xfOolqG7MvN0mOQCLIgMltNG83IbLZPxKHd+ A2eyXk6jm8Lst0aw/fV9q46xBYg9WZLqsVj26Cti1PgzTLmQYayEePZU+Nx7QBsQZV UrhHRVJgKcQlG+uNPBKVPlSbJYHcjXox4m/knos8Ibfu5EnMtjolPfHEG+ZnzwIKYR 61bdIwJ+z379A== Received: by mail-pl1-f198.google.com with SMTP id s19-20020a170902b19300b00149a463ad43so6341302plr.1 for ; Mon, 14 Feb 2022 05:39:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SRJEKKZoHcUzDY4uXyd4yrHqKV3E4Yx0ZF5YRJLggIY=; b=uKMBBdjr07pCkc7C9Mkz+YGlWE8YH6GyRAoEDnSDCEsoBxKrTxzqNlN3fp0PqNrWlp 351m4YPgVXUHswge9uYpSuEjcZMXjgt8m3ccf8fqQCBSHw9VKAUZ3YzY3hqafqsm3DiZ 7bsatLBwYWrFhtyi+bGx55ZWhzQX6ih4N21EWI8lA/JllU3anBgDKtfN22Z4renB9C4l s/K3DPhRiiAAk0dj1qWEQWow9n+fdIim99/wMMzLF2ZzmRuv8j2zZw1GqLDUkwzZF06/ 5Xeee1JFOZT5A2JsyOGLU/fGXAcMATU8vqYlicMLHCatBV5yF9gPJHVelNCdM9ym6lX2 HONQ== X-Gm-Message-State: AOAM531wgsz+DTcql0ytSZKdqA+OQNg86jBaPOGsm6fQJDeUeMz05K1O 0zQWt2Mm/miAn1eWt0AzsudDoU+Ch45qdptdcONyoVrB2F8976lh30ZHdd8VZVYNoXNPS8wjk5x RiSUh3wzl+wtX8NQvWkJtoYYTOnW9y3NoCAqpkokF5w== X-Received: by 2002:a63:8549:: with SMTP id u70mr7461280pgd.266.1644845951838; Mon, 14 Feb 2022 05:39:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJwBr7klZFCX9xFUR/n15rkp+XcukSRi03jRJca0Oy/ds8ijRRxruGxwbHBYRJp+0QWEu/9LlA== X-Received: by 2002:a63:8549:: with SMTP id u70mr7461263pgd.266.1644845951561; Mon, 14 Feb 2022 05:39:11 -0800 (PST) Received: from localhost.localdomain ([69.163.84.166]) by smtp.gmail.com with ESMTPSA id bd34sm4837071pfb.73.2022.02.14.05.39.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Feb 2022 05:39:10 -0800 (PST) From: Tim Gardner To: kernel-team@lists.ubuntu.com Subject: [PATCH 1/4][focal/linux-azure] ext4: check for out-of-order index extents in ext4_valid_extent_entries() Date: Mon, 14 Feb 2022 06:38:58 -0700 Message-Id: <20220214133904.13574-2-tim.gardner@canonical.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220214133904.13574-1-tim.gardner@canonical.com> References: <20220214133904.13574-1-tim.gardner@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Zhang Yi BugLink: https://bugs.launchpad.net/bugs/1960820 After commit 5946d089379a ("ext4: check for overlapping extents in ext4_valid_extent_entries()"), we can check out the overlapping extent entry in leaf extent blocks. But the out-of-order extent entry in index extent blocks could also trigger bad things if the filesystem is inconsistent. So this patch add a check to figure out the out-of-order index extents and return error. Signed-off-by: Zhang Yi Reviewed-by: Theodore Ts'o Link: https://lore.kernel.org/r/20210908120850.4012324-2-yi.zhang@huawei.com Signed-off-by: Theodore Ts'o (cherry picked from commit 8dd27fecede55e8a4e67eef2878040ecad0f0d33) Signed-off-by: Tim Gardner --- fs/ext4/extents.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index 56dfe3e72bcfd..a650ee6a67a12 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -393,6 +393,9 @@ static int ext4_valid_extent_entries(struct inode *inode, ext4_fsblk_t *pblk, int depth) { unsigned short entries; + ext4_lblk_t lblock = 0; + ext4_lblk_t prev = 0; + if (eh->eh_entries == 0) return 1; @@ -401,31 +404,35 @@ static int ext4_valid_extent_entries(struct inode *inode, if (depth == 0) { /* leaf entries */ struct ext4_extent *ext = EXT_FIRST_EXTENT(eh); - ext4_lblk_t lblock = 0; - ext4_lblk_t prev = 0; - int len = 0; while (entries) { if (!ext4_valid_extent(inode, ext)) return 0; /* Check for overlapping extents */ lblock = le32_to_cpu(ext->ee_block); - len = ext4_ext_get_actual_len(ext); if ((lblock <= prev) && prev) { *pblk = ext4_ext_pblock(ext); return 0; } + prev = lblock + ext4_ext_get_actual_len(ext) - 1; ext++; entries--; - prev = lblock + len - 1; } } else { struct ext4_extent_idx *ext_idx = EXT_FIRST_INDEX(eh); while (entries) { if (!ext4_valid_extent_idx(inode, ext_idx)) return 0; + + /* Check for overlapping index extents */ + lblock = le32_to_cpu(ext_idx->ei_block); + if ((lblock <= prev) && prev) { + *pblk = ext4_idx_pblock(ext_idx); + return 0; + } ext_idx++; entries--; + prev = lblock; } } return 1; From patchwork Mon Feb 14 13:38:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Gardner X-Patchwork-Id: 1592544 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=CaIeRQa0; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Jy51B1dtyz9sCD for ; Tue, 15 Feb 2022 00:39:26 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1nJbZX-00066P-57; Mon, 14 Feb 2022 13:39:19 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1nJbZT-00063Q-2S for kernel-team@lists.ubuntu.com; Mon, 14 Feb 2022 13:39:15 +0000 Received: from mail-pf1-f200.google.com (mail-pf1-f200.google.com [209.85.210.200]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id E3FF83F071 for ; Mon, 14 Feb 2022 13:39:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1644845954; bh=v7ixbu8JYaES+MKkV5Hi2W4wfxWo0cIs2H4S/P6/ATo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=CaIeRQa07zb7udiMOg0Ni5naeM3ae9yHXSc0mOYMD78P/AuVib0KHWIciwY883kIg 9uJL/pKCJ/3wPFdm2va93OQ8FxRh/Ks5UrXk2FRQfUSAfmxeQ/MK6XZSsqw75EpMNu QVGFJLZFHwMl2FiNItpB9J3g+l0Uhwqj1Tbs2vSq5kW47Dtzs+IMlsbQmWWvh9kWQ+ 5bvgnZlUWLOSFZjUw36zDWGFcS5yiaUGm+PV3Df2qxHXnXvOZWHf+DljSxelnTfbWn 1RuQCn4BKzWdh3PIZu3U/PayXGx40z4XSaFowkr6AB6Gc8BMn2l8R/7bi9GGJUAOe0 Ud85l3xHIQX3g== Received: by mail-pf1-f200.google.com with SMTP id d16-20020a056a0010d000b004e0204c9753so11780602pfu.7 for ; Mon, 14 Feb 2022 05:39:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=v7ixbu8JYaES+MKkV5Hi2W4wfxWo0cIs2H4S/P6/ATo=; b=rOqqdHiBp3oNjC7BlROI8hHjzox+aE/rLHyg7P6bLv+qrI0meWC5vtUZjECHmbIvZh v8p2BmaHgE2e+HYnR3ccr0cDd2ofN2iuJFfRApQ59zak77N8wzEVs3wdU6PpmieAA8pm IoU9BAb56XcwQ61fKGerqD0hSBc84CNkvBJrc+ESU29cX6bSGMY4MUP/VYaQsNEhFJki qbhMeUdtzRKxQt+z1MqIXJIbjUNbrhYNhnP7HLjX3TuTg77NdiHg/GNjjVGjNDx6Wfp6 yLLxD50SRVjwjkeHL/MXHrtTV7rH+R65EKkpu1/foRioAtWGcdHLDOGZlc1vh/Y+/eeH YL4g== X-Gm-Message-State: AOAM531KYSZRwT2zWxFAG+Fzmfm+ZOo3JNR79yEjdGNGhIhx1dCr0Gnv HUEi4ZkGP2sqT0ksphan4/j/ERG1Z2es27Qz5df8eEpaHF3t2L5EdFUnvI+ViV3uisqC7XpPlg9 uKUl7WOKx/ncybRjaWDm1+UJ/t4zUYNtl+Di7Z0u6Ug== X-Received: by 2002:a17:902:ba91:: with SMTP id k17mr14250122pls.171.1644845953171; Mon, 14 Feb 2022 05:39:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJx0Qi4tuAf+a73bqPisBlOH+U4T9kh+v67dxA1HiHsK18uFteiQ8/vztoTMvWkqSNNb9gZ1EQ== X-Received: by 2002:a17:902:ba91:: with SMTP id k17mr14250095pls.171.1644845952726; Mon, 14 Feb 2022 05:39:12 -0800 (PST) Received: from localhost.localdomain ([69.163.84.166]) by smtp.gmail.com with ESMTPSA id bd34sm4837071pfb.73.2022.02.14.05.39.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Feb 2022 05:39:12 -0800 (PST) From: Tim Gardner To: kernel-team@lists.ubuntu.com Subject: [PATCH 2/4][focal/linux-azure] ext4: avoid ext4_error()'s caused by ENOMEM in the truncate path Date: Mon, 14 Feb 2022 06:38:59 -0700 Message-Id: <20220214133904.13574-3-tim.gardner@canonical.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220214133904.13574-1-tim.gardner@canonical.com> References: <20220214133904.13574-1-tim.gardner@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Theodore Ts'o BugLink: https://bugs.launchpad.net/bugs/1960820 We can't fail in the truncate path without requiring an fsck. Add work around for this by using a combination of retry loops and the __GFP_NOFAIL flag. From: Theodore Ts'o Signed-off-by: Theodore Ts'o Signed-off-by: Anna Pendleton Reviewed-by: Harshad Shirwadkar Link: https://lore.kernel.org/r/20200507175028.15061-1-pendleton@google.com Signed-off-by: Theodore Ts'o (cherry picked from commit 73c384c0cdaa8ea9ca9ef2d0cff6a25930f1648e) [rtg - scaffolding patch upon which 9c6e071913792d80894cd0be98cc3c4b770e26d3 is dependent] Signed-off-by: Tim Gardner --- fs/ext4/ext4.h | 1 + fs/ext4/extents.c | 43 +++++++++++++++++++++++++++++++++---------- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index dc3775e36cc76..9ba6be50b193e 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -628,6 +628,7 @@ enum { */ #define EXT4_EX_NOCACHE 0x40000000 #define EXT4_EX_FORCE_CACHE 0x20000000 +#define EXT4_EX_NOFAIL 0x10000000 /* * Flags used by ext4_free_blocks diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index a650ee6a67a12..9bc6b694093d3 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -290,11 +290,14 @@ ext4_force_split_extent_at(handle_t *handle, struct inode *inode, { struct ext4_ext_path *path = *ppath; int unwritten = ext4_ext_is_unwritten(path[path->p_depth].p_ext); + int flags = EXT4_EX_NOCACHE | EXT4_GET_BLOCKS_PRE_IO; + + if (nofail) + flags |= EXT4_GET_BLOCKS_METADATA_NOFAIL | EXT4_EX_NOFAIL; return ext4_split_extent_at(handle, inode, ppath, lblk, unwritten ? EXT4_EXT_MARK_UNWRIT1|EXT4_EXT_MARK_UNWRIT2 : 0, - EXT4_EX_NOCACHE | EXT4_GET_BLOCKS_PRE_IO | - (nofail ? EXT4_GET_BLOCKS_METADATA_NOFAIL:0)); + flags); } /* @@ -534,8 +537,12 @@ __read_extent_tree_block(const char *function, unsigned int line, { struct buffer_head *bh; int err; + gfp_t gfp_flags = __GFP_MOVABLE | GFP_NOFS; + + if (flags & EXT4_EX_NOFAIL) + gfp_flags |= __GFP_NOFAIL; - bh = sb_getblk_gfp(inode->i_sb, pblk, __GFP_MOVABLE | GFP_NOFS); + bh = sb_getblk_gfp(inode->i_sb, pblk, gfp_flags); if (unlikely(!bh)) return ERR_PTR(-ENOMEM); @@ -877,6 +884,10 @@ ext4_find_extent(struct inode *inode, ext4_lblk_t block, struct ext4_ext_path *path = orig_path ? *orig_path : NULL; short int depth, i, ppos = 0; int ret; + gfp_t gfp_flags = GFP_NOFS; + + if (flags & EXT4_EX_NOFAIL) + gfp_flags |= __GFP_NOFAIL; eh = ext_inode_hdr(inode); depth = ext_depth(inode); @@ -897,7 +908,7 @@ ext4_find_extent(struct inode *inode, ext4_lblk_t block, if (!path) { /* account possible depth increase */ path = kcalloc(depth + 2, sizeof(struct ext4_ext_path), - GFP_NOFS); + gfp_flags); if (unlikely(!path)) return ERR_PTR(-ENOMEM); path[0].p_maxdepth = depth + 1; @@ -1047,9 +1058,13 @@ static int ext4_ext_split(handle_t *handle, struct inode *inode, ext4_fsblk_t newblock, oldblock; __le32 border; ext4_fsblk_t *ablocks = NULL; /* array of allocated blocks */ + gfp_t gfp_flags = GFP_NOFS; int err = 0; size_t ext_size = 0; + if (flags & EXT4_EX_NOFAIL) + gfp_flags |= __GFP_NOFAIL; + /* make decision: where to split? */ /* FIXME: now decision is simplest: at current extent */ @@ -1083,7 +1098,7 @@ static int ext4_ext_split(handle_t *handle, struct inode *inode, * We need this to handle errors and free blocks * upon them. */ - ablocks = kcalloc(depth, sizeof(ext4_fsblk_t), GFP_NOFS); + ablocks = kcalloc(depth, sizeof(ext4_fsblk_t), gfp_flags); if (!ablocks) return -ENOMEM; @@ -2072,7 +2087,7 @@ int ext4_ext_insert_extent(handle_t *handle, struct inode *inode, if (next != EXT_MAX_BLOCKS) { ext_debug("next leaf block - %u\n", next); BUG_ON(npath != NULL); - npath = ext4_find_extent(inode, next, NULL, 0); + npath = ext4_find_extent(inode, next, NULL, gb_flags); if (IS_ERR(npath)) return PTR_ERR(npath); BUG_ON(npath->p_depth != path->p_depth); @@ -2979,7 +2994,8 @@ int ext4_ext_remove_space(struct inode *inode, ext4_lblk_t start, ext4_fsblk_t pblk; /* find extent for or closest extent to this block */ - path = ext4_find_extent(inode, end, NULL, EXT4_EX_NOCACHE); + path = ext4_find_extent(inode, end, NULL, + EXT4_EX_NOCACHE | EXT4_EX_NOFAIL); if (IS_ERR(path)) { ext4_journal_stop(handle); return PTR_ERR(path); @@ -3065,7 +3081,7 @@ int ext4_ext_remove_space(struct inode *inode, ext4_lblk_t start, le16_to_cpu(path[k].p_hdr->eh_entries)+1; } else { path = kcalloc(depth + 1, sizeof(struct ext4_ext_path), - GFP_NOFS); + GFP_NOFS | __GFP_NOFAIL); if (path == NULL) { ext4_journal_stop(handle); return -ENOMEM; @@ -3489,7 +3505,7 @@ static int ext4_split_extent(handle_t *handle, * Update path is required because previous ext4_split_extent_at() may * result in split of original leaf or extent zeroout. */ - path = ext4_find_extent(inode, map->m_lblk, ppath, 0); + path = ext4_find_extent(inode, map->m_lblk, ppath, flags); if (IS_ERR(path)) return PTR_ERR(path); depth = ext_depth(inode); @@ -4610,7 +4626,14 @@ int ext4_ext_truncate(handle_t *handle, struct inode *inode) } if (err) return err; - return ext4_ext_remove_space(inode, last_block, EXT_MAX_BLOCKS - 1); +retry_remove_space: + err = ext4_ext_remove_space(inode, last_block, EXT_MAX_BLOCKS - 1); + if (err == -ENOMEM) { + cond_resched(); + congestion_wait(BLK_RW_ASYNC, HZ/50); + goto retry_remove_space; + } + return err; } static int ext4_alloc_file_blocks(struct file *file, ext4_lblk_t offset, From patchwork Mon Feb 14 13:39:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Gardner X-Patchwork-Id: 1592548 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=G9X3oHJu; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Jy51M2k1Jz9s8s for ; Tue, 15 Feb 2022 00:39:35 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1nJbZf-0006Hn-BM; Mon, 14 Feb 2022 13:39:27 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1nJbZT-00063p-Tc for kernel-team@lists.ubuntu.com; Mon, 14 Feb 2022 13:39:15 +0000 Received: from mail-pj1-f69.google.com (mail-pj1-f69.google.com [209.85.216.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id B5FCE3F1B6 for ; Mon, 14 Feb 2022 13:39:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1644845955; bh=5srSFkaLzOSyMYhNzOZgN1Ci08RsB6jWJf4SO8N/H34=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=G9X3oHJuO6pAQw15fzTZvgiPs5M+Jht7PmVLw7k6eyKrRtLRAJoWBXmjAdRvPhNAi eJOZbFtq2q78gdj/4ZuX7JelH8bzNgAUNW2gWANL0YbwZ778Z6dlZ/MTT/zGcIHkdn eNrLUtg2HVGxJ+2eJTv46VEb6tS2gUUdi6zX7tBK9iYBCndYiXU8OH9n3d5LCq8m4s 2fehMQNYYdF9cIQWQK/13yGcpO+Za0zQkdweOhSdr5CTvXpYtmHI3enqZDwDtSsZU2 h6EPU+Ia3V7gDpOIRM1PP60/Lw2hM3Wte2P/OmpqMy9fklbDOF2bRkSar1V1cFndKS emWOqI+Hg9/kw== Received: by mail-pj1-f69.google.com with SMTP id md16-20020a17090b23d000b001b8bd5e35e2so11005711pjb.0 for ; Mon, 14 Feb 2022 05:39:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5srSFkaLzOSyMYhNzOZgN1Ci08RsB6jWJf4SO8N/H34=; b=6Q5GyU986yLReHpzGecmKWNYm2vtinQOPML6KQZv6GPByzA+wFe+WgjxUm9xem6jCA EQEqK82BP8m/Op18YV0j8uDD0L0FPVGRvR1OidEeZaAePvVYvo+BuZGXEeUbCZgaD+lp OLWv/qe7IqfqcxZ6ys95ZZxGRzwTx5OZ9QdeuGPbM0g7+Gvk/QAUWouu+CVG1ENsOaNr 2m+efXk+MHc9GFrlOd//aP9HEBCmIEX9tFJPahoJQCEU2rtaWglnGjdXvdADU39zVOlm KL13EXu5dD26SWFTX4id4Jop4WXglOZCrSQLlL8vji13/xn8yZ2JOxxgAReKW8GiN8G8 vLsA== X-Gm-Message-State: AOAM5323auOgOp7P8R57i1EpKBGzpvzUkszyOVTSkAdM2v5WuFrTUNDW ciVklutVEz/MjafC9fyzIEzTrjUAVAtR58NLqSx0q6+whLwoVSp9IzQdIHLhruIhJYNXv0rAZ0H 4BV4sPqgy/ZgujUoJ2f79/nuvPhuesDit2k9Kbnm56w== X-Received: by 2002:a17:902:6b8c:: with SMTP id p12mr14150780plk.51.1644845953915; Mon, 14 Feb 2022 05:39:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJxIWpsEiPJ8Luc/dggnpCPFlSXm80JYZBWrn21kXvtzUyfJW6A5ZT/pJBcC0htk8r4pjBSY5g== X-Received: by 2002:a17:902:6b8c:: with SMTP id p12mr14150760plk.51.1644845953602; Mon, 14 Feb 2022 05:39:13 -0800 (PST) Received: from localhost.localdomain ([69.163.84.166]) by smtp.gmail.com with ESMTPSA id bd34sm4837071pfb.73.2022.02.14.05.39.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Feb 2022 05:39:13 -0800 (PST) From: Tim Gardner To: kernel-team@lists.ubuntu.com Subject: [PATCH 3/4][focal/linux-azure] ext4: check for inconsistent extents between index and leaf block Date: Mon, 14 Feb 2022 06:39:00 -0700 Message-Id: <20220214133904.13574-4-tim.gardner@canonical.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220214133904.13574-1-tim.gardner@canonical.com> References: <20220214133904.13574-1-tim.gardner@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Zhang Yi BugLink: https://bugs.launchpad.net/bugs/1960820 Now that we can check out overlapping extents in leaf block and out-of-order index extents in index block. But the .ee_block in the first extent of one leaf block should equal to the .ei_block in it's parent index extent entry. This patch add a check to verify such inconsistent between the index and leaf block. Signed-off-by: Zhang Yi Link: https://lore.kernel.org/r/20210908120850.4012324-3-yi.zhang@huawei.com Signed-off-by: Theodore Ts'o (cherry picked from commit 9c6e071913792d80894cd0be98cc3c4b770e26d3) Signed-off-by: Tim Gardner --- fs/ext4/extents.c | 59 +++++++++++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 23 deletions(-) diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index 9bc6b694093d3..de131f0a97cf6 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -393,7 +393,8 @@ static int ext4_valid_extent_idx(struct inode *inode, static int ext4_valid_extent_entries(struct inode *inode, struct ext4_extent_header *eh, - ext4_fsblk_t *pblk, int depth) + ext4_lblk_t lblk, ext4_fsblk_t *pblk, + int depth) { unsigned short entries; ext4_lblk_t lblock = 0; @@ -407,6 +408,14 @@ static int ext4_valid_extent_entries(struct inode *inode, if (depth == 0) { /* leaf entries */ struct ext4_extent *ext = EXT_FIRST_EXTENT(eh); + + /* + * The logical block in the first entry should equal to + * the number in the index block. + */ + if (depth != ext_depth(inode) && + lblk != le32_to_cpu(ext->ee_block)) + return 0; while (entries) { if (!ext4_valid_extent(inode, ext)) return 0; @@ -423,6 +432,14 @@ static int ext4_valid_extent_entries(struct inode *inode, } } else { struct ext4_extent_idx *ext_idx = EXT_FIRST_INDEX(eh); + + /* + * The logical block in the first entry should equal to + * the number in the parent index block. + */ + if (depth != ext_depth(inode) && + lblk != le32_to_cpu(ext_idx->ei_block)) + return 0; while (entries) { if (!ext4_valid_extent_idx(inode, ext_idx)) return 0; @@ -443,7 +460,7 @@ static int ext4_valid_extent_entries(struct inode *inode, static int __ext4_ext_check(const char *function, unsigned int line, struct inode *inode, struct ext4_extent_header *eh, - int depth, ext4_fsblk_t pblk) + int depth, ext4_fsblk_t pblk, ext4_lblk_t lblk) { const char *error_msg; int max = 0, err = -EFSCORRUPTED; @@ -469,7 +486,7 @@ static int __ext4_ext_check(const char *function, unsigned int line, error_msg = "invalid eh_entries"; goto corrupted; } - if (!ext4_valid_extent_entries(inode, eh, &pblk, depth)) { + if (!ext4_valid_extent_entries(inode, eh, lblk, &pblk, depth)) { error_msg = "invalid extent entries"; goto corrupted; } @@ -499,7 +516,7 @@ static int __ext4_ext_check(const char *function, unsigned int line, } #define ext4_ext_check(inode, eh, depth, pblk) \ - __ext4_ext_check(__func__, __LINE__, (inode), (eh), (depth), (pblk)) + __ext4_ext_check(__func__, __LINE__, (inode), (eh), (depth), (pblk), 0) int ext4_ext_check_inode(struct inode *inode) { @@ -532,16 +549,18 @@ static void ext4_cache_extents(struct inode *inode, static struct buffer_head * __read_extent_tree_block(const char *function, unsigned int line, - struct inode *inode, ext4_fsblk_t pblk, int depth, - int flags) + struct inode *inode, struct ext4_extent_idx *idx, + int depth, int flags) { struct buffer_head *bh; int err; gfp_t gfp_flags = __GFP_MOVABLE | GFP_NOFS; + ext4_fsblk_t pblk; if (flags & EXT4_EX_NOFAIL) gfp_flags |= __GFP_NOFAIL; + pblk = ext4_idx_pblock(idx); bh = sb_getblk_gfp(inode->i_sb, pblk, gfp_flags); if (unlikely(!bh)) return ERR_PTR(-ENOMEM); @@ -554,8 +573,8 @@ __read_extent_tree_block(const char *function, unsigned int line, } if (buffer_verified(bh) && !(flags & EXT4_EX_FORCE_CACHE)) return bh; - err = __ext4_ext_check(function, line, inode, - ext_block_hdr(bh), depth, pblk); + err = __ext4_ext_check(function, line, inode, ext_block_hdr(bh), + depth, pblk, le32_to_cpu(idx->ei_block)); if (err) goto errout; set_buffer_verified(bh); @@ -573,8 +592,8 @@ __read_extent_tree_block(const char *function, unsigned int line, } -#define read_extent_tree_block(inode, pblk, depth, flags) \ - __read_extent_tree_block(__func__, __LINE__, (inode), (pblk), \ +#define read_extent_tree_block(inode, idx, depth, flags) \ + __read_extent_tree_block(__func__, __LINE__, (inode), (idx), \ (depth), (flags)) /* @@ -621,8 +640,7 @@ int ext4_ext_precache(struct inode *inode) i--; continue; } - bh = read_extent_tree_block(inode, - ext4_idx_pblock(path[i].p_idx++), + bh = read_extent_tree_block(inode, path[i].p_idx++, depth - i - 1, EXT4_EX_FORCE_CACHE); if (IS_ERR(bh)) { @@ -929,8 +947,7 @@ ext4_find_extent(struct inode *inode, ext4_lblk_t block, path[ppos].p_depth = i; path[ppos].p_ext = NULL; - bh = read_extent_tree_block(inode, path[ppos].p_block, --i, - flags); + bh = read_extent_tree_block(inode, path[ppos].p_idx, --i, flags); if (IS_ERR(bh)) { ret = PTR_ERR(bh); goto err; @@ -1533,7 +1550,6 @@ static int ext4_ext_search_right(struct inode *inode, struct ext4_extent_header *eh; struct ext4_extent_idx *ix; struct ext4_extent *ex; - ext4_fsblk_t block; int depth; /* Note, NOT eh_depth; depth from top of tree */ int ee_len; @@ -1600,20 +1616,17 @@ static int ext4_ext_search_right(struct inode *inode, * follow it and find the closest allocated * block to the right */ ix++; - block = ext4_idx_pblock(ix); while (++depth < path->p_depth) { /* subtract from p_depth to get proper eh_depth */ - bh = read_extent_tree_block(inode, block, - path->p_depth - depth, 0); + bh = read_extent_tree_block(inode, ix, path->p_depth - depth, 0); if (IS_ERR(bh)) return PTR_ERR(bh); eh = ext_block_hdr(bh); ix = EXT_FIRST_INDEX(eh); - block = ext4_idx_pblock(ix); put_bh(bh); } - bh = read_extent_tree_block(inode, block, path->p_depth - depth, 0); + bh = read_extent_tree_block(inode, ix, path->p_depth - depth, 0); if (IS_ERR(bh)) return PTR_ERR(bh); eh = ext_block_hdr(bh); @@ -3136,9 +3149,9 @@ int ext4_ext_remove_space(struct inode *inode, ext4_lblk_t start, ext_debug("move to level %d (block %llu)\n", i + 1, ext4_idx_pblock(path[i].p_idx)); memset(path + i + 1, 0, sizeof(*path)); - bh = read_extent_tree_block(inode, - ext4_idx_pblock(path[i].p_idx), depth - i - 1, - EXT4_EX_NOCACHE); + bh = read_extent_tree_block(inode, path[i].p_idx, + depth - i - 1, + EXT4_EX_NOCACHE); if (IS_ERR(bh)) { /* should we reset i_size? */ err = PTR_ERR(bh); From patchwork Mon Feb 14 13:39:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Gardner X-Patchwork-Id: 1592546 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=PLdQoiuI; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Jy51G2BDZz9s8s for ; Tue, 15 Feb 2022 00:39:30 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1nJbZa-00069u-7G; Mon, 14 Feb 2022 13:39:22 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1nJbZV-00064j-Ad for kernel-team@lists.ubuntu.com; Mon, 14 Feb 2022 13:39:17 +0000 Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 02AB93F1D0 for ; Mon, 14 Feb 2022 13:39:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1644845957; bh=j5RPu3crWNVgAag5ceUyzHcTBSz9JyVfiJvRk0CkNJo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=PLdQoiuIloSccdGgRkhEfXrSnbCfJTLMCC1qqfzbl81QFajYW5C1aVmGN6cqlF+8J j9Nix8VACP0iat4sDNTzqprFL6F57d83Y5gX+T8rAWFH/QFJaDuEz/dLnzCnnY8v08 7iQcqK2k0R1z9s8lYC5uYG4zcXJPne7Z5JndZZIwm/JW6J4sDiin4tjx3VBmh3h/DG 0+seuNuCtb3/MCE582DzN4ck6AZrpchFtOYsleKTNP9GUCBdlDee31Wf1oJUNQ7A3+ bHL1yOCWYjs/btE2WTFMwFt52/BorcN0EFkQCnMg1e5qplcdSP818wl5/CkQtDKBLz hORCpxKzlWyuA== Received: by mail-pl1-f198.google.com with SMTP id r19-20020a170902be1300b0014edf03f82eso3315395pls.20 for ; Mon, 14 Feb 2022 05:39:16 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=j5RPu3crWNVgAag5ceUyzHcTBSz9JyVfiJvRk0CkNJo=; b=HRiDzH3G/lIadz/OePEEvAGN7zcB3hd1ncE+RSKv+QkKa+ZUY8H+fJ6PVi5PznVsn9 4LVv5k5pCC1EE9DAG2LCDGuhrNBmHLqqOdWuImHTawegWo1cKSXp+EZDEtzvwam0PVqA RurHYx4ih99jbp6nuRe9xd1DxyXROuWqQNMRc2XPKXpQ9/47PemQItpN0faWnVdfGNah LkVdeetp0mst2bOJ+AD/Eik9M19OaoH5DaGdwWI2SZ8BrmHZaHloWdJ7yhgSVsgliwdj HsS6O82vtDW8QebWs8sHZz/DBisxQWkwNT18elIGiSqxws3LW0o0ox9QPLMdDHyAYXaH kW7A== X-Gm-Message-State: AOAM531fRXxAwpcXqsVMv0kOGJp5+kVoiNxk0chhpe3ffu88iL1I+F1q 3g96t5JLiTh2j0B2W/C6PGYet1SIXMISGzUm460QP8YnGuoayy3FCTAZ8eY/biz16XKJSYypylI uk5fEZ9PGRDDPE0Sw05e0LfMbD+Cd7TgxzcvyXsI/pQ== X-Received: by 2002:a05:6a00:1a16:: with SMTP id g22mr14425661pfv.81.1644845955328; Mon, 14 Feb 2022 05:39:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJyM67+VKN9/CzbSNS9qH0V2a5fZJkSCURYdc/f40lmk6apL38+wS3rct4bnd1j71wxAb+55uQ== X-Received: by 2002:a05:6a00:1a16:: with SMTP id g22mr14425634pfv.81.1644845954997; Mon, 14 Feb 2022 05:39:14 -0800 (PST) Received: from localhost.localdomain ([69.163.84.166]) by smtp.gmail.com with ESMTPSA id bd34sm4837071pfb.73.2022.02.14.05.39.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Feb 2022 05:39:14 -0800 (PST) From: Tim Gardner To: kernel-team@lists.ubuntu.com Subject: [PATCH 4/4][focal/linux-azure] ext4: prevent partial update of the extent blocks Date: Mon, 14 Feb 2022 06:39:01 -0700 Message-Id: <20220214133904.13574-5-tim.gardner@canonical.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220214133904.13574-1-tim.gardner@canonical.com> References: <20220214133904.13574-1-tim.gardner@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Zhang Yi BugLink: https://bugs.launchpad.net/bugs/1960820 In the most error path of current extents updating operations are not roll back partial updates properly when some bad things happens(.e.g in ext4_ext_insert_extent()). So we may get an inconsistent extents tree if journal has been aborted due to IO error, which may probability lead to BUGON later when we accessing these extent entries in errors=continue mode. This patch drop extent buffer's verify flag before updatng the contents in ext4_ext_get_access(), and reset it after updating in __ext4_ext_dirty(). After this patch we could force to check the extent buffer if extents tree updating was break off, make sure the extents are consistent. Signed-off-by: Zhang Yi Reviewed-by: Theodore Ts'o Link: https://lore.kernel.org/r/20210908120850.4012324-4-yi.zhang@huawei.com Signed-off-by: Theodore Ts'o (bacported from commit 0f2f87d51aebcf71a709b52f661d681594c7dffa) [rtg - missing commit 188c299e2a26cc33747187f87c9e044dfd85a782 which is pretty big. The fix was a fairly simple context adjustment.] Signed-off-by: Tim Gardner --- fs/ext4/extents.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index de131f0a97cf6..028ed96ec5bf0 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -133,14 +133,24 @@ static int ext4_ext_truncate_extend_restart(handle_t *handle, static int ext4_ext_get_access(handle_t *handle, struct inode *inode, struct ext4_ext_path *path) { + int err = 0; + if (path->p_bh) { /* path points to block */ BUFFER_TRACE(path->p_bh, "get_write_access"); - return ext4_journal_get_write_access(handle, path->p_bh); + err = ext4_journal_get_write_access(handle, path->p_bh); + /* + * The extent buffer's verified bit will be set again in + * __ext4_ext_dirty(). We could leave an inconsistent + * buffer if the extents updating procudure break off du + * to some error happens, force to check it again. + */ + if (!err) + clear_buffer_verified(path->p_bh); } /* path points to leaf/index in inode body */ /* we use in-core data, no need to protect them */ - return 0; + return err; } /* @@ -160,6 +170,9 @@ int __ext4_ext_dirty(const char *where, unsigned int line, handle_t *handle, /* path points to block */ err = __ext4_handle_dirty_metadata(where, line, handle, inode, path->p_bh); + /* Extents updating done, re-set verified flag */ + if (!err) + set_buffer_verified(path->p_bh); } else { /* path points to leaf/index in inode body */ err = ext4_mark_inode_dirty(handle, inode);