Input: synaptics - add transparent pass-through mode for TrackPoint
Subsystems (2)
PATCH v2 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 not left without e.g. Advanced Gesture Mode after a suspend/resume.
- Register the pass-through port only after all fallible init steps so a failed init cannot leak a child port that dereferences the freed synaptics_data.
---
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 +270 -15
371 lines not on this page · raw message
drivers/input/mouse/synaptics.h +2 -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,6 +187,7 @@ 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 */ bool pt_port_open;
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
New issues:
- [High] Calling psmouse_set_state() while holding the parent device's serio_pause_rx guard unconditionally re-enables local interrupts while the parent lock is still held, leading to a self-deadlock.
- [High] Resetting the pass-through port in synaptics_set_transparent_mode blindly casts the child driver data to struct psmouse, leading to memory corruption if a different driver is bound.
- [Medium] Software protocol handler is updated before the hardware exits transparent mode, causing guest data to be misparsed as host data.
Pre-existing issues:
- [High] The pass-through child port is leaked when the parent psmouse driver is explicitly unbound or fails late initialization, leading to a Use-After-Free. --
--- Patch [1]: [PATCH v2] Input: synaptics - add transparent pass-through mode for TrackPoint --- commit 947ac1aeba1f54176e154131535b9d172e064815
Author: laserology oss <[email protected]>
Input: synaptics - add transparent pass-through mode for TrackPoint
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.
Quoted 4 lines
drivers/input/mouse/synaptics.c +0
-0
[ ... ]
Quoted 7 lines
drivers/input/mouse/synaptics.c +1
-1@@ -669,9 +747,28 @@ 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);
drivers/input/mouse/synaptics.c static void synaptics_pt_stop(struct serio *serio) · line 760
Quoted 10 lines
drivers/input/mouse/synaptics.c +9
-1- priv->pt_port =NULL ; + { +guard (serio_pause_rx)(parent->ps2dev.serio); + + priv->pt_port =NULL ; + exit_mode =READ_ONCE (priv->transparent_mode); +WRITE_ONCE (priv->transparent_mode, false); +synaptics_update_protocol_handler (parent); + } +
[Severity: Medium]
Will this cause guest data to be misparsed as host data?
In synaptics_pt_stop(), the software state is preemptively switched to host mode before dropping the rx lock.
Then it calls synaptics_exit_transparent_mode() which sends slow PS/2 commands to switch the hardware.
During this window, the hardware is still in transparent mode sending raw guest bytes, but the software will interpret them as Synaptics absolute mode packets. This can lead to PSMOUSE_BAD_DATA, dropping packets, or triggering spurious host resets.
Quoted 12 lines
drivers/input/mouse/synaptics.c +11
-0+/* +* The guest is going away. If the touchpad was left in transparent +* mode it would keep relaying the guest's byte stream with nobody to +* consume it, leaving hardware and software permanently out of sync, +* so take it out of transparent mode and back to normal operation. +*/ +if (exit_mode) { +if (synaptics_exit_transparent_mode (parent)) +psmouse_warn (parent, +"failed to exit transparent mode after pass-through port removal\n" ); + } }
[ ... ]
Quoted 3 lines
drivers/input/mouse/synaptics.c +0
-0@@ -1438,6 +1552,98 @@ PSMOUSE_DEFINE_ATTR(disable_gesture, S_IWUSR | S_IRUGO, NULL, synaptics_show_disable_gesture, synaptics_set_disable_gesture);
[ ... ]
Quoted 4 lines
drivers/input/mouse/synaptics.c +4
-0+static ssize_t synaptics_set_transparent_mode (struct psmouse *psmouse, +void *data,const char *buf, +size_t len) +{
[ ... ]
Quoted 20 lines
drivers/input/mouse/synaptics.c +20
-0+/* +* Commit the software state with RX paused so the interrupt handler +* never observes a torn (protocol_handler, pktsize) pair while the +* pass-through guest keeps streaming. +*/ +guard (serio_pause_rx)(psmouse->ps2dev.serio); + +WRITE_ONCE (priv->transparent_mode, value); + +synaptics_update_protocol_handler (psmouse); + +/* +* 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 serio *pt_port = priv->pt_port;
drivers/input/mouse/synaptics.c PSMOUSE_DEFINE_ATTR(disable_gesture, S_IWUSR | S_IRUGO, NULL, · line 1632
Quoted 10 lines
drivers/input/mouse/synaptics.c +10
-0+ +/* +* The pass-through port may be registered without a bound +* driver (e.g. no TrackPoint attached), in which case its +* drvdata is NULL and psmouse_from_serio() would produce a +* bogus pointer; only reset the child if there is a real +* psmouse bound to it. +*/ +if (serio_get_drvdata (pt_port)) { +struct psmouse *child =psmouse_from_serio (pt_port);
[Severity: High]
Is it safe to unconditionally cast the child drvdata to struct psmouse here?
If a user unbinds the psmouse driver from the child port and binds a different serio driver (like serio_raw), serio_get_drvdata() would return a pointer to that driver's private structure.
The container_of() macro in psmouse_from_serio() would then produce a bogus pointer, leading to invalid memory accesses when checking child->state.
drivers/input/mouse/synaptics.c PSMOUSE_DEFINE_ATTR(disable_gesture, S_IWUSR | S_IRUGO, NULL, · line 1635
Quoted 3 lines
drivers/input/mouse/synaptics.c +3
-0+ +if (child->state ==PSMOUSE_ACTIVATED ) +psmouse_set_state (child,PSMOUSE_ACTIVATED );
[Severity: High]
Can calling psmouse_set_state() here lead to a deadlock?
The earlier code in synaptics_set_transparent_mode() takes the parent device's rx guard:
guard(serio_pause_rx)(psmouse->ps2dev.serio);
This disables interrupts and takes the parent spinlock.
When psmouse_set_state() is called on the child, it internally takes and releases its own rx guard:
drivers/input/mouse/psmouse-base.c:psmouse_set_state() {
guard(serio_pause_rx)(psmouse->ps2dev.serio);
__psmouse_set_state(psmouse, new_state);
}When this child guard is released, it calls spin_unlock_irq(), which unconditionally re-enables local interrupts while the parent lock is still held. If a hardware interrupt arrives on the same CPU, serio_interrupt() will attempt to acquire the parent lock again, causing a self-deadlock.
Quoted 5 lines
drivers/input/mouse/synaptics.c +5
-0+ } + } + +return len; +}
[ ... ]
Quoted 10 lines
static void
synaptics_disconnect(struct psmouse *psmouse){drivers/input/mouse/synaptics.c +3
-0struct synaptics_data *priv = psmouse->private;@@ -1448,10 +1654,16 @@ static void synaptics_disconnect(struct psmouse *psmouse)*/ psmouse_smbus_cleanup (psmouse); +if (READ_ONCE (priv->transparent_mode)) +synaptics_exit_transparent_mode (psmouse); +
drivers/input/mouse/synaptics.c static void synaptics_disconnect(struct psmouse *psmouse) · line 1669
Quoted 10 lines
drivers/input/mouse/synaptics.c +3
-0if (!priv->absolute_mode &&SYN_ID_DISGEST_SUPPORTED (priv->info.identity))device_remove_file (&psmouse->ps2dev.serio->dev, &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);synaptics_reset (psmouse);kfree (priv);
[Severity: High]
This isn't a bug introduced by this patch, but does this code leak the child pass-through port?
When the host psmouse driver is unbound, synaptics_disconnect() frees the driver private data via kfree(priv).
However, the pass-through child port created earlier in synaptics_pt_create() is never unregistered via serio_unregister_child_port().
Any subsequent interaction with the leaked child port (like binding a new driver to it) will call callbacks that dereference the freed parent structures, leading to a use-after-free.
Quoted 2 lines
drivers/input/mouse/synaptics.c +0
-0@@ -1478,8 +1690,35 @@ static int synaptics_reconnect(struct psmouse *psmouse)*/
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1