diff --git a/libblkid/src/superblocks/bcache.c b/libblkid/src/superblocks/bcache.c index 60bba9311..40e702d75 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) { - 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 000000000..c46ba2221 --- /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 000000000..5d2201b3f Binary files /dev/null and b/tests/ts/blkid/images-fs/bcache-journal.img.xz differ