Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp3909410pxb; Mon, 21 Feb 2022 08:07:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJyAXGvZBSLFgOLwQATX5hgl4V470KyZRiCc7eAesKrsQ0mLD6gnqbUv2i60In/gUG0/PraO X-Received: by 2002:a17:902:f68b:b0:14f:c84c:ad6d with SMTP id l11-20020a170902f68b00b0014fc84cad6dmr3271375plg.155.1645459659228; Mon, 21 Feb 2022 08:07:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645459659; cv=none; d=google.com; s=arc-20160816; b=v2zqS3ijTAWryJwPYTLskyT/4zyGbQFWJKAmFRpMn35UGCGHLvtJ/4OLRWDPYW+5op j6ij+xPNGzmEW6whTVy2TIx+auwgK20zrDJ0u+RN7+opibojtuK5zs+P9sDT2VqXGxEQ +SWwV7AhMopbiqqpT4xZDsVXiQmh4Iz/kAfOV9voMlkjzyWUtXC8dKJrX9FS4t5QTQMe lGeKN9F9Vrhq6r5tU3gUplnfQS41y/qxXGsd6EC7zex2XpAef0lVZAlfUiY2j3dt9cwq Wgw97P7pcgDd4K11KXZyTpFR0V6VmVVJX0RDJ2W35yKf9V5kcpHYXZ8CYSpC+gPfFlc5 cbhg== 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=/O3NQCHemq9BG693L5GzWwFa1z2NG5Mg2SvFM9TKes8=; b=PzPxsSTSD5NCZQ+M6wd6QtJd9wMcthjfCoPIQWXz+b5RJDH2RYYatE0xJROGe7Uv5f EXrc3DJXMCcqzDyiKhgmEX5P7q+TZRzj+tfQr83lm/0aHdxz+EeN0pzJGo/uetpPK3jH JsHwnnZHwesB9sPKk/2cN1w9rEllFwd42NVM6oLHIJNSZiDTh3UaM+GZdDfYnIk5UHXJ j0Y6IaWMzQkDQzQ9AZR0WUXBnSzfNcLKL4Yjw/fE+K5GYJAQ9EzGkE9Ae5QKvZdwL8pH oJ1GMTBSj4+j5DMnUeyT47htlk2aMHEcrJnDDq0bp5nKsoeFgHPqkyDeJTjD219DMI3V wtcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xxNrjbUV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r83si18964014pgr.26.2022.02.21.08.07.23; Mon, 21 Feb 2022 08:07:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xxNrjbUV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347808AbiBUJJ0 (ORCPT + 99 others); Mon, 21 Feb 2022 04:09:26 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:48422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347026AbiBUJEp (ORCPT ); Mon, 21 Feb 2022 04:04:45 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B05F2DD6A; Mon, 21 Feb 2022 00:58:51 -0800 (PST) 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 BC1D3B80EC0; Mon, 21 Feb 2022 08:58:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F3392C340E9; Mon, 21 Feb 2022 08:58:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1645433921; bh=/qkCfwpbbo+NcTqTpe8lchEZWjXUEYoPs8CNx3cbU3Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xxNrjbUV+uVav7QK5kCaSu4/Y0wujxtXGg2QoDRP/cR6DfQeTJiGpDeXEInyGCt0F sAA0oWjxlg9QUehJCn6mGPNVbt5nqyu+zHELe0UARLlsMqb42kjKEM01N+iKlngURb wDUD+0wYNOSPVbq8y35BcQqCtwyXQd0z2mcs/rF0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zhang Yi , Theodore Tso , Leah Rumancik Subject: [PATCH 5.4 31/80] ext4: prevent partial update of the extent blocks Date: Mon, 21 Feb 2022 09:49:11 +0100 Message-Id: <20220221084916.598342313@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220221084915.554151737@linuxfoundation.org> References: <20220221084915.554151737@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=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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: Zhang Yi commit 0f2f87d51aebcf71a709b52f661d681594c7dffa upstream. 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 Signed-off-by: Leah Rumancik Signed-off-by: Greg Kroah-Hartman --- fs/ext4/extents.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -133,14 +133,25 @@ static int ext4_ext_truncate_extend_rest 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 +171,9 @@ int __ext4_ext_dirty(const char *where, /* 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);