From: Anand Jain <anand.jain@oracle.com>
To: Josef Bacik <josef@toxicpanda.com>, linux-btrfs@vger.kernel.org
Cc: syzbot+4cfe71a4da060be47502@syzkaller.appspotmail.com
Subject: Re: [PATCH add reported by] btrfs: fix rw_devices count in __btrfs_free_extra_devids
Date: Wed, 23 Sep 2020 12:42:07 +0800 [thread overview]
Message-ID: <3d5fdbd9-7a2c-d17f-62b7-f312042c7e0a@oracle.com> (raw)
In-Reply-To: <4f924276-2db3-daba-32ec-1b2cf077d15d@toxicpanda.com>
On 22/9/20 9:08 pm, Josef Bacik wrote:
> On 9/22/20 8:33 AM, Anand Jain wrote:
>> syzbot reported a warning [1] in close_fs_devcies() which it reproduces
>> using a crafted image.
>>
>> WARN_ON(fs_devices->rw_devices);
>>
>> The crafted image successfully creates a replace-device with the devid 0.
>> But as there isn't any replace-item. We clean the extra the devid 0, at
>> __btrfs_free_extra_devids().
>>
>> rw_devices is incremented in btrfs_open_one_device() for all write-able
>> devices except for devid == BTRFS_DEV_REPLACE_DEVID.
>> But while we clean up the extra devices in __btrfs_free_extra_devids()
>> we used the BTRFS_DEV_STATE_REPLACE_TGT flag which isn't set because
>> there isn't the replace-item. So rw_devices went below zero.
>>
>> So let __btrfs_free_extra_devids() also depend on the
>> devid != BTRFS_DEV_REPLACE_DEVID to manage the rw_devices.
>>
>
> This is an invalid state for the fs to be in,
OK, to be more specific. There is an alien device that is pretending to
be the replace-target (devid = 0).
> I'd rather fix it by
> detecting we have a devid == BTRFS_DEV_REPLACE_DEVID with no
> corresponding dev_replace item and fail out before we get to this
> point. Thanks,
Yes. __btrfs_free_extra_devids() is already doing in a way the same.
------------------------------------
1040 static void __btrfs_free_extra_devids(struct btrfs_fs_devices
*fs_devices,
::
1059 if (device->devid == BTRFS_DEV_REPLACE_DEVID) {
::
1070 if (step == 0 || test_bit(BTRFS_DEV_STATE_REPLACE_TGT,
1071 &device->dev_state)) {
1072 continue;
1073 }
------------------------------------
OR I did not understand what do you mean.
Thanks, Anand
>
> Josef
next prev parent reply other threads:[~2020-09-23 4:42 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-22 12:30 [PATCH] btrfs: fix rw_devices count in __btrfs_free_extra_devids Anand Jain
2020-09-22 12:33 ` [PATCH add reported by] " Anand Jain
2020-10-06 13:08 ` [PATCH] btrfs: fix devid 0 without a replace item by failing the mount Anand Jain
2020-10-06 13:12 ` [PATCH v2] " Anand Jain
2020-10-12 5:26 ` [PATCH v2 add prerequisite-patch-id] " Anand Jain
2020-10-21 4:02 ` [PATCH RESEND " Anand Jain
2020-10-21 5:49 ` kernel test robot
2020-10-06 14:54 ` [PATCH] " kernel test robot
2020-10-07 2:07 ` Anand Jain
2020-10-12 2:51 ` [kbuild-all] " Rong Chen
2020-10-06 16:44 ` kernel test robot
2020-09-22 13:08 ` [PATCH add reported by] btrfs: fix rw_devices count in __btrfs_free_extra_devids Josef Bacik
2020-09-23 4:42 ` Anand Jain [this message]
2020-09-23 13:42 ` Josef Bacik
2020-09-24 5:19 ` Anand Jain
2020-09-24 11:25 ` David Sterba
2020-09-24 14:02 ` Josef Bacik
2020-09-25 10:11 ` Anand Jain
2020-09-25 14:28 ` Josef Bacik
2020-10-06 13:12 ` Anand Jain
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=3d5fdbd9-7a2c-d17f-62b7-f312042c7e0a@oracle.com \
--to=anand.jain@oracle.com \
--cc=josef@toxicpanda.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=syzbot+4cfe71a4da060be47502@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;
as well as URLs for NNTP newsgroup(s).