* [PATCH v1 1/1] Input: psmouse - bail out when device path can't fit buffer
@ 2025-04-22 18:57 Andy Shevchenko
0 siblings, 0 replies; only message in thread
From: Andy Shevchenko @ 2025-04-22 18:57 UTC (permalink / raw)
To: Dmitry Torokhov, linux-input, linux-kernel; +Cc: Andy Shevchenko
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 <andriy.shevchenko@linux.intel.com>
---
drivers/input/mouse/psmouse-base.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c
index a2c9f7144864..bd7d908be7a5 100644
--- a/drivers/input/mouse/psmouse-base.c
+++ b/drivers/input/mouse/psmouse-base.c
@@ -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;
}
--
2.47.2
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2025-04-22 18:57 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-22 18:57 [PATCH v1 1/1] Input: psmouse - bail out when device path can't fit buffer Andy Shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).