Skip to contentSkip to conversation

f2fs: check filename length in recover_dentry

PATCH In review Chao Yu 2 participants 3 messages Dec 23, 2013 – Dec 26, 2013

Subsystems (2)
lore
Share & tools
lore

Chao Yu

author
#0 lore raw

PATCH v2 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.

V2:
o add WARN_ON() as Jaegeuk Kim suggested.

---
 fs/f2fs/dir.c      |    3 ---
 fs/f2fs/recovery.c |    6 ++++++
 2 files changed, 6 insertions(+), 3 deletions(-)
fs/f2fs/dir.c +0 -3
index 07ad850..f0b4630 100644
@@ -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 +6 -0
index a3f4542..4d411a2 100644
@@ -62,6 +62,12 @@ 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)) {
+		WARN_ON(1);
+		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
#1 lore raw

Hi,

2013-12-23 (월), 11:12 +0800, Chao Yu:

Quoted 8 lines

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.

The f2fs_find_entry is called by f2fs_unlink and f2fs_rename too. So, you can't remove this, instead it'd be better remove it from f2fs_lookup.
Thanks,

Quoted 41 lines

V2:
o add WARN_ON() as Jaegeuk Kim suggested.

---
 fs/f2fs/dir.c      |    3 ---
 fs/f2fs/recovery.c |    6 ++++++
 2 files changed, 6 insertions(+), 3 deletions(-)
fs/f2fs/dir.c +0 -3
index 07ad850..f0b4630 100644
@@ -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 +6 -0
index a3f4542..4d411a2 100644
@@ -62,6 +62,12 @@ 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)) {
+		WARN_ON(1);
+		err = -ENAMETOOLONG;
+		goto out;
+	}
 retry:
 	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
author
#2 lore raw

Hi,

Quoted 15 lines

-----Original Message-----
From: Jaegeuk Kim [mailto:[email protected]]
Sent: Thursday, December 26, 2013 6:55 AM
To: Chao Yu
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [f2fs-dev] [PATCH 1/3 V2] f2fs: check filename length in recover_dentry

Hi,

2013-12-23 (월), 11:12 +0800, Chao Yu:

Quoted 5 lines

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.

Quoted 5 lines
Quoted 3 lines

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.

The f2fs_find_entry is called by f2fs_unlink and f2fs_rename too.

As I check code and test, f2fs_unlink and f2fs_rename is protected by f2fs_lookup well.
Oldfile/newfile/deletedfile name length is check previously in f2fs_lookup.

Quoted 2 lines

So, you can't remove this, instead it'd be better remove it from f2fs_lookup.

I think verification of filename length could not be removed from lookup. Ever you remove it, we could create file in f2fs device with filename length that vfs not supported.
In my test, kernel seems not be stable after that kind of file created in f2fs.

Quoted 32 lines

Thanks,

Quoted 30 lines

V2:
o add WARN_ON() as Jaegeuk Kim suggested.

---
 fs/f2fs/dir.c      |    3 ---
 fs/f2fs/recovery.c |    6 ++++++
 2 files changed, 6 insertions(+), 3 deletions(-)
fs/f2fs/dir.c +0 -3
index 07ad850..f0b4630 100644
@@ -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
index a3f4542..4d411a2 100644
@@ -62,6 +62,12 @@ static int recover_dentry(struct page *ipage, struct inode *inode)
 
Quoted 15 lines

fs/f2fs/recovery.c static int recover_dentry(struct page *ipage, struct inode *inode) · line 73

Quoted 11 lines
fs/f2fs/recovery.c +6 -0
 	name.len = le32_to_cpu(raw_inode->i_namelen);
 	name.name = raw_inode->i_name;
+
+	if (unlikely(name.len > F2FS_NAME_LEN)) {
+		WARN_ON(1);
+		err = -ENAMETOOLONG;
+		goto out;
+	}
 retry:
 	de = f2fs_find_entry(dir, &name, &page);
 	if (de && inode->i_ino == le32_to_cpu(de->ino))

--
Jaegeuk Kim
Samsung

--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html