Skip to contentSkip to conversation

thunderbolt: Fix double free of drom buffer

PATCH In review Andreas Noever 2 participants 3 messages Apr 10, 2016 – May 2, 2016

Subsystems (3)
lore
Share & tools
lore

Andreas Noever

author maintainer
#0 lore raw

PATCH 1/1 thunderbolt: Fix double free of drom buffer

If tb_drom_read fails sw->drom is freed but not set to NULL. sw->drom is then freed again in the error path of sw_switch_alloc.

The bug can be triggered by unplugging a thunderbolt device shortly after it is detected by the thunderbolt driver.

---
 drivers/thunderbolt/eeprom.c | 1 +
 1 file changed, 1 insertion(+)
drivers/thunderbolt/eeprom.c +1 -0
index 0dde34e..545c60c 100644
@@ -444,6 +444,7 @@ int tb_drom_read(struct tb_switch *sw)
 	return tb_drom_parse_entries(sw);
 err:
 	kfree(sw->drom);
+	sw->drom = NULL;
 	return -EIO;
 
 }
Signature · 1 line
2.8.0
#1 lore raw
Quoted 2 lines · Andreas Noever

If tb_drom_read fails sw->drom is freed but not set to NULL. sw->drom is then freed again in the error path of sw_switch_alloc.

s/sw_switch_alloc/tb_switch_alloc/ ?

Quoted 6 lines

The bug can be triggered by unplugging a thunderbolt device shortly after it is detected by the thunderbolt driver.

How far back would this need to be applied? What is the commit where the but was introduced?

I applied this to pci/thunderbolt for v4.7 with the following changelog. If I did it wrong, I'll gladly update it, especially if you have specific symptoms of a bug or oops that would help people find this fix.

thunderbolt: Fix double free of drom buffer

If tb_drom_read() fails, sw->drom is freed but not set to NULL. sw->drom is then freed again in the error path of tb_switch_alloc().

The bug can be triggered by unplugging a thunderbolt device shortly after it is detected by the thunderbolt driver.

Clear sw->drom if tb_drom_read() fails.

[bhelgaas: add Fixes:, stable versions of interest]
Fixes 343fcb8c70d7 ("thunderbolt: Fix nontrivial endpoint devices.")
CC [email protected] # v3.17+
CC Lukas Wunner <[email protected]>
Quoted 23 lines
---
 drivers/thunderbolt/eeprom.c | 1 +
 1 file changed, 1 insertion(+)
drivers/thunderbolt/eeprom.c +1 -0
index 0dde34e..545c60c 100644
@@ -444,6 +444,7 @@ int tb_drom_read(struct tb_switch *sw)
 	return tb_drom_parse_entries(sw);
 err:
 	kfree(sw->drom);
+	sw->drom = NULL;
 	return -EIO;
 
 }
Signature · 6 lines
2.8.0

--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
author maintainer
#2 lore raw
Quoted 23 lines · Bjorn Helgaas
Quoted 2 lines · Andreas Noever

If tb_drom_read fails sw->drom is freed but not set to NULL. sw->drom is then freed again in the error path of sw_switch_alloc.

s/sw_switch_alloc/tb_switch_alloc/ ?

Quoted 6 lines

The bug can be triggered by unplugging a thunderbolt device shortly after it is detected by the thunderbolt driver.

How far back would this need to be applied? What is the commit where the but was introduced?

I applied this to pci/thunderbolt for v4.7 with the following changelog. If I did it wrong, I'll gladly update it, especially if you have specific symptoms of a bug or oops that would help people find this fix.

thunderbolt: Fix double free of drom buffer

Quoted 7 lines

If tb_drom_read() fails, sw->drom is freed but not set to NULL. sw->drom is then freed again in the error path of tb_switch_alloc().

The bug can be triggered by unplugging a thunderbolt device shortly after it is detected by the thunderbolt driver.

Clear sw->drom if tb_drom_read() fails.

The changelog is correct. The bug can be triggered starting from 343fcb8c ("thunderbolt: Fix nontrivial endpoint devices.") which is in 3.17-rc1. I observed crashes during subsequent hotplug operations (pci core, sometimes in pciehp). But by nature of a double free bug these were not very reliable (used kasan to track it down).

Thanks
Andreas

Quoted 30 lines
[bhelgaas: add Fixes:, stable versions of interest]
Fixes 343fcb8c70d7 ("thunderbolt: Fix nontrivial endpoint devices.")
CC [email protected] # v3.17+
CC Lukas Wunner <[email protected]>
Quoted 23 lines
---
 drivers/thunderbolt/eeprom.c | 1 +
 1 file changed, 1 insertion(+)
drivers/thunderbolt/eeprom.c +1 -1
index 0dde34e..545c60c 100644
@@ -444,6 +444,7 @@ int tb_drom_read(struct tb_switch *sw)
      return tb_drom_parse_entries(sw);
 err:
      kfree(sw->drom);
+     sw->drom = NULL;
      return -EIO;
 
 }
--

2.8.0

--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html