Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: Nikolay Borisov <nborisov@suse.com>
To: Johannes Thumshirn <johannes.thumshirn@wdc.com>,
	David Sterba <dsterba@suse.com>
Cc: linux-btrfs@vger.kernel.org, Anand Jain <anand.jain@oracle.com>,
	syzbot+582e66e5edf36a22c7b0@syzkaller.appspotmail.com
Subject: Re: [PATCH] btrfs: don't access possibly stale fs_info data for printing duplicate device
Date: Thu, 12 Nov 2020 14:02:58 +0200	[thread overview]
Message-ID: <3454d885-21db-199a-76bf-0da6f9971671@suse.com> (raw)
In-Reply-To: <2bb63b693331e27b440768b163a84935fe01edda.1605182240.git.johannes.thumshirn@wdc.com>



On 12.11.20 г. 13:59 ч., Johannes Thumshirn wrote:
> Syzbot reported a possible use-after-free when printing a duplicate device
> warning device_list_add().
> 
> At this point it can happen that a btrfs_device::fs_info is not correctly
> setup yet, so we're accessing stale data, when printing the warning
> message using the btrfs_printk() wrappers.
> 
> Instead of printing possibly uninitialized or already freed memory in
> btrfs_printk(), use a normal pr_warn().
> 
> Reported-by: syzbot+582e66e5edf36a22c7b0@syzkaller.appspotmail.com
> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

Reviewed-by: Nikolay Borisov <nborisov@suse.com> , though see below for
a suggestion.

> ---
> 
> This is an alternative and IMHO simpler aproach to what Anand proposed in
> https://lore.kernel.org/linux-btrfs/20200114060920.4527-2-anand.jain@oracle.com/T/
> 
> 
>  fs/btrfs/volumes.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index bb1aa96e1233..eb1af5e3d596 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -940,8 +940,8 @@ static noinline struct btrfs_device *device_list_add(const char *path,
>  			if (device->bdev != path_bdev) {
>  				bdput(path_bdev);
>  				mutex_unlock(&fs_devices->device_list_mutex);
> -				btrfs_warn_in_rcu(device->fs_info,
> -	"duplicate device %s devid %llu generation %llu scanned by %s (%d)",
> +				pr_warn(
> +	"BTRFS: duplicate device %s devid %llu generation %llu scanned by %s (%d)",
>  						  path, devid, found_transid,
>  						  current->comm,
>  						  task_pid_nr(current));
> 


Would a simple 'if()' here catch the case where fs_info is not
initialized essentially open-coding what Anand has proposed? My idea is
to be able to provide the filesystem id when we can (best effort) and
simply use pr_warn otherwise, but without having to change the internals
of btrfs_printk and instead handle the single problematic call site ?

  reply	other threads:[~2020-11-12 12:03 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-12 11:59 [PATCH] btrfs: don't access possibly stale fs_info data for printing duplicate device Johannes Thumshirn
2020-11-12 12:02 ` Nikolay Borisov [this message]
2020-11-12 12:09   ` Johannes Thumshirn
2020-11-12 12:25     ` Nikolay Borisov
2020-11-13 16:53     ` David Sterba
2020-11-13 16:57       ` David Sterba
2020-11-13 18:41         ` Johannes Thumshirn
2020-11-13 18:45           ` Johannes Thumshirn

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=3454d885-21db-199a-76bf-0da6f9971671@suse.com \
    --to=nborisov@suse.com \
    --cc=anand.jain@oracle.com \
    --cc=dsterba@suse.com \
    --cc=johannes.thumshirn@wdc.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=syzbot+582e66e5edf36a22c7b0@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