Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: David Sterba <dsterba@suse.cz>
To: Josef Bacik <josef@toxicpanda.com>
Cc: Nikolay Borisov <nborisov@suse.com>,
	linux-btrfs@vger.kernel.org, kernel-team@fb.com,
	stable@vger.kernel.org
Subject: Re: [PATCH] btrfs: avoid double put of block group when emptying cluster
Date: Wed, 10 Feb 2021 23:50:14 +0100	[thread overview]
Message-ID: <20210210225014.GA1993@twin.jikos.cz> (raw)
In-Reply-To: <ad0ea42a-5e41-f9b9-986d-8c70e9f2eed3@toxicpanda.com>

On Tue, Jan 26, 2021 at 09:30:45AM -0500, Josef Bacik wrote:
> On 1/26/21 4:02 AM, Nikolay Borisov wrote:
> > On 25.01.21 г. 23:42 ч., Josef Bacik wrote:
> >> In __btrfs_return_cluster_to_free_space we will bail doing the cleanup
> >> of the cluster if the block group we passed in doesn't match the block
> >> group on the cluster.  However we drop a reference to block_group, as
> >> the cluster holds a reference to the block group while it's attached to
> >> the cluster.  If cluster->block_group != block_group however then this
> >> is an extra put, which means we'll go negative and free this block group
> >> down the line, leading to a UAF.
> > 
> > Was this found by code inspection or did you hit in production. Also why
> > in btrfs_remove_free_space_cache just before
> > __btrfs_return_cluster_to_free_space there is:
> > 
> 
> It was found in production sort of halfway.  I was doing something for WhatsApp 
> and had to convert our block group reference counting to the refcount stuff so I 
> could find where I made a mistake.  Turns out this was where the problem was, my 
> stuff had just made it way more likely to happen.  I don't have the stack trace 
> because this was like 6 months ago, I'm going through all my WhatsApp magic and 
> getting them actually usable for upstream.
> 
> > WARN_ON(cluster->block_group != block_group);
> > 
> > IMO this patch should also remove the WARN_ON if it's a valid condition
> > to have the passed bg be different than the one in the cluster. Also
> > that WARN_ON is likely racy since it's done outside of cluster->lock.
> > 
> 
> Yup that's in a follow up thing, I wanted to get the actual fix out before I got 
> distracted by my mountain of meetings this week.  Thanks,

Removing the WARN_ON in a separate patch sounds ok to me, this patch
clearly fixes the refcounting bug, the warning condition is the same but
would need a different reasoning.

Nikolay, if you're ok with current patch version let me know if you want
a rev-by added.

  reply	other threads:[~2021-02-10 22:53 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-25 21:42 [PATCH] btrfs: avoid double put of block group when emptying cluster Josef Bacik
2021-01-26  9:02 ` Nikolay Borisov
2021-01-26 14:30   ` Josef Bacik
2021-02-10 22:50     ` David Sterba [this message]
2021-02-11 11:25       ` Nikolay Borisov
2021-02-17 17:29         ` David Sterba

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=20210210225014.GA1993@twin.jikos.cz \
    --to=dsterba@suse.cz \
    --cc=josef@toxicpanda.com \
    --cc=kernel-team@fb.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=nborisov@suse.com \
    --cc=stable@vger.kernel.org \
    /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