From: Thomas Weißschuh Date: Thu, 27 Feb 2025 17:16:03 +0000 (+0100) Subject: libblkid: ddf_read: validate header checksum X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e60a96560d3b1c60fcf8adb06df2f00c8385ac93;p=thirdparty%2Futil-linux.git libblkid: ddf_read: validate header checksum The DDF header contains a checksum. Validate it. Signed-off-by: Thomas Weißschuh --- diff --git a/libblkid/src/superblocks/ddf_raid.c b/libblkid/src/superblocks/ddf_raid.c index f5b52bff2..bf346330f 100644 --- a/libblkid/src/superblocks/ddf_raid.c +++ b/libblkid/src/superblocks/ddf_raid.c @@ -13,6 +13,7 @@ #include #include +#include "crc32.h" #include "superblocks.h" /* http://www.snia.org/standards/home */ @@ -71,6 +72,21 @@ struct ddf_header { uint8_t pad4[256]; /* 0xff */ } __attribute__((packed)); +static int ddf_verify_csum(blkid_probe pr, const struct ddf_header *ddf) +{ + uint32_t expected, crc; + + expected = be32_to_cpu(ddf->crc); + + crc = ul_crc32_exclude_offset(0, + (const unsigned char *)ddf, sizeof(*ddf), + offsetof(__typeof__(*ddf), crc), + sizeof_member(__typeof__(*ddf), crc), + 0xff); + + return blkid_probe_verify_csum(pr, crc, expected); +} + static int probe_ddf(blkid_probe pr, const struct blkid_idmag *mag __attribute__((__unused__))) { @@ -88,7 +104,7 @@ static int probe_ddf(blkid_probe pr, sizeof(struct ddf_header)); if (!ddf) return errno ? -errno : 1; - if (ddf->signature == cpu_to_be32(DDF_MAGIC)) + if (ddf->signature == cpu_to_be32(DDF_MAGIC) && ddf_verify_csum(pr, ddf)) break; ddf = NULL; }