From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EC73BC43603 for ; Wed, 11 Dec 2019 15:35:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C0B422173E for ; Wed, 11 Dec 2019 15:35:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576078545; bh=Tx3kSEwE6ylePXAPDzE2LCN8rgqLVHwCTmUZNQTDgN0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=V3uG71Y+B+cO5lQm5K9DnvHmSmvbt6OYTilkroBgO2ZK4t4Eu1imDeRuYaVjK0cUy nHCoerWpddkMvzf7dRhmWEgAhHJSYjDubdn7gVw804FQh6Or/RyIbDDLopRCajJU4W se4V3gecRavMqaVIiaUPdlffnc8Br8K7alcGGE8E= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388211AbfLKPfp (ORCPT ); Wed, 11 Dec 2019 10:35:45 -0500 Received: from mail.kernel.org ([198.145.29.99]:44912 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733249AbfLKPfo (ORCPT ); Wed, 11 Dec 2019 10:35:44 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B80B12465B; Wed, 11 Dec 2019 15:35:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576078543; bh=Tx3kSEwE6ylePXAPDzE2LCN8rgqLVHwCTmUZNQTDgN0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SjedRVlzeQDjOFEM0yBng+kUQiUVswDv6uZ13I1xH6vv9h495R3584wq6ugPx5X+0 jqvehDbwwGcMtyoTmrJA9dP5AbYirftfhOqA1iWzAkOrSgY0ZyF6OUvZ3q5s5HXjv0 EfBN4EErz3PUw7aV2WMD2V40vqpKtBoV9gEYleWQ= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Theodore Ts'o , stable@kernel.org, Andreas Dilger , Sasha Levin , linux-ext4@vger.kernel.org Subject: [PATCH AUTOSEL 4.9 31/42] ext4: work around deleting a file with i_nlink == 0 safely Date: Wed, 11 Dec 2019 10:34:59 -0500 Message-Id: <20191211153510.23861-31-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191211153510.23861-1-sashal@kernel.org> References: <20191211153510.23861-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Theodore Ts'o [ Upstream commit c7df4a1ecb8579838ec8c56b2bb6a6716e974f37 ] If the file system is corrupted such that a file's i_links_count is too small, then it's possible that when unlinking that file, i_nlink will already be zero. Previously we were working around this kind of corruption by forcing i_nlink to one; but we were doing this before trying to delete the directory entry --- and if the file system is corrupted enough that ext4_delete_entry() fails, then we exit with i_nlink elevated, and this causes the orphan inode list handling to be FUBAR'ed, such that when we unmount the file system, the orphan inode list can get corrupted. A better way to fix this is to simply skip trying to call drop_nlink() if i_nlink is already zero, thus moving the check to the place where it makes the most sense. https://bugzilla.kernel.org/show_bug.cgi?id=205433 Link: https://lore.kernel.org/r/20191112032903.8828-1-tytso@mit.edu Signed-off-by: Theodore Ts'o Cc: stable@kernel.org Reviewed-by: Andreas Dilger Signed-off-by: Sasha Levin --- fs/ext4/namei.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index 29dc02758a52b..b8082ca9e3bac 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -3078,18 +3078,17 @@ static int ext4_unlink(struct inode *dir, struct dentry *dentry) if (IS_DIRSYNC(dir)) ext4_handle_sync(handle); - if (inode->i_nlink == 0) { - ext4_warning_inode(inode, "Deleting file '%.*s' with no links", - dentry->d_name.len, dentry->d_name.name); - set_nlink(inode, 1); - } retval = ext4_delete_entry(handle, dir, de, bh); if (retval) goto end_unlink; dir->i_ctime = dir->i_mtime = ext4_current_time(dir); ext4_update_dx_flag(dir); ext4_mark_inode_dirty(handle, dir); - drop_nlink(inode); + if (inode->i_nlink == 0) + ext4_warning_inode(inode, "Deleting file '%.*s' with no links", + dentry->d_name.len, dentry->d_name.name); + else + drop_nlink(inode); if (!inode->i_nlink) ext4_orphan_add(handle, inode); inode->i_ctime = ext4_current_time(inode); -- 2.20.1