Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d6b7d4b3 authored by Chao Yu's avatar Chao Yu Committed by Jaegeuk Kim
Browse files

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: default avatarChao Yu <chao2.yu@samsung.com>
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
parent 8bc6f60e
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -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)
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))
	if (unlikely(nid >= NM_I(sbi)->max_nid))
		return -EINVAL;
		return -EINVAL;
	return 0;
	return 0;
+1 −0
Original line number Original line Diff line number Diff line
@@ -78,6 +78,7 @@ static int do_read_inode(struct inode *inode)
	if (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",
		f2fs_msg(inode->i_sb, KERN_ERR, "bad inode number: %lu",
			 (unsigned long) inode->i_ino);
			 (unsigned long) inode->i_ino);
		WARN_ON(1);
		return -EINVAL;
		return -EINVAL;
	}
	}


+1 −3
Original line number Original line Diff line number Diff line
@@ -689,9 +689,7 @@ static struct inode *f2fs_nfs_get_inode(struct super_block *sb,
	struct f2fs_sb_info *sbi = F2FS_SB(sb);
	struct f2fs_sb_info *sbi = F2FS_SB(sb);
	struct inode *inode;
	struct inode *inode;


	if (unlikely(ino < F2FS_ROOT_INO(sbi)))
	if (check_nid_range(sbi, ino))
		return ERR_PTR(-ESTALE);
	if (unlikely(ino >= NM_I(sbi)->max_nid))
		return ERR_PTR(-ESTALE);
		return ERR_PTR(-ESTALE);


	/*
	/*