]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libblkid: ubifs: add checksum support
authorThomas Weißschuh <thomas@t-8ch.de>
Tue, 13 Sep 2022 12:26:37 +0000 (14:26 +0200)
committerThomas Weißschuh <thomas@t-8ch.de>
Tue, 13 Sep 2022 12:57:27 +0000 (14:57 +0200)
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
libblkid/src/superblocks/ubifs.c

index dc84260632fdbaa066a51b1a08073289eb950f36..06314232906b92749c23a0f53395f7f4dae3afbb 100644 (file)
@@ -11,6 +11,7 @@
 #include <stdint.h>
 
 #include "superblocks.h"
+#include "crc32.h"
 
 /*
  * struct ubifs_ch - common header node.
@@ -93,6 +94,15 @@ struct ubifs_sb_node {
        uint8_t padding2[3968];
 } __attribute__ ((packed));
 
+static int ubifs_verify_csum(blkid_probe pr, const struct ubifs_sb_node *sb)
+{
+       size_t csummed_offset = offsetof(struct ubifs_ch, sqnum);
+       uint32_t crc = ul_crc32(~0LL,
+                       (unsigned char *) sb + csummed_offset,
+                       sizeof(*sb) - csummed_offset);
+       return blkid_probe_verify_csum(pr, crc, le32_to_cpu(sb->ch.crc));
+}
+
 static int probe_ubifs(blkid_probe pr, const struct blkid_idmag *mag)
 {
        struct ubifs_sb_node *sb;
@@ -101,6 +111,9 @@ static int probe_ubifs(blkid_probe pr, const struct blkid_idmag *mag)
        if (!sb)
                return errno ? -errno : 1;
 
+       if (!ubifs_verify_csum(pr, sb))
+               return 1;
+
        blkid_probe_set_uuid(pr, sb->uuid);
        blkid_probe_sprintf_version(pr, "w%dr%d",
                        le32_to_cpu(sb->fmt_version),