Received: by 2002:a17:90a:9103:0:0:0:0 with SMTP id k3csp11816489pjo; Thu, 2 Jan 2020 14:47:36 -0800 (PST) X-Google-Smtp-Source: APXvYqyLdmqrlO68V24yGhu2cs1D781fTcpsnbcjgo3xeNJ+p3V+B86DHdel4t4nVU6AY4EcFUb7 X-Received: by 2002:a9d:69ce:: with SMTP id v14mr97730080oto.248.1578005256500; Thu, 02 Jan 2020 14:47:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578005256; cv=none; d=google.com; s=arc-20160816; b=IMiaDm6Xx4ea4djNy+q5g99ZH2qMWvkNvPl+MHpyvTuGInS/xrurJ3k+ZHuSWZ2p5C TEg1HzTQ7v7DxQ0WVemr+k3N591Jem4zpqEWXhnoN2PsAFDAO2LppmXOqtTgrJPwAAJ2 Pk7UAsakiqtVrQYK2uDAjPdsUROngboID1k8h7MltkGV4AfPww7e3NLRrPQKTXy1xjPt 4qnNox3hu0qpXE0/vjt+akVEJsJrQXyk5x3i1K0jH+8R5s0iOr14dqGDJwMTubEYM/C2 3zfZr2YDRAbIX8MvayoOcaq0bHCeJ+2zosVzMjVqoL+HzLX44H0kog3GxAqAm7bWD8iS rf1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=p1tXlbKPCDcUKdQo5Nuh2o4ehKtUz1ejbiMwPaUh67c=; b=rzRmVhe/53Mvyuqk1rXnG2eOUiPDxu5Wo5hqSngbPPMT+j2aRii3pYdIzCig0gLt9Z 6yCgHQvmkr4bDWs9WTXPHfc0fiyzLydkc15JWtkPJU6gF+GYSgLZrBC0MHR6qJLuERP6 iYwIaLoN5P1fS8bhsKfMWmH0dflii1+PabAjVWZlXH6y/xX1BE6n5iZKKFEXuCsFZwhY 85WJELEmtxM5rXnEtkSnViVJjfROMKO4L9VukOjR+OF6PWvU/FMB6EAANsvhRySUjQQj 720bss2BBOfQytEChMtoktjoVPFZ4YpjY3r8k81x14DSaEJaXeJBxRKNkI1mj7pn0UfJ blbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XD4QRki4; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f22si27207769otp.178.2020.01.02.14.47.24; Thu, 02 Jan 2020 14:47:36 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XD4QRki4; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729603AbgABWpP (ORCPT + 99 others); Thu, 2 Jan 2020 17:45:15 -0500 Received: from mail.kernel.org ([198.145.29.99]:38698 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730409AbgABWcZ (ORCPT ); Thu, 2 Jan 2020 17:32:25 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 59307222C3; Thu, 2 Jan 2020 22:32:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578004344; bh=QVQNXYhm774xEJ0esdujKP+OZHgv/yx5eUykMewmE/w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XD4QRki4isF9c9yxpr/3VIg1wWtQlzRggTGA2MaxEAAUT2B+PYSc0Ym2d06xecokS Kj5RFGTuLjCxe4cLQuxqEOaendq2tJGDaqx2IfQ/5kDW2O3HQY8ubj8G/mrCIMDPKb jTb3K6Nsk6EAmgM+R9axrlOE7BtoioIpEDNwjB6Q= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Theodore Tso , stable@kernel.org, Andreas Dilger , Sasha Levin Subject: [PATCH 4.9 140/171] ext4: work around deleting a file with i_nlink == 0 safely Date: Thu, 2 Jan 2020 23:07:51 +0100 Message-Id: <20200102220606.559791102@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200102220546.960200039@linuxfoundation.org> References: <20200102220546.960200039@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 6608cc01a3db..f0ce535d514c 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -3082,18 +3082,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