linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
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 16/17] ovl: use vfs_get_link()
Date: Mon, 12 Sep 2016 21:29:18 +0200	[thread overview]
Message-ID: <1473708559-12714-17-git-send-email-mszeredi@redhat.com> (raw)
In-Reply-To: <1473708559-12714-1-git-send-email-mszeredi@redhat.com>

Resulting in a complete removal of a function basically implementing the
inverse of vfs_readlink().

As a bonus, now the proper security hook is also called.

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
---
 fs/overlayfs/copy_up.c | 45 ++++++---------------------------------------
 fs/overlayfs/inode.c   |  5 +----
 2 files changed, 7 insertions(+), 43 deletions(-)

diff --git a/fs/overlayfs/copy_up.c b/fs/overlayfs/copy_up.c
index a2d4c10dd74d..c3371d62d931 100644
--- a/fs/overlayfs/copy_up.c
+++ b/fs/overlayfs/copy_up.c
@@ -167,39 +167,6 @@ out_fput:
 	return error;
 }
 
-static char *ovl_read_symlink(struct dentry *realdentry)
-{
-	int res;
-	char *buf;
-	struct inode *inode = realdentry->d_inode;
-	mm_segment_t old_fs;
-
-	res = -EINVAL;
-	if (!inode->i_op->get_link)
-		goto err;
-
-	res = -ENOMEM;
-	buf = (char *) __get_free_page(GFP_KERNEL);
-	if (!buf)
-		goto err;
-
-	old_fs = get_fs();
-	set_fs(get_ds());
-	/* The cast to a user pointer is valid due to the set_fs() */
-	res = vfs_readlink(realdentry, (char __user *)buf, PAGE_SIZE - 1);
-	set_fs(old_fs);
-	if (res < 0) {
-		free_page((unsigned long) buf);
-		goto err;
-	}
-	buf[res] = '\0';
-
-	return buf;
-
-err:
-	return ERR_PTR(res);
-}
-
 static int ovl_set_timestamps(struct dentry *upperdentry, struct kstat *stat)
 {
 	struct iattr attr = {
@@ -331,19 +298,21 @@ out_cleanup:
 int ovl_copy_up_one(struct dentry *parent, struct dentry *dentry,
 		    struct path *lowerpath, struct kstat *stat)
 {
+	DEFINE_DELAYED_CALL(done);
 	struct dentry *workdir = ovl_workdir(dentry);
 	int err;
 	struct kstat pstat;
 	struct path parentpath;
+	struct dentry *lowerdentry = lowerpath->dentry;
 	struct dentry *upperdir;
 	struct dentry *upperdentry;
 	const struct cred *old_cred;
-	char *link = NULL;
+	const char *link = NULL;
 
 	if (WARN_ON(!workdir))
 		return -EROFS;
 
-	ovl_do_check_copy_up(lowerpath->dentry);
+	ovl_do_check_copy_up(lowerdentry);
 
 	ovl_path_upper(parent, &parentpath);
 	upperdir = parentpath.dentry;
@@ -353,7 +322,7 @@ int ovl_copy_up_one(struct dentry *parent, struct dentry *dentry,
 		return err;
 
 	if (S_ISLNK(stat->mode)) {
-		link = ovl_read_symlink(lowerpath->dentry);
+		link = vfs_get_link(lowerdentry, d_inode(lowerdentry), &done);
 		if (IS_ERR(link))
 			return PTR_ERR(link);
 	}
@@ -381,9 +350,7 @@ int ovl_copy_up_one(struct dentry *parent, struct dentry *dentry,
 out_unlock:
 	unlock_rename(workdir, upperdir);
 	revert_creds(old_cred);
-
-	if (link)
-		free_page((unsigned long) link);
+	do_delayed_call(&done);
 
 	return err;
 }
diff --git a/fs/overlayfs/inode.c b/fs/overlayfs/inode.c
index db8975f59021..6be9bb470fd9 100644
--- a/fs/overlayfs/inode.c
+++ b/fs/overlayfs/inode.c
@@ -164,11 +164,8 @@ static const char *ovl_get_link(struct dentry *dentry,
 	realdentry = ovl_dentry_real(dentry);
 	realinode = realdentry->d_inode;
 
-	if (WARN_ON(!realinode->i_op->get_link))
-		return ERR_PTR(-EPERM);
-
 	old_cred = ovl_override_creds(dentry->d_sb);
-	p = realinode->i_op->get_link(realdentry, realinode, done);
+	p = vfs_get_link(realdentry, realinode, done);
 	revert_creds(old_cred);
 	return p;
 }
-- 
2.5.5


  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 ` [PATCH 08/17] proc: merge proc_pid_readlink() into proc_pid_get_link() Miklos Szeredi
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 ` Miklos Szeredi [this message]
2016-09-12 19:29 ` [PATCH 17/17] ecryptfs: use vfs_get_link() 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-17-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).