All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jaegeuk Kim <jaegeuk@kernel.org>, To: Chao Yu <chao@kernel.org>;
Cc: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net
Subject: Re: [f2fs-dev] [PATCH v2] f2fs: fix to disallow getting inner inode via f2fs_iget()
Date: Mon, 12 Sep 2022 22:54:14 -0700	[thread overview]
Message-ID: <YyAbBroLzLPaSyCF@google.com> (raw)
In-Reply-To: <6c54e0b1-9c75-af90-565b-61174ddb5cbc@kernel.org>

On 09/13, Chao Yu wrote:
> On 2022/9/12 23:39, Jaegeuk Kim wrote:
> > On 09/08, Chao Yu wrote:
> > > On 2022/9/8 10:19, Jaegeuk Kim wrote:
> > > > On 09/08, Chao Yu wrote:
> > > > > On 2022/9/8 10:02, Jaegeuk Kim wrote:
> > > > > > On 08/31, Chao Yu wrote:
> > > > > > > From: Chao Yu <chao.yu@oppo.com>
> > > > > > > 
> > > > > > > Introduce f2fs_iget_inner() for f2fs_fill_super() to get inner inode:
> > > > > > > meta inode, node inode or compressed inode, and add f2fs_check_nid_range()
> > > > > > > in f2fs_iget() to avoid getting inner inode from external interfaces.
> > > > > > 
> > > > > > So, we don't want to check the range of inner inode numbers? What'd be the
> > > > > > way to check it's okay?
> > > > > 
> > > > > For node_ino, meta_ino, root_ino, we have checked them in sanity_check_raw_super()
> > > > > as below:
> > > > > 
> > > > > 	/* check reserved ino info */
> > > > > 	if (le32_to_cpu(raw_super->node_ino) != 1 ||
> > > > > 		le32_to_cpu(raw_super->meta_ino) != 2 ||
> > > > > 		le32_to_cpu(raw_super->root_ino) != 3) {
> > > > > 		f2fs_info(sbi, "Invalid Fs Meta Ino: node(%u) meta(%u) root(%u)",
> > > > > 			  le32_to_cpu(raw_super->node_ino),
> > > > > 			  le32_to_cpu(raw_super->meta_ino),
> > > > > 			  le32_to_cpu(raw_super->root_ino));
> > > > > 		return -EFSCORRUPTED;
> > > > > 	}
> > > > > 
> > > > > compressed_ino should always be NM_I(sbi)->max_nid, it can be checked in
> > > > > f2fs_init_compress_inode()?
> > > > 
> > > > Hmm, I'm not sure whether we really need this patch, since it'd look better
> > > > to handle all the iget with single f2fs_iget?
> > > 
> > > Well, the main concern is previously f2fs_iget() won't check validation for inner
> > > inode due to it will skip do_read_inode() - f2fs_check_nid_range(), so that in a
> > > fuzzed image, caller may pass inner ino into f2fs_iget(), result in incorrect use
> > > of inner inode. So I add f2fs_check_nid_range() in prior to f2fs_iget_inner() in
> > > f2fs_iget() as below to detect and avoid this case.
> > 
> > FWIW, sanity_check_raw_super() checked the inode numbers.
> 
> However, previously, f2fs_iget() will return inner inode to caller directly, if caller
> passes meta_ino, node_ino or compress_ino to f2fs_iget()?

Do you want to do sanity check on corrupted dentry? If so, how about checking
it in f2fs_iget instead?

	if (is_meta_ino(ino)) {
		if (!(inode->i_state & I_NEW) 
			return -EFSCORRUPTED;
		goto make_now;
	}

> 
> Thanks,
> 
> > 
> > > 
> > > > > > > +struct inode *f2fs_iget(struct super_block *sb, unsigned long ino)
> > > > > > > +{
> > > > > > > +	int ret;
> > > > > > > +
> > > > > > > +	ret = f2fs_check_nid_range(F2FS_SB(sb), ino);
> > > > > > > +	if (ret)
> > > > > > > +		return ERR_PTR(ret);
> > > > > > > +
> > > > > > > +	return f2fs_iget_inner(sb, ino);


_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

  reply	other threads:[~2022-09-13  5:54 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-30 22:53 [f2fs-dev] [PATCH v2] f2fs: fix to disallow getting inner inode via f2fs_iget() Chao Yu
2022-08-30 22:53 ` Chao Yu
2022-09-08  1:58 ` [f2fs-dev] " Chao Yu
2022-09-08  1:58   ` Chao Yu
2022-09-08  2:02 ` [f2fs-dev] " Jaegeuk Kim
2022-09-08  2:02   ` Jaegeuk Kim
2022-09-08  2:11   ` [f2fs-dev] " Chao Yu
2022-09-08  2:11     ` Chao Yu
2022-09-08  2:19     ` [f2fs-dev] " Jaegeuk Kim
2022-09-08  2:19       ` Jaegeuk Kim
2022-09-08  4:04       ` [f2fs-dev] " Chao Yu
2022-09-08  4:04         ` Chao Yu
2022-09-12 15:39         ` [f2fs-dev] " Jaegeuk Kim
2022-09-12 15:39           ` Jaegeuk Kim
2022-09-13  1:26           ` [f2fs-dev] " Chao Yu
2022-09-13  1:26             ` Chao Yu
2022-09-13  5:54             ` Jaegeuk Kim, Chao Yu [this message]
2022-09-13  6:44               ` [f2fs-dev] " Chao Yu
2022-09-13  6:44                 ` Chao Yu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YyAbBroLzLPaSyCF@google.com \
    --to=jaegeuk@kernel.org \
    --cc=chao@kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.