Skip to contentSkip to conversation

mtd: maps: add INT0800 firmware-flash map driver

PATCH Superseded Stephen Bancroft 3 participants 6 messages Sep 21 – Sep 25 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 mtd: maps: add INT0800 firmware-flash map driver

Add a read-only mapping driver that binds the ACPI INT0800 "Intel 82802 firmware hub" device and exposes the system firmware flash as an MTD ROM device.

On x86 machines the boot flash is decoded into the physical address space below 4 GB, so a plain ioremap() of the declared resource window is sufficient for reads - no SPI or LPC controller access is needed. The window may be larger than the real flash; undecoded holes read as 0xff.

This gives userspace a clean, safe way to read firmware flash contents without flashrom or relaxed /dev/mem access - for firmware analysis, and for extracting option ROMs stored inside EFI firmware volumes (e.g. the NVIDIA VBIOS on EFI-booted Apple machines, which can then be fed to nouveau via nouveau.config=NvBios=). There is deliberately no write or erase support.

Tested on a MacBookPro4,1 (ICH8M): /dev/mtd0 reads are byte-identical to a flashrom dump of the 2 MiB SST25VF016B, except for live NVRAM variable-store regions.

---
Changes in v3:
- MODULE_AUTHOR: use full author identity (per Miquèl Raynal's review)

Changes in v2:
- Per-device state via devm_kzalloc instead of globals (fixes shared state corruption with multiple INT0800 devices)
- Clean up map probe on mtd_device_register() failure (fixes memory/mapping leak)
- Use %pa for resource_size_t in dev_info (fixes format string on 32-bit)
- Add missing Signed-off-by

 drivers/mtd/maps/Kconfig   |  17 ++++++
 drivers/mtd/maps/Makefile  |   1 +
 drivers/mtd/maps/int0800.c | 108 +++++++++++++++++++++++++++++++++++++
 3 files changed, 126 insertions(+)
 create mode 100644 drivers/mtd/maps/int0800.c
drivers/mtd/maps/Kconfig +17 -0
index 1bb3dba2631d..649fd145e15d 100644
@@ -161,6 +161,23 @@ config MTD_AMD76XROM
 
 	  BE VERY CAREFUL.
 
+config MTD_INT0800
+	tristate "Read-only BIOS/firmware flash via ACPI INT0800"
+	depends on X86 && ACPI
+	select MTD_ROM
+	help
+	  Support for reading the system firmware (BIOS/EFI) flash chip
+	  through the memory window described by the ACPI INT0800
+	  "82802 firmware hub" device, present on most x86 machines.
+
+	  The flash is exposed read-only via the ROM chip driver, e.g.
+	  for firmware analysis or extracting option ROMs (such as
+	  video BIOS images embedded in EFI firmware volumes). There is
+	  no write or erase support.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called int0800.
+
 config MTD_ICHXROM
 	tristate "BIOS flash chip on Intel Controller Hub 2/3/4/5"
 	depends on X86 && MTD_JEDECPROBE
drivers/mtd/maps/Makefile +1 -0
index 01745eca1f73..2f1a7375e13c 100644
@@ -14,6 +14,7 @@ obj-$(CONFIG_MTD_L440GX)	+= l440gx.o
 obj-$(CONFIG_MTD_AMD76XROM)	+= amd76xrom.o
 obj-$(CONFIG_MTD_ESB2ROM)	+= esb2rom.o
 obj-$(CONFIG_MTD_ICHXROM)	+= ichxrom.o
+obj-$(CONFIG_MTD_INT0800)	+= int0800.o
 obj-$(CONFIG_MTD_CK804XROM)	+= ck804xrom.o
 obj-$(CONFIG_MTD_TSUNAMI)	+= tsunami_flash.o
 obj-$(CONFIG_MTD_PXA2XX)	+= pxa2xx-flash.o
drivers/mtd/maps/int0800.c new file +108 -0

108 lines not on this page · raw message

Signature · 1 line
2.43.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] mtd: maps: Use-After-Free in int0800 via sysfs driver unbind --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] mtd: maps: Use-After-Free in int0800 via sysfs driver unbind
--

commit 2d904c4a0ae5009245dd1587c804f0ac6e9402b8
Author: Stephen Bancroft <[email protected]>

mtd: maps: add INT0800 firmware-flash map driver

Adds a read-only MTD mapping driver that binds the ACPI INT0800 device and exposes the system firmware flash as an MTD ROM device.

Quoted 5 lines
drivers/mtd/maps/int0800.c new file +0 -0
new file mode 100644
index 0000000000000..0188d58b168d9

[ ... ]

drivers/mtd/maps/int0800.c line 88

Quoted 7 lines
drivers/mtd/maps/int0800.c new file +7 -0
+static void int0800_remove(struct platform_device *pdev)
+{
+	struct int0800 *fw = platform_get_drvdata(pdev);
+
+	mtd_device_unregister(fw->mtd);
+	map_destroy(fw->mtd);
+}

[Severity: High]
Can this lead to a use-after-free and unmapped memory dereference if a user forces a driver unbind via sysfs while the character device is still open?

If a privileged user opens /dev/mtdX and then writes to /sys/bus/platform/drivers/int0800/unbind, int0800_remove() is invoked. This unconditionally calls map_destroy(fw->mtd), freeing the mtd_info structure and allowing devres to unmap fw->map.virt.

Since mtdchar_open() incrementing the module use-count does not prevent forced sysfs unbinds, a subsequent read() on the still-open file descriptor would dereference the freed mtd_info and read from the unmapped memory.

Should this driver set .suppress_bind_attrs = true in the platform_driver to prevent forced sysfs unbinds?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw

PATCH v4 1/1 mtd: maps: add INT0800 firmware-flash map driver

In reply to Stephen Bancroft

Add a read-only mapping driver that binds the ACPI INT0800 "Intel 82802 firmware hub" device and exposes the system firmware flash as an MTD ROM device.

On x86 machines the boot flash is decoded into the physical address space below 4 GB, so a plain ioremap() of the declared resource window is sufficient for reads - no SPI or LPC controller access is needed. The window may be larger than the real flash; undecoded holes read as 0xff.

This gives userspace a clean, safe way to read firmware flash contents without flashrom or relaxed /dev/mem access - for firmware analysis, and for extracting option ROMs stored inside EFI firmware volumes (e.g. the NVIDIA VBIOS on EFI-booted Apple machines, which can then be fed to nouveau via nouveau.config=NvBios=). There is deliberately no write or erase support.

Tested on a MacBookPro4,1 (ICH8M): /dev/mtd0 reads are byte-identical to a flashrom dump of the 2 MiB SST25VF016B, except for live NVRAM variable-store regions.

---
Changes in v4:
- Set .suppress_bind_attrs: remove() frees the mtd_info and lets devres unmap the window unconditionally, so a sysfs driver unbind while a /dev/mtdX fd is still open would leave userspace holding a dangling pointer into freed/unmapped memory (Sashiko AI review). Module unload is now the only teardown path and is already blocked by open fds via mtd->owner.

Changes in v3:
- MODULE_AUTHOR: use full author identity (per Miquèl Raynal's review)

Changes in v2:
- Per-device state via devm_kzalloc instead of globals (fixes shared state corruption with multiple INT0800 devices)
- Clean up map probe on mtd_device_register() failure (fixes memory/mapping leak)
- Use %pa for resource_size_t in dev_info (fixes format string on 32-bit)
- Add missing Signed-off-by

 drivers/mtd/maps/Kconfig   |  17 ++++++
 drivers/mtd/maps/Makefile  |   1 +
 drivers/mtd/maps/int0800.c | 115 +++++++++++++++++++++++++++++++++++++
 3 files changed, 133 insertions(+)
 create mode 100644 drivers/mtd/maps/int0800.c
drivers/mtd/maps/Kconfig +17 -0
index 1bb3dba2631d..649fd145e15d 100644
@@ -161,6 +161,23 @@ config MTD_AMD76XROM
 
 	  BE VERY CAREFUL.
 
+config MTD_INT0800
+	tristate "Read-only BIOS/firmware flash via ACPI INT0800"
+	depends on X86 && ACPI
+	select MTD_ROM
+	help
+	  Support for reading the system firmware (BIOS/EFI) flash chip
+	  through the memory window described by the ACPI INT0800
+	  "82802 firmware hub" device, present on most x86 machines.
+
+	  The flash is exposed read-only via the ROM chip driver, e.g.
+	  for firmware analysis or extracting option ROMs (such as
+	  video BIOS images embedded in EFI firmware volumes). There is
+	  no write or erase support.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called int0800.
+
 config MTD_ICHXROM
 	tristate "BIOS flash chip on Intel Controller Hub 2/3/4/5"
 	depends on X86 && MTD_JEDECPROBE
drivers/mtd/maps/Makefile +1 -0
index 01745eca1f73..2f1a7375e13c 100644
@@ -14,6 +14,7 @@ obj-$(CONFIG_MTD_L440GX)	+= l440gx.o
 obj-$(CONFIG_MTD_AMD76XROM)	+= amd76xrom.o
 obj-$(CONFIG_MTD_ESB2ROM)	+= esb2rom.o
 obj-$(CONFIG_MTD_ICHXROM)	+= ichxrom.o
+obj-$(CONFIG_MTD_INT0800)	+= int0800.o
 obj-$(CONFIG_MTD_CK804XROM)	+= ck804xrom.o
 obj-$(CONFIG_MTD_TSUNAMI)	+= tsunami_flash.o
 obj-$(CONFIG_MTD_PXA2XX)	+= pxa2xx-flash.o
drivers/mtd/maps/int0800.c new file +115 -0

115 lines not on this page · raw message

Signature · 1 line
2.43.0
#3 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] mtd: maps: UAF of mtd_info and I/O memory on device unregistration --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] mtd: maps: UAF of mtd_info and I/O memory on device unregistration --

commit ad3016fe3893b23f61acf9f96913ff51726ac3a0
Author: Stephen Bancroft <[email protected]>

mtd: maps: add INT0800 firmware-flash map driver

Add a read-only mapping driver that binds the ACPI INT0800 "Intel 82802 firmware hub" device and exposes the system firmware flash as an MTD ROM device.

Quoted 5 lines
drivers/mtd/maps/int0800.c new file +0 -0
new file mode 100644
index 0000000000000..c5f108aa34797

[ ... ]

drivers/mtd/maps/int0800.c line 87

Quoted 6 lines
drivers/mtd/maps/int0800.c new file +6 -0
+static void int0800_remove(struct platform_device *pdev)
+{
+	struct int0800 *fw = platform_get_drvdata(pdev);
+
+	mtd_device_unregister(fw->mtd);
+	map_destroy(fw->mtd);

[Severity: High]
Does this teardown path force a use-after-free if the device is removed while a file descriptor is open?

While the driver sets .suppress_bind_attrs = true to prevent manual sysfs unbinds, the driver core can still invoke remove() when the underlying device is unregistered. This can happen if root unbinds the parent bridge in sysfs, or via ACPI SSDT unloading.

If int0800_remove() is invoked while userspace holds an open file descriptor, mtd_device_unregister() puts the kref but does not release the struct device because the character device retains an active reference.

Unconditionally calling map_destroy(fw->mtd) then frees the mtd_info structure. Could subsequent /dev/mtd0 reads or sysfs accesses dereference this freed memory and access unmapped devm I/O memory?

Quoted 1 line

+}

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#4 lore raw

The remaining removal paths don't apply to this device. The platform device is only unregistered via ACPI_RECONFIG_DEVICE_REMOVE, which requires the INT0800 ACPI node to leave the namespace. INT0800 is a static DSDT device: it has no _EJ0 (the eject sysfs attribute is never created for it), cannot live in an unloadable SSDT overlay, and has no hotplug notify source. Unbinding a parent device/driver does not invoke a child's remove(). With .suppress_bind_attrs the sysfs unbind is gone, and module unload is blocked by open fds via mtd->owner. The residual "rmmod -f with CONFIG_MODULE_FORCE_UNLOAD" bypasses refcounting for every driver. FWIW, the underlying limitation — map providers freeing mtd_info while the core cannot wait for open fds — is shared by all existing drivers/mtd/maps users; addressing it would be an MTD core lifetime change beyond this driver.

Quoted 50 lines · On Wed, 23 Sept 2026 at 19:41, <[email protected]> wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] mtd: maps: UAF of mtd_info and I/O memory on device unregistration --

commit ad3016fe3893b23f61acf9f96913ff51726ac3a0
Author: Stephen Bancroft <[email protected]>

mtd: maps: add INT0800 firmware-flash map driver

Add a read-only mapping driver that binds the ACPI INT0800 "Intel 82802 firmware hub" device and exposes the system firmware flash as an MTD ROM device.

Quoted 5 lines
drivers/mtd/maps/int0800.c new file +0 -0
new file mode 100644
index 0000000000000..c5f108aa34797

[ ... ]

drivers/mtd/maps/int0800.c line 87

Quoted 6 lines
drivers/mtd/maps/int0800.c new file +6 -0
+static void int0800_remove(struct platform_device *pdev)
+{
+     struct int0800 *fw = platform_get_drvdata(pdev);
+
+     mtd_device_unregister(fw->mtd);
+     map_destroy(fw->mtd);

[Severity: High]
Does this teardown path force a use-after-free if the device is removed while a file descriptor is open?

While the driver sets .suppress_bind_attrs = true to prevent manual sysfs unbinds, the driver core can still invoke remove() when the underlying device is unregistered. This can happen if root unbinds the parent bridge in sysfs, or via ACPI SSDT unloading.

If int0800_remove() is invoked while userspace holds an open file descriptor, mtd_device_unregister() puts the kref but does not release the struct device because the character device retains an active reference.

Unconditionally calling map_destroy(fw->mtd) then frees the mtd_info structure. Could subsequent /dev/mtd0 reads or sysfs accesses dereference this freed memory and access unmapped devm I/O memory?

Quoted 1 line

+}

--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1

Signature · 3 lines
Steve Reaver
http://www.stevereaver.com/
Electronic Music Production
maintainer Applied
#5 lore raw
In reply to Stephen Bancroft
Quoted 11 lines · Stephen Bancroft

Add a read-only mapping driver that binds the ACPI INT0800 "Intel 82802 firmware hub" device and exposes the system firmware flash as an MTD ROM device.

On x86 machines the boot flash is decoded into the physical address space below 4 GB, so a plain ioremap() of the declared resource window is sufficient for reads - no SPI or LPC controller access is needed. The window may be larger than the real flash; undecoded holes read as 0xff.

[...]

Applied to mtd/next, thanks!

[1/1] mtd: maps: add INT0800 firmware-flash map driver

      commit: c4f64a86a28d218f3b16cd7b18691993aa60db60

Patche(s) should be available on mtd/linux.git and will be part of the next PR (provided that no robot complains by then).

Kind regards,
Miquèl