* [PATCH] Input: synaptics-rmi4 - fix UAF of IRQ domain on driver removal
@ 2024-02-22 14:26 Mathias Krause
2024-03-08 0:20 ` Dmitry Torokhov
0 siblings, 1 reply; 2+ messages in thread
From: Mathias Krause @ 2024-02-22 14:26 UTC (permalink / raw)
To: Dmitry Torokhov, Torsten Hilbrich
Cc: Dan Carpenter, Nick Dyer, Brad Spengler, Sasha Levin,
Jiapeng Chong, linux-input, linux-kernel, 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.
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")
Reported-by: Torsten Hilbrich <torsten.hilbrich@secunet.com>
Signed-off-by: Mathias Krause <minipli@grsecurity.net>
---
Torsten, could you please confirm (again) that this patch, instead of
[1], fixes the bug for you?
[1] https://lore.kernel.org/lkml/e77756aa-c0f1-44a8-bcd6-a46fe954b195@moroto.mountain/
drivers/input/rmi4/rmi_driver.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/input/rmi4/rmi_driver.c b/drivers/input/rmi4/rmi_driver.c
index 258d5fe3d395..42eaebb3bf5c 100644
--- a/drivers/input/rmi4/rmi_driver.c
+++ b/drivers/input/rmi4/rmi_driver.c
@@ -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;
}
--
2.30.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] Input: synaptics-rmi4 - fix UAF of IRQ domain on driver removal
2024-02-22 14:26 [PATCH] Input: synaptics-rmi4 - fix UAF of IRQ domain on driver removal Mathias Krause
@ 2024-03-08 0:20 ` Dmitry Torokhov
0 siblings, 0 replies; 2+ messages in thread
From: Dmitry Torokhov @ 2024-03-08 0:20 UTC (permalink / raw)
To: Mathias Krause
Cc: Torsten Hilbrich, Dan Carpenter, Nick Dyer, Brad Spengler,
Sasha Levin, Jiapeng Chong, linux-input, linux-kernel
On Thu, Feb 22, 2024 at 03:26:54PM +0100, Mathias Krause wrote:
> 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")
> Reported-by: Torsten Hilbrich <torsten.hilbrich@secunet.com>
> Signed-off-by: Mathias Krause <minipli@grsecurity.net>
Applied, thank you.
--
Dmitry
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-03-08 0:20 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-22 14:26 [PATCH] Input: synaptics-rmi4 - fix UAF of IRQ domain on driver removal Mathias Krause
2024-03-08 0:20 ` Dmitry Torokhov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox