public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: David Sterba <dsterba@suse.cz>
To: Qu Wenruo <wqu@suse.com>
Cc: dsterba@suse.cz, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH v5] btrfs: Don't submit any btree write bio if the fs has error
Date: Mon, 24 Feb 2020 18:06:15 +0100	[thread overview]
Message-ID: <20200224170615.GZ2902@twin.jikos.cz> (raw)
In-Reply-To: <8e100fed-13ba-febf-14da-452635094aad@suse.com>

On Fri, Feb 21, 2020 at 09:40:32PM +0800, Qu Wenruo wrote:
> 
> 
> On 2020/2/21 下午9:35, David Sterba wrote:
> > On Wed, Feb 12, 2020 at 02:12:44PM +0800, Qu Wenruo wrote:
> >> @@ -4036,7 +4037,39 @@ int btree_write_cache_pages(struct address_space *mapping,
> >>  		end_write_bio(&epd, ret);
> >>  		return ret;
> >>  	}
> >> -	ret = flush_write_bio(&epd);
> >> +	/*
> >> +	 * If something went wrong, don't allow any metadata write bio to be
> >> +	 * submitted.
> >> +	 *
> >> +	 * This would prevent use-after-free if we had dirty pages not
> >> +	 * cleaned up, which can still happen by fuzzed images.
> >> +	 *
> >> +	 * - Bad extent tree
> >> +	 *   Allowing existing tree block to be allocated for other trees.
> >> +	 *
> >> +	 * - Log tree operations
> >> +	 *   Exiting tree blocks get allocated to log tree, bumps its
> >> +	 *   generation, then get cleaned in tree re-balance.
> >> +	 *   Such tree block will not be written back, since it's clean,
> >> +	 *   thus no WRITTEN flag set.
> >> +	 *   And after log writes back, this tree block is not traced by
> >> +	 *   any dirty extent_io_tree.
> >> +	 *
> >> +	 * - Offending tree block gets re-dirtied from its original owner
> >> +	 *   Since it has bumped generation, no WRITTEN flag, it can be
> >> +	 *   reused without COWing. This tree block will not be traced
> >> +	 *   by btrfs_transaction::dirty_pages.
> >> +	 *
> >> +	 *   Now such dirty tree block will not be cleaned by any dirty
> >> +	 *   extent io tree. Thus we don't want to submit such wild eb
> >> +	 *   if the fs already has error.
> >> +	 */
> >> +	if (!test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) {
> >> +		ret = flush_write_bio(&epd);
> >> +	} else {
> >> +		ret = -EUCLEAN;
> >> +		end_write_bio(&epd, ret);
> >> +	}
> > 
> > This replaces one instance of flush_write_bio, would it make sense to
> > wrap it to flush_write_bio or some other helper? There might be places
> > where not handling the fs error state would be acceptable, so eg.
> > 
> > flush_write_bio = as it is now
> > 
> > flush_write_bio_or_end = does the above
> > 
> 
> I don't believe there are other call sites needs such special handling,
> thus a wrapper only used once doesn't make much sense.
> 
> Unless we're going to introduce more path for btree writeback, current
> one would be good enough I guess.

I see, thanks. The steps to reproduce are quite complicated already and
expecting crafted data. There's probably more but would need a similarly
convoluted way of hitting a missing error code fixup.

We could add more invariant checks that would catch that something is
done at a wrong time, like here metadata writeback after everything has
been shut down.

  reply	other threads:[~2020-02-24 17:06 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-12  6:12 [PATCH v5] btrfs: Don't submit any btree write bio if the fs has error Qu Wenruo
2020-02-12 12:50 ` Josef Bacik
2020-02-21 13:35 ` David Sterba
2020-02-21 13:40   ` Qu Wenruo
2020-02-24 17:06     ` David Sterba [this message]
2020-02-25  0:02       ` Qu Wenruo

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=20200224170615.GZ2902@twin.jikos.cz \
    --to=dsterba@suse.cz \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=wqu@suse.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