From: Nikolay Borisov <nborisov@suse.com>
To: Naohiro Aota <naohiro.aota@wdc.com>, linux-btrfs@vger.kernel.org
Cc: David Sterba <dsterba@suse.com>
Subject: Re: [PATCH] btrfs: fix extent_state leak in btrfs_lock_and_flush_ordered_range
Date: Fri, 26 Jul 2019 11:49:08 +0300 [thread overview]
Message-ID: <1f016f72-28fb-5895-c3b3-5bcb831ef142@suse.com> (raw)
In-Reply-To: <20190726074705.27513-1-naohiro.aota@wdc.com>
On 26.07.19 г. 10:47 ч., Naohiro Aota wrote:
> btrfs_lock_and_flush_ordered_range() loads given "*cached_state" into
> cachedp, which, in general, is NULL. Then, lock_extent_bits() updates
> "cachedp", but it never goes backs to the caller. Thus the caller still
> see its "cached_state" to be NULL and never free the state allocated
> under btrfs_lock_and_flush_ordered_range(). As a result, we will
> see massive state leak with e.g. fstests btrfs/005. Fix this bug by
> properly handling the pointers.
>
> Fixes: bd80d94efb83 ("btrfs: Always use a cached extent_state in btrfs_lock_and_flush_ordered_range")
> Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
> ---
> fs/btrfs/ordered-data.c | 11 ++++++-----
> 1 file changed, 6 insertions(+), 5 deletions(-)
>
> diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c
> index df02ed25b7db..ab31b1a1b624 100644
> --- a/fs/btrfs/ordered-data.c
> +++ b/fs/btrfs/ordered-data.c
> @@ -982,13 +982,14 @@ void btrfs_lock_and_flush_ordered_range(struct extent_io_tree *tree,
> struct extent_state **cached_state)
> {
> struct btrfs_ordered_extent *ordered;
> - struct extent_state *cachedp = NULL;
> + struct extent_state *cache = NULL;
> + struct extent_state **cachedp = &cache;
>
> if (cached_state)
> - cachedp = *cached_state;
> + cachedp = cached_state;
>
> while (1) {
> - lock_extent_bits(tree, start, end, &cachedp);
> + lock_extent_bits(tree, start, end, cachedp);
> ordered = btrfs_lookup_ordered_range(inode, start,
> end - start + 1);
> if (!ordered) {
> @@ -998,10 +999,10 @@ void btrfs_lock_and_flush_ordered_range(struct extent_io_tree *tree,
> * aren't exposing it outside of this function
> */
> if (!cached_state)
> - refcount_dec(&cachedp->refs);
> + refcount_dec(&cache->refs);
> break;
> }
> - unlock_extent_cached(tree, start, end, &cachedp);
> + unlock_extent_cached(tree, start, end, cachedp);
> btrfs_start_ordered_extent(&inode->vfs_inode, ordered, 1);
> btrfs_put_ordered_extent(ordered);
> }
>
next prev parent reply other threads:[~2019-07-26 8:49 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-26 7:47 [PATCH] btrfs: fix extent_state leak in btrfs_lock_and_flush_ordered_range Naohiro Aota
2019-07-26 8:49 ` Nikolay Borisov [this message]
2019-07-26 10:33 ` 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=1f016f72-28fb-5895-c3b3-5bcb831ef142@suse.com \
--to=nborisov@suse.com \
--cc=dsterba@suse.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=naohiro.aota@wdc.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