⬢ DragonFlyBSD Kernel Audit
DF-2964 / fix.diff
← back to finding ↓ download raw
--- a/sys/kern/subr_diskgpt.c	2026-06-29 12:51:19.000000000 +0000
+++ b/sys/kern/subr_diskgpt.c	2026-10-26 00:25:42.789042927 +0000
@@ -109,6 +109,11 @@
 	 * Header sanity check
 	 */
 	gpt = (void *)bp1->b_data;
+	if (bcmp(gpt->hdr_sig, GPT_HDR_SIG, 8) != 0) {
+		kprintf("%s: Wrong GPT signature\n", dname);
+		error = EINVAL;
+		goto done;
+	}
 	len = le32toh(gpt->hdr_size);
 	if (len < GPT_MIN_HDR_SIZE || len > info->d_media_blksize) {
 		kprintf("%s: Illegal GPT header size %d\n", dname, len);
@@ -175,6 +180,20 @@
 	ssp = *sspp = dsmakeslicestruct(BASE_SLICE + MAX_GPT_ENTRIES, info);
 
 	/*
+	 * Validate the partition-entry array CRC the header promises.
+	 */
+	{
+		uint32_t tbl_crc = le32toh(gpt->hdr_crc_table);
+
+		if (crc32(bp2->b_data, entries * entsz) != tbl_crc) {
+			kprintf("%s: GPT partition table CRC did not match\n",
+				dname);
+			error = EINVAL;
+			goto done;
+		}
+	}
+
+	/*
 	 * Create a slice for each partition.
 	 */
 	for (i = 0; i < (int)entries && i < MAX_GPT_ENTRIES; ++i) {