summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaegeuk Kim <jaegeuk@kernel.org>2015-12-25 03:13:09 +0300
committerJaegeuk Kim <jaegeuk@kernel.org>2015-12-30 21:14:19 +0300
commit8dc0d6a11e7d985dd466ce0a8c71eaea50dd7cc6 (patch)
tree46ffa60753b849730256f2b5655eb090dd3675fb
parente96248bb45d42375b23e1c083ec5a55151503e82 (diff)
downloadlinux-8dc0d6a11e7d985dd466ce0a8c71eaea50dd7cc6.tar.xz
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: Jaegeuk Kim <jaegeuk@kernel.org>
-rw-r--r--fs/f2fs/namei.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c
index fb41c8082696..6c4a94310b54 100644
--- a/fs/f2fs/namei.c
+++ b/fs/f2fs/namei.c
@@ -931,7 +931,7 @@ static const char *f2fs_encrypted_follow_link(struct dentry *dentry, void **cook
{
struct page *cpage = 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 inode *inode = d_inode(dentry);
struct f2fs_encrypted_symlink_data *sd;
@@ -952,6 +952,12 @@ static const char *f2fs_encrypted_follow_link(struct dentry *dentry, void **cook
/* Symlink is encrypted */
sd = (struct f2fs_encrypted_symlink_data *)caddr;
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);
if (!cstr.name) {
res = -ENOMEM;
@@ -960,7 +966,7 @@ static const char *f2fs_encrypted_follow_link(struct dentry *dentry, void **cook
memcpy(cstr.name, sd->encrypted_path, cstr.len);
/* this is broken symlink case */
- if (cstr.name[0] == 0 && cstr.len == 0) {
+ if (unlikely(cstr.name[0] == 0)) {
res = -ENOENT;
goto errout;
}