Commit 8dc0d6a1 authored by Jaegeuk Kim's avatar Jaegeuk Kim

f2fs: early check broken symlink length in the encrypted case

If link is broken, its len is zero, and we don't need to move forward.
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
parent e96248bb
...@@ -931,7 +931,7 @@ static const char *f2fs_encrypted_follow_link(struct dentry *dentry, void **cook ...@@ -931,7 +931,7 @@ static const char *f2fs_encrypted_follow_link(struct dentry *dentry, void **cook
{ {
struct page *cpage = NULL; struct page *cpage = NULL;
char *caddr, *paddr = NULL; char *caddr, *paddr = NULL;
struct f2fs_str cstr; struct f2fs_str cstr = FSTR_INIT(NULL, 0);
struct f2fs_str pstr = FSTR_INIT(NULL, 0); struct f2fs_str pstr = FSTR_INIT(NULL, 0);
struct inode *inode = d_inode(dentry); struct inode *inode = d_inode(dentry);
struct f2fs_encrypted_symlink_data *sd; struct f2fs_encrypted_symlink_data *sd;
...@@ -952,6 +952,12 @@ static const char *f2fs_encrypted_follow_link(struct dentry *dentry, void **cook ...@@ -952,6 +952,12 @@ static const char *f2fs_encrypted_follow_link(struct dentry *dentry, void **cook
/* Symlink is encrypted */ /* Symlink is encrypted */
sd = (struct f2fs_encrypted_symlink_data *)caddr; sd = (struct f2fs_encrypted_symlink_data *)caddr;
cstr.len = le16_to_cpu(sd->len); cstr.len = le16_to_cpu(sd->len);
/* this is broken symlink case */
if (unlikely(cstr.len == 0)) {
res = -ENOENT;
goto errout;
}
cstr.name = kmalloc(cstr.len, GFP_NOFS); cstr.name = kmalloc(cstr.len, GFP_NOFS);
if (!cstr.name) { if (!cstr.name) {
res = -ENOMEM; res = -ENOMEM;
...@@ -960,7 +966,7 @@ static const char *f2fs_encrypted_follow_link(struct dentry *dentry, void **cook ...@@ -960,7 +966,7 @@ static const char *f2fs_encrypted_follow_link(struct dentry *dentry, void **cook
memcpy(cstr.name, sd->encrypted_path, cstr.len); memcpy(cstr.name, sd->encrypted_path, cstr.len);
/* this is broken symlink case */ /* this is broken symlink case */
if (cstr.name[0] == 0 && cstr.len == 0) { if (unlikely(cstr.name[0] == 0)) {
res = -ENOENT; res = -ENOENT;
goto errout; goto errout;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment