]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libblkid/minix: Use same checks for version 3
authorNate Clark <nate@neworld.us>
Wed, 4 Jan 2017 20:24:32 +0000 (15:24 -0500)
committerNate Clark <nate@neworld.us>
Wed, 4 Jan 2017 20:24:32 +0000 (15:24 -0500)
fsck.minix performs the same sanity checks on all versions of the
superblock. Update the probe to perform the same sanity checks so it is
less likely a different type of filesystem will be identified as minix.

Signed-off-by: Nate Clark <nate@neworld.us>
libblkid/src/superblocks/minix.c

index 628b246ee89b487e1dd4dbf51af4dc63b672c595..3e126e0ea38e5cf8568ba88d1db1d140475cd53f 100644 (file)
@@ -87,14 +87,12 @@ static int probe_minix(blkid_probe pr,
        if (version < 1)
                return 1;
 
+       unsigned long zones, ninodes, imaps, zmaps;
+       off_t firstz;
+       size_t zone_size;
+
        if (version <= 2) {
                struct minix_super_block *sb = (struct minix_super_block *) data;
-               unsigned long zones, ninodes, imaps, zmaps;
-               off_t firstz;
-
-               if (sb->s_imap_blocks == 0 || sb->s_zmap_blocks == 0 ||
-                   sb->s_log_zone_size != 0)
-                       return 1;
 
                zones = version == 2 ? minix_swab32(swabme, sb->s_zones) :
                                       minix_swab16(swabme, sb->s_nzones);
@@ -102,19 +100,30 @@ static int probe_minix(blkid_probe pr,
                imaps   = minix_swab16(swabme, sb->s_imap_blocks);
                zmaps   = minix_swab16(swabme, sb->s_zmap_blocks);
                firstz  = minix_swab16(swabme, sb->s_firstdatazone);
-
-               /* sanity checks to be sure that the FS is really minix */
-               if (imaps * MINIX_BLOCK_SIZE * 8 < ninodes + 1)
-                       return 1;
-               if (zmaps * MINIX_BLOCK_SIZE * 8 < zones - firstz + 1)
-                       return 1;
+               zone_size = sb->s_log_zone_size;
        } else if (version == 3) {
                struct minix3_super_block *sb = (struct minix3_super_block *) data;
 
-               if (sb->s_imap_blocks == 0 || sb->s_zmap_blocks == 0)
-                       return 1;
+               zones = minix_swab32(swabme, sb->s_zones);
+               ninodes = minix_swab32(swabme, sb->s_ninodes);
+               imaps   = minix_swab16(swabme, sb->s_imap_blocks);
+               zmaps   = minix_swab16(swabme, sb->s_zmap_blocks);
+               firstz  = minix_swab16(swabme, sb->s_firstdatazone);
+               zone_size = sb->s_log_zone_size;
        }
 
+       /* sanity checks to be sure that the FS is really minix.
+        * see disk-utils/fsck.minix.c read_superblock
+        */
+       if (zone_size != 0 || ninodes == 0 || ninodes == UINT32_MAX)
+               return 1;
+       if (imaps * MINIX_BLOCK_SIZE * 8 < ninodes + 1)
+               return 1;
+       if (firstz > (off_t) zones)
+               return 1;
+       if (zmaps * MINIX_BLOCK_SIZE * 8 < zones - firstz + 1)
+               return 1;
+
        /* unfortunately, some parts of ext3 is sometimes possible to
         * interpreted as minix superblock. So check for extN magic
         * string. (For extN magic string and offsets see ext.c.)