* [PATCH] usb: gadget: mv_u3d: replace deprecated strncpy with strscpy
@ 2024-03-18 23:31 Justin Stitt
2024-03-20 2:43 ` Kees Cook
0 siblings, 1 reply; 2+ messages in thread
From: Justin Stitt @ 2024-03-18 23:31 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: linux-usb, linux-kernel, linux-hardening, Justin Stitt
strncpy() is deprecated for use on NUL-terminated destination strings
[1] and as such we should prefer more robust and less ambiguous string
interfaces.
Let's opt for the new 2-argument version of strscpy() which guarantees
NUL-termination on the destination buffer and simplifies snytax. The
NUL-padding behavior that strncpy() provides is not required as u3d->eps
is already zero-allocated:
| u3d->eps = kzalloc(size, GFP_KERNEL);
Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1]
Link: https://manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en.html [2]
Link: https://github.com/KSPP/linux/issues/90
Cc: linux-hardening@vger.kernel.org
Signed-off-by: Justin Stitt <justinstitt@google.com>
---
Note: build-tested only.
Found with: $ rg "strncpy\("
---
drivers/usb/gadget/udc/mv_u3d_core.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/usb/gadget/udc/mv_u3d_core.c b/drivers/usb/gadget/udc/mv_u3d_core.c
index 2a421f0ff931..e1dd5cf25d08 100644
--- a/drivers/usb/gadget/udc/mv_u3d_core.c
+++ b/drivers/usb/gadget/udc/mv_u3d_core.c
@@ -1307,7 +1307,7 @@ static int mv_u3d_eps_init(struct mv_u3d *u3d)
/* initialize ep0, ep0 in/out use eps[1] */
ep = &u3d->eps[1];
ep->u3d = u3d;
- strncpy(ep->name, "ep0", sizeof(ep->name));
+ strscpy(ep->name, "ep0");
ep->ep.name = ep->name;
ep->ep.ops = &mv_u3d_ep_ops;
ep->wedge = 0;
@@ -1337,7 +1337,7 @@ static int mv_u3d_eps_init(struct mv_u3d *u3d)
ep->ep.caps.dir_out = true;
}
ep->u3d = u3d;
- strncpy(ep->name, name, sizeof(ep->name));
+ strscpy(ep->name, name);
ep->ep.name = ep->name;
ep->ep.caps.type_iso = true;
---
base-commit: bf3a69c6861ff4dc7892d895c87074af7bc1c400
change-id: 20240318-strncpy-drivers-usb-gadget-udc-mv_u3d_core-c-50ea7422311c
Best regards,
--
Justin Stitt <justinstitt@google.com>
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] usb: gadget: mv_u3d: replace deprecated strncpy with strscpy
2024-03-18 23:31 [PATCH] usb: gadget: mv_u3d: replace deprecated strncpy with strscpy Justin Stitt
@ 2024-03-20 2:43 ` Kees Cook
0 siblings, 0 replies; 2+ messages in thread
From: Kees Cook @ 2024-03-20 2:43 UTC (permalink / raw)
To: Justin Stitt; +Cc: Greg Kroah-Hartman, linux-usb, linux-kernel, linux-hardening
On Mon, Mar 18, 2024 at 11:31:53PM +0000, Justin Stitt wrote:
> strncpy() is deprecated for use on NUL-terminated destination strings
> [1] and as such we should prefer more robust and less ambiguous string
> interfaces.
>
> Let's opt for the new 2-argument version of strscpy() which guarantees
> NUL-termination on the destination buffer and simplifies snytax. The
> NUL-padding behavior that strncpy() provides is not required as u3d->eps
> is already zero-allocated:
> | u3d->eps = kzalloc(size, GFP_KERNEL);
>
> Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1]
> Link: https://manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en.html [2]
> Link: https://github.com/KSPP/linux/issues/90
> Cc: linux-hardening@vger.kernel.org
> Signed-off-by: Justin Stitt <justinstitt@google.com>
Thanks!
Reviewed-by: Kees Cook <keescook@chromium.org>
--
Kees Cook
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-03-20 2:43 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-18 23:31 [PATCH] usb: gadget: mv_u3d: replace deprecated strncpy with strscpy Justin Stitt
2024-03-20 2:43 ` Kees Cook
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.