Page MenuHomeFreeBSD

D36717.id110994.diff
No OneTemporary

D36717.id110994.diff

diff --git a/sys/geom/part/g_part_gpt.c b/sys/geom/part/g_part_gpt.c
--- a/sys/geom/part/g_part_gpt.c
+++ b/sys/geom/part/g_part_gpt.c
@@ -85,6 +85,7 @@
GPT_STATE_MISSING, /* No signature found. */
GPT_STATE_CORRUPT, /* Checksum mismatch. */
GPT_STATE_INVALID, /* Nonconformant/invalid. */
+ GPT_STATE_UNSUPPORTED, /* Not supported. */
GPT_STATE_OK /* Perfectly fine. */
};
@@ -148,13 +149,16 @@
{ 0, 0 }
};
+#define MAXTBLENTS 4096
+#define MAXENTSIZE 1024
+
static struct g_part_scheme g_part_gpt_scheme = {
"GPT",
g_part_gpt_methods,
sizeof(struct g_part_gpt_table),
.gps_entrysz = sizeof(struct g_part_gpt_entry),
.gps_minent = 128,
- .gps_maxent = 4096,
+ .gps_maxent = MAXTBLENTS,
.gps_bootcodesz = MBRSIZE,
};
G_PART_SCHEME_DECLARE(g_part_gpt);
@@ -518,9 +522,13 @@
if (lba >= hdr->hdr_lba_start && lba <= hdr->hdr_lba_end)
goto fail;
- table->state[elt] = GPT_STATE_OK;
- le_uuid_dec(&buf->hdr_uuid, &hdr->hdr_uuid);
- hdr->hdr_crc_table = le32toh(buf->hdr_crc_table);
+ if (hdr->hdr_entries > MAXTBLENTS || hdr->hdr_entsz > MAXENTSIZE)
+ table->state[elt] = GPT_STATE_UNSUPPORTED;
+ else {
+ table->state[elt] = GPT_STATE_OK;
+ le_uuid_dec(&buf->hdr_uuid, &hdr->hdr_uuid);
+ hdr->hdr_crc_table = le32toh(buf->hdr_crc_table);
+ }
/* save LBA for secondary header */
if (elt == GPT_ELT_PRIHDR)
@@ -958,6 +966,19 @@
sectbl = NULL;
}
+ /* Fail if both tables are unsupported */
+ if (table->state[GPT_ELT_PRIHDR] == GPT_STATE_UNSUPPORTED &&
+ table->state[GPT_ELT_SECHDR] == GPT_STATE_UNSUPPORTED) {
+ printf("GEOM: %s: unsupported GPT detected.\n",
+ pp->name);
+ printf("GEOM: %s: GPT rejected.\n", pp->name);
+ if (prihdr != NULL)
+ g_free(prihdr);
+ if (sechdr != NULL)
+ g_free(sechdr);
+ return (EINVAL);
+ }
+
/* Fail if we haven't got any good tables at all. */
if (table->state[GPT_ELT_PRITBL] != GPT_STATE_OK &&
table->state[GPT_ELT_SECTBL] != GPT_STATE_OK) {

File Metadata

Mime Type
text/plain
Expires
Mon, Feb 9, 10:17 AM (20 h, 48 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
28567323
Default Alt Text
D36717.id110994.diff (1 KB)

Event Timeline