Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3415549rwa; Tue, 23 Aug 2022 04:31:40 -0700 (PDT) X-Google-Smtp-Source: AA6agR5nO33ZzhmvaUEN3GQy/UHvKlg7VMqmQeM9ZO0d0C2qbfIEb+XOsYHMSk/m2E8A9dlvDnbJ X-Received: by 2002:aa7:8818:0:b0:536:6e37:633c with SMTP id c24-20020aa78818000000b005366e37633cmr12528337pfo.37.1661254199941; Tue, 23 Aug 2022 04:29:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661254199; cv=none; d=google.com; s=arc-20160816; b=QhOqLq9gSKQ2NbyVHCPNmGbSpLwyGb74ihuxQJ1ZoRevVuVVcgYXAGo+9g9jMP5L3c twF3kmwcOMKXcoG0FcIUnhJq92FLt4n8/x9P71dRucs5GHwXHHo7SpKBvQqHW9Er/+ko yuASauM3iDapcpsp5tdqCBuQRhklq2wHOVIj1Urvc45I6ggvRa5/hW1msN9eNkh5ljdQ fNMrdM9C8RZGYKkLMSAsXHuCPSJ96RlXw7IvN0U/ZJeuoWKoNl/QmFyrYf5W0loSWCCD laqpaH3hhT+EK4iGxOxrG91OLr/KSZYiKv1QmQLFhbFiW0Gyoeeh/tIQQqn4FX860J5M PWIQ== 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=fwQmnDQcZtYUJxpYPu/mQldVqvk4jp6gKt4GAn55qXE=; b=AtbUNRBDXKjmT63bwxxSPKAQVwM0akcPMjvyFqYsLN7PanmfhjTzyNWTyZd3shy33L +7i+g0fCdhNINBlME57ufBcy0QvI1ANlltp+faGcjoPfifKsecadGnfhhZiA6TOclOdq UncHFK29OA+axhTHEZy/Y+XVpTlunj3K9KnMQx8q241wUP7d28+Qt0T8ebmqEaJyz3tj Pnt8eJ60fOMtBqSUY1SzIpvSeskeueKQxlPc4JRrSbwTvFJrZLGG/ZhKO82EG8hOL8v8 jj+epev1f653ylTnmCnbThmaARLliBZgcUA2VPmA6wJjDZTGaAFOc7lsRxgfQIU9zuNN 6j/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=aAMTEnnx; 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 t32-20020a634460000000b00415ef8c15f1si14462422pgk.486.2022.08.23.04.29.48; Tue, 23 Aug 2022 04:29:59 -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=aAMTEnnx; 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 S1356938AbiHWLE2 (ORCPT + 99 others); Tue, 23 Aug 2022 07:04:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357227AbiHWLBp (ORCPT ); Tue, 23 Aug 2022 07:01:45 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC3F4AF0EE; Tue, 23 Aug 2022 02:14:23 -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 9F8A8B81C65; Tue, 23 Aug 2022 09:13:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D5E73C433C1; Tue, 23 Aug 2022 09:13:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661246038; bh=za6cP4qVD0yTtyzAS0PYUcIWi7apHcLLt0B3+bVmPIE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aAMTEnnxtXLVDsgZJXt94j6fFQrylD0k72HTMGULGcirVYVLfkiG3qd5zdcwehKk9 N3O4K9wDwC76FqdVScGLik9D3exFcEpnBqxNAdo/QYDgol9AMXhx96KMQQOnjYNoSc Moc9FeCKWGEZx9hX0Ynx1jUsNWWKzaLf/9bi6uAA= 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 4.19 268/287] ext4: avoid remove directory when directory is corrupted Date: Tue, 23 Aug 2022 10:27:17 +0200 Message-Id: <20220823080110.381049371@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080100.268827165@linuxfoundation.org> References: <20220823080100.268827165@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 ebc8e75e1ef1..a878b9a8d9ea 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -2842,11 +2842,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