[PATCH v3 1/2] thunderbolt: require complete DROM entry headers

From: Pengpeng Hou

Date: Thu Aug 13 2026 - 11:27:10 EST


tb_drom_parse_entries() checks for one byte remaining before reading a
DROM entry header, but the header occupies two bytes. It also accepts a
declared length of one byte.

A one-byte tail consequently makes the parser read entry->len outside
the DROM. A one-byte generic string entry reaches the subtype parser and
underflows its payload-length calculation.

Require a complete entry header before reading it and require the
declared entry length to cover that header. Use subtraction-based bounds
checks so the firmware-provided length cannot overflow the DROM extent
calculation.

Fixes: cd22e73bdf5e ("thunderbolt: Read port configuration from eeprom.")
Assisted-by: Codex:gpt-5
Signed-off-by: Pengpeng Hou <pengpeng@xxxxxxxxxxx>
---
drivers/thunderbolt/eeprom.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/drivers/thunderbolt/eeprom.c b/drivers/thunderbolt/eeprom.c
index 2a13fa6888ba..52d654048f07 100644
--- a/drivers/thunderbolt/eeprom.c
+++ b/drivers/thunderbolt/eeprom.c
@@ -421,9 +421,16 @@ static int tb_drom_parse_entries(struct tb_switch *sw, size_t header_size)
int res;

while (pos < drom_size) {
- struct tb_drom_entry_header *entry = (void *) (sw->drom + pos);
- if (pos + 1 == drom_size || pos + entry->len > drom_size
- || !entry->len) {
+ struct tb_drom_entry_header *entry;
+
+ if (drom_size - pos < sizeof(*entry)) {
+ tb_sw_warn(sw, "DROM buffer overrun\n");
+ return -EIO;
+ }
+
+ entry = (void *)(sw->drom + pos);
+ if (entry->len < sizeof(*entry) ||
+ entry->len > drom_size - pos) {
tb_sw_warn(sw, "DROM buffer overrun\n");
return -EIO;
}
--
2.50.1 (Apple Git-155)