From patchwork Thu Aug 29 18:45:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 1155497 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ubuntu.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46KBPg42vFz9sN1; Fri, 30 Aug 2019 04:45:27 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1i3PQ5-0002W0-Ui; Thu, 29 Aug 2019 18:45:17 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.86_2) (envelope-from ) id 1i3PQ5-0002Vp-1m for kernel-team@lists.ubuntu.com; Thu, 29 Aug 2019 18:45:17 +0000 Received: from [213.220.153.21] (helo=localhost.localdomain) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.76) (envelope-from ) id 1i3PQ4-0006mC-Kv; Thu, 29 Aug 2019 18:45:16 +0000 From: Christian Brauner To: kernel-team@lists.ubuntu.com, seth.forshee@canonical.com Subject: [PATCH][SRU][Disco] UBUNTU: SAUCE: shiftfs: fix buggy unlink logic Date: Thu, 29 Aug 2019 20:45:07 +0200 Message-Id: <20190829184507.21173-1-christian.brauner@ubuntu.com> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: stgraber@ubuntu.com Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" BugLink: https://bugs.launchpad.net/bugs/1841977 The way we messed with setting i_nlink was brittle and wrong. We used to set the i_nlink of the shiftfs dentry to be deleted to the i_nlink count of the underlay dentry of the directory it resided in which makes no sense whatsoever. We also missed drop_nlink() which is crucial since i_nlink affects whether a dentry is cleaned up on dput(). With this I cannot reproduce the bug anymore where shiftfs misleads zfs into believing that a deleted file can not be removed from disk because it is still referenced. Fixes: commit 87011da41961 ("shiftfs: rework and extend") Signed-off-by: Christian Brauner Acked-by: Seth Forshee Acked-by: Stefan Bader Acked-by: Connor Kuehl --- fs/shiftfs.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/fs/shiftfs.c b/fs/shiftfs.c index 57e04a02d74c..084aa7a25566 100644 --- a/fs/shiftfs.c +++ b/fs/shiftfs.c @@ -585,6 +585,7 @@ static int shiftfs_rm(struct inode *dir, struct dentry *dentry, bool rmdir) { struct dentry *lowerd = dentry->d_fsdata; struct inode *loweri = dir->i_private; + struct inode *inode = d_inode(dentry); int err; const struct cred *oldcred; @@ -594,15 +595,19 @@ static int shiftfs_rm(struct inode *dir, struct dentry *dentry, bool rmdir) err = vfs_rmdir(loweri, lowerd); else err = vfs_unlink(loweri, lowerd, NULL); - inode_unlock(loweri); revert_creds(oldcred); - shiftfs_copyattr(loweri, dir); - set_nlink(d_inode(dentry), loweri->i_nlink); - if (!err) + if (!err) { d_drop(dentry); - set_nlink(dir, loweri->i_nlink); + if (rmdir) + clear_nlink(inode); + else + drop_nlink(inode); + } + inode_unlock(loweri); + + shiftfs_copyattr(loweri, dir); return err; }