bonding: don't cast const buf in sysfs store
authorNikolay Aleksandrov <nikolay@cumulusnetworks.com>
Sun, 22 Jul 2018 08:37:31 +0000 (11:37 +0300)
committerDavid S. Miller <davem@davemloft.net>
Sun, 22 Jul 2018 17:09:30 +0000 (10:09 -0700)
As was recently discussed [1], let's avoid casting the const buf in
bonding_sysfs_store_option and use kstrndup/kfree instead.

[1] http://lists.openwall.net/netdev/2018/07/22/25

Signed-off-by: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/bonding/bond_sysfs.c

index 6096440e96eaaa225cade7d90fa25471fb405bc0..35847250da5aa935a0286b1b28396813dfcc0ee2 100644 (file)
@@ -160,14 +160,19 @@ static ssize_t bonding_sysfs_store_option(struct device *d,
 {
        struct bonding *bond = to_bond(d);
        const struct bond_option *opt;
+       char *buffer_clone;
        int ret;
 
        opt = bond_opt_get_by_name(attr->attr.name);
        if (WARN_ON(!opt))
                return -ENOENT;
-       ret = bond_opt_tryset_rtnl(bond, opt->id, (char *)buffer);
+       buffer_clone = kstrndup(buffer, count, GFP_KERNEL);
+       if (!buffer_clone)
+               return -ENOMEM;
+       ret = bond_opt_tryset_rtnl(bond, opt->id, buffer_clone);
        if (!ret)
                ret = count;
+       kfree(buffer_clone);
 
        return ret;
 }