Skip to contentSkip to conversation

Input: synaptics-rmi4 - fix UAF of IRQ domain on driver removal

PATCH Applied Mathias Krause 2 participants 2 messages Feb 22, 2024 – Mar 8, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Input: synaptics-rmi4 - fix UAF of IRQ domain on driver removal

Calling irq_domain_remove() will lead to freeing the IRQ domain prematurely. The domain is still referenced and will be attempted to get used via rmi_free_function_list() -> rmi_unregister_function() -> irq_dispose_mapping() -> irq_get_irq_data()'s ->domain pointer.

With PaX's MEMORY_SANITIZE this will lead to an access fault when attempting to dereference embedded pointers, as in Torsten's report that was faulting on the 'domain->ops->unmap' test.

Fix this by releasing the IRQ domain only after all related IRQs have been deactivated.

Fixes 24d28e4f1271 ("Input: synaptics-rmi4 - convert irq distribution to irq_domain")

---
Torsten, could you please confirm (again) that this patch, instead of [1], fixes the bug for you?

[1] https://lore.kernel.org/lkml/[email protected]/

 drivers/input/rmi4/rmi_driver.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/input/rmi4/rmi_driver.c +3 -3
index 258d5fe3d395..42eaebb3bf5c 100644
@@ -978,12 +978,12 @@ static int rmi_driver_remove(struct device *dev)
 
 	rmi_disable_irq(rmi_dev, false);
 
+	rmi_f34_remove_sysfs(rmi_dev);
+	rmi_free_function_list(rmi_dev);
+
 	irq_domain_remove(data->irqdomain);
 	data->irqdomain = NULL;
 
-	rmi_f34_remove_sysfs(rmi_dev);
-	rmi_free_function_list(rmi_dev);
-
 	return 0;
 }
 
Signature · 1 line
2.30.2
maintainer Applied
#1 lore raw
Quoted 9 lines · Mathias Krause

Calling irq_domain_remove() will lead to freeing the IRQ domain prematurely. The domain is still referenced and will be attempted to get used via rmi_free_function_list() -> rmi_unregister_function() -> irq_dispose_mapping() -> irq_get_irq_data()'s ->domain pointer.

With PaX's MEMORY_SANITIZE this will lead to an access fault when attempting to dereference embedded pointers, as in Torsten's report that was faulting on the 'domain->ops->unmap' test.

Quoted 6 lines

Fix this by releasing the IRQ domain only after all related IRQs have been deactivated.

Fixes 24d28e4f1271 ("Input: synaptics-rmi4 - convert irq distribution to irq_domain")

Applied, thank you.

Signature · 1 line
Dmitry