All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hao Lee <haolee.swjtu@gmail.com>
To: akpm@linux-foundation.org
Cc: christian.brauner@ubuntu.com, keescook@chromium.org,
	adobriyan@gmail.com, jamorris@linux.microsoft.com,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	haolee.swjtu@gmail.com
Subject: [PATCH] proc: use kmalloc instead of __get_free_page() to alloc path buffer
Date: Sun, 23 Jan 2022 10:08:37 +0000	[thread overview]
Message-ID: <20220123100837.GA1491@haolee.io> (raw)

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

Signed-off-by: Hao Lee <haolee.swjtu@gmail.com>
---
 fs/proc/base.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/fs/proc/base.c b/fs/proc/base.c
index d654ce7150fd..74cfef87fe45 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -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;
 }
 
-- 
2.34.1


             reply	other threads:[~2022-01-23 10:08 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-23 10:08 Hao Lee [this message]
2022-01-23 13:55 ` [PATCH] proc: use kmalloc instead of __get_free_page() to alloc path buffer Alexey Dobriyan
2022-01-23 13:58   ` [PATCH v2] proc: alloc PATH_MAX bytes for /proc/${pid}/fd/ symlinks Alexey Dobriyan
2022-01-23 14:23     ` Hao Lee
2022-01-25 14:03 ` [PATCH] proc: use kmalloc instead of __get_free_page() to alloc path buffer Torin Carey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220123100837.GA1491@haolee.io \
    --to=haolee.swjtu@gmail.com \
    --cc=adobriyan@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=christian.brauner@ubuntu.com \
    --cc=jamorris@linux.microsoft.com \
    --cc=keescook@chromium.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.