dect
/
linux-2.6
Archived
13
0
Fork 0

get rid of pointless allocations and copying in ecryptfs_follow_link()

switch to generic_readlink(), while we are at it

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
Al Viro 2012-05-03 09:34:20 -04:00
parent 28fe3c1963
commit 408bd629ba
1 changed files with 11 additions and 41 deletions

View File

@ -660,11 +660,10 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
{ {
struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry); struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry);
char *lower_buf; char *lower_buf;
size_t lower_bufsiz = PATH_MAX;
mm_segment_t old_fs; mm_segment_t old_fs;
int rc; int rc;
lower_buf = kmalloc(lower_bufsiz, GFP_KERNEL); lower_buf = kmalloc(PATH_MAX, GFP_KERNEL);
if (!lower_buf) { if (!lower_buf) {
rc = -ENOMEM; rc = -ENOMEM;
goto out; goto out;
@ -673,58 +672,29 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
set_fs(get_ds()); set_fs(get_ds());
rc = lower_dentry->d_inode->i_op->readlink(lower_dentry, rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
(char __user *)lower_buf, (char __user *)lower_buf,
lower_bufsiz); PATH_MAX);
set_fs(old_fs); set_fs(old_fs);
if (rc < 0) if (rc < 0)
goto out; goto out;
lower_bufsiz = rc;
rc = ecryptfs_decode_and_decrypt_filename(buf, bufsiz, dentry, rc = ecryptfs_decode_and_decrypt_filename(buf, bufsiz, dentry,
lower_buf, lower_bufsiz); lower_buf, rc);
out: out:
kfree(lower_buf); kfree(lower_buf);
return rc; return rc;
} }
static int
ecryptfs_readlink(struct dentry *dentry, char __user *buf, int bufsiz)
{
char *kbuf;
size_t kbufsiz, copied;
int rc;
rc = ecryptfs_readlink_lower(dentry, &kbuf, &kbufsiz);
if (rc)
goto out;
copied = min_t(size_t, bufsiz, kbufsiz);
rc = copy_to_user(buf, kbuf, copied) ? -EFAULT : copied;
kfree(kbuf);
fsstack_copy_attr_atime(dentry->d_inode,
ecryptfs_dentry_to_lower(dentry)->d_inode);
out:
return rc;
}
static void *ecryptfs_follow_link(struct dentry *dentry, struct nameidata *nd) static void *ecryptfs_follow_link(struct dentry *dentry, struct nameidata *nd)
{ {
char *buf; char *buf;
int len = PAGE_SIZE, rc; size_t len = PATH_MAX;
mm_segment_t old_fs; int rc;
/* Released in ecryptfs_put_link(); only release here on error */ rc = ecryptfs_readlink_lower(dentry, &buf, &len);
buf = kmalloc(len, GFP_KERNEL); if (rc)
if (!buf) {
buf = ERR_PTR(-ENOMEM);
goto out; goto out;
} fsstack_copy_attr_atime(dentry->d_inode,
old_fs = get_fs(); ecryptfs_dentry_to_lower(dentry)->d_inode);
set_fs(get_ds()); buf[len] = '\0';
rc = dentry->d_inode->i_op->readlink(dentry, (char __user *)buf, len);
set_fs(old_fs);
if (rc < 0) {
kfree(buf);
buf = ERR_PTR(rc);
} else
buf[rc] = '\0';
out: out:
nd_set_link(nd, buf); nd_set_link(nd, buf);
return NULL; return NULL;
@ -1153,7 +1123,7 @@ out:
} }
const struct inode_operations ecryptfs_symlink_iops = { const struct inode_operations ecryptfs_symlink_iops = {
.readlink = ecryptfs_readlink, .readlink = generic_readlink,
.follow_link = ecryptfs_follow_link, .follow_link = ecryptfs_follow_link,
.put_link = ecryptfs_put_link, .put_link = ecryptfs_put_link,
.permission = ecryptfs_permission, .permission = ecryptfs_permission,