net: prefer strscpy over strcpy
authorHongbo Li <lihongbo22@huawei.com>
Wed, 28 Aug 2024 12:32:19 +0000 (20:32 +0800)
committerJakub Kicinski <kuba@kernel.org>
Thu, 29 Aug 2024 19:33:07 +0000 (12:33 -0700)
The deprecated helper strcpy() performs no bounds checking on the
destination buffer. This could result in linear overflows beyond
the end of the buffer, leading to all kinds of misbehaviors.
The safe replacement is strscpy() [1].

Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy
Signed-off-by: Hongbo Li <lihongbo22@huawei.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/core/dev.c

index 63987b8b7c853c0ed3331d8cf2d12172fec51cb8..932d67b975f5013281e4efd7786fc18061797a23 100644 (file)
@@ -11143,7 +11143,7 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name,
        if (!dev->ethtool)
                goto free_all;
 
-       strcpy(dev->name, name);
+       strscpy(dev->name, name);
        dev->name_assign_type = name_assign_type;
        dev->group = INIT_NETDEV_GROUP;
        if (!dev->ethtool_ops)