]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libblkid: ddf_read: validate header checksum
authorThomas Weißschuh <thomas@t-8ch.de>
Thu, 27 Feb 2025 17:16:03 +0000 (18:16 +0100)
committerThomas Weißschuh <thomas@t-8ch.de>
Thu, 27 Feb 2025 17:16:03 +0000 (18:16 +0100)
The DDF header contains a checksum.

Validate it.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
libblkid/src/superblocks/ddf_raid.c

index f5b52bff2b37b7fa20c99d0ed6a70dfff6eef4ed..bf346330f9ca5a80d21032ee0e037494bb4e4055 100644 (file)
@@ -13,6 +13,7 @@
 #include <string.h>
 #include <stdint.h>
 
+#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;
        }