Hi Minseong,
On Thu, Dec 11, 2025 at 12:11:31PM +0900, Minseong Kim wrote:
lkkbd_interrupt() schedules lk->tq with schedule_work(), and the work handler lkkbd_reinit() dereferences the lkkbd structure and its serio/input_dev fields.
lkkbd_disconnect() frees the lkkbd structure without cancelling this work, so the work can run after the structure has been freed, leading to a potential use-after-free.
Cancel the pending work in lkkbd_disconnect() before unregistering and freeing the device, following the same pattern as sunkbd.
Thank you for spotting this.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Reported-by: Minseong Kim ii4gsp@gmail.com Cc: stable@vger.kernel.org Signed-off-by: Minseong Kim ii4gsp@gmail.com
drivers/input/keyboard/lkkbd.c | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/drivers/input/keyboard/lkkbd.c b/drivers/input/keyboard/lkkbd.c index c035216dd27c..72c477aab1fc 100644 --- a/drivers/input/keyboard/lkkbd.c +++ b/drivers/input/keyboard/lkkbd.c @@ -684,6 +684,8 @@ static void lkkbd_disconnect(struct serio *serio) { struct lkkbd *lk = serio_get_drvdata(serio);
- cancel_work_sync(&lk->tq);
We should use disable_work_sync() here because even if we cancel the work there is a chance it will be queued again (up until the moment serio_close() returns).
We also need to call disable_work_sync() in lkkbd_connect() in error paths once serio_open() has been called.
Thanks.