Skip to content

Commit 7b63a88

Browse files
committed
Input: psmouse - fix OOB access in Elantech protocol
The kernel only allocate 5 MT slots; check that transmitted slot ID falls within the acceptable range. Link: https://lore.kernel.org/r/[email protected] Cc: [email protected] Signed-off-by: Dmitry Torokhov <[email protected]>
1 parent 20a99a2 commit 7b63a88

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

drivers/input/mouse/elantech.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -674,10 +674,11 @@ static void process_packet_head_v4(struct psmouse *psmouse)
674674
struct input_dev *dev = psmouse->dev;
675675
struct elantech_data *etd = psmouse->private;
676676
unsigned char *packet = psmouse->packet;
677-
int id = ((packet[3] & 0xe0) >> 5) - 1;
677+
int id;
678678
int pres, traces;
679679

680-
if (id < 0)
680+
id = ((packet[3] & 0xe0) >> 5) - 1;
681+
if (id < 0 || id >= ETP_MAX_FINGERS)
681682
return;
682683

683684
etd->mt[id].x = ((packet[1] & 0x0f) << 8) | packet[2];
@@ -707,7 +708,7 @@ static void process_packet_motion_v4(struct psmouse *psmouse)
707708
int id, sid;
708709

709710
id = ((packet[0] & 0xe0) >> 5) - 1;
710-
if (id < 0)
711+
if (id < 0 || id >= ETP_MAX_FINGERS)
711712
return;
712713

713714
sid = ((packet[3] & 0xe0) >> 5) - 1;
@@ -728,7 +729,7 @@ static void process_packet_motion_v4(struct psmouse *psmouse)
728729
input_report_abs(dev, ABS_MT_POSITION_X, etd->mt[id].x);
729730
input_report_abs(dev, ABS_MT_POSITION_Y, etd->mt[id].y);
730731

731-
if (sid >= 0) {
732+
if (sid >= 0 && sid < ETP_MAX_FINGERS) {
732733
etd->mt[sid].x += delta_x2 * weight;
733734
etd->mt[sid].y -= delta_y2 * weight;
734735
input_mt_slot(dev, sid);

0 commit comments

Comments
 (0)