]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
Input: synaptics-rmi4 - fix UAF of IRQ domain on driver removal
authorMathias Krause <minipli@grsecurity.net>
Wed, 9 Oct 2024 05:41:48 +0000 (05:41 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 17 Oct 2024 13:11:49 +0000 (15:11 +0200)
commit fbf8d71742557abaf558d8efb96742d442720cc2 upstream.

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>
Link: https://lore.kernel.org/r/20240222142654.856566-1-minipli@grsecurity.net
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/input/rmi4/rmi_driver.c

index aa32371f04af6c8838efa1e9cb3ab1e8a3100dc6..ef9ea295f9e035fd3bb5ea733a009ba72f32a833 100644 (file)
@@ -978,12 +978,12 @@ static int rmi_driver_remove(struct device *dev)
 
        rmi_disable_irq(rmi_dev, false);
 
-       irq_domain_remove(data->irqdomain);
-       data->irqdomain = NULL;
-
        rmi_f34_remove_sysfs(rmi_dev);
        rmi_free_function_list(rmi_dev);
 
+       irq_domain_remove(data->irqdomain);
+       data->irqdomain = NULL;
+
        return 0;
 }