dcavalca / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone

Blame SOURCES/0152-libblkid-minix-Use-same-checks-for-version-3.patch

e42290
From 0ade71743e5f96fbdb0f4a85c3eef22b88363f13 Mon Sep 17 00:00:00 2001
e42290
From: Nate Clark <nate@neworld.us>
e42290
Date: Wed, 4 Jan 2017 15:24:32 -0500
e42290
Subject: [PATCH 152/152] libblkid/minix: Use same checks for version 3
e42290
e42290
fsck.minix performs the same sanity checks on all versions of the
e42290
superblock. Update the probe to perform the same sanity checks so it is
e42290
less likely a different type of filesystem will be identified as minix.
e42290
e42290
Upstream: http://github.com/karelzak/util-linux/commit/f82c804869bb8613fa0924e3111b7eb55bb04fcd
e42290
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1594681
e42290
Signed-off-by: Nate Clark <nate@neworld.us>
e42290
Signed-off-by: Karel Zak <kzak@redhat.com>
e42290
---
e42290
 libblkid/src/superblocks/minix.c | 38 +++++++++++++++++++++++---------------
e42290
 1 file changed, 23 insertions(+), 15 deletions(-)
e42290
e42290
diff --git a/libblkid/src/superblocks/minix.c b/libblkid/src/superblocks/minix.c
e42290
index 4e70fda8f..21b3bf8bb 100644
e42290
--- a/libblkid/src/superblocks/minix.c
e42290
+++ b/libblkid/src/superblocks/minix.c
e42290
@@ -75,6 +75,9 @@ static int probe_minix(blkid_probe pr, const struct blkid_idmag *mag)
e42290
 	unsigned char *ext;
e42290
 	const unsigned char *data;
e42290
 	int version = 0, swabme = 0;
e42290
+	unsigned long zones, ninodes, imaps, zmaps;
e42290
+	off_t firstz;
e42290
+	size_t zone_size;
e42290
 
e42290
 	data = blkid_probe_get_buffer(pr, 1024,
e42290
 			max(sizeof(struct minix_super_block),
e42290
@@ -85,14 +88,9 @@ static int probe_minix(blkid_probe pr, const struct blkid_idmag *mag)
e42290
 	if (version < 1)
e42290
 		return 1;
e42290
 
e42290
+
e42290
 	if (version <= 2) {
e42290
 		struct minix_super_block *sb = (struct minix_super_block *) data;
e42290
-		unsigned long zones, ninodes, imaps, zmaps;
e42290
-		off_t firstz;
e42290
-
e42290
-		if (sb->s_imap_blocks == 0 || sb->s_zmap_blocks == 0)
e42290
-			return 1;
e42290
-
e42290
 		uint16_t state = minix_swab16(swabme, sb->s_state);
e42290
 		if ((state & (MINIX_VALID_FS | MINIX_ERROR_FS)) != state)
e42290
 			return 1;
e42290
@@ -103,20 +101,30 @@ static int probe_minix(blkid_probe pr, const struct blkid_idmag *mag)
e42290
 		imaps   = minix_swab16(swabme, sb->s_imap_blocks);
e42290
 		zmaps   = minix_swab16(swabme, sb->s_zmap_blocks);
e42290
 		firstz  = minix_swab16(swabme, sb->s_firstdatazone);
e42290
-
e42290
-		/* sanity checks to be sure that the FS is really minix */
e42290
-		if (imaps * MINIX_BLOCK_SIZE * 8 < ninodes + 1)
e42290
-			return 1;
e42290
-		if (zmaps * MINIX_BLOCK_SIZE * 8 < zones - firstz + 1)
e42290
-			return 1;
e42290
-
e42290
+		zone_size = sb->s_log_zone_size;
e42290
 	} else if (version == 3) {
e42290
 		struct minix3_super_block *sb = (struct minix3_super_block *) data;
e42290
 
e42290
-		if (sb->s_imap_blocks == 0 || sb->s_zmap_blocks == 0)
e42290
-			return 1;
e42290
+		zones = minix_swab32(swabme, sb->s_zones);
e42290
+		ninodes = minix_swab32(swabme, sb->s_ninodes);
e42290
+		imaps   = minix_swab16(swabme, sb->s_imap_blocks);
e42290
+		zmaps   = minix_swab16(swabme, sb->s_zmap_blocks);
e42290
+		firstz  = minix_swab16(swabme, sb->s_firstdatazone);
e42290
+		zone_size = sb->s_log_zone_size;
e42290
 	}
e42290
 
e42290
+	/* sanity checks to be sure that the FS is really minix.
e42290
+	 * see disk-utils/fsck.minix.c read_superblock
e42290
+	 */
e42290
+	if (zone_size != 0 || ninodes == 0 || ninodes == UINT32_MAX)
e42290
+		return 1;
e42290
+	if (imaps * MINIX_BLOCK_SIZE * 8 < ninodes + 1)
e42290
+		return 1;
e42290
+	if (firstz > (off_t) zones)
e42290
+		return 1;
e42290
+	if (zmaps * MINIX_BLOCK_SIZE * 8 < zones - firstz + 1)
e42290
+		return 1;
e42290
+
e42290
 	/* unfortunately, some parts of ext3 is sometimes possible to
e42290
 	 * interpreted as minix superblock. So check for extN magic
e42290
 	 * string. (For extN magic string and offsets see ext.c.)
e42290
-- 
e42290
2.14.4
e42290