Commit 6c988f57 authored by Miklos Szeredi's avatar Miklos Szeredi

ecryptfs: use vfs_get_link()

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

 - commit e54ad7f1 ("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: default avatarMiklos Szeredi <>
Cc: Tyler Hicks <>
parent 3f9ca755
......@@ -631,28 +631,23 @@ ecryptfs_rename(struct inode *old_dir, struct dentry *old_dentry,
static char *ecryptfs_readlink_lower(struct dentry *dentry, size_t *bufsiz)
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();
rc = d_inode(lower_dentry)->i_op->readlink(lower_dentry,
(char __user *)lower_buf,
if (rc < 0)
goto out;
link = vfs_get_link(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);
return rc ? ERR_PTR(rc) : buf;
link, strlen(link));
if (rc)
return ERR_PTR(rc);
return buf;
static const char *ecryptfs_get_link(struct dentry *dentry,
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment