usb: gadget: u_ether: replace deprecated strncpy with strscpy
authorJustin Stitt <justinstitt@google.com>
Mon, 18 Mar 2024 23:10:34 +0000 (23:10 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 26 Mar 2024 09:44:29 +0000 (10:44 +0100)
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 use the new 2-argument strscpy() as this guarantees
NUL-termination on the destination buffer and also uses the destination
buffer's size to bound the operation.

Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings
Link: https://manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en.html
Link: https://github.com/KSPP/linux/issues/90
Cc: linux-hardening@vger.kernel.org
Signed-off-by: Justin Stitt <justinstitt@google.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20240318-strncpy-drivers-usb-gadget-function-u_ether-c-v1-1-e8543a1db24a@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/gadget/function/u_ether.c

index 444212c0b5a98cc38b3795d9368b648f01754949..11dd0b9e847f0d3ea8b889491b9291d0e07c0952 100644 (file)
@@ -1032,7 +1032,7 @@ int gether_set_ifname(struct net_device *net, const char *name, int len)
        if (!p || p[1] != 'd' || strchr(p + 2, '%'))
                return -EINVAL;
 
-       strncpy(net->name, tmp, sizeof(net->name));
+       strscpy(net->name, tmp);
        dev->ifname_set = true;
 
        return 0;