dcavalca / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone

Blame SOURCES/0079-libblkid-limit-amount-of-parsed-partitions.patch

8ecbbe
From 24f5385f4a54b90f4b7674e23f30567591962bcb Mon Sep 17 00:00:00 2001
8ecbbe
From: Samanta Navarro <ferivoz@riseup.net>
8ecbbe
Date: Tue, 10 Nov 2020 11:48:04 +0100
8ecbbe
Subject: libblkid: limit amount of parsed partitions
8ecbbe
8ecbbe
The linux kernel does not support more than 256 partitions
8ecbbe
(DISK_MAX_PARTS). The atari and mac block devices have no such limits.
8ecbbe
8ecbbe
Use dos logical partition limit for atari as well (100).
8ecbbe
Use the kernel limit for mac (256).
8ecbbe
8ecbbe
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=2060030
8ecbbe
Upstream: http://github.com/util-linux/util-linux/commit/c70b4f2a5b99876d230b8f4f413c3bb3ee6647f1
8ecbbe
Signed-off-by: Karel Zak <kzak@redhat.com>
8ecbbe
Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
8ecbbe
---
8ecbbe
 libblkid/src/partitions/atari.c |  6 +++++-
8ecbbe
 libblkid/src/partitions/mac.c   | 15 +++++++++++----
8ecbbe
 2 files changed, 16 insertions(+), 5 deletions(-)
8ecbbe
8ecbbe
diff --git a/libblkid/src/partitions/atari.c b/libblkid/src/partitions/atari.c
8ecbbe
index c3f77117a..fdd5498b5 100644
8ecbbe
--- a/libblkid/src/partitions/atari.c
8ecbbe
+++ b/libblkid/src/partitions/atari.c
8ecbbe
@@ -141,12 +141,16 @@ static int parse_extended(blkid_probe pr, blkid_partlist ls,
8ecbbe
 	blkid_parttable tab, struct atari_part_def *part)
8ecbbe
 {
8ecbbe
 	uint32_t x0start, xstart;
8ecbbe
-	unsigned i = 0;
8ecbbe
+	unsigned ct = 0, i = 0;
8ecbbe
 	int rc;
8ecbbe
 
8ecbbe
 	x0start = xstart = be32_to_cpu(part->start);
8ecbbe
 	while (1) {
8ecbbe
 		struct atari_rootsector *xrs;
8ecbbe
+
8ecbbe
+		if (++ct > 100)
8ecbbe
+			break;
8ecbbe
+
8ecbbe
 		xrs = (struct atari_rootsector *) blkid_probe_get_sector(pr, xstart);
8ecbbe
 		if (!xrs) {
8ecbbe
 			if (errno)
8ecbbe
diff --git a/libblkid/src/partitions/mac.c b/libblkid/src/partitions/mac.c
8ecbbe
index 2be91a620..092d31d32 100644
8ecbbe
--- a/libblkid/src/partitions/mac.c
8ecbbe
+++ b/libblkid/src/partitions/mac.c
8ecbbe
@@ -79,7 +79,7 @@ static int probe_mac_pt(blkid_probe pr,
8ecbbe
 	blkid_partlist ls;
8ecbbe
 	uint16_t block_size;
8ecbbe
 	uint16_t ssf;	/* sector size fragment */
8ecbbe
-	uint32_t nblks, i;
8ecbbe
+	uint32_t nblks, nprts, i;
8ecbbe
 
8ecbbe
 
8ecbbe
 	/* The driver descriptor record is always located at physical block 0,
8ecbbe
@@ -122,8 +122,15 @@ static int probe_mac_pt(blkid_probe pr,
8ecbbe
 
8ecbbe
 	ssf = block_size / 512;
8ecbbe
 	nblks = be32_to_cpu(p->map_count);
8ecbbe
-
8ecbbe
-	for (i = 0; i < nblks; ++i) {
8ecbbe
+	if (nblks > 256) {
8ecbbe
+		nprts = 256;
8ecbbe
+		DBG(LOWPROBE, ul_debug(
8ecbbe
+			"mac: map_count too large, entry[0]: %u, "
8ecbbe
+			"enforcing limit of %u", nblks, nprts));
8ecbbe
+	} else
8ecbbe
+		nprts = nblks;
8ecbbe
+
8ecbbe
+	for (i = 0; i < nprts; ++i) {
8ecbbe
 		blkid_partition par;
8ecbbe
 		uint32_t start;
8ecbbe
 		uint32_t size;
8ecbbe
@@ -140,7 +147,7 @@ static int probe_mac_pt(blkid_probe pr,
8ecbbe
 		if (be32_to_cpu(p->map_count) != nblks) {
8ecbbe
 			DBG(LOWPROBE, ul_debug(
8ecbbe
 				"mac: inconsistent map_count in partition map, "
8ecbbe
-				"entry[0]: %d, entry[%d]: %d",
8ecbbe
+				"entry[0]: %u, entry[%u]: %u",
8ecbbe
 				nblks, i,
8ecbbe
 				be32_to_cpu(p->map_count)));
8ecbbe
 		}
8ecbbe
-- 
8ecbbe
2.36.1
8ecbbe