public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: David Sterba <dsterba@suse.cz>
To: Qu Wenruo <quwenruo.btrfs@gmx.com>
Cc: Kaiwen Hu <kevinhu@synology.com>,
	linux-btrfs@vger.kernel.org, robbieko@synology.com,
	cccheng@synology.com, seanding@synology.com
Subject: Re: [PATCH] btrfs: prevent subvol with swapfile from being deleted
Date: Tue, 22 Mar 2022 20:39:32 +0100	[thread overview]
Message-ID: <20220322193932.GI12643@twin.jikos.cz> (raw)
In-Reply-To: <b1c66869-2920-9055-faa1-a84b05958289@gmx.com>

On Tue, Mar 22, 2022 at 06:47:59PM +0800, Qu Wenruo wrote:
> > @@ -10419,7 +10425,17 @@ static int btrfs_swap_activate(struct swap_info_struct *sis, struct file *file,
> >   	 * before walking the extents because we don't want a concurrent
> >   	 * snapshot to run after we've already checked the extents.
> >   	 */
> > +	spin_lock(&root->root_item_lock);
> > +	if (btrfs_root_dead(root)) {
> 
> This looks a little weird to me.
> 
> If the root is already dead, it means we should not be able to access
> any file inside the subvolume.
> 
> How could we go into btrfs_swap_activate() while the root is already dead?
> 
> Or is there some special race I missed?

The deletion has a few steps, eg. the dentry is removed, root is marked
as dead and different thing locking protection.

I was wondering about file descriptor access to the subvolume and
calling swapon on that, but swapon/swapoff is a syscall and work with a
path argument so that can't happen. I haven't checked in what order are
the dentry removal and dead flag done, it could be theoretically
possible that there's a short window where the dentry is accessible and
subvolume already marked.

  reply	other threads:[~2022-03-22 19:43 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-22 10:27 [PATCH] btrfs: prevent subvol with swapfile from being deleted Kaiwen Hu
2022-03-22 10:47 ` Qu Wenruo
2022-03-22 19:39   ` David Sterba [this message]
2022-03-23  3:13     ` Kaiwen Hu
2022-03-23  4:40       ` Qu Wenruo
2022-03-23  7:10         ` [PATCH v2] " Kaiwen Hu
2022-03-23  7:59           ` Qu Wenruo
2022-03-23 12:34           ` David Sterba
2022-03-23 13:33             ` Filipe Manana
2022-03-23 13:37           ` Filipe Manana
2022-03-23 21:45           ` David Sterba
2022-03-24  4:59             ` Kaiwen Hu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220322193932.GI12643@twin.jikos.cz \
    --to=dsterba@suse.cz \
    --cc=cccheng@synology.com \
    --cc=kevinhu@synology.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=quwenruo.btrfs@gmx.com \
    --cc=robbieko@synology.com \
    --cc=seanding@synology.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox