Skip to content

Commit 5b3df17

Browse files
Nikolay Aleksandrovdavem330
authored andcommitted
bonding: don't cast const buf in sysfs store
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 <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent fb42c83 commit 5b3df17

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

drivers/net/bonding/bond_sysfs.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,19 @@ static ssize_t bonding_sysfs_store_option(struct device *d,
160160
{
161161
struct bonding *bond = to_bond(d);
162162
const struct bond_option *opt;
163+
char *buffer_clone;
163164
int ret;
164165

165166
opt = bond_opt_get_by_name(attr->attr.name);
166167
if (WARN_ON(!opt))
167168
return -ENOENT;
168-
ret = bond_opt_tryset_rtnl(bond, opt->id, (char *)buffer);
169+
buffer_clone = kstrndup(buffer, count, GFP_KERNEL);
170+
if (!buffer_clone)
171+
return -ENOMEM;
172+
ret = bond_opt_tryset_rtnl(bond, opt->id, buffer_clone);
169173
if (!ret)
170174
ret = count;
175+
kfree(buffer_clone);
171176

172177
return ret;
173178
}

0 commit comments

Comments
 (0)