mirror-linux/drivers/input/mouse
Duoming Zhou bf40644ef8 Input: alps - fix use-after-free bugs caused by dev3_register_work
The dev3_register_work delayed work item is initialized within
alps_reconnect() and scheduled upon receipt of the first bare
PS/2 packet from an external PS/2 device connected to the ALPS
touchpad. During device detachment, the original implementation
calls flush_workqueue() in psmouse_disconnect() to ensure
completion of dev3_register_work. However, the flush_workqueue()
in psmouse_disconnect() only blocks and waits for work items that
were already queued to the workqueue prior to its invocation. Any
work items submitted after flush_workqueue() is called are not
included in the set of tasks that the flush operation awaits.
This means that after flush_workqueue() has finished executing,
the dev3_register_work could still be scheduled. Although the
psmouse state is set to PSMOUSE_CMD_MODE in psmouse_disconnect(),
the scheduling of dev3_register_work remains unaffected.

The race condition can occur as follows:

CPU 0 (cleanup path)     | CPU 1 (delayed work)
psmouse_disconnect()     |
  psmouse_set_state()    |
  flush_workqueue()      | alps_report_bare_ps2_packet()
  alps_disconnect()      |   psmouse_queue_work()
    kfree(priv); // FREE | alps_register_bare_ps2_mouse()
                         |   priv = container_of(work...); // USE
                         |   priv->dev3 // USE

Add disable_delayed_work_sync() in alps_disconnect() to ensure
that dev3_register_work is properly canceled and prevented from
executing after the alps_data structure has been deallocated.

This bug is identified by static analysis.

Fixes: 04aae283ba ("Input: ALPS - do not mix trackstick and external PS/2 mouse data")
Cc: stable@kernel.org
Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
Link: https://patch.msgid.link/b57b0a9ccca51a3f06be141bfc02b9ffe69d1845.1765939397.git.duoming@zju.edu.cn
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
2025-12-17 10:08:44 -08:00
..
Kconfig Revert "Input: Add driver for PixArt PS/2 touchpad" 2024-10-01 03:54:05 -07:00
Makefile Revert "Input: Add driver for PixArt PS/2 touchpad" 2024-10-01 03:54:05 -07:00
alps.c Input: alps - fix use-after-free bugs caused by dev3_register_work 2025-12-17 10:08:44 -08:00
alps.h
amimouse.c Input: switch back to struct platform_driver::remove() 2024-10-15 11:43:25 -07:00
appletouch.c Input: mouse - use sizeof(*pointer) instead of sizeof(type) 2024-06-02 21:32:02 -07:00
atarimouse.c
bcm5974.c Input: bcm5974 - use guard notation when acquiring mutex 2024-08-29 11:00:21 -07:00
byd.c treewide, timers: Rename from_timer() to timer_container_of() 2025-06-08 09:07:37 +02:00
byd.h
cyapa.c objtool, Input: cyapa - Remove undefined behavior in cyapa_update_fw_store() 2025-03-25 23:00:15 +01:00
cyapa.h
cyapa_gen3.c move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
cyapa_gen5.c move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
cyapa_gen6.c move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
cypress_ps2.c Input: cypress_ps2 - fix waiting for command response 2024-08-29 10:46:17 -07:00
cypress_ps2.h Input: cypress_ps2 - fix error handling when sending command fails 2024-07-03 13:48:53 -07:00
elan_i2c.h Input: elan_i2c - reduce the resume time for controller in Whitebox 2021-09-06 22:30:34 -07:00
elan_i2c_core.c Input: Use str_enable_disable-like helpers 2025-01-14 13:41:41 -08:00
elan_i2c_i2c.c Input updates for v6.13-rc0 2024-11-25 10:31:39 -08:00
elan_i2c_smbus.c Merge branch 'next' into for-linus 2020-12-14 16:27:23 -08:00
elantech.c move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
elantech.h Input: elantech - fix protocol errors for some trackpoints in SMBus mode 2020-12-11 00:15:05 -08:00
focaltech.c Input: mouse - use sizeof(*pointer) instead of sizeof(type) 2024-06-02 21:32:02 -07:00
focaltech.h
gpio_mouse.c Input: gpio_mouse - fix typos in comments 2022-06-22 15:29:35 -07:00
hgpk.c Input: mouse - use sizeof(*pointer) instead of sizeof(type) 2024-06-02 21:32:02 -07:00
hgpk.h
inport.c input: drop empty comment blocks 2022-09-29 16:25:42 -07:00
lifebook.c Input: lifebook - switch to use scnprintf() to suppress truncation warning 2025-06-03 21:51:27 -07:00
lifebook.h
logibm.c input: drop empty comment blocks 2022-09-29 16:25:42 -07:00
logips2pp.c
logips2pp.h
maplemouse.c Input: mouse - use sizeof(*pointer) instead of sizeof(type) 2024-06-02 21:32:02 -07:00
pc110pad.c input: drop empty comment blocks 2022-09-29 16:25:42 -07:00
psmouse-base.c Input: psmouse - switch to use scnprintf() to suppress truncation warning 2025-06-03 21:51:28 -07:00
psmouse-smbus.c Input: psmouse-smbus - use guard notation when acquiring mutex 2024-10-03 08:39:21 -07:00
psmouse.h Revert "Input: Add driver for PixArt PS/2 touchpad" 2024-10-01 03:54:05 -07:00
rpcmouse.c
sentelic.c Input: mouse - use sizeof(*pointer) instead of sizeof(type) 2024-06-02 21:32:02 -07:00
sentelic.h
sermouse.c Input: mouse - use sizeof(*pointer) instead of sizeof(type) 2024-06-02 21:32:02 -07:00
synaptics.c Input: synaptics - enable InterTouch on Dell Precision M3800 2025-05-07 14:56:05 -07:00
synaptics.h Input: synaptics - fix crash when enabling pass-through port 2025-01-20 21:27:02 -08:00
synaptics_i2c.c Input: mouse - use sizeof(*pointer) instead of sizeof(type) 2024-06-02 21:32:02 -07:00
synaptics_usb.c Input: move from strlcpy with unused retval to strscpy 2022-08-18 15:44:08 -07:00
touchkit_ps2.c
touchkit_ps2.h
trackpoint.c Input: libps2 - attach ps2dev instances as serio port's drvdata 2023-05-18 11:40:32 -07:00
trackpoint.h Input: trackpoint - add new trackpoint variant IDs 2020-09-14 12:24:46 -07:00
vmmouse.c input/vmmouse: Use VMware hypercall API 2024-06-25 17:15:47 +02:00
vmmouse.h
vsxxxaa.c Input: mouse - use sizeof(*pointer) instead of sizeof(type) 2024-06-02 21:32:02 -07:00