Version in base suite: 6.2-1 Base version: btrfs-progs_6.2-1 Target version: btrfs-progs_6.2-1+deb12u1 Base file: /srv/ftp-master.debian.org/ftp/pool/main/b/btrfs-progs/btrfs-progs_6.2-1.dsc Target file: /srv/ftp-master.debian.org/policy/pool/main/b/btrfs-progs/btrfs-progs_6.2-1+deb12u1.dsc changelog | 9 + patches/convert-fix-bad-csum-for-migrated-range.diff | 96 +++++++++++++++++++ patches/series | 1 3 files changed, 106 insertions(+) gpgv: Signature made Wed Mar 1 00:34:57 2023 UTC gpgv: using RSA key 9236557B170C87F8821C0AC3C1E0D92E986F7C7E gpgv: Can't check signature: No public key dpkg-source: warning: failed to verify signature on /srv/release.debian.org/tmp/tmpcwrakm77/btrfs-progs_6.2-1.dsc diff -Nru btrfs-progs-6.2/debian/changelog btrfs-progs-6.2/debian/changelog --- btrfs-progs-6.2/debian/changelog 2023-02-28 23:17:49.000000000 +0000 +++ btrfs-progs-6.2/debian/changelog 2024-10-16 17:59:06.000000000 +0000 @@ -1,3 +1,12 @@ +btrfs-progs (6.2-1+deb12u1) bookworm; urgency=medium + + * Non-maintainer upload. + * Add patch to fix bad checksum in btrfs-convert (closes: #1085207). + It will produce corrupted checksum when converting from ext4 fs + with 64K block size. + + -- Shengqi Chen Thu, 17 Oct 2024 01:59:06 +0800 + btrfs-progs (6.2-1) unstable; urgency=medium * New upstream release. diff -Nru btrfs-progs-6.2/debian/patches/convert-fix-bad-csum-for-migrated-range.diff btrfs-progs-6.2/debian/patches/convert-fix-bad-csum-for-migrated-range.diff --- btrfs-progs-6.2/debian/patches/convert-fix-bad-csum-for-migrated-range.diff 1970-01-01 00:00:00.000000000 +0000 +++ btrfs-progs-6.2/debian/patches/convert-fix-bad-csum-for-migrated-range.diff 2024-10-16 17:59:06.000000000 +0000 @@ -0,0 +1,96 @@ +From 416507904c65c5436c2e0bd356669a816365eaf4 Mon Sep 17 00:00:00 2001 +From: Qu Wenruo +Date: Tue, 9 May 2023 08:43:14 +0800 +Subject: [PATCH] btrfs-progs: convert: fix bad csum for migrated range. + +[BUG] +There is a report that btrfs-convert leads to bad csum for the image +file. + +The reproducer looks like this: +(note the 64K block size, it's used to force a certain chunk layout) + + # touch test.img + # truncate -s 10G test.img + # mkfs.ext4 -b 64K test.img + # btrfs-convert -N 64K test.img + # btrfs check --check-data-csum test.img + Opening filesystem to check... + Checking filesystem on /home/adam/test.img + UUID: 39d49537-a9f5-47f1-b6ab-7857707b9133 + [1/7] checking root items + [2/7] checking extents + [3/7] checking free space cache + [4/7] checking fs roots + [5/7] checking csums against data + mirror 1 bytenr 4563140608 csum 0x3f1fa0ef expected csum 0xa4c4c072 + mirror 1 bytenr 4563206144 csum 0x55dcf0d3 expected csum 0xa4c4c072 + mirror 1 bytenr 4563271680 csum 0x4491b00a expected csum 0xa4c4c072 + mirror 1 bytenr 4563337216 csum 0x655d1f61 expected csum 0xa4c4c072 + mirror 1 bytenr 4563402752 csum 0xd37114d3 expected csum 0xa4c4c072 + mirror 1 bytenr 4563468288 csum 0x4c2dab30 expected csum 0xa4c4c072 + mirror 1 bytenr 4563533824 csum 0xa80fceed expected csum 0xa4c4c072 + mirror 1 bytenr 4563599360 csum 0xaf610db8 expected csum 0xa4c4c072 + mirror 1 bytenr 4563795968 csum 0x67b3c8a0 expected csum 0xa4c4c072 + ERROR: errors found in csum tree + [6/7] checking root refs + ... + +[CAUSE] +Above initial failure is for logical bytenr of 4563140608, which is +inside the relocated range of the image file offset [0, 1M). + +During convert, we migrate the original image file ranges which would +later be covered by super and other reserved ranges. + +The migration happens as: + +- Read out the original data +- Reserve a new file extent +- Write the data back to the file extent + Note that, the new file extent can be inside some new data chunks, + thus it's no longer 1:1 mapped. +- Generate the new csum for the new file extent + +The problem happens at the last stage. We should read out the data from +the new file extent, but we call read_disk_extent() using the logical +bytenr, however read_disk_extent() is not doing logical -> physical +mapping. + +Thus we will read some garbage, not the newly written data, and use +those garbage to generate csum. And caused the above problem. + +[FIX] +Instead of read_disk_extent(), call read_data_from_disk(), which would +do the proper logical -> physical mapping, thus would fix the bug. + +Signed-off-by: Qu Wenruo +Signed-off-by: David Sterba +Forwarded: not-needed +--- + convert/main.c | 12 ++++++++++-- + 1 file changed, 10 insertions(+), 2 deletions(-) + +--- a/convert/main.c ++++ b/convert/main.c +@@ -190,10 +190,18 @@ + if (!buffer) + return -ENOMEM; + for (offset = 0; offset < num_bytes; offset += blocksize) { +- ret = read_disk_extent(root, disk_bytenr + offset, +- blocksize, buffer); ++ u64 read_len = blocksize; ++ ++ ret = read_data_from_disk(root->fs_info, buffer, ++ disk_bytenr + offset, &read_len, 0); + if (ret) + break; ++ if (read_len == 0) { ++ error("failed to read logical bytenr %llu", ++ disk_bytenr + offset); ++ ret = -EIO; ++ break; ++ } + ret = btrfs_csum_file_block(trans, + disk_bytenr + num_bytes, + disk_bytenr + offset, diff -Nru btrfs-progs-6.2/debian/patches/series btrfs-progs-6.2/debian/patches/series --- btrfs-progs-6.2/debian/patches/series 1970-01-01 00:00:00.000000000 +0000 +++ btrfs-progs-6.2/debian/patches/series 2024-10-16 17:59:06.000000000 +0000 @@ -0,0 +1 @@ +convert-fix-bad-csum-for-migrated-range.diff