mirror of
https://github.com/torvalds/linux.git
synced 2026-06-09 15:12:59 +02:00
f2fs: switch to fscrypt_get_symlink()
Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
This commit is contained in:
parent
6b76f58e24
commit
7ac4756a24
|
|
@ -1093,65 +1093,21 @@ static int f2fs_rename2(struct inode *old_dir, struct dentry *old_dentry,
|
||||||
|
|
||||||
static const char *f2fs_encrypted_follow_link(struct dentry *dentry, void **cookie)
|
static const char *f2fs_encrypted_follow_link(struct dentry *dentry, void **cookie)
|
||||||
{
|
{
|
||||||
struct page *cpage = NULL;
|
|
||||||
char *caddr, *paddr = NULL;
|
|
||||||
struct fscrypt_str cstr = FSTR_INIT(NULL, 0);
|
|
||||||
struct fscrypt_str pstr = FSTR_INIT(NULL, 0);
|
|
||||||
struct fscrypt_symlink_data *sd;
|
|
||||||
struct inode *inode = d_inode(dentry);
|
struct inode *inode = d_inode(dentry);
|
||||||
u32 max_size = inode->i_sb->s_blocksize;
|
struct page *page;
|
||||||
int res;
|
void *target;
|
||||||
|
|
||||||
res = fscrypt_get_encryption_info(inode);
|
if (!dentry)
|
||||||
if (res)
|
return ERR_PTR(-ECHILD);
|
||||||
return ERR_PTR(res);
|
|
||||||
|
|
||||||
cpage = read_mapping_page(inode->i_mapping, 0, NULL);
|
page = read_mapping_page(inode->i_mapping, 0, NULL);
|
||||||
if (IS_ERR(cpage))
|
if (IS_ERR(page))
|
||||||
return ERR_CAST(cpage);
|
return ERR_CAST(page);
|
||||||
caddr = page_address(cpage);
|
|
||||||
|
|
||||||
/* Symlink is encrypted */
|
target = fscrypt_get_symlink(inode, page_address(page),
|
||||||
sd = (struct fscrypt_symlink_data *)caddr;
|
inode->i_sb->s_blocksize);
|
||||||
cstr.name = sd->encrypted_path;
|
put_page(page);
|
||||||
cstr.len = le16_to_cpu(sd->len);
|
return *cookie = target;
|
||||||
|
|
||||||
/* this is broken symlink case */
|
|
||||||
if (unlikely(cstr.len == 0)) {
|
|
||||||
res = -ENOENT;
|
|
||||||
goto errout;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((cstr.len + sizeof(struct fscrypt_symlink_data) - 1) > max_size) {
|
|
||||||
/* Symlink data on the disk is corrupted */
|
|
||||||
res = -EIO;
|
|
||||||
goto errout;
|
|
||||||
}
|
|
||||||
res = fscrypt_fname_alloc_buffer(inode, cstr.len, &pstr);
|
|
||||||
if (res)
|
|
||||||
goto errout;
|
|
||||||
|
|
||||||
res = fscrypt_fname_disk_to_usr(inode, 0, 0, &cstr, &pstr);
|
|
||||||
if (res)
|
|
||||||
goto errout;
|
|
||||||
|
|
||||||
/* this is broken symlink case */
|
|
||||||
if (unlikely(pstr.name[0] == 0)) {
|
|
||||||
res = -ENOENT;
|
|
||||||
goto errout;
|
|
||||||
}
|
|
||||||
|
|
||||||
paddr = pstr.name;
|
|
||||||
|
|
||||||
/* Null-terminate the name */
|
|
||||||
paddr[pstr.len] = '\0';
|
|
||||||
|
|
||||||
put_page(cpage);
|
|
||||||
return *cookie = paddr;
|
|
||||||
errout:
|
|
||||||
fscrypt_fname_free_buffer(&pstr);
|
|
||||||
put_page(cpage);
|
|
||||||
return ERR_PTR(res);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct inode_operations f2fs_encrypted_symlink_inode_operations = {
|
const struct inode_operations f2fs_encrypted_symlink_inode_operations = {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user