Skip to content

Commit

Permalink
mac80211: add NULL terminator to debugfs_netdev write buf
Browse files Browse the repository at this point in the history
Some debugfs write functions call kstrto* functions, which
assume the string is null-terminated. Make it valid by changing
ieee80211_if_write() to use static buffer instead of allocating
one, and set the last char to NULL.

(The write functions try to parse some integer/mac address,
so 64 bytes buffer should be enough)

Signed-off-by: Eliad Peller <[email protected]>
Signed-off-by: John W. Linville <[email protected]>
  • Loading branch information
elp authored and linvjw committed Mar 15, 2012
1 parent ba6fa29 commit ada577c
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions net/mac80211/debugfs_netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,22 @@ static ssize_t ieee80211_if_write(
size_t count, loff_t *ppos,
ssize_t (*write)(struct ieee80211_sub_if_data *, const char *, int))
{
u8 *buf;
char buf[64];
ssize_t ret;

buf = kmalloc(count, GFP_KERNEL);
if (!buf)
return -ENOMEM;
if (count >= sizeof(buf))
return -E2BIG;

ret = -EFAULT;
if (copy_from_user(buf, userbuf, count))
goto freebuf;
return -EFAULT;
buf[count] = '\0';

ret = -ENODEV;
rtnl_lock();
if (sdata->dev->reg_state == NETREG_REGISTERED)
ret = (*write)(sdata, buf, count);
rtnl_unlock();

freebuf:
kfree(buf);
return ret;
}

Expand Down

0 comments on commit ada577c

Please sign in to comment.