Commit a7503434 authored by Oleg Drokin's avatar Oleg Drokin Committed by Greg Kroah-Hartman

staging/lustre/llite: fix ll_getname user buffer copy

strncpy_from_user could return negative values on error,
so need to take those into account.
Since ll_getname is used to get a single component name from userspace
to transfer to server as-is, there's no need to allocate 4k buffer
as done by __getname. Allocate NAME_MAX+1 buffer instead to ensure
we have enough for a null terminated max valid length buffer.

This was discovered by Al Viro in https://lkml.org/lkml/2015/4/11/243Signed-off-by: default avatarOleg Drokin <green@linuxhacker.ru>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent d8bc89a7
......@@ -1213,29 +1213,34 @@ static int quotactl_ioctl(struct ll_sb_info *sbi, struct if_quotactl *qctl)
return rc;
}
static char *
ll_getname(const char __user *filename)
/* This function tries to get a single name component,
* to send to the server. No actual path traversal involved,
* so we limit to NAME_MAX */
static char *ll_getname(const char __user *filename)
{
int ret = 0, len;
char *tmp = __getname();
char *tmp;
tmp = kzalloc(NAME_MAX + 1, GFP_KERNEL);
if (!tmp)
return ERR_PTR(-ENOMEM);
len = strncpy_from_user(tmp, filename, PATH_MAX);
if (len == 0)
len = strncpy_from_user(tmp, filename, NAME_MAX + 1);
if (len < 0)
ret = len;
else if (len == 0)
ret = -ENOENT;
else if (len > PATH_MAX)
else if (len > NAME_MAX && tmp[NAME_MAX] != 0)
ret = -ENAMETOOLONG;
if (ret) {
__putname(tmp);
kfree(tmp);
tmp = ERR_PTR(ret);
}
return tmp;
}
#define ll_putname(filename) __putname(filename)
#define ll_putname(filename) kfree(filename)
static long ll_dir_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
......
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