Skip to content

Commit 08bd5b7

Browse files
committed
Input: synaptics - fix crash when enabling pass-through port
When enabling a pass-through port an interrupt might come before psmouse driver binds to the pass-through port. However synaptics sub-driver tries to access psmouse instance presumably associated with the pass-through port to figure out if only 1 byte of response or entire protocol packet needs to be forwarded to the pass-through port and may crash if psmouse instance has not been attached to the port yet. Fix the crash by introducing open() and close() methods for the port and check if the port is open before trying to access psmouse instance. Because psmouse calls serio_open() only after attaching psmouse instance to serio port instance this prevents the potential crash. Reported-by: Takashi Iwai <[email protected]> Fixes: 100e169 ("Input: libps2 - attach ps2dev instances as serio port's drvdata") Link: https://bugzilla.suse.com/show_bug.cgi?id=1219522 Cc: [email protected] Reviewed-by: Takashi Iwai <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Dmitry Torokhov <[email protected]>
1 parent 907bc92 commit 08bd5b7

File tree

2 files changed

+43
-14
lines changed

2 files changed

+43
-14
lines changed

drivers/input/mouse/synaptics.c

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -665,23 +665,50 @@ static void synaptics_pt_stop(struct serio *serio)
665665
priv->pt_port = NULL;
666666
}
667667

668+
static int synaptics_pt_open(struct serio *serio)
669+
{
670+
struct psmouse *parent = psmouse_from_serio(serio->parent);
671+
struct synaptics_data *priv = parent->private;
672+
673+
guard(serio_pause_rx)(parent->ps2dev.serio);
674+
priv->pt_port_open = true;
675+
676+
return 0;
677+
}
678+
679+
static void synaptics_pt_close(struct serio *serio)
680+
{
681+
struct psmouse *parent = psmouse_from_serio(serio->parent);
682+
struct synaptics_data *priv = parent->private;
683+
684+
guard(serio_pause_rx)(parent->ps2dev.serio);
685+
priv->pt_port_open = false;
686+
}
687+
668688
static int synaptics_is_pt_packet(u8 *buf)
669689
{
670690
return (buf[0] & 0xFC) == 0x84 && (buf[3] & 0xCC) == 0xC4;
671691
}
672692

673-
static void synaptics_pass_pt_packet(struct serio *ptport, u8 *packet)
693+
static void synaptics_pass_pt_packet(struct synaptics_data *priv, u8 *packet)
674694
{
675-
struct psmouse *child = psmouse_from_serio(ptport);
695+
struct serio *ptport;
676696

677-
if (child && child->state == PSMOUSE_ACTIVATED) {
678-
serio_interrupt(ptport, packet[1], 0);
679-
serio_interrupt(ptport, packet[4], 0);
680-
serio_interrupt(ptport, packet[5], 0);
681-
if (child->pktsize == 4)
682-
serio_interrupt(ptport, packet[2], 0);
683-
} else {
684-
serio_interrupt(ptport, packet[1], 0);
697+
ptport = priv->pt_port;
698+
if (!ptport)
699+
return;
700+
701+
serio_interrupt(ptport, packet[1], 0);
702+
703+
if (priv->pt_port_open) {
704+
struct psmouse *child = psmouse_from_serio(ptport);
705+
706+
if (child->state == PSMOUSE_ACTIVATED) {
707+
serio_interrupt(ptport, packet[4], 0);
708+
serio_interrupt(ptport, packet[5], 0);
709+
if (child->pktsize == 4)
710+
serio_interrupt(ptport, packet[2], 0);
711+
}
685712
}
686713
}
687714

@@ -720,6 +747,8 @@ static void synaptics_pt_create(struct psmouse *psmouse)
720747
serio->write = synaptics_pt_write;
721748
serio->start = synaptics_pt_start;
722749
serio->stop = synaptics_pt_stop;
750+
serio->open = synaptics_pt_open;
751+
serio->close = synaptics_pt_close;
723752
serio->parent = psmouse->ps2dev.serio;
724753

725754
psmouse->pt_activate = synaptics_pt_activate;
@@ -1216,11 +1245,10 @@ static psmouse_ret_t synaptics_process_byte(struct psmouse *psmouse)
12161245

12171246
if (SYN_CAP_PASS_THROUGH(priv->info.capabilities) &&
12181247
synaptics_is_pt_packet(psmouse->packet)) {
1219-
if (priv->pt_port)
1220-
synaptics_pass_pt_packet(priv->pt_port,
1221-
psmouse->packet);
1222-
} else
1248+
synaptics_pass_pt_packet(priv, psmouse->packet);
1249+
} else {
12231250
synaptics_process_packet(psmouse);
1251+
}
12241252

12251253
return PSMOUSE_FULL_PACKET;
12261254
}

drivers/input/mouse/synaptics.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ struct synaptics_data {
188188
bool disable_gesture; /* disable gestures */
189189

190190
struct serio *pt_port; /* Pass-through serio port */
191+
bool pt_port_open;
191192

192193
/*
193194
* Last received Advanced Gesture Mode (AGM) packet. An AGM packet

0 commit comments

Comments
 (0)