Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3326468rwa; Tue, 23 Aug 2022 02:55:03 -0700 (PDT) X-Google-Smtp-Source: AA6agR5+PSh9d9jFY/j4wY/ysA1rXvplDXcZmEbq1p06nIPmKB6ncSRu87ZnI1jZLQWGtjW2JHT/ X-Received: by 2002:a17:906:9b89:b0:73d:6a55:c489 with SMTP id dd9-20020a1709069b8900b0073d6a55c489mr9217923ejc.406.1661248503507; Tue, 23 Aug 2022 02:55:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661248503; cv=none; d=google.com; s=arc-20160816; b=mHwkRgRxb+LYgK2kOJ4y7JIqr8+C0q3g9F+lbK0OoGlC+YRD5i1SO/oOdFHNeH2+Jw kXkaqFzqTVh8essX4VAXP4QOiedgFY5hFHqT2grysXp9viDY46W5Pgdfzw0B66Osk2yR BYrU+ZdKnDW+90bgj+2aeJ5ol9e1jrXHBPHp4RMdjBh3fSgEKytCu/WZqS19mYv6gHL7 jNE6SfeAe3mr/u6bPLmENdEqmU0uiw+hy7MraaZJXXiGu3YeaepquFjHN7M+jO8BLh6W B/K+UMnNoEbHJrDmzQOMGe8O/aQ3tnxRWF9FZc5Df3KMVkS/QxcNu+QhvIxTJmRYYQfI WqIg== 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=Q3Kc3+SAt4c+mrdSAJ1rLUh5ZXukzVbxpwK1BZiKiWM=; b=dT1YPLytteaV7vsFb8o1J422NCWqZGSTEYYxhWaEzYExsZFdqq+W9G1eGf4SZURbdo Z+aEcs56YEWvU98hlrQzpyh7vwcfylALbyuUz4ftCzV1XT7SCUjzBr2m3QIa65gnhmqf nf2Xfu8Gd+GAJumg3k81YZ2GQSA1A8JTqE5BuNL/Gj6QPAoBj7IdxfSq8jCOq+J7mk3C WGbv1sjiMSMrWUDCsbYrJ06HPUGEf8+utLH0OhTMl5rX5fJbXGQefO3GvuEYscEYbqWZ LYbYuAgWdtiz14zxpK5DAtS5qTCnK4SmNvaEFpiZbY8GN+ZAaTpV7LWS19XmkO5CZXhf Ihiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=MTj6T79u; 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 j26-20020a1709062a1a00b0073099d0fe90si9876475eje.216.2022.08.23.02.54.38; Tue, 23 Aug 2022 02:55:03 -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=MTj6T79u; 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 S245547AbiHWIeo (ORCPT + 99 others); Tue, 23 Aug 2022 04:34:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346657AbiHWIcB (ORCPT ); Tue, 23 Aug 2022 04:32:01 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F4177539C; Tue, 23 Aug 2022 01:16:16 -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 15B566134C; Tue, 23 Aug 2022 08:16:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AABF0C433C1; Tue, 23 Aug 2022 08:16:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661242563; bh=2htKD0ZVb8ymIyt/eORaBdYvZL9X0W3ftn7vz42gtyE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MTj6T79ubT4o0xwsnuQaxuo/EW0ufIoTJGbyY7hkMbZzIxzYaOoeb5dJOFQ0VOuqY JsG9TQX9fExCAKDhEZR4z3E+WpiEfHzhN5MsHeR+Cbw5yYEAOLuWAoB5CR3Z4KZs7F BgBDabtyQF1yrotfhyPTXg5/M+892dTaFaYQslrg= 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.9 092/101] ext4: avoid remove directory when directory is corrupted Date: Tue, 23 Aug 2022 10:04:05 +0200 Message-Id: <20220823080038.061683696@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080034.579196046@linuxfoundation.org> References: <20220823080034.579196046@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 84754700ebe1..1281181215aa 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -2793,11 +2793,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