dcavalca / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone

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

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