public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <wqu@suse.com>
To: Josef Bacik <josef@toxicpanda.com>,
	Qu Wenruo <quwenruo.btrfs@gmx.com>,
	linux-btrfs@vger.kernel.org
Subject: Re: [PATCH v3 3/5] btrfs: Detect unbalanced tree with empty leaf before crashing btree operations
Date: Wed, 12 Aug 2020 09:53:18 +0800	[thread overview]
Message-ID: <442f2087-d0e0-ebb9-06f1-7a97d7557204@suse.com> (raw)
In-Reply-To: <727019b8-254f-d2eb-f886-3f46e7b522c7@toxicpanda.com>



On 2020/8/12 上午9:50, Josef Bacik wrote:
> On 8/11/20 8:29 PM, Qu Wenruo wrote:
>>
>>
>> On 2020/8/12 上午8:23, Josef Bacik wrote:
>>> On 8/11/20 7:04 PM, Qu Wenruo wrote:
>>>>
>>>>
>> [...]
>>>>> Which I assume is the problem?  The generation is 19, is that >
>>>>> last_trans_committed?  Seems like this check just needs to be moved
>>>>> lower, right?  Thanks,
>>>>
>>>> Nope, that generation 19 is valid. That fs has a higher generation, so
>>>> that's completely valid.
>>>>
>>>> The generation 19 is there because there is another csum leaf whose
>>>> generation is 19.
>>>>
>>>
>>> Then this patch does nothing, because we already have this check lower,
>>> so how exactly did it make the panic go away?  Thanks,
>>>
>>> Josef
>>
>> Sorry, I don't get your point.
>>
>> The generation 19 isn't larger than last_trans_committed, so that check
>> has nothing to do with this case.
>>
>> And then it goes to the header_nritems() check, which is 0, and with
>> first_key present, which is invalid and we error out, rejecting the
>> corrupted leaf.
>>
>> What's the problem then?
> 
> 
>         /* We have @first_key, so this @eb must have at least one item */
>         if (btrfs_header_nritems(eb) == 0) {
>                 btrfs_err(fs_info,
>                 "invalid tree nritems, bytenr=%llu nritems=0 expect >0",
>                           eb->start);
>                 WARN_ON(IS_ENABLED(CONFIG_BTRFS_DEBUG));
>                 return -EUCLEAN;
>         }
> 
>         /*
>          * For live tree block (new tree blocks in current transaction),
>          * we need proper lock context to avoid race, which is
> impossible here.
>          * So we only checks tree blocks which is read from disk, whose
>          * generation <= fs_info->last_trans_committed.
>          */
>         if (btrfs_header_generation(eb) > fs_info->last_trans_committed)
>                 return 0;
> 
>         /* We have @first_key, so this @eb must have at least one item */
>         if (btrfs_header_nritems(eb) == 0) {
>                 btrfs_err(fs_info,
>                 "invalid tree nritems, bytenr=%llu nritems=0 expect >0",
>                           eb->start);
>                 WARN_ON(IS_ENABLED(CONFIG_BTRFS_DEBUG));
>                 return -EUCLEAN;
>         }
> 
> 
> This is the code, you have the exact same check above the header
> generation thing, and that's not the problem, so I don't understand why
> you have added this check.

Oh, you're right.

A bad auto merge, which we have merged the same patch before...

Thanks for spotting this!
Qu
> 
> Josef
> 


  reply	other threads:[~2020-08-12  1:53 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-09 12:09 [PATCH v3 0/5] btrfs: Enhanced runtime defence against fuzzed images Qu Wenruo
2020-08-09 12:09 ` [PATCH v3 1/5] btrfs: extent_io: Do extra check for extent buffer read write functions Qu Wenruo
2020-08-11 18:42   ` Josef Bacik
2020-08-09 12:09 ` [PATCH v3 2/5] btrfs: extent-tree: Kill BUG_ON() in __btrfs_free_extent() and do better comment Qu Wenruo
2020-08-11 18:45   ` Josef Bacik
2020-08-09 12:09 ` [PATCH v3 3/5] btrfs: Detect unbalanced tree with empty leaf before crashing btree operations Qu Wenruo
2020-08-11 18:48   ` Josef Bacik
2020-08-11 23:04     ` Qu Wenruo
2020-08-12  0:23       ` Josef Bacik
2020-08-12  0:29         ` Qu Wenruo
2020-08-12  1:50           ` Josef Bacik
2020-08-12  1:53             ` Qu Wenruo [this message]
2020-08-09 12:09 ` [PATCH v3 4/5] btrfs: extent-tree: Kill the BUG_ON() in insert_inline_extent_backref() Qu Wenruo
2020-08-11 18:50   ` Josef Bacik
2020-08-09 12:09 ` [PATCH v3 5/5] btrfs: ctree: Checking key orders before merged tree blocks Qu Wenruo
2020-08-11 18:53   ` Josef Bacik

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=442f2087-d0e0-ebb9-06f1-7a97d7557204@suse.com \
    --to=wqu@suse.com \
    --cc=josef@toxicpanda.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=quwenruo.btrfs@gmx.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