Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3408838rwa; Tue, 23 Aug 2022 04:24:41 -0700 (PDT) X-Google-Smtp-Source: AA6agR4FPZfdMD8DwmbspsEPx9DpQwzYD3rhd+7xFOEVLgWVgsCfbwcLfSoHNN64cs0HXXgdDtel X-Received: by 2002:a17:90b:4b8f:b0:1fb:10e2:5c99 with SMTP id lr15-20020a17090b4b8f00b001fb10e25c99mr2892445pjb.194.1661253881642; Tue, 23 Aug 2022 04:24:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661253881; cv=none; d=google.com; s=arc-20160816; b=REA+a/0t5wKIwTmsSTQL5SwRaES6ouC0PWWRKetw8+EW4+AB0hD/RAZ3lrROnviEeR lTunlJCw5uRXVx2etQ91Y8IpIQJwevWFJJ9pkIUg0GsDRPA4PTXJ24bxKBOAsdPsCRbl 1EwGXCIBKdou08a+5/MGSXy6j6U9slDjSYhxEyyDx1JiImkgOOJJDh1gNzLsv53kHb4L 8MXC31xm1PTanW0AADXT7aek//tsx7rjBr6HQZdO4tOtlMwnxq6lPCGkH7IhcJ4y57zy h06MH16uzzwH60EuV308E0aWMWu2b49exBCmryWcgSwp/SoCgwiFo/AOXiFrM5ax4cRZ jCHg== 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=qpHkCmi7Kb6I2aSX674oUv0I/qDYTD7k/Il8NwsV5Uc=; b=vgTSLHT+3B0Uta9Iwz8BfMeq69+eQ6v4NFXCKMXryldUmb6Llby/SqkT+tZskwgQ9s 9qVkyOrtx+ejhlJEBMBlW7DmqpWv1cNNuPg1XPXymGiRXlCJBnnnAhJ+bxsf+qrAi1TX 6IdArPN4p3RXI2IhzWcYwp3VjQrd7Kmz+BsvWlLrn+JnjpvnlHRZiks4sM/kUTpmZtyw RdPeMVRL7ReeM1lRY8e8sw1f9G7fdfPwtCsdXlRySb0GD0rAZRwVhYjUC1jSNrQWZvQP 9RBtO9C0M/CJ7I1L8H5USVHuls8qHHt/2DYMnFdjqLoS4RRxfvhASxfuA22unPfwsxpi 3mZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TXjA+DVr; 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 a4-20020a170902ecc400b00172ccb0862fsi12801682plh.88.2022.08.23.04.24.30; Tue, 23 Aug 2022 04:24:41 -0700 (PDT) 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=TXjA+DVr; 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 S1354547AbiHWKZx (ORCPT + 99 others); Tue, 23 Aug 2022 06:25:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353626AbiHWKLp (ORCPT ); Tue, 23 Aug 2022 06:11:45 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B57FE167F0; Tue, 23 Aug 2022 01:57:49 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 5314B6155E; Tue, 23 Aug 2022 08:57:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5910FC433D6; Tue, 23 Aug 2022 08:57:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661245068; bh=sDPGvO3iaQnn+7wjvslt/FtR26VgUYouggIzz/B690o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TXjA+DVrZdxAQvZYGKF4176f+ratBdVBNUlM4BGDLv/4ySjPQ/FveFZJYWH90yKGQ Sc1qQp8/dcTBAuJwx1WENt1C4IQSjkY41/mKxjnngSoxdeKF7DVqR8N/gG/d2TcONJ Rk1ZeNlbWi82ADvuwhpHjhPDMfI7oEqnxlwBerrA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ye Bin , Jan Kara , Theodore Tso , Sasha Levin Subject: [PATCH 5.15 204/244] ext4: avoid remove directory when directory is corrupted Date: Tue, 23 Aug 2022 10:26:03 +0200 Message-Id: <20220823080106.309197493@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080059.091088642@linuxfoundation.org> References: <20220823080059.091088642@linuxfoundation.org> User-Agent: quilt/0.67 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: Ye Bin [ Upstream commit b24e77ef1c6d4dbf42749ad4903c97539cc9755a ] Now if check directoy entry is corrupted, ext4_empty_dir may return true then directory will be removed when file system mounted with "errors=continue". In order not to make things worse just return false when directory is corrupted. Signed-off-by: Ye Bin Reviewed-by: Jan Kara Link: https://lore.kernel.org/r/20220622090223.682234-1-yebin10@huawei.com Signed-off-by: Theodore Ts'o Signed-off-by: Sasha Levin --- fs/ext4/namei.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index 5821638cb893..7d3ec39121f7 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -3090,11 +3090,8 @@ bool ext4_empty_dir(struct inode *inode) de = (struct ext4_dir_entry_2 *) (bh->b_data + (offset & (sb->s_blocksize - 1))); if (ext4_check_dir_entry(inode, NULL, de, bh, - bh->b_data, bh->b_size, offset)) { - offset = (offset | (sb->s_blocksize - 1)) + 1; - continue; - } - if (le32_to_cpu(de->inode)) { + bh->b_data, bh->b_size, offset) || + le32_to_cpu(de->inode)) { brelse(bh); return false; } -- 2.35.1