Input: synaptics - add transparent pass-through mode for TrackPoint
Subsystems (2)
PATCH 1/1 Input: synaptics - add transparent pass-through mode for TrackPoint
From: laserology oss <[email protected]>
This reworks an earlier implementation by Miroslav Bendík from 2022 that was never merged. It keeps the same hardware-mode approach but commits the mode flag only after a successful mode command, moves the reconnect handling into a generic psmouse hook instead of protocol- specific checks in psmouse-interrupt, and documents the interface.
Changes in v2 (addressing review feedback):
- Only consult the parent serio in psmouse_receive_byte() when it is a genuine psmouse pass-through port; a psmouse attached to a ps2mult child port has a parent whose drvdata is not a struct psmouse, so the unconditional cast could read a bogus function pointer.
- Guard the guest state reset in synaptics_set_transparent_mode() on the pass-through port actually being bound to a psmouse, and commit the protocol handler/pktsize update with RX paused to avoid a torn update.
- Exit transparent mode on the hardware as well as in software when the pass-through guest port is removed while the mode is active.
- Re-run the full initialization (query, identity check, mode setup) before re-entering transparent mode during reconnect, so the device is in a known configuration after a reset.
- Use psmouse_set_state(PSMOUSE_ACTIVATED) to drop stale guest data instead of the bare pktcnt = 0 assignment, which could leave the psmouse state machine (flags, state) out of sync with the packet counter.
- Move the dev-attr creation ahead of the pass-through port registration so that an attribute creation failure cannot leak a registered child port whose callbacks reference freed synaptics_data.
Changes in v3 (addressing AI review findings):
- Scope the serio_pause_rx guard in synaptics_set_transparent_mode() to the protocol-handler commit only; calling psmouse_set_state() inside it re-enables interrupts via serio_continue_rx() while the parent lock is held, which can deadlock.
- Track the child psmouse via a pt_psmouse field set in synaptics_pt_open() instead of reaching into serio_get_drvdata() on the pass-through port; a non-psmouse driver could be bound to the port, and the unconditional cast risks memory corruption.
- In synaptics_pt_stop(), exit hardware transparent mode before updating the software protocol handler, so guest data is never misparsed as host touchpad packets.
- Unregister and free the pass-through serio port in synaptics_disconnect() so it is not leaked when the parent psmouse driver is unbound.
--- .../ABI/testing/sysfs-driver-synaptics | 28 ++ MAINTAINERS | 1 + drivers/input/mouse/psmouse-base.c | 17 +- drivers/input/mouse/psmouse.h | 7 + drivers/input/mouse/synaptics.c | 288 +++++++++++++++++- drivers/input/mouse/synaptics.h | 4 + 6 files changed, 329 insertions(+), 16 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-driver-synaptics
Documentation/ABI/testing/sysfs-driver-synaptics new file +28 -0
@@ -0,0 +1,28 @@ +What: /sys/bus/serio/devices/serioX/transparent_mode +Date: August 2026 +Contact: [email protected] +Description: + Controls the transparent pass-through mode of Synaptics + touchpads that feature a pass-through (PS/2 guest) port, such as + those used for a TrackPoint. + + In normal operation the touchpad serves as the PS/2 host for + the pass-through guest: it scans the guest during its own scan + cycle and encapsulates the guest's data into its own packets, + which limits the guest to the touchpad's low poll rate. When + transparent mode is enabled the touchpad stops generating its + own packets and simply relays the raw byte stream of the + pass-through guest, letting the guest run at its high poll rate + while the touchpad is effectively disabled. + + Write 1 to enable the mode, or 0 to disable it. Reading the + attribute returns the current state ("0" or "1"). + + Note that both devices cannot be serviced at full rate at the + same time on this hardware; enabling the mode disables the + touchpad until it is disabled again. The attribute is present + only on devices that report the pass-through capability. + +Users: Userspace that arbitrates between full-rate TrackPoint and + full-rate touchpad operation. No consumer exists yet; the + interface is provided so that one can be developed.
MAINTAINERS +1 -0
@@ -12817,6 +12817,7 @@ L: [email protected] S: Maintained Q: http://patchwork.kernel.org/project/linux-input/list/ T: git git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input.git +F: Documentation/ABI/testing/sysfs-driver-synaptics F: Documentation/devicetree/bindings/input/ F: Documentation/devicetree/bindings/serio/ F: Documentation/input/
drivers/input/mouse/psmouse-base.c +16 -1
@@ -385,8 +385,23 @@ static void psmouse_receive_byte(struct ps2dev *ps2dev, u8 data) }if (psmouse->packet[1 ] ==PSMOUSE_RET_ID ) { +struct serio *serio = ps2dev->serio; +struct psmouse *parent_psmouse =NULL ; +__psmouse_set_state (psmouse,PSMOUSE_IGNORE ); -serio_reconnect (ps2dev->serio); +/* +* Some devices need parent to be reconnected instead. +* Only consult the parent if this is a genuine psmouse +* pass-through port; other serio children may have a +* parent whose drvdata is not a struct psmouse. +*/ +if (serio->parent && serio->id.type ==SERIO_PS_PSTHRU ) + parent_psmouse =psmouse_from_serio (serio->parent); +if (parent_psmouse && parent_psmouse->pt_reconnect_parent && + parent_psmouse->pt_reconnect_parent (parent_psmouse)) +serio_reconnect (serio->parent); +else +serio_reconnect (serio);return ; }
drivers/input/mouse/psmouse.h +7 -0
@@ -128,6 +128,13 @@ struct psmouse {void (*pt_activate)(struct psmouse *psmouse);void (*pt_deactivate)(struct psmouse *psmouse); + +/* +* Called on the parent device when a pass-through guest reports a new +* device announcement (0xAA 0x00). Return true if the parent, and not +* the guest, should be reconnected. +*/ +bool (*pt_reconnect_parent)(struct psmouse *psmouse); };struct psmouse *psmouse_from_serio (struct serio *serio);
drivers/input/mouse/synaptics.c +273 -15
390 lines not on this page · raw message
drivers/input/mouse/synaptics.h +4 -0
@@ -24,6 +24,7 @@/* synaptics modes */ #define SYN_BIT_ABSOLUTE_MODE BIT(7)#define SYN_BIT_HIGH_RATE BIT(6) +#define SYN_BIT_TRANSPARENT_MODE BIT(5)#define SYN_BIT_SLEEP_MODE BIT(3)#define SYN_BIT_DISABLE_GESTURE BIT(2)#define SYN_BIT_FOUR_BYTE_CLIENT BIT(1)
@@ -186,8 +187,11 @@ struct synaptics_data {bool absolute_mode;/* run in Absolute mode */ bool disable_gesture;/* disable gestures */ +bool transparent_mode;/* pass packets directly from guest */ struct serio *pt_port;/* Pass-through serio port */ +struct serio *pt_serio;/* Allocated pass-through serio port */ +struct psmouse *pt_psmouse;/* Child psmouse bound to the pt port */ bool pt_port_open;/*
Signature · 1 line
2.55.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [Critical] Self-deadlock and Use-After-Free/Double-Free of the pass-through serio port during parent…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Critical] Self-deadlock and Use-After-Free/Double-Free of the pass-through serio port during parent driver unbind or port unregistration.
- [Critical] Type confusion in synaptics_pt_open() leads to arbitrary memory corruption when toggling transparent mode.
- [High] Bypassed mutex synchronization in synaptics_pt_write() causes concurrent hardware command injection and data races. --
--- Patch [1]: [PATCH] Input: synaptics - add transparent pass-through mode for TrackPoint --- commit 1a99c1461a4c3bd59a184b3551c27088c1845e41
Author: laserology oss <[email protected]>
Input: synaptics - add transparent pass-through mode for TrackPoint
This patch reworks an earlier implementation to add a transparent pass-through mode for Synaptics touchpads with a TrackPoint. It documents the interface and modifies the protocol handling to support relaying the raw byte stream of the pass-through guest.
Quoted 4 lines
drivers/input/mouse/synaptics.c +0
-0
[ ... ]
drivers/input/mouse/synaptics.c static void synaptics_set_rate(struct psmouse *psmouse, unsigned int rate) · line 720
Quoted 10 lines
static int
synaptics_pt_write(struct serio *serio, u8 c){drivers/input/mouse/synaptics.c +4
-0struct psmouse *parent =psmouse_from_serio (serio->parent); +struct synaptics_data *priv = parent->private;u8 rate_param =SYN_PS_CLIENT_CMD ;/* indicates that we want pass-through port */ int error; +if (READ_ONCE (priv->transparent_mode)) +return parent->ps2dev.serio->write (parent->ps2dev.serio, c); +
[Severity: High]
Does this bypass the parent's ps2_cmd_mutex? Since the child port uses its own isolated ps2_cmd_mutex, returning parent->ps2dev.serio->write(...) directly could allow concurrent hardware commands. This could interleave raw PS/2 bytes if userspace triggers a command on the parent device (like changing transparent_mode) while the child is writing.
Quoted 3 lines
drivers/input/mouse/synaptics.c +0
-0error =ps2_sliced_command (&parent->ps2dev, c);if (error)return error;
[ ... ]
Quoted 12 lines
drivers/input/mouse/synaptics.c +5
-2@@ -669,9 +747,30 @@ static void synaptics_pt_stop(struct serio *serio) {struct psmouse *parent =psmouse_from_serio (serio->parent);struct synaptics_data *priv = parent->private; +bool exit_mode; -guard (serio_pause_rx)(parent->ps2dev.serio); - priv->pt_port =NULL ; + exit_mode =READ_ONCE (priv->transparent_mode); + +/* +* The guest is going away. Take the hardware out of transparent
drivers/input/mouse/synaptics.c static void synaptics_pt_stop(struct serio *serio) · line 765
Quoted 10 lines
drivers/input/mouse/synaptics.c +10
-0+* mode first so the device stops relaying the guest's byte stream +* and resumes producing host packets, then update the software state +* with RX paused so the interrupt handler never observes a torn +* configuration. +*/ +if (exit_mode) { +if (synaptics_exit_transparent_mode (parent)) +psmouse_warn (parent, +"failed to exit transparent mode after pass-through port removal\n" ); + }
[Severity: High]
Does this create a data race if a driver like serio_raw is bound to the child port? Unbinding serio_raw invokes synaptics_pt_stop() without holding the global psmouse_mutex. Modifying hardware state and priv->transparent_mode here could race with synaptics_set_transparent_mode() running concurrently on the parent device.
Quoted 12 lines
drivers/input/mouse/synaptics.c +8
-0+ + { +guard (serio_pause_rx)(parent->ps2dev.serio); + + priv->pt_port =NULL ; +WRITE_ONCE (priv->transparent_mode, false); +synaptics_update_protocol_handler (parent); + } }static int synaptics_pt_open (struct serio *serio)
drivers/input/mouse/synaptics.c static int synaptics_pt_open(struct serio *serio) · line 783
Quoted 4 lines
drivers/input/mouse/synaptics.c +1
-0@@ -681,6 +780,7 @@ static int synaptics_pt_open(struct serio *serio)guard (serio_pause_rx)(parent->ps2dev.serio); priv->pt_port_open = true; + priv->pt_psmouse =psmouse_from_serio (serio);
[Severity: Critical]
Can this cast cause memory corruption? If userspace binds a non-psmouse driver (like serio_raw) to the pass-through port, the driver data points to a different structure (e.g., struct serio_raw). This caches a bogus pointer in priv->pt_psmouse, which is later dereferenced in synaptics_set_transparent_mode().
Quoted 3 lines
drivers/input/mouse/synaptics.c +0
-0return 0 ; }
[ ... ]
drivers/input/mouse/synaptics.c PSMOUSE_DEFINE_ATTR(disable_gesture, S_IWUSR | S_IRUGO, NULL, · line 1631
Quoted 12 lines
drivers/input/mouse/synaptics.c +12
-0+/* +* The touchpad is stopped for the duration of the mode switch, but the +* pass-through guest keeps streaming. It may therefore be left with a +* partially assembled packet from the previous mode. Drop it so the +* stream restarts cleanly in the new mode and no stale bytes are +* misparsed as pointer motion or spurious button clicks. +*/ +if (READ_ONCE (priv->pt_port)) { +struct psmouse *child =READ_ONCE (priv->pt_psmouse); + +if (child && child->state ==PSMOUSE_ACTIVATED ) +psmouse_set_state (child,PSMOUSE_ACTIVATED );
[Severity: Critical]
If a different driver (like serio_raw) is bound, this could interpret arbitrary memory as a struct psmouse. By manipulating the serio_raw queue buffer to match PSMOUSE_ACTIVATED and injecting a pointer, could this result in psmouse_set_state() dereferencing an attacker-controlled pointer to acquire a spinlock?
Quoted 4 lines
drivers/input/mouse/synaptics.c +4
-0+ } + +return len; +}
[ ... ]
Quoted 15 lines
static void
synaptics_disconnect(struct psmouse *psmouse){drivers/input/mouse/synaptics.c +5
-0struct synaptics_data *priv = psmouse->private;@@ -1448,10 +1649,24 @@ static void synaptics_disconnect(struct psmouse *psmouse)*/ psmouse_smbus_cleanup (psmouse); +if (READ_ONCE (priv->transparent_mode)) { +synaptics_exit_transparent_mode (psmouse); +WRITE_ONCE (priv->transparent_mode, false); + } +if (!priv->absolute_mode &&SYN_ID_DISGEST_SUPPORTED (priv->info.identity)) device_remove_file(&psmouse->ps2dev.serio->dev,
drivers/input/mouse/synaptics.c static void synaptics_disconnect(struct psmouse *psmouse) · line 1669
Quoted 10 lines
drivers/input/mouse/synaptics.c +9
-0&psmouse_attr_disable_gesture.dattr); +if (SYN_CAP_PASS_THROUGH (priv->info.capabilities)) +device_remove_file (&psmouse->ps2dev.serio->dev, + &psmouse_attr_transparent_mode.dattr); + +if (priv->pt_serio) { +serio_unregister_port (priv->pt_serio); +kfree (priv->pt_serio); + priv->pt_serio =NULL ; + }
[Severity: Critical]
Can this cause a use-after-free, double-free, and self-deadlock?
If the parent port is unregistered (e.g. physical removal), the serio core traverses the tree depth-first and synchronously destroys the child pass-through port, freeing its memory. When synaptics_disconnect() is then called for the parent, calling serio_unregister_port() and kfree() on the dangling priv->pt_serio pointer could use freed memory and deadlock on serio_mutex, which is already held by the core's unregistration path.
Alternatively, if userspace manually unbinds the parent driver via sysfs:
psmouse_disconnect() (acquires psmouse_mutex)
synaptics_disconnect()
serio_unregister_port()
(unbinds child driver)
psmouse_disconnect() for child
(tries to acquire psmouse_mutex)
Could this sequence lead to a permanent self-deadlock on psmouse_mutex?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1