mm-commits.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* + proc-alloc-path_max-bytes-for-proc-pid-fd-symlinks.patch added to -mm tree
@ 2022-01-25  0:13 akpm
  0 siblings, 0 replies; only message in thread
From: akpm @ 2022-01-25  0:13 UTC (permalink / raw)
  To: adobriyan, christian.brauner, haolee.swjtu, jamorris, keescook,
	mm-commits


The patch titled
     Subject: proc: alloc PATH_MAX bytes for /proc/${pid}/fd/ symlinks
has been added to the -mm tree.  Its filename is
     proc-alloc-path_max-bytes-for-proc-pid-fd-symlinks.patch

This patch should soon appear at
    https://ozlabs.org/~akpm/mmots/broken-out/proc-alloc-path_max-bytes-for-proc-pid-fd-symlinks.patch
and later at
    https://ozlabs.org/~akpm/mmotm/broken-out/proc-alloc-path_max-bytes-for-proc-pid-fd-symlinks.patch

Before you just go and hit "reply", please:
   a) Consider who else should be cc'ed
   b) Prefer to cc a suitable mailing list as well
   c) Ideally: find the original patch on the mailing list and do a
      reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***

The -mm tree is included into linux-next and is updated
there every 3-4 working days

------------------------------------------------------
From: Hao Lee <haolee.swjtu@gmail.com>
Subject: 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

Link: https://lkml.kernel.org/r/Ye1fCxyZZ0I5lgOL@localhost.localdomain
Signed-off-by: Hao Lee <haolee.swjtu@gmail.com>
Signed-off-by: Alexey 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: Andrew Morton <akpm@linux-foundation.org>
---

 fs/proc/base.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

--- a/fs/proc/base.c~proc-alloc-path_max-bytes-for-proc-pid-fd-symlinks
+++ a/fs/proc/base.c
@@ -1764,25 +1764,25 @@ out:
 
 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;
 }
 
_

Patches currently in -mm which might be from haolee.swjtu@gmail.com are

proc-alloc-path_max-bytes-for-proc-pid-fd-symlinks.patch


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-01-25  3:46 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-25  0:13 + proc-alloc-path_max-bytes-for-proc-pid-fd-symlinks.patch added to -mm tree akpm

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).