Input: psmouse - bail out when device path can't fit buffer
Subsystems (2)
PATCH 1/1 Input: psmouse - bail out when device path can't fit buffer
When creating a physical device name in the driver the snprintf() takes an up to 32 characters argument along with the additional 8 characters and tries to pack this into 32 bytes array. GCC complains about that when build with make W=1:
drivers/input/mouse/psmouse-base.c:1603:9: note: ‘snprintf’ output between 8 and 39 bytes into a destination of size 32
1603 | snprintf(psmouse->phys, sizeof(psmouse->phys), "%s/input0", serio->phys);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Fix these by checking for the potential overflow.
Signed-off-by Andy Shevchenko <[email protected]>
--- drivers/input/mouse/psmouse-base.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/input/mouse/psmouse-base.c +9 -4
@@ -1578,7 +1578,8 @@ static int psmouse_connect(struct serio *serio, struct serio_driver *drv) {struct psmouse *psmouse, *parent =NULL ;struct input_dev *input_dev; -int retval =0 , error = -ENOMEM ; +int error = -ENOMEM ; +int n;mutex_lock (&psmouse_mutex);
@@ -1600,7 +1601,12 @@ static int psmouse_connect(struct serio *serio, struct serio_driver *drv) psmouse_pre_receive_byte, psmouse_receive_byte);INIT_DELAYED_WORK (&psmouse->resync_work, psmouse_resync); psmouse->dev = input_dev; -snprintf (psmouse->phys,sizeof (psmouse->phys),"%s/input0" , serio->phys); + + n =snprintf (psmouse->phys,sizeof (psmouse->phys),"%s/input0" , serio->phys); +if (n >=sizeof (psmouse->phys)) { + error = -E2BIG ; + goto err_free; + }psmouse_set_state (psmouse,PSMOUSE_INITIALIZING );
@@ -1654,7 +1660,7 @@ static int psmouse_connect(struct serio *serio, struct serio_driver *drv)psmouse_activate (parent);mutex_unlock (&psmouse_mutex); -return retval; +return error; err_protocol_disconnect:if (psmouse->disconnect)
@@ -1668,7 +1674,6 @@ static int psmouse_connect(struct serio *serio, struct serio_driver *drv)input_free_device (input_dev);kfree (psmouse); - retval = error; goto out; }
Signature · 1 line
2.47.2