]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libblkid: (bcache) also calculate checksum over journal buckets
authorThomas Weißschuh <thomas@t-8ch.de>
Sat, 3 Jun 2023 11:13:52 +0000 (13:13 +0200)
committerThomas Weißschuh <thomas@t-8ch.de>
Sat, 3 Jun 2023 11:50:51 +0000 (13:50 +0200)
Fixes #2291

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
libblkid/src/superblocks/bcache.c
tests/expected/blkid/low-probe-bcache-journal [new file with mode: 0644]
tests/ts/blkid/images-fs/bcache-journal.img.xz [new file with mode: 0644]

index dd80b2c934ccc5f3dec0e91f4d4f43324f760024..d1c8977eedede8807d7207facb789a26d24626a8 100644 (file)
@@ -140,8 +140,6 @@ struct bcachefs_super_block {
 #define BCACHE_SB_MAGIC_OFF offsetof(struct bcache_super_block, magic)
 /* start of checksummed data within superblock */
 #define BCACHE_SB_CSUMMED_START 8
-/* end of checksummed data within superblock */
-#define BCACHE_SB_CSUMMED_END 208
 /* granularity of offset and length fields within superblock */
 #define BCACHEFS_SECTOR_SIZE   512
 /* maximum superblock size */
@@ -156,9 +154,19 @@ struct bcachefs_super_block {
 static int bcache_verify_checksum(blkid_probe pr, const struct blkid_idmag *mag,
                const struct bcache_super_block *bcs)
 {
-       const unsigned char *csummed = blkid_probe_get_sb_buffer(pr, mag, BCACHE_SB_CSUMMED_END);
-       uint64_t csum = ul_crc64_we(csummed + BCACHE_SB_CSUMMED_START,
-                       BCACHE_SB_CSUMMED_END - BCACHE_SB_CSUMMED_START);
+       const unsigned char *csummed;
+       size_t csummed_size;
+       uint64_t csum;
+
+       if (le16_to_cpu(bcs->keys) > ARRAY_SIZE(bcs->d))
+               return 0;
+
+       /* up to the end of bcs->d[] */
+       csummed_size = offsetof(typeof(*bcs), d) +
+               sizeof(bcs->d[0]) * le16_to_cpu(bcs->keys);
+       csummed = blkid_probe_get_sb_buffer(pr, mag, csummed_size);
+       csum = ul_crc64_we(csummed + BCACHE_SB_CSUMMED_START,
+                          csummed_size - BCACHE_SB_CSUMMED_START);
        return blkid_probe_verify_csum(pr, csum, le64_to_cpu(bcs->csum));
 }
 
diff --git a/tests/expected/blkid/low-probe-bcache-journal b/tests/expected/blkid/low-probe-bcache-journal
new file mode 100644 (file)
index 0000000..c46ba22
--- /dev/null
@@ -0,0 +1,4 @@
+ID_FS_TYPE=bcache
+ID_FS_USAGE=other
+ID_FS_UUID=fc6ea56f-372e-474e-bc5b-2ddc8430ddd1
+ID_FS_UUID_ENC=fc6ea56f-372e-474e-bc5b-2ddc8430ddd1
diff --git a/tests/ts/blkid/images-fs/bcache-journal.img.xz b/tests/ts/blkid/images-fs/bcache-journal.img.xz
new file mode 100644 (file)
index 0000000..5d2201b
Binary files /dev/null and b/tests/ts/blkid/images-fs/bcache-journal.img.xz differ