f2fs: check filename length in recover_dentry
Subsystems (2)
PATCH 1/3 f2fs: check filename length in recover_dentry
In current flow, we will get Null return value of f2fs_find_entry in recover_dentry when name.len is bigger than F2FS_NAME_LEN, and then we still add this inode into its dir entry.
To avoid this situation, we must check filename length before we use it.
Another point is that we could remove the code of checking filename length In f2fs_find_entry, because f2fs_lookup will be called previously to ensure of validity of filename length.
--- fs/f2fs/dir.c | 3 --- fs/f2fs/recovery.c | 5 +++++ 2 files changed, 5 insertions(+), 3 deletions(-)
fs/f2fs/dir.c +0 -3
@@ -190,9 +190,6 @@ struct f2fs_dir_entry *f2fs_find_entry(struct inode *dir,unsigned int max_depth;unsigned int level; -if (unlikely (namelen >F2FS_NAME_LEN )) -return NULL ; -if (npages ==0 )return NULL ;
fs/f2fs/recovery.c +5 -0
@@ -62,6 +62,11 @@ static int recover_dentry(struct page *ipage, struct inode *inode) name.len =le32_to_cpu (raw_inode->i_namelen); name.name = raw_inode->i_name; + +if (unlikely (name.len >F2FS_NAME_LEN )) { + err = -ENAMETOOLONG ; + goto out; + } retry: de =f2fs_find_entry (dir, &name, &page);if (de && inode->i_ino ==le32_to_cpu (de->ino))
Signature · 9 lines
1.7.9.5 ------------------------------------------------------------------------------ Rapidly troubleshoot problems before they affect your business. Most IT organizations don't have a clear picture of how application performance affects their revenue. With AppDynamics, you get 100% visibility into your Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro! http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
2013-12-21 (토), 18:01 +0800, Chao Yu:
Quoted 34 lines
In current flow, we will get Null return value of
f2fs_find_entryinrecover_dentrywhen name.len is bigger thanF2FS_NAME_LEN, and then we still add this inode into its dir entry.
To avoid this situation, we must check filename length before we use it.Another point is that we could remove the code of checking filename length In
f2fs_find_entry, becausef2fs_lookupwill be called previously to ensure of validity of filename length.Signed-off-by Chao Yu <[email protected]>--- fs/f2fs/dir.c | 3 --- fs/f2fs/recovery.c | 5 +++++ 2 files changed, 5 insertions(+), 3 deletions(-)fs/f2fs/dir.c +0
-3@@ -190,9 +190,6 @@ struct f2fs_dir_entry *f2fs_find_entry(struct inode *dir,unsigned int max_depth;unsigned int level; -if (unlikely (namelen >F2FS_NAME_LEN )) -return NULL ; -if (npages ==0 )return NULL ;fs/f2fs/recovery.c +0
-0
fs/f2fs/recovery.c static int recover_dentry(struct page *ipage, struct inode *inode) · line 69
Quoted 8 lines
fs/f2fs/recovery.c +5
-0@@ -62,6 +62,11 @@ static int recover_dentry(struct page *ipage, struct inode *inode) name.len =le32_to_cpu (raw_inode->i_namelen); name.name = raw_inode->i_name; + +if (unlikely (name.len >F2FS_NAME_LEN )) { + err = -ENAMETOOLONG ; + goto out; + }
Have you seen this before?
This is a trivial bug case, so, if you have got this bug, we should fix the bug first instead of adding any workaround patch.
Let's add WARN_ON() at least.
Thanks,
Quoted 3 lines
fs/f2fs/recovery.c +0
-0retry: de =f2fs_find_entry (dir, &name, &page);if (de && inode->i_ino ==le32_to_cpu (de->ino))
Signature · 15 lines
Jaegeuk Kim Samsung ------------------------------------------------------------------------------ Rapidly troubleshoot problems before they affect your business. Most IT organizations don't have a clear picture of how application performance affects their revenue. With AppDynamics, you get 100% visibility into your Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro! http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Hi Kim,
Quoted 43 lines
-----Original Message-----
From: Jaegeuk Kim [mailto:[email protected]]
Sent: Monday, December 23, 2013 9:26 AM
To: Chao Yu
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [f2fs-dev] [PATCH 1/3] f2fs: check filename length inrecover_dentry2013-12-21 (토), 18:01 +0800, Chao Yu:
Quoted 35 lines
In current flow, we will get Null return value of
f2fs_find_entryinrecover_dentrywhen name.len is bigger thanF2FS_NAME_LEN, and then we still add this inode into its dir entry.
To avoid this situation, we must check filename length before we use it.Another point is that we could remove the code of checking filename length In
f2fs_find_entry, becausef2fs_lookupwill be called previously to ensure of validity of filename length.Signed-off-by Chao Yu <[email protected]>--- fs/f2fs/dir.c | 3 --- fs/f2fs/recovery.c | 5 +++++ 2 files changed, 5 insertions(+), 3 deletions(-)fs/f2fs/dir.c +0
-3@@ -190,9 +190,6 @@ struct f2fs_dir_entry *f2fs_find_entry(struct inode *dir,unsigned int max_depth;unsigned int level; -if (unlikely (namelen >F2FS_NAME_LEN )) -return NULL ; -if (npages ==0 )return NULL ;fs/f2fs/recovery.c +0
-0@@ -62,6 +62,11 @@ static int recover_dentry(struct page *ipage, struct inode *inode)
Quoted 9 lines
fs/f2fs/recovery.c static int recover_dentry(struct page *ipage, struct inode *inode) · line 69
Quoted 7 lines
fs/f2fs/recovery.c +5
-0name.len =le32_to_cpu (raw_inode->i_namelen); name.name = raw_inode->i_name; + +if (unlikely (name.len >F2FS_NAME_LEN )) { + err = -ENAMETOOLONG ; + goto out; + }Have you seen this before?
Not yet.
Quoted 2 lines
This is a trivial bug case, so, if you have got this bug, we should fix the bug first instead of adding any workaround patch.
What I worry about is that not only f2fs bug lead to this trivial problem, but also other program with operation in raw disk could do this.
Quoted 1 line
Let's add
WARN_ON()at least.
Alright.
Thanks.
Quoted 9 lines
Thanks,
fs/f2fs/recovery.c static int recover_dentry(struct page *ipage, struct inode *inode) · line 72
Quoted 3 lines
fs/f2fs/recovery.c +0
-0retry: de =f2fs_find_entry (dir, &name, &page);if (de && inode->i_ino ==le32_to_cpu (de->ino))--
Jaegeuk Kim
Samsung