diff options
author | Chao Yu <chao2.yu@samsung.com> | 2014-06-12 01:23:41 -0400 |
---|---|---|
committer | Jaegeuk Kim <jaegeuk@kernel.org> | 2014-07-09 08:58:08 -0400 |
commit | d6b7d4b31dfd5a454a71c445b8086bc098237334 (patch) | |
tree | b4316bf1bf36d7c22c243a520488259b19986f5c /fs | |
parent | 8bc6f60e3f7f31c4ce370b4b27b8f4b355b7f07e (diff) |
f2fs: check lower bound nid value in check_nid_range
This patch add lower bound verification for nid in check_nid_range, so nids
reserved like 0, node, meta passed by caller could be checked there.
And then check_nid_range could be used in f2fs_nfs_get_inode for simplifying
code.
Signed-off-by: Chao Yu <chao2.yu@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/f2fs/f2fs.h | 3 | ||||
-rw-r--r-- | fs/f2fs/inode.c | 1 | ||||
-rw-r--r-- | fs/f2fs/super.c | 4 |
3 files changed, 4 insertions, 4 deletions
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 7ef7acdb9350..58df97e174d0 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h | |||
@@ -641,7 +641,8 @@ static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi) | |||
641 | */ | 641 | */ |
642 | static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid) | 642 | static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid) |
643 | { | 643 | { |
644 | WARN_ON((nid >= NM_I(sbi)->max_nid)); | 644 | if (unlikely(nid < F2FS_ROOT_INO(sbi))) |
645 | return -EINVAL; | ||
645 | if (unlikely(nid >= NM_I(sbi)->max_nid)) | 646 | if (unlikely(nid >= NM_I(sbi)->max_nid)) |
646 | return -EINVAL; | 647 | return -EINVAL; |
647 | return 0; | 648 | return 0; |
diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c index adc622c6bdce..2cf6962f6cc8 100644 --- a/fs/f2fs/inode.c +++ b/fs/f2fs/inode.c | |||
@@ -78,6 +78,7 @@ static int do_read_inode(struct inode *inode) | |||
78 | if (check_nid_range(sbi, inode->i_ino)) { | 78 | if (check_nid_range(sbi, inode->i_ino)) { |
79 | f2fs_msg(inode->i_sb, KERN_ERR, "bad inode number: %lu", | 79 | f2fs_msg(inode->i_sb, KERN_ERR, "bad inode number: %lu", |
80 | (unsigned long) inode->i_ino); | 80 | (unsigned long) inode->i_ino); |
81 | WARN_ON(1); | ||
81 | return -EINVAL; | 82 | return -EINVAL; |
82 | } | 83 | } |
83 | 84 | ||
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index b2b18637cb9e..8f96d9372ade 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c | |||
@@ -689,9 +689,7 @@ static struct inode *f2fs_nfs_get_inode(struct super_block *sb, | |||
689 | struct f2fs_sb_info *sbi = F2FS_SB(sb); | 689 | struct f2fs_sb_info *sbi = F2FS_SB(sb); |
690 | struct inode *inode; | 690 | struct inode *inode; |
691 | 691 | ||
692 | if (unlikely(ino < F2FS_ROOT_INO(sbi))) | 692 | if (check_nid_range(sbi, ino)) |
693 | return ERR_PTR(-ESTALE); | ||
694 | if (unlikely(ino >= NM_I(sbi)->max_nid)) | ||
695 | return ERR_PTR(-ESTALE); | 693 | return ERR_PTR(-ESTALE); |
696 | 694 | ||
697 | /* | 695 | /* |