All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anand Jain <anand.jain@oracle.com>
To: Johannes Thumshirn <Johannes.Thumshirn@wdc.com>,
	David Sterba <dsterba@suse.com>
Cc: "linux-btrfs@vger.kernel.org" <linux-btrfs@vger.kernel.org>,
	Nikolay Borisov <nborisov@suse.com>,
	"syzbot+582e66e5edf36a22c7b0@syzkaller.appspotmail.com" 
	<syzbot+582e66e5edf36a22c7b0@syzkaller.appspotmail.com>
Subject: Re: [PATCH v2] btrfs: don't access possibly stale fs_info data for printing duplicate device
Date: Tue, 17 Nov 2020 18:50:39 +0800	[thread overview]
Message-ID: <4ff4fd75-8867-9a32-580a-2d84768f8063@oracle.com> (raw)
In-Reply-To: <SN4PR0401MB359815F550099C9117016F359BE20@SN4PR0401MB3598.namprd04.prod.outlook.com>



On 17/11/20 4:19 pm, Johannes Thumshirn wrote:
> On 17/11/2020 08:20, Anand Jain wrote:
>>    This patch fixes the issue in a very gross way, as I mentioned.
> 
> I know but I've not found a better way.
> 

>>    Instead, do we know more about what/how threads were racing,
>>    leading to the access of the freed fs_info?
> 




> If I read the reproducer code correctly it's just mounting a crafted
> image twice via different /dev/loop devices.
> 
> This image is rejected by the mount code, because it can't read the chunk
> tree.
 >
> As far as I've debugged it down scan_one_device() is racing with
> deactivate_locked_super(), so fs_info->sb can already be freed, when
> device_list_add() calls btrfs_warn_in_rcu(device->fs_info,...) leading
> to a use-after-free in btrfs_printk() accessing fs_info->sb_s_id.
> 

  This explains the problem how it happened, IMO this should go into the
  change log.

> It feels like we're missing a mutex_lock(&uuid_mutex) in btrfs_kill_super()

  Yes.
  But uuid_mutex (or device_list_mutex) is too sever for a simple
  problem, and there are other constraints with device_list_mutex.

  Ok let us take out use of fs_info from the device_list_add().

  I am ok with either NO_FS_INFO approach or just NULL.

Thanks, Anand

> but this hasn't led me to anything.

> 
> I'm all ears for a pointer to the correct fix.
> 



      reply	other threads:[~2020-11-17 10:50 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-16  7:52 [PATCH v2] btrfs: don't access possibly stale fs_info data for printing duplicate device Johannes Thumshirn
2020-11-16  7:59 ` Nikolay Borisov
2020-11-16 15:38 ` David Sterba
2020-11-17  7:20 ` Anand Jain
2020-11-17  8:19   ` Johannes Thumshirn
2020-11-17 10:50     ` Anand Jain [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=4ff4fd75-8867-9a32-580a-2d84768f8063@oracle.com \
    --to=anand.jain@oracle.com \
    --cc=Johannes.Thumshirn@wdc.com \
    --cc=dsterba@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=nborisov@suse.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.