Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3396048rwa; Tue, 23 Aug 2022 04:12:09 -0700 (PDT) X-Google-Smtp-Source: AA6agR79qRaAxCK2B4iemJ1ZbIxdhRUHz5pmHmbryL2VxPw+2RBAQ32vHvjU85rvZEoMqRKK3mXh X-Received: by 2002:a17:907:9808:b0:73d:78f2:1267 with SMTP id ji8-20020a170907980800b0073d78f21267mr7164606ejc.692.1661253129096; Tue, 23 Aug 2022 04:12:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661253129; cv=none; d=google.com; s=arc-20160816; b=0v1uM3+cau9kCBCs+hLZsI+MHAH1fYduIu4KCT2OpyWqDKbUXoMe98Md9QDJJzXifB EpOollB5LLPBFKQJqjaCYUBdvamYDQBiw3g4NuezrmJSDyiSEl5RormdWJmRIpx6WsYc U8oZ6uTRHZXXHqNevaaIOshWmqlF0jPirflNUeb3UvudES/wIu5dAjykYP8krLADVdzD 4Pw2tlLHZ3fbtF5LdlBVY/JPJX9hZBxjv0Glws3KzaVOHZfVHUebhSwQBj4pBlC5eQzE GaU93w85uSA/iZtKmhfJN/CpNc24vEG8Gx1pnf7o8XaJFpGufyftmj+sf/ajGicqsDc5 B49Q== 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=A81xDrQk1/CWpRw+dfR2UI6rPaWs6wz6U5bBqQPmUDY=; b=kCn2C7ya+Ccss52diF/JA/pqQ+e3SIAXR64w1PClEfKwfPIug/SBg8fUyb4W2WE3Xw TlgjJcCUCJ/UCs33IJ1LjcsC+NuDSCK+VrzQejsK6p3Y/YihICAXpSA6ZoKzj2TQ8/kt V5cumbq3beotxYqQrlervh/93A29GFnfozlGDXJosHcv0h/xSANYYAZIG1wUuaVpvLWD 2R6z9bL4VSYbF7VqbKA2XBiOurIO2VvEFdBzE2LLL6RHhm0+qPuK4mbwGefIstpaOLL3 niPbUANWd13AM5zJjPYKs7sETLHAHom48H0Dv7lo/41sNEcKKyqdlb7blgBoPT6mbtEs G3mQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=u8APzQHe; 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 v19-20020a50d593000000b00441ec11be8esi1694285edi.111.2022.08.23.04.11.41; Tue, 23 Aug 2022 04:12:09 -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=u8APzQHe; 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 S1354251AbiHWK1Z (ORCPT + 99 others); Tue, 23 Aug 2022 06:27:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353912AbiHWKMR (ORCPT ); Tue, 23 Aug 2022 06:12:17 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 516312C675; Tue, 23 Aug 2022 01:58:37 -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 DE267B81C3B; Tue, 23 Aug 2022 08:58:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 39AD1C433C1; Tue, 23 Aug 2022 08:58:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661245114; bh=W5thjdNhmcdbfx2aKtOkCtX5IKQ/BpSrlifsGJ0KU9k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=u8APzQHeirtONSv95I8CZhDSWDjYMt0i+LyKHxePdQzC5jVAhWOUR+udZqxsyylwz U6DsjV/Rvag+jguZUw/fmT3FINfOU7oY42VrKTwOM76po6VNK2i63Sv/TVrq5NsJ0n NoZAa41j5X4SJ3pyV3xWbAy69y1aiqe/Cgi1SSjk= 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.14 219/229] ext4: avoid remove directory when directory is corrupted Date: Tue, 23 Aug 2022 10:26:20 +0200 Message-Id: <20220823080101.469565686@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080053.202747790@linuxfoundation.org> References: <20220823080053.202747790@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 4b78fa4dbcc1..e1cade9dbd30 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -2820,11 +2820,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