Skip to contentSkip to conversation

input: psmouse: fix potential input register race in psmouse_connect()

PATCH Applied Andres Salomon 2 participants 2 messages Jan 12, 2008 – Jan 15, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 input: psmouse: fix potential input register race in psmouse_connect()

If we successfully call input_register_device() in psmouse_connect but sysfs_create_group() fails, we'll enter the error path without ever having called input_unregister_device() (potentially leaking memory, or creating a race condition if something else attempts to access the new input device). This calls input_unregister_device from the error path, and sets input_dev to NULL so that we don't attempt to also call input_free_device on it.

---
 drivers/input/mouse/psmouse-base.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
drivers/input/mouse/psmouse-base.c +2 -0
index 21a9c0b..df25e7b 100644
@@ -1247,6 +1247,8 @@ static int psmouse_connect(struct serio *serio, struct serio_driver *drv)
  err_pt_deactivate:
 	if (parent && parent->pt_deactivate)
 		parent->pt_deactivate(parent);
+	input_unregister_device(psmouse->dev);
+	input_dev = NULL;
  err_protocol_disconnect:
 	if (psmouse->disconnect)
 		psmouse->disconnect(psmouse);
Signature · 1 line
1.5.3.5
maintainer Applied
#1 lore raw
Quoted 10 lines · Andres Salomon

If we successfully call input_register_device() in psmouse_connect but sysfs_create_group() fails, we'll enter the error path without ever having called input_unregister_device() (potentially leaking memory, or creating a race condition if something else attempts to access the new input device). This calls input_unregister_device from the error path, and sets input_dev to NULL so that we don't attempt to also call input_free_device on it.

Applied, thank you Andres.

Signature · 1 line
Dmitry