From: Qu Wenruo <wqu@suse.com>
To: Hrutvik Kanabar <hrkanabar@gmail.com>,
Hrutvik Kanabar <hrutvik@google.com>
Cc: Marco Elver <elver@google.com>,
Aleksandr Nogikh <nogikh@google.com>,
kasan-dev@googlegroups.com,
Alexander Viro <viro@zeniv.linux.org.uk>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
Theodore Ts'o <tytso@mit.edu>,
Andreas Dilger <adilger.kernel@dilger.ca>,
linux-ext4@vger.kernel.org, Chris Mason <clm@fb.com>,
Josef Bacik <josef@toxicpanda.com>,
David Sterba <dsterba@suse.com>,
linux-btrfs@vger.kernel.org, Jaegeuk Kim <jaegeuk@kernel.org>,
Chao Yu <chao@kernel.org>,
linux-f2fs-devel@lists.sourceforge.net,
"Darrick J . Wong" <djwong@kernel.org>,
linux-xfs@vger.kernel.org, Namjae Jeon <linkinjeon@kernel.org>,
Sungjong Seo <sj1557.seo@samsung.com>,
Anton Altaparmakov <anton@tuxera.com>,
linux-ntfs-dev@lists.sourceforge.net
Subject: Re: [PATCH RFC 3/7] fs/btrfs: support `DISABLE_FS_CSUM_VERIFICATION` config option
Date: Fri, 14 Oct 2022 18:23:39 +0800 [thread overview]
Message-ID: <5bc906b3-ccb5-a385-fcb6-fc51c8fea3fd@suse.com> (raw)
In-Reply-To: <20221014084837.1787196-4-hrkanabar@gmail.com>
On 2022/10/14 16:48, Hrutvik Kanabar wrote:
> From: Hrutvik Kanabar <hrutvik@google.com>
>
> When `DISABLE_FS_CSUM_VERIFICATION` is enabled, bypass checksum
> verification.
>
> Signed-off-by: Hrutvik Kanabar <hrutvik@google.com>
I always want more fuzz for btrfs, so overall this is pretty good.
But there are some comments related to free space cache part.
Despite the details, I'm wondering would it be possible for your fuzzing
tool to do a better job at user space? Other than relying on loosen
checks from kernel?
For example, implement a (mostly) read-only tool to do the following
workload:
- Open the fs
Including understand the checksum algo, how to re-generate the csum.
- Read out the used space bitmap
In btrfs case, it's going to read the extent tree, process the
backrefs items.
- Choose the victim sectors and corrupt them
Obviously, vitims should be choosen from above used space bitmap.
- Re-calculate the checksum for above corrupted sectors
For btrfs, if it's a corrupted metadata, re-calculate the checksum.
By this, we can avoid such change to kernel, and still get a much better
coverage.
If you need some help on such user space tool, I'm pretty happy to
provide help.
> ---
> fs/btrfs/check-integrity.c | 3 ++-
> fs/btrfs/disk-io.c | 6 ++++--
> fs/btrfs/free-space-cache.c | 3 ++-
> fs/btrfs/inode.c | 3 ++-
> fs/btrfs/scrub.c | 9 ++++++---
> 5 files changed, 16 insertions(+), 8 deletions(-)
>
> diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
> index 98c6e5feab19..eab82593a325 100644
> --- a/fs/btrfs/check-integrity.c
> +++ b/fs/btrfs/check-integrity.c
> @@ -1671,7 +1671,8 @@ static noinline_for_stack int btrfsic_test_for_metadata(
> crypto_shash_update(shash, data, sublen);
> }
> crypto_shash_final(shash, csum);
> - if (memcmp(csum, h->csum, fs_info->csum_size))
> + if (!IS_ENABLED(CONFIG_DISABLE_FS_CSUM_VERIFICATION) &&
> + memcmp(csum, h->csum, fs_info->csum_size))
> return 1;
>
> return 0; /* is metadata */
> diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
> index a2da9313c694..7cd909d44b24 100644
> --- a/fs/btrfs/disk-io.c
> +++ b/fs/btrfs/disk-io.c
> @@ -184,7 +184,8 @@ static int btrfs_check_super_csum(struct btrfs_fs_info *fs_info,
> crypto_shash_digest(shash, raw_disk_sb + BTRFS_CSUM_SIZE,
> BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE, result);
>
> - if (memcmp(disk_sb->csum, result, fs_info->csum_size))
> + if (!IS_ENABLED(CONFIG_DISABLE_FS_CSUM_VERIFICATION) &&
> + memcmp(disk_sb->csum, result, fs_info->csum_size))
> return 1;
>
> return 0;
> @@ -494,7 +495,8 @@ static int validate_extent_buffer(struct extent_buffer *eb)
> header_csum = page_address(eb->pages[0]) +
> get_eb_offset_in_page(eb, offsetof(struct btrfs_header, csum));
>
> - if (memcmp(result, header_csum, csum_size) != 0) {
> + if (!IS_ENABLED(CONFIG_DISABLE_FS_CSUM_VERIFICATION) &&
> + memcmp(result, header_csum, csum_size) != 0) {
I believe this is the main thing fuzzing would take advantage of.
It would be much better if this is the only override...
> btrfs_warn_rl(fs_info,
> "checksum verify failed on logical %llu mirror %u wanted " CSUM_FMT " found " CSUM_FMT " level %d",
> eb->start, eb->read_mirror,
> diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
> index f4023651dd68..203c8a9076a6 100644
> --- a/fs/btrfs/free-space-cache.c
> +++ b/fs/btrfs/free-space-cache.c
> @@ -574,7 +574,8 @@ static int io_ctl_check_crc(struct btrfs_io_ctl *io_ctl, int index)
> io_ctl_map_page(io_ctl, 0);
> crc = btrfs_crc32c(crc, io_ctl->orig + offset, PAGE_SIZE - offset);
> btrfs_crc32c_final(crc, (u8 *)&crc);
> - if (val != crc) {
> + if (!IS_ENABLED(CONFIG_DISABLE_FS_CSUM_VERIFICATION) &&
> + val != crc) {
I'm already seeing this to cause problems, especially for btrfs.
Btrfs has a very strong dependency on free space tracing, as all of our
metadata (and data by default) relies on COW to keep the fs consistent.
I tried a lot of different methods in the past to make sure we won't
write into previously used space, but it's causing a lot of performance
impact.
Unlike tree-checker, we can not easily got a centerlized space to handle
all the free space cross-check thing (thus it's only verified by things
like btrfs-check).
Furthermore, even if you skip this override, with latest default
free-space-tree feature, free space info is stored in regular btrfs
metadata (tree blocks), with regular metadata checksum protection.
Thus I'm pretty sure we will have tons of reports on this, and
unfortunately we can only go whac-a-mole way for it.
> btrfs_err_rl(io_ctl->fs_info,
> "csum mismatch on free space cache");
> io_ctl_unmap_page(io_ctl);
> diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
> index b0807c59e321..1a49d897b5c1 100644
> --- a/fs/btrfs/inode.c
> +++ b/fs/btrfs/inode.c
> @@ -3434,7 +3434,8 @@ int btrfs_check_sector_csum(struct btrfs_fs_info *fs_info, struct page *page,
> crypto_shash_digest(shash, kaddr, fs_info->sectorsize, csum);
> kunmap_local(kaddr);
>
> - if (memcmp(csum, csum_expected, fs_info->csum_size))
> + if (!IS_ENABLED(CONFIG_DISABLE_FS_CSUM_VERIFICATION) &&
> + memcmp(csum, csum_expected, fs_info->csum_size))
This skips data csum check, I don't know how valueable it is, but this
should be harmless mostly.
If we got reports related to this, it would be a nice surprise.
> return -EIO;
> return 0;
> }
> diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
> index f260c53829e5..a7607b492f47 100644
> --- a/fs/btrfs/scrub.c
> +++ b/fs/btrfs/scrub.c
> @@ -1997,7 +1997,8 @@ static int scrub_checksum_data(struct scrub_block *sblock)
>
> crypto_shash_digest(shash, kaddr, fs_info->sectorsize, csum);
>
> - if (memcmp(csum, sector->csum, fs_info->csum_size))
> + if (!IS_ENABLED(CONFIG_DISABLE_FS_CSUM_VERIFICATION) &&
> + memcmp(csum, sector->csum, fs_info->csum_size))
Same as data csum verification overide.
Not necessary/useful but good to have.
> sblock->checksum_error = 1;
> return sblock->checksum_error;
> }
> @@ -2062,7 +2063,8 @@ static int scrub_checksum_tree_block(struct scrub_block *sblock)
> }
>
> crypto_shash_final(shash, calculated_csum);
> - if (memcmp(calculated_csum, on_disk_csum, sctx->fs_info->csum_size))
> + if (!IS_ENABLED(CONFIG_DISABLE_FS_CSUM_VERIFICATION) &&
> + memcmp(calculated_csum, on_disk_csum, sctx->fs_info->csum_size))
This is much less valueable, since it's only affecting scrub, and scrub
itself is already very little checking the content of metadata.
Thanks,
Qu
> sblock->checksum_error = 1;
>
> return sblock->header_error || sblock->checksum_error;
> @@ -2099,7 +2101,8 @@ static int scrub_checksum_super(struct scrub_block *sblock)
> crypto_shash_digest(shash, kaddr + BTRFS_CSUM_SIZE,
> BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE, calculated_csum);
>
> - if (memcmp(calculated_csum, s->csum, sctx->fs_info->csum_size))
> + if (!IS_ENABLED(CONFIG_DISABLE_FS_CSUM_VERIFICATION) &&
> + memcmp(calculated_csum, s->csum, sctx->fs_info->csum_size))
> ++fail_cor;
>
> return fail_cor + fail_gen;
next prev parent reply other threads:[~2022-10-14 10:24 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-14 8:48 [PATCH RFC 0/7] fs: Debug config option to disable filesystem checksum verification for fuzzing Hrutvik Kanabar
2022-10-14 8:48 ` [PATCH RFC 1/7] fs: create `DISABLE_FS_CSUM_VERIFICATION` config option Hrutvik Kanabar
2022-10-14 8:48 ` [PATCH RFC 2/7] fs/ext4: support " Hrutvik Kanabar
2022-10-14 8:48 ` [PATCH RFC 3/7] fs/btrfs: " Hrutvik Kanabar
2022-10-14 10:23 ` Qu Wenruo [this message]
2022-10-17 8:43 ` Dmitry Vyukov
2022-10-17 9:35 ` Qu Wenruo
2022-10-14 8:48 ` [PATCH RFC 4/7] fs/exfat: " Hrutvik Kanabar
2022-10-14 8:48 ` [PATCH RFC 5/7] fs/xfs: " Hrutvik Kanabar
2022-10-14 15:44 ` Darrick J. Wong
2022-10-17 8:32 ` Dmitry Vyukov
2022-10-14 8:48 ` [PATCH RFC 6/7] fs/ntfs: " Hrutvik Kanabar
2022-10-14 8:48 ` [PATCH RFC 7/7] fs/f2fs: " Hrutvik Kanabar
2022-10-14 9:15 ` [PATCH RFC 0/7] fs: Debug config option to disable filesystem checksum verification for fuzzing David Sterba
2022-10-17 8:31 ` Dmitry Vyukov
2022-10-17 12:02 ` David Sterba
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=5bc906b3-ccb5-a385-fcb6-fc51c8fea3fd@suse.com \
--to=wqu@suse.com \
--cc=adilger.kernel@dilger.ca \
--cc=anton@tuxera.com \
--cc=chao@kernel.org \
--cc=clm@fb.com \
--cc=djwong@kernel.org \
--cc=dsterba@suse.com \
--cc=elver@google.com \
--cc=hrkanabar@gmail.com \
--cc=hrutvik@google.com \
--cc=jaegeuk@kernel.org \
--cc=josef@toxicpanda.com \
--cc=kasan-dev@googlegroups.com \
--cc=linkinjeon@kernel.org \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-ntfs-dev@lists.sourceforge.net \
--cc=linux-xfs@vger.kernel.org \
--cc=nogikh@google.com \
--cc=sj1557.seo@samsung.com \
--cc=tytso@mit.edu \
--cc=viro@zeniv.linux.org.uk \
/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).