Input: ps2-gpio - flush TX work when closing port
Subsystems (2)
Dmitry Torokhov
maintainerPATCH 1/1 Input: ps2-gpio - flush TX work when closing port
To ensure that TX work is not running after serio port has been torn down, let's flush it when closing the port.
--- drivers/input/serio/ps2-gpio.c | 1 + 1 file changed, 1 insertion(+)
drivers/input/serio/ps2-gpio.c +1 -0
@@ -76,6 +76,7 @@ static void ps2_gpio_close(struct serio *serio) {struct ps2_gpio_data *drvdata = serio->port_data; +flush_work (&drvdata->tx_work.work);disable_irq (drvdata->irq); }
Signature · 5 lines
2.20.1.611.gfbb209baf1-goog -- Dmitry
Dmitry Torokhov
maintainerQuoted 14 lines · Dmitry Torokhov
To ensure that TX work is not running after serio port has been torn down, let's flush it when closing the port.
Reported-by Sven Van Asbroeck <[email protected]>Signed-off-by Dmitry Torokhov <[email protected]>--- drivers/input/serio/ps2-gpio.c | 1 + 1 file changed, 1 insertion(+)drivers/input/serio/ps2-gpio.c +0
-0
drivers/input/serio/ps2-gpio.c static void ps2_gpio_close(struct serio *serio) · line 79
Quoted 4 lines
drivers/input/serio/ps2-gpio.c +1
-0@@ -76,6 +76,7 @@ static void ps2_gpio_close(struct serio *serio) {struct ps2_gpio_data *drvdata = serio->port_data; +flush_work (&drvdata->tx_work.work);
Ah, we have flush_delayed_work() now, I'll change it before committing once we agree on the patch in principle.
Quoted 9 lines
drivers/input/serio/ps2-gpio.c +0
-0disable_irq (drvdata->irq); }Signature · 5 lines
2.20.1.611.gfbb209baf1-goog -- Dmitry
Signature · 1 line
Dmitry
Quoted 2 lines · Dmitry Torokhov
+
flush_work(&drvdata->tx_work.work);
Would cancel_work_sync() be better than flush_work() ?
Dmitry Torokhov
maintainerQuoted 6 lines · Sven Van Asbroeck
Quoted 2 lines · Dmitry Torokhov
+
flush_work(&drvdata->tx_work.work);Would
cancel_work_sync()be better thanflush_work()?
No, because we want to have interrupt and gpios in a consistent state. If we cancel then we need to see if we should disable it or it may already be disabled, etc. This way we know it is enabled after flush_delayed_work() returns, and we need to disable it.
Thanks.
Signature · 1 line
Dmitry
Danilo Krummrich
Acked-byQuoted 6 lines · Dmitry Torokhov
Quoted 5 lines · Sven Van Asbroeck
Quoted 2 lines · Dmitry Torokhov
+
flush_work(&drvdata->tx_work.work);
Quoted 8 lines
Quoted 1 line
Would
cancel_work_sync()be better thanflush_work()?No, because we want to have interrupt and gpios in a consistent state. If we cancel then we need to see if we should disable it or it may already be disabled, etc. This way we know it is enabled after
flush_delayed_work()returns, and we need to disable it.Thanks.
I agree with Dmitry - thanks for the fix.
Sven Van Asbroeck
Reviewed-byQuoted 3 lines · Danilo Krummrich
I agree with Dmitry
So do I, you guys are absolutely right.
As far as I can see, this patch fixes the user-after-free. So, after Dmitry changes flush_work() to flush_delayed_work() :