* [PATCH 0/2] btrfs-progs: make corrupt-block metadata geneartion corruption work again
@ 2022-09-13 7:19 Qu Wenruo
2022-09-13 7:19 ` [PATCH 1/2] btrfs-progs: unexport csum_tree_block() Qu Wenruo
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Qu Wenruo @ 2022-09-13 7:19 UTC (permalink / raw)
To: linux-btrfs
This is preparing for the incoming metadata validation refactor in
kernel, thus I need a way to corrupt transid reliably with correct
checksum.
The first patch is to unexport csum_tree_block() which also has a stale
definition .
The second patch is to fix the csum for metadata block with corrupted
generation.
Now btrfs-corrupt-block can properly corrupt the generation of a tree
block.
(But unfortunately it corrupts all copies, which is still not exactly
what I need, but is already good enough)
Qu Wenruo (2):
btrfs-progs: unexport csum_tree_block()
btrfs-progs: corrupt-block: re-generate the checksum for generation
corruption
btrfs-corrupt-block.c | 2 ++
common/utils.h | 2 --
kernel-shared/disk-io.c | 4 ++--
3 files changed, 4 insertions(+), 4 deletions(-)
--
2.37.3
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] btrfs-progs: unexport csum_tree_block()
2022-09-13 7:19 [PATCH 0/2] btrfs-progs: make corrupt-block metadata geneartion corruption work again Qu Wenruo
@ 2022-09-13 7:19 ` Qu Wenruo
2022-09-13 7:19 ` [PATCH 2/2] btrfs-progs: corrupt-block: re-generate the checksum for generation corruption Qu Wenruo
2022-09-15 14:34 ` [PATCH 0/2] btrfs-progs: make corrupt-block metadata geneartion corruption work again David Sterba
2 siblings, 0 replies; 4+ messages in thread
From: Qu Wenruo @ 2022-09-13 7:19 UTC (permalink / raw)
To: linux-btrfs
The function csum_tree_block() is not really utilized by anyone, all
current callers just use csum_tree_block_size().
Furthermore there is a stale definition in common/utils.h which is using
the old "struct btrfs_root" as the first argument, while we have already
migrated to "struct btrfs_fs_info".
So just unexport csum_tree_block() and remove the stale definition.
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
common/utils.h | 2 --
kernel-shared/disk-io.c | 4 ++--
2 files changed, 2 insertions(+), 4 deletions(-)
diff --git a/common/utils.h b/common/utils.h
index ea05fe5b21fe..f6cdb7f4dc70 100644
--- a/common/utils.h
+++ b/common/utils.h
@@ -61,8 +61,6 @@ int set_label(const char *btrfs_dev, const char *label);
int check_arg_type(const char *input);
int get_label_mounted(const char *mount_path, char *labelp);
int get_label_unmounted(const char *dev, char *label);
-int csum_tree_block(struct btrfs_fs_info *root, struct extent_buffer *buf,
- int verify);
int ask_user(const char *question);
int lookup_path_rootid(int fd, u64 *rootid);
int find_mount_fsroot(const char *subvol, const char *subvolid, char **mount);
diff --git a/kernel-shared/disk-io.c b/kernel-shared/disk-io.c
index 2701c464cbfc..857280cc7cb7 100644
--- a/kernel-shared/disk-io.c
+++ b/kernel-shared/disk-io.c
@@ -208,8 +208,8 @@ int verify_tree_block_csum_silent(struct extent_buffer *buf, u16 csum_size,
return __csum_tree_block_size(buf, csum_size, 1, 1, csum_type);
}
-int csum_tree_block(struct btrfs_fs_info *fs_info,
- struct extent_buffer *buf, int verify)
+static int csum_tree_block(struct btrfs_fs_info *fs_info,
+ struct extent_buffer *buf, int verify)
{
u16 csum_size = fs_info->csum_size;
u16 csum_type = fs_info->csum_type;
--
2.37.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] btrfs-progs: corrupt-block: re-generate the checksum for generation corruption
2022-09-13 7:19 [PATCH 0/2] btrfs-progs: make corrupt-block metadata geneartion corruption work again Qu Wenruo
2022-09-13 7:19 ` [PATCH 1/2] btrfs-progs: unexport csum_tree_block() Qu Wenruo
@ 2022-09-13 7:19 ` Qu Wenruo
2022-09-15 14:34 ` [PATCH 0/2] btrfs-progs: make corrupt-block metadata geneartion corruption work again David Sterba
2 siblings, 0 replies; 4+ messages in thread
From: Qu Wenruo @ 2022-09-13 7:19 UTC (permalink / raw)
To: linux-btrfs
[BUG]
If using btrfs-corrupt-block to corrupt the generation of a tree
block (in my example, it's csum root), it will cause csum mismatch other
than the expected transid mismatch:
# ./btrfs-corrupt-block --metadata-block 30474240 -f generation \
/dev/test/scratch1
# btrfs check /dev/test/scratch1
Opening filesystem to check...
checksum verify failed on 30474240 wanted 0xb3e8059a found 0xb4a4b45c
checksum verify failed on 30474240 wanted 0xb3e8059a found 0xb4a4b45c
checksum verify failed on 30474240 wanted 0xb3e8059a found 0xb4a4b45c
Csum didn't match
ERROR: could not setup csum tree
ERROR: cannot open file system
[CAUSE]
Inside the switch branch BTRFS_METADATA_BLOCK_GENERATION in
corrupt_metadata_block(), we just set the generation and trigger
write_and_map_eb().
However write_and_map_eb() doesn't re-generate the checksum by itself,
thus we make the victim tree block to have a stale checksum.
[FIX]
Just call csum_tree_block_size() before write_and_map_eb().
Now the corrupted fs have the expected corruption pattern now:
# btrfs check /dev/test/scratch1
Opening filesystem to check...
parent transid verify failed on 30474240 wanted 7 found 11814770867473404344
parent transid verify failed on 30474240 wanted 7 found 11814770867473404344
parent transid verify failed on 30474240 wanted 7 found 11814770867473404344
Ignoring transid failure
...
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
btrfs-corrupt-block.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/btrfs-corrupt-block.c b/btrfs-corrupt-block.c
index 4fa27b98fe16..b6aefe658ead 100644
--- a/btrfs-corrupt-block.c
+++ b/btrfs-corrupt-block.c
@@ -885,6 +885,8 @@ static int corrupt_metadata_block(struct btrfs_fs_info *fs_info, u64 block,
u64 bogus = generate_u64(orig);
btrfs_set_header_generation(eb, bogus);
+ csum_tree_block_size(eb, fs_info->csum_size, 0,
+ fs_info->csum_type);
ret = write_and_map_eb(fs_info, eb);
free_extent_buffer(eb);
if (ret < 0) {
--
2.37.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 0/2] btrfs-progs: make corrupt-block metadata geneartion corruption work again
2022-09-13 7:19 [PATCH 0/2] btrfs-progs: make corrupt-block metadata geneartion corruption work again Qu Wenruo
2022-09-13 7:19 ` [PATCH 1/2] btrfs-progs: unexport csum_tree_block() Qu Wenruo
2022-09-13 7:19 ` [PATCH 2/2] btrfs-progs: corrupt-block: re-generate the checksum for generation corruption Qu Wenruo
@ 2022-09-15 14:34 ` David Sterba
2 siblings, 0 replies; 4+ messages in thread
From: David Sterba @ 2022-09-15 14:34 UTC (permalink / raw)
To: Qu Wenruo; +Cc: linux-btrfs
On Tue, Sep 13, 2022 at 03:19:24PM +0800, Qu Wenruo wrote:
> This is preparing for the incoming metadata validation refactor in
> kernel, thus I need a way to corrupt transid reliably with correct
> checksum.
>
> The first patch is to unexport csum_tree_block() which also has a stale
> definition .
>
> The second patch is to fix the csum for metadata block with corrupted
> generation.
>
> Now btrfs-corrupt-block can properly corrupt the generation of a tree
> block.
>
> (But unfortunately it corrupts all copies, which is still not exactly
> what I need, but is already good enough)
>
> Qu Wenruo (2):
> btrfs-progs: unexport csum_tree_block()
> btrfs-progs: corrupt-block: re-generate the checksum for generation
> corruption
Added to devel, thanks.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-09-15 14:41 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-13 7:19 [PATCH 0/2] btrfs-progs: make corrupt-block metadata geneartion corruption work again Qu Wenruo
2022-09-13 7:19 ` [PATCH 1/2] btrfs-progs: unexport csum_tree_block() Qu Wenruo
2022-09-13 7:19 ` [PATCH 2/2] btrfs-progs: corrupt-block: re-generate the checksum for generation corruption Qu Wenruo
2022-09-15 14:34 ` [PATCH 0/2] btrfs-progs: make corrupt-block metadata geneartion corruption work again David Sterba
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox