From 45dc116cb7eea07e02aa3e29700aa833e0cfabf9 Mon Sep 17 00:00:00 2001 From: jakllsch Date: Sun, 23 Aug 2015 18:40:15 +0000 Subject: [PATCH] Quadruple GPT partition entry count limit (to 512 entries or 64KiB). The UEFI 2.3.1 specification states that: "A minimum of 16,384 bytes of space must be reserved for the GPT Partition Entry Array." and [the size of a partition entry shall be a power of two greater than 128] and that [the defined fields of a partition entry total 128 bytes]. Clamping the entries means that no partitions on the drive will be detected, as this will result in an incorrect partition entry array CRC. This change reduces the likelyhood of useless partitions, while still not allowing a huge kernel memory allocation to load the partition entries into. In the future this code should probably be reworked to checksum and evaluate the partition array in chunks while still limiting the number of GPT wedges added per drive to something reasonable. --- sys/dev/dkwedge/dkwedge_gpt.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sys/dev/dkwedge/dkwedge_gpt.c b/sys/dev/dkwedge/dkwedge_gpt.c index 44767de68468..c3d4b17b7121 100644 --- a/sys/dev/dkwedge/dkwedge_gpt.c +++ b/sys/dev/dkwedge/dkwedge_gpt.c @@ -1,4 +1,4 @@ -/* $NetBSD: dkwedge_gpt.c,v 1.14 2014/11/04 07:43:00 mlelstv Exp $ */ +/* $NetBSD: dkwedge_gpt.c,v 1.15 2015/08/23 18:40:15 jakllsch Exp $ */ /*- * Copyright (c) 2004 The NetBSD Foundation, Inc. @@ -34,7 +34,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: dkwedge_gpt.c,v 1.14 2014/11/04 07:43:00 mlelstv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: dkwedge_gpt.c,v 1.15 2015/08/23 18:40:15 jakllsch Exp $"); #include #include @@ -178,11 +178,11 @@ dkwedge_discover_gpt(struct disk *pdk, struct vnode *vp) } gpe_crc = le32toh(hdr->hdr_crc_table); - /* XXX Clamp entries at 128 for now. */ - if (entries > 128) { + /* XXX Clamp entries at 512 for now. */ + if (entries > 512) { aprint_error("%s: WARNING: clamping number of GPT entries to " - "128 (was %u)\n", pdk->dk_name, entries); - entries = 128; + "512 (was %u)\n", pdk->dk_name, entries); + entries = 512; } lba_start = le64toh(hdr->hdr_lba_start);