Commit b3dc3e65 authored by Dan Carpenter's avatar Dan Carpenter Committed by Willy Tarreau

libertas: potential oops in debugfs

If we do a zero size allocation then it will oops.  Also we can't be
sure the user passes us a NUL terminated string so I've added a
terminator.

This code can only be triggered by root.
Reported-by: default avatarNico Golde <nico@ngolde.de>
Reported-by: default avatarFabian Yamaguchi <fabs@goesec.de>
Signed-off-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Acked-by: default avatarDan Williams <dcbw@redhat.com>
Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
(cherry picked from commit a497e47d)
Signed-off-by: default avatarWilly Tarreau <w@1wt.eu>
parent a5334235
...@@ -925,7 +925,10 @@ static ssize_t lbs_debugfs_write(struct file *f, const char __user *buf, ...@@ -925,7 +925,10 @@ static ssize_t lbs_debugfs_write(struct file *f, const char __user *buf,
char *p2; char *p2;
struct debug_data *d = (struct debug_data *)f->private_data; struct debug_data *d = (struct debug_data *)f->private_data;
pdata = kmalloc(cnt, GFP_KERNEL); if (cnt == 0)
return 0;
pdata = kmalloc(cnt + 1, GFP_KERNEL);
if (pdata == NULL) if (pdata == NULL)
return 0; return 0;
...@@ -934,6 +937,7 @@ static ssize_t lbs_debugfs_write(struct file *f, const char __user *buf, ...@@ -934,6 +937,7 @@ static ssize_t lbs_debugfs_write(struct file *f, const char __user *buf,
kfree(pdata); kfree(pdata);
return 0; return 0;
} }
pdata[cnt] = '\0';
p0 = pdata; p0 = pdata;
for (i = 0; i < num_of_items; i++) { for (i = 0; i < num_of_items; i++) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment