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 e54ad7f1ee
("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>
This commit is contained in:
parent
3f9ca75516
commit
6c988f5759
|
@ -631,28 +631,23 @@ out_lock:
|
||||||
|
|
||||||
static char *ecryptfs_readlink_lower(struct dentry *dentry, size_t *bufsiz)
|
static char *ecryptfs_readlink_lower(struct dentry *dentry, size_t *bufsiz)
|
||||||
{
|
{
|
||||||
|
DEFINE_DELAYED_CALL(done);
|
||||||
struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry);
|
struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry);
|
||||||
char *lower_buf;
|
const char *link;
|
||||||
char *buf;
|
char *buf;
|
||||||
mm_segment_t old_fs;
|
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
lower_buf = kmalloc(PATH_MAX, GFP_KERNEL);
|
link = vfs_get_link(lower_dentry, &done);
|
||||||
if (!lower_buf)
|
if (IS_ERR(link))
|
||||||
return ERR_PTR(-ENOMEM);
|
return ERR_CAST(link);
|
||||||
old_fs = get_fs();
|
|
||||||
set_fs(get_ds());
|
|
||||||
rc = d_inode(lower_dentry)->i_op->readlink(lower_dentry,
|
|
||||||
(char __user *)lower_buf,
|
|
||||||
PATH_MAX);
|
|
||||||
set_fs(old_fs);
|
|
||||||
if (rc < 0)
|
|
||||||
goto out;
|
|
||||||
rc = ecryptfs_decode_and_decrypt_filename(&buf, bufsiz, dentry->d_sb,
|
rc = ecryptfs_decode_and_decrypt_filename(&buf, bufsiz, dentry->d_sb,
|
||||||
lower_buf, rc);
|
link, strlen(link));
|
||||||
out:
|
do_delayed_call(&done);
|
||||||
kfree(lower_buf);
|
if (rc)
|
||||||
return rc ? ERR_PTR(rc) : buf;
|
return ERR_PTR(rc);
|
||||||
|
|
||||||
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *ecryptfs_get_link(struct dentry *dentry,
|
static const char *ecryptfs_get_link(struct dentry *dentry,
|
||||||
|
|
Loading…
Reference in New Issue