proc: use kmalloc instead of __get_free_page() to alloc path buffer
Subsystems (2)
PATCH 1/1 proc: use kmalloc instead of __get_free_page() to alloc path buffer
It's not a standard approach that use __get_free_page() to alloc path buffer directly. We'd better use kmalloc and PATH_MAX.
--- fs/proc/base.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
fs/proc/base.c +6 -5
@@ -1764,25 +1764,26 @@ static const char *proc_pid_get_link(struct dentry *dentry,static int do_proc_readlink (struct path *path,char __user *buffer,int buflen) { -char *tmp = (char *)__get_free_page (GFP_KERNEL ); +char *buf =NULL ;char *pathname;int len; -if (!tmp) + buf =kmalloc (PATH_MAX ,GFP_KERNEL ); +if (!buf)return -ENOMEM ; - pathname =d_path (path, tmp,PAGE_SIZE ); + pathname =d_path (path, buf,PATH_MAX ); len =PTR_ERR (pathname);if (IS_ERR (pathname)) goto out; - len = tmp +PAGE_SIZE -1 - pathname; + len = buf +PATH_MAX -1 - pathname;if (len > buflen) len = buflen;if (copy_to_user (buffer, pathname, len)) len = -EFAULT ; out: -free_page ((unsigned long )tmp); +kfree (buf);return len; }
Signature · 1 line
2.34.1
fs/proc/base.c static const char *proc_pid_get_link(struct dentry *dentry, · line 1767
Quoted 11 lines · Hao Lee
It's not a standard approach that use
__get_free_page()to alloc path buffer directly. We'd better use kmalloc andPATH_MAX.fs/proc/base.c +1
-1@@ -1764,25 +1764,26 @@ static const char *proc_pid_get_link(struct dentry *dentry,static int do_proc_readlink (struct path *path,char __user *buffer,int buflen) { -char *tmp = (char *)__get_free_page (GFP_KERNEL ); +char *buf =NULL ;
I'd rather not rename anything but keep it minimal.
PATCH v2 1/1 proc: alloc PATH_MAX bytes for /proc/${pid}/fd/ symlinks
From: Hao Lee <[email protected]>
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
---
fs/proc/base.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
fs/proc/base.c +4 -4
@@ -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) { -char *tmp = (char *)__get_free_page (GFP_KERNEL ); +char *tmp = (char *)kmalloc (PATH_MAX ,GFP_KERNEL );char *pathname;int len;if (!tmp)return -ENOMEM ; - pathname =d_path (path, tmp,PAGE_SIZE ); + pathname =d_path (path, tmp,PATH_MAX ); len =PTR_ERR (pathname);if (IS_ERR (pathname)) goto out; - len = tmp +PAGE_SIZE -1 - pathname; + len = tmp +PATH_MAX -1 - pathname;if (len > buflen) len = buflen;if (copy_to_user (buffer, pathname, len)) len = -EFAULT ; out: -free_page ((unsigned long )tmp); +kfree (tmp);return len; }
Re: [PATCH v2] proc: alloc PATH_MAX bytes for /proc/${pid}/fd/ symlinks
Quoted 7 lines · Alexey Dobriyan
From: Hao Lee <[email protected]>
It's not a standard approach that use
__get_free_page()to alloc path buffer directly. We'd better use kmalloc andPATH_MAX.
PAGE_SIZEis different on different archs.
This is indeed a worthy addition. Thanks.
Regards,
Hao Lee
Quoted 43 lines
An unlinked file
with very long canonical pathname will readlink differently because "(deleted)" eats into a buffer. --adobriyanSigned-off-by Hao Lee <[email protected]>Signed-off-by Alexey Dobriyan <[email protected]>---
fs/proc/base.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)fs/proc/base.c +4
-4@@ -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) { -char *tmp = (char *)__get_free_page (GFP_KERNEL ); +char *tmp = (char *)kmalloc (PATH_MAX ,GFP_KERNEL );char *pathname;int len;if (!tmp)return -ENOMEM ; - pathname =d_path (path, tmp,PAGE_SIZE ); + pathname =d_path (path, tmp,PATH_MAX ); len =PTR_ERR (pathname);if (IS_ERR (pathname)) goto out; - len = tmp +PAGE_SIZE -1 - pathname; + len = tmp +PATH_MAX -1 - pathname;if (len > buflen) len = buflen;if (copy_to_user (buffer, pathname, len)) len = -EFAULT ; out: -free_page ((unsigned long )tmp); +kfree (tmp);return len; }
Quoted 2 lines · Hao Lee
It's not a standard approach that use
__get_free_page()to alloc path buffer directly. We'd better use kmalloc andPATH_MAX.
If we're allocating PATH_MAX sized buffers for names, wouldn't it be suitable to use the name slab names_cachep declared in include/linux/fs.h using __getname() and __putname()?
Best,
Torin