Skip to contentSkip to conversation

Input: psmouse: add NULL check to psmouse_from_serio()

PATCH RESEND In review Takashi Iwai 2 participants 3 messages Dec 30, 2024 – Jan 9, 2025

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

PATCH RESEND 1/1 Input: psmouse: add NULL check to psmouse_from_serio()

The serio drvdata can be still NULL while the PS/2 interrupt is processed. This leaded to crash with a NULL dereference Oops, as psmouse_from_serio() blindly assumes the non-NULL ps2dev object.

Add a NULL check and return NULL from psmouse_from_serio(). The returned NULL is handled properly in the caller side, skipping the rest gracefully.

The log in the bugzilla entry showed that the probe of synaptics driver succeeded after that point. So this is a stop-gap solution.

---

It was submitted in a few months ago
https://lore.kernel.org/[email protected]
but seems forgotten. Simply resubmitted.

 drivers/input/mouse/psmouse-base.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/input/mouse/psmouse-base.c +2 -0
index a2c9f7144864..d428e9ac86f6 100644
@@ -120,6 +120,8 @@ struct psmouse *psmouse_from_serio(struct serio *serio)
 {
 	struct ps2dev *ps2dev = serio_get_drvdata(serio);
 
+	if (!ps2dev)
+		return NULL;
 	return container_of(ps2dev, struct psmouse, ps2dev);
 }
 
Signature · 1 line
2.43.0
maintainer
#1 lore raw

Hi Takashi,

Quoted 28 lines · Takashi Iwai

The serio drvdata can be still NULL while the PS/2 interrupt is processed. This leaded to crash with a NULL dereference Oops, as psmouse_from_serio() blindly assumes the non-NULL ps2dev object.

Add a NULL check and return NULL from psmouse_from_serio(). The returned NULL is handled properly in the caller side, skipping the rest gracefully.

The log in the bugzilla entry showed that the probe of synaptics driver succeeded after that point. So this is a stop-gap solution.

---

It was submitted in a few months ago
https://lore.kernel.org/[email protected]
but seems forgotten. Simply resubmitted.

 drivers/input/mouse/psmouse-base.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/input/mouse/psmouse-base.c +0 -0
index a2c9f7144864..d428e9ac86f6 100644

drivers/input/mouse/psmouse-base.c struct psmouse *psmouse_from_serio(struct serio *serio) · line 124

Quoted 5 lines
drivers/input/mouse/psmouse-base.c +2 -0
@@ -120,6 +120,8 @@ struct psmouse *psmouse_from_serio(struct serio *serio)
 {
 	struct ps2dev *ps2dev = serio_get_drvdata(serio);
 
+	if (!ps2dev)
+		return NULL;

Thank you for resending and reminding me of this issue, however psmouse_from_serio() should not return NULL as most callers do not expect it. Synaptics driver needs to make sure the port is bound to an instance of psmouse and do it in interrupt-safe way. I will make a patch.

Quoted 6 lines
drivers/input/mouse/psmouse-base.c +0 -0
 	return container_of(ps2dev, struct psmouse, ps2dev);
 }
 
Signature · 1 line
2.43.0

Thanks.

Signature · 1 line
Dmitry
#2 lore raw
Quoted 36 lines · Dmitry Torokhov

Hi Takashi,

Quoted 31 lines · Takashi Iwai

The serio drvdata can be still NULL while the PS/2 interrupt is processed. This leaded to crash with a NULL dereference Oops, as psmouse_from_serio() blindly assumes the non-NULL ps2dev object.

Add a NULL check and return NULL from psmouse_from_serio(). The returned NULL is handled properly in the caller side, skipping the rest gracefully.

The log in the bugzilla entry showed that the probe of synaptics driver succeeded after that point. So this is a stop-gap solution.

---

It was submitted in a few months ago
https://lore.kernel.org/[email protected]
but seems forgotten. Simply resubmitted.

 drivers/input/mouse/psmouse-base.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/input/mouse/psmouse-base.c +0 -0
index a2c9f7144864..d428e9ac86f6 100644
@@ -120,6 +120,8 @@ struct psmouse *psmouse_from_serio(struct serio *serio)
 {
 	struct ps2dev *ps2dev = serio_get_drvdata(serio);
 
Quoted 8 lines

drivers/input/mouse/psmouse-base.c struct psmouse *psmouse_from_serio(struct serio *serio) · line 124

Quoted 2 lines
drivers/input/mouse/psmouse-base.c +2 -0
+	if (!ps2dev)
+		return NULL;

Thank you for resending and reminding me of this issue, however psmouse_from_serio() should not return NULL as most callers do not expect it. Synaptics driver needs to make sure the port is bound to an instance of psmouse and do it in interrupt-safe way. I will make a patch.

Fair enough. My patch was intended to be a band-aid fix, so it's fine to skip it.

Let me know if the proper fix patch is available.

thanks,

Takashi