]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
f2fs: check lower bound nid value in check_nid_range
authorChao Yu <chao2.yu@samsung.com>
Thu, 12 Jun 2014 05:23:41 +0000 (13:23 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Wed, 9 Jul 2014 12:58:08 +0000 (05:58 -0700)
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>
fs/f2fs/f2fs.h
fs/f2fs/inode.c
fs/f2fs/super.c

index 7ef7acdb93502176df3438a045c536851872c274..58df97e174d015398ab55741c6b9ba3bac2b508e 100644 (file)
@@ -641,7 +641,8 @@ static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi)
  */
 static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid)
 {
-       WARN_ON((nid >= NM_I(sbi)->max_nid));
+       if (unlikely(nid < F2FS_ROOT_INO(sbi)))
+               return -EINVAL;
        if (unlikely(nid >= NM_I(sbi)->max_nid))
                return -EINVAL;
        return 0;
index adc622c6bdce68fd5363e1fb7f12e1d1bc9ccbbb..2cf6962f6cc859ed3c1e5712175a1ee39aad789a 100644 (file)
@@ -78,6 +78,7 @@ static int do_read_inode(struct inode *inode)
        if (check_nid_range(sbi, inode->i_ino)) {
                f2fs_msg(inode->i_sb, KERN_ERR, "bad inode number: %lu",
                         (unsigned long) inode->i_ino);
+               WARN_ON(1);
                return -EINVAL;
        }
 
index b2b18637cb9eff9a959167b1b0d88dbe0a5116ed..8f96d9372adebc0d1ccf47545515e44de68b749d 100644 (file)
@@ -689,9 +689,7 @@ static struct inode *f2fs_nfs_get_inode(struct super_block *sb,
        struct f2fs_sb_info *sbi = F2FS_SB(sb);
        struct inode *inode;
 
-       if (unlikely(ino < F2FS_ROOT_INO(sbi)))
-               return ERR_PTR(-ESTALE);
-       if (unlikely(ino >= NM_I(sbi)->max_nid))
+       if (check_nid_range(sbi, ino))
                return ERR_PTR(-ESTALE);
 
        /*