diff mbox series

Input: synaptics-rmi4 - fix use after free in rmi_unregister_function()

Message ID 706efd36-7561-42f3-adfa-dd1d0bd4f5a1@moroto.mountain
State Accepted
Commit eb988e46da2e4eae89f5337e047ce372fe33d5b1
Headers show
Series Input: synaptics-rmi4 - fix use after free in rmi_unregister_function() | expand

Commit Message

Dan Carpenter Oct. 27, 2023, 12:18 p.m. UTC
The put_device() calls rmi_release_function() which frees "fn" so the
dereference on the next line "fn->num_of_irqs" is a use after free.
Move the put_device() to the end to fix this.

Fixes: 24d28e4f1271 ("Input: synaptics-rmi4 - convert irq distribution to irq_domain")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
 drivers/input/rmi4/rmi_bus.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Dmitry Torokhov Oct. 29, 2023, 2:54 a.m. UTC | #1
On Fri, Oct 27, 2023 at 03:18:28PM +0300, Dan Carpenter wrote:
> The put_device() calls rmi_release_function() which frees "fn" so the
> dereference on the next line "fn->num_of_irqs" is a use after free.
> Move the put_device() to the end to fix this.
> 
> Fixes: 24d28e4f1271 ("Input: synaptics-rmi4 - convert irq distribution to irq_domain")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>

Applied, thank you.
diff mbox series

Patch

diff --git a/drivers/input/rmi4/rmi_bus.c b/drivers/input/rmi4/rmi_bus.c
index f2e093b0b998..1b45b1d3077d 100644
--- a/drivers/input/rmi4/rmi_bus.c
+++ b/drivers/input/rmi4/rmi_bus.c
@@ -277,11 +277,11 @@  void rmi_unregister_function(struct rmi_function *fn)
 
 	device_del(&fn->dev);
 	of_node_put(fn->dev.of_node);
-	put_device(&fn->dev);
 
 	for (i = 0; i < fn->num_of_irqs; i++)
 		irq_dispose_mapping(fn->irq[i]);
 
+	put_device(&fn->dev);
 }
 
 /**