All of lore.kernel.org
 help / color / mirror / Atom feed
From: yangerkun <yangerkun@huawei.com>
To: Theodore Ts'o <tytso@mit.edu>, Jan Kara <jack@suse.cz>
Cc: <linux-ext4@vger.kernel.org>, <yukuai3@huawei.com>
Subject: Re: [PATCH 2/2] ext4: check magic even the extent block bh is verified
Date: Mon, 25 Oct 2021 09:10:29 +0800	[thread overview]
Message-ID: <e61a2f3c-9aae-9e7d-5027-bec0ec017ef7@huawei.com> (raw)
In-Reply-To: <91ba3949-3ee3-e661-aad5-61e6ddc1b9d1@huawei.com>



在 2021/10/14 15:21, yangerkun 写道:
> 
> 在 2021/10/1 22:09, Theodore Ts'o 写道:
>> On Fri, Oct 01, 2021 at 11:18:33AM +0200, Jan Kara wrote:
>>>>
>>>> Digging deep and we found it's actually a xattr block which can 
>>>> happened
>>>> with follow steps:
>>>>
>>>> 1. extent update for file1 and will remove a leaf extent block(block A)
>>>> 2. we need update the idx extent block too
>>>> 3. block A has been allocated as a xattr block and will set verified
>>>> 3. io error happened for this idx block and will the buffer has been
>>>>     released late
>>>> 4. extent find for file1 will read the idx block and see block A again
>>>> 5. since the buffer of block A is already verified, we will use it
>>>>     directly, which can lead the upper OOB
>>>>
>>>> Same as __ext4_xattr_check_block, we can check magic even the buffer is
>>>> verified to fix the problem.
>>>>
>>>> Signed-off-by: yangerkun <yangerkun@huawei.com>
>>>
>>> Honestly, I'm not sure if this is worth it. What you suggest will 
>>> work if
>>> the magic is overwritten but if we reallocate the block for something 
>>> else
>>> but the magic happens to stay intact, we have a problem. The 
>>> filesystem is
>>> corrupted at that point with metadata blocks being multiply claimed and
>>> that's very difficult to deal with. Maybe we should start ignoring
>>> buffer_verified() bit once the fs is known to have errors and recheck 
>>> the
>>> buffer contents on each access? Sure it will be slow but I have little
>>> sympathy towards people running filesystems with errors... What do 
>>> people
>>> think?
>>
>> At some point, if we transition away from using buffer_heads for the
>> jbd2 layer, and use our own ext4_metadata_buf structure which
>> incorporates the journal_head and buffer_head fields, this will allow
>> us to control our own writeback, and allow us to have our own error
>> callbacks so we can do things like declare an inode to be bad and not
>> to be referenced again.  This would allow us to have a metadata type
>> field, so we could know that a buffer had been verified as an inode
>> table block, or bitmap block, or an xattr block.
>>
>> However, I think the bigger issue is that even if we had a metadata
>> type field in the buffer_head (or ext4_metadata_buf), we should be
>> using the metadata validation, and buffer_verified bit, as a backup.
>> It should not be the primary line of defense.
>>
>> So what I would suggest doing is preventing the out of bounds
>> reference in ext4_find_extent() in the first place.  I note we're not
>> sanity checking the values of EXT4_{FIRST,LAST}_{EXTENT,INDEX} used in
>> ext4_ext_binsearch() and ext4_ext_binsearch_idx(), and that's probably
>> how we triggered the out of bounds read in the first place.  The cost
>> of making sure that pointers returned by
>> EXT4_{FIRST,LAST}_{EXTENT,INDEX} don't exceed the bounds of the extent
>> tree node would be minimal, and it would be an additional cross check
>> which would protect us against the buffer getting corrupted while in
>> memory (bit flips, or wild pointer dereferences).
> 
> Sorry for the latter replay.
> 
> This can prevent a corrupt extent block buffer(maybe a xattr block for 
> another file) with verified trigger the OOB. But once corrupt data in 
> extent block buffer won't trigger OOB. We pass the check and will use a 
> xattr block's data as a extent block. This may trigger other 
> unpredictable result...
> 
> The patch I send check the magic to ensure the block is really a extent 
> block which prevent this case. But for the case a extent block been 
> reallocated as another file's extent block. This seems useless and will 
> lead to some problem too. But we may first stop the unpredictable result 
> like the OOB or other error.

Hi,

Does there some advise for this...

Thanks,
Kun.

> 
>>
>> Cheers,
>>
>>                         - Ted
>> .
>>
> .

  reply	other threads:[~2021-10-25  1:10 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-04  4:49 [PATCH 0/2] bugfix for read_extent_tree_block yangerkun
2021-09-04  4:49 ` [PATCH 1/2] ext4: avoid recheck extent for EXT4_EX_FORCE_CACHE yangerkun
2021-10-01  9:04   ` Jan Kara
2021-09-04  4:49 ` [PATCH 2/2] ext4: check magic even the extent block bh is verified yangerkun
2021-10-01  9:18   ` Jan Kara
2021-10-01 14:09     ` Theodore Ts'o
2021-10-14  7:21       ` yangerkun
2021-10-25  1:10         ` yangerkun [this message]
2021-10-08  1:38     ` yangerkun
2021-09-24  9:32 ` [PATCH 0/2] bugfix for read_extent_tree_block yangerkun

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=e61a2f3c-9aae-9e7d-5027-bec0ec017ef7@huawei.com \
    --to=yangerkun@huawei.com \
    --cc=jack@suse.cz \
    --cc=linux-ext4@vger.kernel.org \
    --cc=tytso@mit.edu \
    --cc=yukuai3@huawei.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.