From: Thomas Weißschuh Date: Sat, 3 Jun 2023 11:13:52 +0000 (+0200) Subject: libblkid: (bcache) also calculate checksum over journal buckets X-Git-Tag: v2.40-rc1~405^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7140635881f620172e90814b5a5043f250963ce0;p=thirdparty%2Futil-linux.git libblkid: (bcache) also calculate checksum over journal buckets Fixes #2291 Signed-off-by: Thomas Weißschuh --- diff --git a/libblkid/src/superblocks/bcache.c b/libblkid/src/superblocks/bcache.c index dd80b2c934..d1c8977eed 100644 --- a/libblkid/src/superblocks/bcache.c +++ b/libblkid/src/superblocks/bcache.c @@ -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 index 0000000000..c46ba22214 --- /dev/null +++ b/tests/expected/blkid/low-probe-bcache-journal @@ -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 index 0000000000..5d2201b3f6 Binary files /dev/null and b/tests/ts/blkid/images-fs/bcache-journal.img.xz differ