linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Btrfs: prevent deletion of mounted subvolumes
@ 2015-03-30  9:02 Omar Sandoval
  2015-03-30  9:30 ` Timo Kokkonen
  2015-03-30 12:30 ` David Sterba
  0 siblings, 2 replies; 11+ messages in thread
From: Omar Sandoval @ 2015-03-30  9:02 UTC (permalink / raw)
  To: Chris Mason, Josef Bacik, David Sterba
  Cc: Eric W. Biederman, Timo Kokkonen, linux-btrfs, linux-kernel,
	Omar Sandoval

Before commit bafc9b754f75 ("vfs: More precise tests in d_invalidate"),
d_invalidate() could return -EBUSY when a dentry for a directory had
more than one reference to it. This is what prevented a mounted
subvolume from being deleted, as struct vfsmount holds a reference to
the subvolume dentry. However, that commit removed that case, and later
commits in that patch series removed the return code from d_invalidate()
completely, so we don't get that check for free anymore. So, reintroduce
it in btrfs_ioctl_snap_destroy().

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=93021
Reported-by: Timo Kokkonen <timo.kokkonen@offcode.fi>
Fixes: bafc9b754f75 ("vfs: More precise tests in d_invalidate")
Signed-off-by: Omar Sandoval <osandov@osandov.com>
---
This applies to 4.0-rc6. To be honest, I'm not sure that this is the most
correct fix for this bug, but it's equivalent to the pre-3.18 behavior and it's
the best that I could come up with. Thoughts?

 fs/btrfs/ioctl.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 74609b9..39b0538 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -2384,6 +2384,12 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file,
 		goto out_dput;
 	}
 
+	spin_lock(&dentry->d_lock);
+	err = dentry->d_lockref.count > 1 ? -EBUSY : 0;
+	spin_unlock(&dentry->d_lock);
+	if (err)
+		goto out_dput;
+
 	mutex_lock(&inode->i_mutex);
 
 	/*
-- 
2.3.4


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2015-04-03 21:08 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-30  9:02 [PATCH] Btrfs: prevent deletion of mounted subvolumes Omar Sandoval
2015-03-30  9:30 ` Timo Kokkonen
2015-03-30 12:30 ` David Sterba
2015-03-30 18:41   ` Omar Sandoval
2015-04-01  3:54     ` Eric W. Biederman
2015-04-01  7:03       ` Omar Sandoval
2015-04-01  7:27         ` Timo Kokkonen
2015-04-01 11:22         ` David Sterba
2015-04-02  3:49           ` Omar Sandoval
2015-04-02 15:02             ` David Sterba
2015-04-03 21:08               ` Omar Sandoval

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).