mirror of https://lore.kernel.org/lkml/
 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>,
	Tyler Hicks <tyhicks@canonical.com>
Subject: [PATCH 17/17] ecryptfs: use vfs_get_link()
Date: Mon, 12 Sep 2016 21:29:19 +0200	[thread overview]
Message-ID: <1473708559-12714-18-git-send-email-mszeredi@redhat.com> (raw)
In-Reply-To: <1473708559-12714-1-git-send-email-mszeredi@redhat.com>

Here again we are copying form one buffer to another, while jumping through
hoops to make kernel memory look like userspace memory.

For no good reason, since vfs_get_link() provides exactly what is needed.

As a bonus, now the security hook for readlink is also called on the
underlying inode.

Note: this can be called from link-following context.  But this is okay:

 - not in RCU mode

 - e54ad7f1ee26 ("proc: prevent stacking filesystems on top")

 - ecryptfs is *reading* the underlying symlink not following it, so the
   right security hook is being called

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Cc: Tyler Hicks <tyhicks@canonical.com>
---
 fs/ecryptfs/inode.c | 27 ++++++++++++---------------
 1 file changed, 12 insertions(+), 15 deletions(-)

diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
index fb2d831b7030..95e51b2af2de 100644
--- a/fs/ecryptfs/inode.c
+++ b/fs/ecryptfs/inode.c
@@ -627,26 +627,23 @@ out_lock:
 
 static char *ecryptfs_readlink_lower(struct dentry *dentry, size_t *bufsiz)
 {
+	DEFINE_DELAYED_CALL(done);
 	struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry);
-	char *lower_buf;
+	const char *link;
 	char *buf;
-	mm_segment_t old_fs;
 	int rc;
 
-	lower_buf = kmalloc(PATH_MAX, GFP_KERNEL);
-	if (!lower_buf)
-		return ERR_PTR(-ENOMEM);
-	old_fs = get_fs();
-	set_fs(get_ds());
-	rc = vfs_readlink(lower_dentry, (char __user *)lower_buf, PATH_MAX);
-	set_fs(old_fs);
-	if (rc < 0)
-		goto out;
+	link = vfs_get_link(lower_dentry, d_inode(lower_dentry), &done);
+	if (IS_ERR(link))
+		return ERR_CAST(link);
+
 	rc = ecryptfs_decode_and_decrypt_filename(&buf, bufsiz, dentry->d_sb,
-						  lower_buf, rc);
-out:
-	kfree(lower_buf);
-	return rc ? ERR_PTR(rc) : buf;
+						  link, strlen(link));
+	do_delayed_call(&done);
+	if (rc)
+		return ERR_PTR(rc);
+
+	return buf;
 }
 
 static const char *ecryptfs_get_link(struct dentry *dentry,
-- 
2.5.5

  parent reply	other threads:[~2016-09-12 19:30 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 ` [PATCH 16/17] ovl: use vfs_get_link() Miklos Szeredi
2016-09-12 19:29 ` Miklos Szeredi [this message]
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-18-git-send-email-mszeredi@redhat.com \
    --to=mszeredi@redhat.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tyhicks@canonical.com \
    --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

all inboxes | Powered by JetHome®