From: Miklos Szeredi <mszeredi@redhat.com>
To: linux-fsdevel@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Al Viro <viro@zeniv.linux.org.uk>
Subject: [PATCH 08/17] proc: merge proc_pid_readlink() into proc_pid_get_link()
Date: Mon, 12 Sep 2016 21:29:10 +0200 [thread overview]
Message-ID: <1473708559-12714-9-git-send-email-mszeredi@redhat.com> (raw)
In-Reply-To: <1473708559-12714-1-git-send-email-mszeredi@redhat.com>
This will allow us to move the generic readlink logic into the VFS and get
rid of the readlink method.
And it's a cleanup, removing more lines than it adds, since the two
functions have a lot in common.
/proc/$$/map_files/A allowed reading the symlink with the normal proc
permission checks, but following only allowed for CAP_SYS_ADMIN capable
tasks. So in proc_map_files_get_link() check for is_following_link()
before bailing out if not CAP_SYS_ADMIN capable.
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
---
fs/proc/base.c | 68 ++++++++++++++++++----------------------------------------
1 file changed, 21 insertions(+), 47 deletions(-)
diff --git a/fs/proc/base.c b/fs/proc/base.c
index ac0df4dde823..84769c763afe 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -1578,6 +1578,7 @@ static const char *proc_pid_get_link(struct dentry *dentry,
{
struct path path;
int error = -EACCES;
+ char *res;
if (!dentry)
return ERR_PTR(-ECHILD);
@@ -1590,58 +1591,31 @@ static const char *proc_pid_get_link(struct dentry *dentry,
if (error)
goto out;
- nd_jump_link(&path);
- return NULL;
-out:
- return ERR_PTR(error);
-}
-
-static int do_proc_readlink(struct path *path, char __user *buffer, int buflen)
-{
- char *tmp = (char*)__get_free_page(GFP_TEMPORARY);
- char *pathname;
- int len;
-
- if (!tmp)
- return -ENOMEM;
-
- pathname = d_path(path, tmp, PAGE_SIZE);
- len = PTR_ERR(pathname);
- if (IS_ERR(pathname))
- goto out;
- len = tmp + PAGE_SIZE - 1 - pathname;
-
- if (len > buflen)
- len = buflen;
- if (copy_to_user(buffer, pathname, len))
- len = -EFAULT;
- out:
- free_page((unsigned long)tmp);
- return len;
-}
-
-static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int buflen)
-{
- int error = -EACCES;
- struct inode *inode = d_inode(dentry);
- struct path path;
+ if (is_following_link()) {
+ nd_jump_link(&path);
+ res = NULL;
+ } else {
+ char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
- /* Are we allowed to snoop on the tasks file descriptors? */
- if (!proc_fd_access_allowed(inode))
- goto out;
+ error = -ENOMEM;
+ if (!buf)
+ goto out;
- error = PROC_I(inode)->op.proc_get_link(dentry, &path);
- if (error)
- goto out;
+ res = d_path(&path, buf, PAGE_SIZE);
+ if (IS_ERR(res))
+ kfree(buf);
+ else
+ set_delayed_call(done, kfree_link, buf);
+ }
+ return res;
- error = do_proc_readlink(&path, buffer, buflen);
- path_put(&path);
out:
- return error;
+ return ERR_PTR(error);
}
+
const struct inode_operations proc_pid_link_inode_operations = {
- .readlink = proc_pid_readlink,
+ .readlink = generic_readlink,
.get_link = proc_pid_get_link,
.setattr = proc_setattr,
};
@@ -1966,7 +1940,7 @@ proc_map_files_get_link(struct dentry *dentry,
struct inode *inode,
struct delayed_call *done)
{
- if (!capable(CAP_SYS_ADMIN))
+ if (is_following_link() && !capable(CAP_SYS_ADMIN))
return ERR_PTR(-EPERM);
return proc_pid_get_link(dentry, inode, done);
@@ -1976,7 +1950,7 @@ proc_map_files_get_link(struct dentry *dentry,
* Identical to proc_pid_link_inode_operations except for get_link()
*/
static const struct inode_operations proc_map_files_link_inode_operations = {
- .readlink = proc_pid_readlink,
+ .readlink = generic_readlink,
.get_link = proc_map_files_get_link,
.setattr = proc_setattr,
};
--
2.5.5
next prev parent reply other threads:[~2016-09-12 19:29 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-12 19:29 [PATCH 00/17] clean up readlinks Miklos Szeredi
2016-09-12 19:29 ` [PATCH 01/17] bad_inode: add missing i_op initializers Miklos Szeredi
2016-09-12 19:29 ` [PATCH 02/17] ovl: use generic_readlink Miklos Szeredi
2016-09-12 19:29 ` [PATCH 03/17] proc/self: " Miklos Szeredi
2016-09-12 19:29 ` [PATCH 04/17] afs: " Miklos Szeredi
2016-09-12 19:29 ` [PATCH 05/17] bad_inode: " Miklos Szeredi
2016-09-12 19:29 ` [PATCH 06/17] vfs: remove page_readlink() Miklos Szeredi
2016-09-12 19:29 ` [PATCH 07/17] vfs: add is_following_link() helper Miklos Szeredi
2016-09-12 19:29 ` Miklos Szeredi [this message]
2016-09-12 19:29 ` [PATCH 09/17] proc: merge proc_ns_readlink() into proc_ns_get_link() Miklos Szeredi
2016-09-12 19:29 ` [PATCH 10/17] nsfs: clean up ns_get_name() interface Miklos Szeredi
2016-09-12 19:29 ` [PATCH 11/17] vfs: replace calling i_op->readlink with vfs_readlink() Miklos Szeredi
2016-09-12 19:29 ` [PATCH 12/17] vfs: remove ".readlink = generic_readlink" assignments Miklos Szeredi
2016-09-12 19:29 ` [PATCH 13/17] vfs: remove unused i_op->readlink Miklos Szeredi
2016-09-12 19:29 ` [PATCH 14/17] vfs: remove unused generic_readlink() Miklos Szeredi
2016-09-12 19:29 ` [PATCH 15/17] vfs: add vfs_get_link() helper Miklos Szeredi
2016-09-12 19:29 ` [PATCH 16/17] ovl: use vfs_get_link() Miklos Szeredi
2016-09-12 19:29 ` [PATCH 17/17] ecryptfs: " Miklos Szeredi
2016-09-27 3:10 ` [PATCH 00/17] clean up readlinks Al Viro
2016-09-27 9:38 ` Miklos Szeredi
2016-09-28 2:17 ` Al Viro
2016-09-28 14:47 ` Miklos Szeredi
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=1473708559-12714-9-git-send-email-mszeredi@redhat.com \
--to=mszeredi@redhat.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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 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).