Linux USB
 help / color / mirror / Atom feed
* [PATCH] thunderbolt: validate DROM entry lengths
@ 2026-07-06  9:15 Pengpeng Hou
  2026-07-27 11:34 ` Mika Westerberg
  0 siblings, 1 reply; 2+ messages in thread
From: Pengpeng Hou @ 2026-07-06  9:15 UTC (permalink / raw)
  To: Andreas Noever
  Cc: Pengpeng, Mika Westerberg, Yehezkel Bernat, linux-usb,
	linux-kernel

From: Pengpeng <pengpeng@iscas.ac.cn>

tb_drom_parse_entries() checks that a DROM entry does not run past the
end of the DROM, but it did not require the declared entry length to
cover the entry header itself.

Require each entry to contain its two-byte header before dispatching to
the type-specific DROM entry parsers.

Signed-off-by: Pengpeng <pengpeng@iscas.ac.cn>
---
 drivers/thunderbolt/eeprom.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/thunderbolt/eeprom.c b/drivers/thunderbolt/eeprom.c
index 5681c17f82ec..270bb34aff42 100644
--- a/drivers/thunderbolt/eeprom.c
+++ b/drivers/thunderbolt/eeprom.c
@@ -414,9 +414,15 @@ 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.43.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-07-27 11:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-06  9:15 [PATCH] thunderbolt: validate DROM entry lengths Pengpeng Hou
2026-07-27 11:34 ` Mika Westerberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox