Skip to contentSkip to conversation

f2fs: avoid BUG_ON from check_nid_range and update return path in do_read_inode

PATCH In review Namjae Jeon 2 participants 4 messages Mar 17, 2013 – Mar 18, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 5/5 f2fs: avoid BUG_ON from check_nid_range and update return path in do_read_inode

From: Namjae Jeon <[email protected]>

In function check_nid_range, there is no need to trigger BUG_ON and make kernel stop. Instead it could just check and indicate the inode number to be EINVAL. Update the return path in do_read_inode to use the return from check_nid_range.

---
 fs/f2fs/f2fs.h  |    6 ++++--
 fs/f2fs/inode.c |    6 +++++-
 2 files changed, 9 insertions(+), 3 deletions(-)
fs/f2fs/f2fs.h +4 -2
index be7ae70..1dae921 100644
@@ -515,9 +515,11 @@ static inline void mutex_unlock_op(struct f2fs_sb_info *sbi, enum lock_type t)
 /*
  * Check whether the given nid is within node id range.
  */
-static inline void check_nid_range(struct f2fs_sb_info *sbi, nid_t nid)
+static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid)
 {
-	BUG_ON((nid >= NM_I(sbi)->max_nid));
+	if (nid >= NM_I(sbi)->max_nid)
+		return -EINVAL;
+	return 0;
 }
 
 #define F2FS_DEFAULT_ALLOCATED_BLOCKS	1
fs/f2fs/inode.c +5 -1
index ddae412..6d82020 100644
@@ -44,7 +44,11 @@ static int do_read_inode(struct inode *inode)
 	struct f2fs_inode *ri;
 
 	/* Check if ino is within scope */
-	check_nid_range(sbi, inode->i_ino);
+	if (check_nid_range(sbi, inode->i_ino)) {
+		f2fs_msg(inode->i_sb, KERN_ERR, "bad inode number: %lu",
+			 (unsigned long) inode->i_ino);
+		return -EINVAL;
+	}
 
 	node_page = get_node_page(sbi, inode->i_ino);
 	if (IS_ERR(node_page))
Signature · 1 line
1.7.9.5
#1 lore raw

2013-03-17 (일), 17:27 +0900, Namjae Jeon:

Quoted 18 lines

From: Namjae Jeon <[email protected]>

In function check_nid_range, there is no need to trigger BUG_ON and make kernel stop. Instead it could just check and indicate the inode number to be EINVAL. Update the return path in do_read_inode to use the return from check_nid_range.

---
 fs/f2fs/f2fs.h  |    6 ++++--
 fs/f2fs/inode.c |    6 +++++-
 2 files changed, 9 insertions(+), 3 deletions(-)
fs/f2fs/f2fs.h +0 -0
index be7ae70..1dae921 100644

fs/f2fs/f2fs.h static inline void mutex_unlock_op(struct f2fs_sb_info *sbi, enum lock_type t) · line 522

Quoted 10 lines
fs/f2fs/f2fs.h +4 -2
@@ -515,9 +515,11 @@ static inline void mutex_unlock_op(struct f2fs_sb_info *sbi, enum lock_type t)
 /*
  * Check whether the given nid is within node id range.
  */
-static inline void check_nid_range(struct f2fs_sb_info *sbi, nid_t nid)
+static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid)
 {
-	BUG_ON((nid >= NM_I(sbi)->max_nid));
+	if (nid >= NM_I(sbi)->max_nid)
+		return -EINVAL;
+	return 0;

At this moment, I'd like to apply this patch and remain BUG_ON together since we should find real bugs in f2fs.
How do you think?

Quoted 20 lines
fs/f2fs/f2fs.h +0 -0
 }
 
 #define F2FS_DEFAULT_ALLOCATED_BLOCKS	1
fs/f2fs/inode.c +5 -1
index ddae412..6d82020 100644
@@ -44,7 +44,11 @@ static int do_read_inode(struct inode *inode)
 	struct f2fs_inode *ri;
 
 	/* Check if ino is within scope */
-	check_nid_range(sbi, inode->i_ino);
+	if (check_nid_range(sbi, inode->i_ino)) {
+		f2fs_msg(inode->i_sb, KERN_ERR, "bad inode number: %lu",
+			 (unsigned long) inode->i_ino);
+		return -EINVAL;
+	}
 
 	node_page = get_node_page(sbi, inode->i_ino);
 	if (IS_ERR(node_page))
Signature · 2 lines
Jaegeuk Kim
Samsung
#2 lore raw

2013/3/18, Jaegeuk Kim <[email protected]>:

Quoted 16 lines

2013-03-17 (일), 17:27 +0900, Namjae Jeon:

Quoted 15 lines

From: Namjae Jeon <[email protected]>

In function check_nid_range, there is no need to trigger BUG_ON and make kernel stop.
Instead it could just check and indicate the inode number to be EINVAL. Update the return path in do_read_inode to use the return from check_nid_range.

---
 fs/f2fs/f2fs.h  |    6 ++++--
 fs/f2fs/inode.c |    6 +++++-
 2 files changed, 9 insertions(+), 3 deletions(-)
Quoted 17 lines
Quoted 6 lines
fs/f2fs/f2fs.h +0 -0
index be7ae70..1dae921 100644
@@ -515,9 +515,11 @@ static inline void mutex_unlock_op(struct
 f2fs_sb_info *sbi, enum lock_type t)

fs/f2fs/f2fs.h static inline void mutex_unlock_op(struct · line 523

Quoted 10 lines
fs/f2fs/f2fs.h +4 -2
 /*
  * Check whether the given nid is within node id range.
  */
-static inline void check_nid_range(struct f2fs_sb_info *sbi, nid_t nid)
+static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid)
 {
-	BUG_ON((nid >= NM_I(sbi)->max_nid));
+	if (nid >= NM_I(sbi)->max_nid)
+		return -EINVAL;
+	return 0;

Hi Jaegeuk.

Quoted 3 lines

At this moment, I'd like to apply this patch and remain BUG_ON together since we should find real bugs in f2fs.
How do you think?

Instead of BUG_ON, we can make use of WARN_ON as that can also solve our purpose of finding the real bugs with the same information (back trace) and will also keep system running.

Thanks :)

Quoted 26 lines
Quoted 11 lines
fs/f2fs/f2fs.h +0 -0
 }
 

#define F2FS_DEFAULT_ALLOCATED_BLOCKS 1

fs/f2fs/inode.c +0 -0
index ddae412..6d82020 100644
@@ -44,7 +44,11 @@ static int do_read_inode(struct inode *inode)
 	struct f2fs_inode *ri;
 

fs/f2fs/inode.c static int do_read_inode(struct inode *inode) · line 54

Quoted 10 lines
fs/f2fs/inode.c +5 -1
 	/* Check if ino is within scope */
-	check_nid_range(sbi, inode->i_ino);
+	if (check_nid_range(sbi, inode->i_ino)) {
+		f2fs_msg(inode->i_sb, KERN_ERR, "bad inode number: %lu",
+			 (unsigned long) inode->i_ino);
+		return -EINVAL;
+	}
 
 	node_page = get_node_page(sbi, inode->i_ino);
 	if (IS_ERR(node_page))

--
Jaegeuk Kim
Samsung

#3 lore raw

2013-03-18 (월), 14:23 +0900, Namjae Jeon:

Quoted 34 lines

2013/3/18, Jaegeuk Kim <[email protected]>:

Quoted 16 lines

2013-03-17 (일), 17:27 +0900, Namjae Jeon:

Quoted 15 lines

From: Namjae Jeon <[email protected]>

In function check_nid_range, there is no need to trigger BUG_ON and make kernel stop.
Instead it could just check and indicate the inode number to be EINVAL. Update the return path in do_read_inode to use the return from check_nid_range.

---
 fs/f2fs/f2fs.h  |    6 ++++--
 fs/f2fs/inode.c |    6 +++++-
 2 files changed, 9 insertions(+), 3 deletions(-)
Quoted 17 lines
Quoted 6 lines
fs/f2fs/f2fs.h +0 -0
index be7ae70..1dae921 100644
@@ -515,9 +515,11 @@ static inline void mutex_unlock_op(struct
 f2fs_sb_info *sbi, enum lock_type t)

fs/f2fs/f2fs.h static inline void mutex_unlock_op(struct · line 523

Quoted 10 lines
fs/f2fs/f2fs.h +4 -2
 /*
  * Check whether the given nid is within node id range.
  */
-static inline void check_nid_range(struct f2fs_sb_info *sbi, nid_t nid)
+static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid)
 {
-	BUG_ON((nid >= NM_I(sbi)->max_nid));
+	if (nid >= NM_I(sbi)->max_nid)
+		return -EINVAL;
+	return 0;
Quoted 8 lines

Hi Jaegeuk.

Quoted 3 lines

At this moment, I'd like to apply this patch and remain BUG_ON together since we should find real bugs in f2fs.
How do you think?

Instead of BUG_ON, we can make use of WARN_ON as that can also solve our purpose of finding the real bugs with the same information (back trace) and will also keep system running.

Got it~!
Thanks,

Quoted 32 lines

Thanks :)

Quoted 19 lines
Quoted 19 lines
fs/f2fs/f2fs.h +0 -0
 }
 

#define F2FS_DEFAULT_ALLOCATED_BLOCKS 1

fs/f2fs/inode.c +5 -1
index ddae412..6d82020 100644
@@ -44,7 +44,11 @@ static int do_read_inode(struct inode *inode)
 	struct f2fs_inode *ri;
 
 	/* Check if ino is within scope */
-	check_nid_range(sbi, inode->i_ino);
+	if (check_nid_range(sbi, inode->i_ino)) {
+		f2fs_msg(inode->i_sb, KERN_ERR, "bad inode number: %lu",
+			 (unsigned long) inode->i_ino);
+		return -EINVAL;
+	}
 
Quoted 7 lines

fs/f2fs/inode.c static int do_read_inode(struct inode *inode) · line 54

Quoted 2 lines
fs/f2fs/inode.c +0 -0
 	node_page = get_node_page(sbi, inode->i_ino);
 	if (IS_ERR(node_page))

--
Jaegeuk Kim
Samsung

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

Signature · 2 lines
Jaegeuk Kim
Samsung