Commit 3a72917c authored by Hao Lee's avatar Hao Lee Committed by Linus Torvalds

proc: alloc PATH_MAX bytes for /proc/${pid}/fd/ symlinks

It's not a standard approach that use __get_free_page() to alloc path
buffer directly.  We'd better use kmalloc and PATH_MAX.

	PAGE_SIZE is different on different archs. An unlinked file
	with very long canonical pathname will readlink differently
	because "(deleted)" eats into a buffer.	--adobriyan

[akpm@linux-foundation.org: remove now-unneeded cast]

Link: https://lkml.kernel.org/r/Ye1fCxyZZ0I5lgOL@localhost.localdomainSigned-off-by: default avatarHao Lee <haolee.swjtu@gmail.com>
Signed-off-by: default avatarAlexey Dobriyan <adobriyan@gmail.com>
Cc: Christian Brauner <christian.brauner@ubuntu.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: James Morris <jamorris@linux.microsoft.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent f443e374
...@@ -1764,25 +1764,25 @@ static const char *proc_pid_get_link(struct dentry *dentry, ...@@ -1764,25 +1764,25 @@ static const char *proc_pid_get_link(struct dentry *dentry,
static int do_proc_readlink(struct path *path, char __user *buffer, int buflen) static int do_proc_readlink(struct path *path, char __user *buffer, int buflen)
{ {
char *tmp = (char *)__get_free_page(GFP_KERNEL); char *tmp = kmalloc(PATH_MAX, GFP_KERNEL);
char *pathname; char *pathname;
int len; int len;
if (!tmp) if (!tmp)
return -ENOMEM; return -ENOMEM;
pathname = d_path(path, tmp, PAGE_SIZE); pathname = d_path(path, tmp, PATH_MAX);
len = PTR_ERR(pathname); len = PTR_ERR(pathname);
if (IS_ERR(pathname)) if (IS_ERR(pathname))
goto out; goto out;
len = tmp + PAGE_SIZE - 1 - pathname; len = tmp + PATH_MAX - 1 - pathname;
if (len > buflen) if (len > buflen)
len = buflen; len = buflen;
if (copy_to_user(buffer, pathname, len)) if (copy_to_user(buffer, pathname, len))
len = -EFAULT; len = -EFAULT;
out: out:
free_page((unsigned long)tmp); kfree(tmp);
return len; return len;
} }
......
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