* [PATCH] Input: mouse: vsxxxaa: Replace strlcat() with strscpy()
@ 2026-11-04 6:23 Mariia Nikitash
2026-11-04 11:21 ` Alejandro Colomar
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Mariia Nikitash @ 2026-11-04 6:23 UTC (permalink / raw)
To: dmitry.torokhov
Cc: linux-input, linux-kernel, linux-hardening, kees, justinstitt,
morbo, Mariia Nikitash
In preparation for removing the deprecated strlcat() API[1], use
strscpy() to initialize the mouse device name.
The destination is zero-initialized, and the constant string fits
within the buffer. Since the return value is unused, this preserves
the existing behavior.
Link: https://github.com/KSPP/linux/issues/370 [1]
Signed-off-by: Mariia Nikitash <nikitash.mariiaw@gmail.com>
---
drivers/input/mouse/vsxxxaa.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/input/mouse/vsxxxaa.c b/drivers/input/mouse/vsxxxaa.c
index 042a17fe81db..b3a0d7ff5738 100644
--- a/drivers/input/mouse/vsxxxaa.c
+++ b/drivers/input/mouse/vsxxxaa.c
@@ -463,8 +463,8 @@ static int vsxxxaa_connect(struct serio *serio, struct serio_driver *drv)
mouse->dev = input_dev;
mouse->serio = serio;
- strlcat(mouse->name, "DEC VSXXX-AA/-GA mouse or VSXXX-AB digitizer",
- sizeof(mouse->name));
+ strscpy(mouse->name, "DEC VSXXX-AA/-GA mouse or VSXXX-AB digitizer",
+ sizeof(mouse->name));
snprintf(mouse->phys, sizeof(mouse->phys), "%s/input0", serio->phys);
input_dev->name = mouse->name;
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH] Input: mouse: vsxxxaa: Replace strlcat() with strscpy() 2026-11-04 6:23 [PATCH] Input: mouse: vsxxxaa: Replace strlcat() with strscpy() Mariia Nikitash @ 2026-11-04 11:21 ` Alejandro Colomar 2026-11-04 16:33 ` Shihuang Liu 2026-11-05 11:28 ` David Laight 2 siblings, 0 replies; 5+ messages in thread From: Alejandro Colomar @ 2026-11-04 11:21 UTC (permalink / raw) To: Mariia Nikitash Cc: dmitry.torokhov, linux-input, linux-kernel, linux-hardening, kees, justinstitt, morbo [-- Attachment #1: Type: text/plain, Size: 1698 bytes --] Hi Mariia, > Date: 2026-11-03 22:23:18-0800 > From: Mariia Nikitash <nikitash.mariiaw@gmail.com> > > In preparation for removing the deprecated strlcat() API[1], use > strscpy() to initialize the mouse device name. > > The destination is zero-initialized, and the constant string fits > within the buffer. Since the return value is unused, this preserves > the existing behavior. Huh! Indeed, it was very weird that it was using strlcat(3), when strlcpy(3) would have been okay. The commit that added strlcat(3) was obviously confused: 08ffce4560e0 (2006-06-26; "Input: fix potential overflows in driver/input/mouse"). > > Link: https://github.com/KSPP/linux/issues/370 [1] > Signed-off-by: Mariia Nikitash <nikitash.mariiaw@gmail.com> Reviewed-by: Alejandro Colomar <alx@kernel.org> Have a lovely day! Alex > --- > drivers/input/mouse/vsxxxaa.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/input/mouse/vsxxxaa.c b/drivers/input/mouse/vsxxxaa.c > index 042a17fe81db..b3a0d7ff5738 100644 > --- a/drivers/input/mouse/vsxxxaa.c > +++ b/drivers/input/mouse/vsxxxaa.c > @@ -463,8 +463,8 @@ static int vsxxxaa_connect(struct serio *serio, struct serio_driver *drv) > > mouse->dev = input_dev; > mouse->serio = serio; > - strlcat(mouse->name, "DEC VSXXX-AA/-GA mouse or VSXXX-AB digitizer", > - sizeof(mouse->name)); > + strscpy(mouse->name, "DEC VSXXX-AA/-GA mouse or VSXXX-AB digitizer", > + sizeof(mouse->name)); > snprintf(mouse->phys, sizeof(mouse->phys), "%s/input0", serio->phys); > > input_dev->name = mouse->name; > -- > 2.43.0 > > -- <https://www.alejandro-colomar.es> [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 833 bytes --] ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Input: mouse: vsxxxaa: Replace strlcat() with strscpy() 2026-11-04 6:23 [PATCH] Input: mouse: vsxxxaa: Replace strlcat() with strscpy() Mariia Nikitash 2026-11-04 11:21 ` Alejandro Colomar @ 2026-11-04 16:33 ` Shihuang Liu 2026-11-05 11:28 ` David Laight 2 siblings, 0 replies; 5+ messages in thread From: Shihuang Liu @ 2026-11-04 16:33 UTC (permalink / raw) To: Mariia Nikitash Cc: dmitry.torokhov, linux-input, linux-kernel, linux-hardening, kees, justinstitt, morbo On Tue, Nov 03, 2026 at 10:23:18PM -0800, Mariia Nikitash wrote: > In preparation for removing the deprecated strlcat() API[1], use > strscpy() to initialize the mouse device name. > > The destination is zero-initialized, and the constant string fits > within the buffer. Since the return value is unused, this preserves > the existing behavior. > > Link: https://github.com/KSPP/linux/issues/370 [1] > Signed-off-by: Mariia Nikitash <nikitash.mariiaw@gmail.com> Reviewed-by: Shihuang Liu <shlomojune6@gmail.com> ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Input: mouse: vsxxxaa: Replace strlcat() with strscpy() 2026-11-04 6:23 [PATCH] Input: mouse: vsxxxaa: Replace strlcat() with strscpy() Mariia Nikitash 2026-11-04 11:21 ` Alejandro Colomar 2026-11-04 16:33 ` Shihuang Liu @ 2026-11-05 11:28 ` David Laight 2026-11-05 11:49 ` Alejandro Colomar 2 siblings, 1 reply; 5+ messages in thread From: David Laight @ 2026-11-05 11:28 UTC (permalink / raw) To: Mariia Nikitash Cc: dmitry.torokhov, linux-input, linux-kernel, linux-hardening, kees, justinstitt, morbo On Tue, 3 Nov 2026 22:23:18 -0800 Mariia Nikitash <nikitash.mariiaw@gmail.com> wrote: > In preparation for removing the deprecated strlcat() API[1], use > strscpy() to initialize the mouse device name. > > The destination is zero-initialized, and the constant string fits > within the buffer. Since the return value is unused, this preserves > the existing behavior. > > Link: https://github.com/KSPP/linux/issues/370 [1] > Signed-off-by: Mariia Nikitash <nikitash.mariiaw@gmail.com> > --- > drivers/input/mouse/vsxxxaa.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/input/mouse/vsxxxaa.c b/drivers/input/mouse/vsxxxaa.c > index 042a17fe81db..b3a0d7ff5738 100644 > --- a/drivers/input/mouse/vsxxxaa.c > +++ b/drivers/input/mouse/vsxxxaa.c > @@ -463,8 +463,8 @@ static int vsxxxaa_connect(struct serio *serio, struct serio_driver *drv) > > mouse->dev = input_dev; > mouse->serio = serio; > - strlcat(mouse->name, "DEC VSXXX-AA/-GA mouse or VSXXX-AB digitizer", > - sizeof(mouse->name)); > + strscpy(mouse->name, "DEC VSXXX-AA/-GA mouse or VSXXX-AB digitizer", > + sizeof(mouse->name)); You might as well use the 2 argument form. Moreover, if you use strcpy() you'll get a compile-time error if the string doesn't fit. strscpy() will truncate and return an errors. The other question is whether mouse->name even has to be char[]. Personally I think that while there are issues with strlcat() (mostly to do with its return value), and that there are often much better (and faster - so sprintf is out) ways of getting the same result, the deprecation really needs to propose a sensible alternative (not inlined strlen() + strscpy()). This case is, of course one of the 'better ways' cases. David > snprintf(mouse->phys, sizeof(mouse->phys), "%s/input0", serio->phys); > > input_dev->name = mouse->name; ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Input: mouse: vsxxxaa: Replace strlcat() with strscpy() 2026-11-05 11:28 ` David Laight @ 2026-11-05 11:49 ` Alejandro Colomar 0 siblings, 0 replies; 5+ messages in thread From: Alejandro Colomar @ 2026-11-05 11:49 UTC (permalink / raw) To: David Laight Cc: Mariia Nikitash, dmitry.torokhov, linux-input, linux-kernel, linux-hardening, kees, justinstitt, morbo [-- Attachment #1: Type: text/plain, Size: 3671 bytes --] Hi David, > Date: 2026-11-05 11:28:13+0000 > From: David Laight <david.laight.linux@gmail.com> > > On Tue, 3 Nov 2026 22:23:18 -0800 > Mariia Nikitash <nikitash.mariiaw@gmail.com> wrote: > > > In preparation for removing the deprecated strlcat() API[1], use > > strscpy() to initialize the mouse device name. > > > > The destination is zero-initialized, and the constant string fits > > within the buffer. Since the return value is unused, this preserves > > the existing behavior. > > > > Link: https://github.com/KSPP/linux/issues/370 [1] > > Signed-off-by: Mariia Nikitash <nikitash.mariiaw@gmail.com> > > --- > > drivers/input/mouse/vsxxxaa.c | 4 ++-- > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > diff --git a/drivers/input/mouse/vsxxxaa.c b/drivers/input/mouse/vsxxxaa.c > > index 042a17fe81db..b3a0d7ff5738 100644 > > --- a/drivers/input/mouse/vsxxxaa.c > > +++ b/drivers/input/mouse/vsxxxaa.c > > @@ -463,8 +463,8 @@ static int vsxxxaa_connect(struct serio *serio, struct serio_driver *drv) > > > > mouse->dev = input_dev; > > mouse->serio = serio; > > - strlcat(mouse->name, "DEC VSXXX-AA/-GA mouse or VSXXX-AB digitizer", > > - sizeof(mouse->name)); > > + strscpy(mouse->name, "DEC VSXXX-AA/-GA mouse or VSXXX-AB digitizer", > > + sizeof(mouse->name)); > > You might as well use the 2 argument form. > Moreover, if you use strcpy() you'll get a compile-time error if the > string doesn't fit. > strscpy() will truncate and return an errors. > > The other question is whether mouse->name even has to be char[]. > > Personally I think that while there are issues with strlcat() > (mostly to do with its return value), and that there are often > much better (and faster - so sprintf is out) ways of getting > the same result, the deprecation really needs to propose a > sensible alternative (not inlined strlen() + strscpy()). One alternative would be to add strscat(), with the obvious internal strlen(3). This would be a drop-in replacement, and wouldn't have the issues of strlcat(3) --mainly, the DoS vulnerability which is consequence of the return value, and also the more difficult error handling of doing '>=sizeof(...)' than '<0'--. There's an implementation of strscat() in shadow-utils, where we call it strtcat() --because what it does is Truncating the string, so a T feels more appropriate--: <https://github.com/shadow-maint/shadow/blob/214a2e6e0a5f81fa281b272be7cf9e9d3aff8f34/lib/string/strcpy/strtcat.h#L28> Another alternative which would avoid the internal strlen(3) call, and thus would be faster, would be to add a stpecpy() function, similar to stpcpy(3), but which would take a pointer one-past-the-last element in the buffer, to perform truncation. This is fundamentally Plan9's strecpy(2), except that Plan9's API has a bug. There's an implementation of stpecpy() in shadow-utils: <https://github.com/shadow-maint/shadow/blob/214a2e6e0a5f81fa281b272be7cf9e9d3aff8f34/lib/string/strcpy/stpecpy.h#L28> We've been using stpecpy() quite extensively in shadow-utils, and it's a great API. Of course, there's also the decades-long experience in Plan9, which apart from their bug --which I found, by comparing their implementation to mine--, shows that it's a quite useful API. And stpecpy() produces the simplest code of all truncating functions. Have a lovely day! Alex > This case is, of course one of the 'better ways' cases. > > David > > > snprintf(mouse->phys, sizeof(mouse->phys), "%s/input0", serio->phys); > > > > input_dev->name = mouse->name; > > -- <https://www.alejandro-colomar.es> [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 833 bytes --] ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-05 11:50 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-11-04 6:23 [PATCH] Input: mouse: vsxxxaa: Replace strlcat() with strscpy() Mariia Nikitash 2026-11-04 11:21 ` Alejandro Colomar 2026-11-04 16:33 ` Shihuang Liu 2026-11-05 11:28 ` David Laight 2026-11-05 11:49 ` Alejandro Colomar
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox