mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Sterba <dsterba@suse.cz>
To: Anand Jain <anand.jain@oracle.com>
Cc: Dongliang Mu <dzm91@hust.edu.cn>,
	Dongliang Mu <mudongliangabcd@gmail.com>,
	linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org,
	Chris Mason <clm@fb.com>,
	syzbot+82650a4e0ed38f218363@syzkaller.appspotmail.com,
	Josef Bacik <josef@toxicpanda.com>,
	dsterba@suse.cz, David Sterba <dsterba@suse.com>
Subject: Re: [PATCH] btrfs: don't access possibly stale fs_info data in device_list_add
Date: Fri, 4 Mar 2022 14:50:49 +0100	[thread overview]
Message-ID: <20220304135049.GY12643@twin.jikos.cz> (raw)
In-Reply-To: <e3f0ab62-3d1f-a316-2d7b-a0b791120f87@oracle.com>

On Fri, Mar 04, 2022 at 07:53:27AM +0800, Anand Jain wrote:
> On 04/03/2022 02:24, David Sterba wrote:
> > On Thu, Mar 03, 2022 at 10:40:27PM +0800, Dongliang Mu wrote:
> >>
> >> Fix this by modifying device->fs_info to NULL too.
> >>
> >> Reported-and-tested-by: syzbot+82650a4e0ed38f218363@syzkaller.appspotmail.com
> >> Signed-off-by: Dongliang Mu <mudongliangabcd@gmail.com>
> >> ---
> >>   fs/btrfs/volumes.c | 2 +-
> >>   1 file changed, 1 insertion(+), 1 deletion(-)
> >>
> >> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> >> index b07d382d53a8..c1325bdae9a1 100644
> >> --- a/fs/btrfs/volumes.c
> >> +++ b/fs/btrfs/volumes.c
> >> @@ -954,7 +954,7 @@ static noinline struct btrfs_device *device_list_add(const char *path,
> >>   						  task_pid_nr(current));
> >>   				return ERR_PTR(-EEXIST);
> >>   			}
> >> -			btrfs_info_in_rcu(device->fs_info,
> >> +			btrfs_info_in_rcu(NULL,
> > 
> > A few lines above this is also NULL and was fixed by 0697d9a61099
> > ("btrfs: don't access possibly stale fs_info data for printing duplicate
> > device"), so yeah we probably need the same here.
> 
> So it appears that device->fs_info was garbage instead of NULL OR
> fs_info->sb was NULL?

I think it's a warning that something could happen, in this case
potential garbage value of fs_info.

> Because we always had a check if fs_info is null in btrfs_printk()
> further the commit a0f6d924cada ("btrfs: remove stub device info from
> messages when we have no fs_info") made it better.

Yeah, that's removing a potential crash but still the NULL value could
come from a freed memory. Seems taht we can't rely on fs_info in
device_list_add at all and passing NULL is the only safe way.

  reply	other threads:[~2022-03-04 13:54 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-03 14:40 Dongliang Mu
2022-03-03 18:24 ` David Sterba
2022-03-03 23:53   ` Anand Jain
2022-03-04 13:50     ` David Sterba [this message]
2022-03-04 14:07 ` 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=20220304135049.GY12643@twin.jikos.cz \
    --to=dsterba@suse.cz \
    --cc=anand.jain@oracle.com \
    --cc=clm@fb.com \
    --cc=dsterba@suse.com \
    --cc=dzm91@hust.edu.cn \
    --cc=josef@toxicpanda.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mudongliangabcd@gmail.com \
    --cc=syzbot+82650a4e0ed38f218363@syzkaller.appspotmail.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

all inboxes | Powered by JetHome®