From: Lee Jones <lee@kernel.org>
To: dsterba@suse.cz, Jia-Ju Bai <baijiaju1990@gmail.com>,
clm@fb.com, josef@toxicpanda.com, dsterba@suse.com,
linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] fs: btrfs: fix possible use-after-free bug in error handling code of btrfs_get_root_ref()
Date: Wed, 23 Aug 2023 09:07:02 +0100 [thread overview]
Message-ID: <20230823080702.GA2472023@google.com> (raw)
In-Reply-To: <20230823080044.GA2468513@google.com>
On Wed, 23 Aug 2023, Lee Jones wrote:
> On Fri, 01 Apr 2022, David Sterba wrote:
>
> > On Fri, Mar 25, 2022 at 04:04:17PM +0800, Jia-Ju Bai wrote:
> > > >> @@ -1850,9 +1850,10 @@ static struct btrfs_root *btrfs_get_root_ref(struct btrfs_fs_info *fs_info,
> > > >>
> > > >> ret = btrfs_insert_fs_root(fs_info, root);
> > > >> if (ret) {
> > > >> - btrfs_put_root(root);
> > > >> - if (ret == -EEXIST)
> > > >> + if (ret == -EEXIST) {
> > > >> + btrfs_put_root(root);
> > > > I think this fix is correct, though it's not that clear. If you look how
> > > > the code changed, there was the unconditional put and then followed by a
> > > > free:
> > > >
> > > > 8c38938c7bb0 ("btrfs: move the root freeing stuff into btrfs_put_root")
> > > >
> > > > Here it's putting twice where one will be the final free.
> > > >
> > > > And then the whole refcounting gets updated in
> > > >
> > > > 4785e24fa5d2 ("btrfs: don't take an extra root ref at allocation time")
> > > >
> > > > which could be removing the wrong put, I'm not yet sure.
> > >
> > > Thanks for the reply!
> > >
> > > I think the bug should be introduced by this commit:
> > > bc44d7c4b2b1 ("btrfs: push btrfs_grab_fs_root into btrfs_get_fs_root")
> > >
> > > This commit has a change:
> > > ret = btrfs_insert_fs_root(fs_info, root);
> > > if (ret) {
> > > + btrfs_put_fs_root(root);
> > > if (ret == -EEXIST) {
> > > btrfs_free_fs_root(root);
> > > goto again;
> > > }
> > >
> > > I could add a Fixes tag of this commit in my V2 patch.
> > > Is it okay?
> >
> > I can add it myself, that's a minor thing. The fix is correct, I've
> > rewritten the changelog a bit, patch now added to misc-next, thanks.
>
> Where is 'misc-next' please?
Nevermind. I've just seen a) how old this thread is and b) the commit
subject was changed and subsequently committed as:
168a2f776b976 ("btrfs: fix root ref counts in error handling in btrfs_get_root_ref")
--
Lee Jones [李琼斯]
prev parent reply other threads:[~2023-08-23 8:09 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-24 13:44 [PATCH] fs: btrfs: fix possible use-after-free bug in error handling code of btrfs_get_root_ref() Jia-Ju Bai
2022-03-24 18:19 ` David Sterba
2022-03-25 8:04 ` Jia-Ju Bai
2022-04-01 15:54 ` David Sterba
2023-08-23 8:00 ` Lee Jones
2023-08-23 8:07 ` Lee Jones [this message]
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=20230823080702.GA2472023@google.com \
--to=lee@kernel.org \
--cc=baijiaju1990@gmail.com \
--cc=clm@fb.com \
--cc=dsterba@suse.com \
--cc=dsterba@suse.cz \
--cc=josef@toxicpanda.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-kernel@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