mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chao Yu <chao@kernel.org>
To: Wenjie Qi <qwjhust@gmail.com>, jaegeuk@kernel.org
Cc: chao@kernel.org, chur.lee@samsung.com,
	linux-f2fs-devel@lists.sourceforge.net,
	linux-kernel@vger.kernel.org, qiwenjie@xiaomi.com,
	stable@kernel.org
Subject: Re: [PATCH] f2fs: validate orphan inode entry count
Date: Tue, 26 May 2026 10:19:48 +0800	[thread overview]
Message-ID: <86c2f79d-ee26-4009-8051-82d25abf6d7b@kernel.org> (raw)
In-Reply-To: <20260525114621.571845-1-qiwenjie@xiaomi.com>

On 5/25/26 19:46, Wenjie Qi wrote:
> f2fs_recover_orphan_inodes() trusts the orphan block entry_count when
> replaying orphan inodes from the checkpoint pack.  A corrupted
> entry_count larger than F2FS_ORPHANS_PER_BLOCK makes the recovery loop
> read past the ino[] array and interpret footer or following data as
> inode numbers.
> 
> On a crafted image, mounting an unpatched kernel can drive orphan
> recovery into f2fs_bug_on() and panic the kernel.  Validate entry_count
> before consuming entries so corrupted checkpoint data fails the mount
> with -EFSCORRUPTED and requests fsck instead.
> 
> Fixes: 127e670abfa7 ("f2fs: add checkpoint operations")
> Cc: stable@kernel.org
> Signed-off-by: Wenjie Qi <qiwenjie@xiaomi.com>
> ---
>  fs/f2fs/checkpoint.c | 13 ++++++++++++-
>  1 file changed, 12 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c
> index c00a6b6ebcbd..fc72b69ff769 100644
> --- a/fs/f2fs/checkpoint.c
> +++ b/fs/f2fs/checkpoint.c
> @@ -943,6 +943,7 @@ int f2fs_recover_orphan_inodes(struct f2fs_sb_info *sbi)
>  	for (i = 0; i < orphan_blocks; i++) {
>  		struct folio *folio;
>  		struct f2fs_orphan_block *orphan_blk;
> +		unsigned int entry_count;
>  
>  		folio = f2fs_get_meta_folio(sbi, start_blk + i);
>  		if (IS_ERR(folio)) {
> @@ -951,7 +952,17 @@ int f2fs_recover_orphan_inodes(struct f2fs_sb_info *sbi)
>  		}
>  
>  		orphan_blk = folio_address(folio);
> -		for (j = 0; j < le32_to_cpu(orphan_blk->entry_count); j++) {
> +		entry_count = le32_to_cpu(orphan_blk->entry_count);
> +		if (entry_count > F2FS_ORPHANS_PER_BLOCK) {
> +			f2fs_err(sbi, "invalid orphan inode entry count %u",
> +				 entry_count);
> +			set_sbi_flag(sbi, SBI_NEED_FSCK);

Well, at this stage, I guess there is no chance to persist SBI_NEED_FSCK flag,
what about introduce ERROR_INCONSISTENT_ORPHAN in enum f2fs_error, so that
we can persist the new bit to provide hint to fsck?

Thanks,

> +			err = -EFSCORRUPTED;
> +			f2fs_folio_put(folio, true);
> +			goto out;
> +		}
> +
> +		for (j = 0; j < entry_count; j++) {
>  			nid_t ino = le32_to_cpu(orphan_blk->ino[j]);
>  
>  			err = recover_orphan_inode(sbi, ino);


  reply	other threads:[~2026-05-26  2:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-25 11:46 Wenjie Qi
2026-05-26  2:19 ` Chao Yu [this message]
2026-05-26  5:38   ` Wenjie Qi
2026-05-26 11:03     ` Chao Yu
2026-05-26 11:39       ` Wenjie Qi

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=86c2f79d-ee26-4009-8051-82d25abf6d7b@kernel.org \
    --to=chao@kernel.org \
    --cc=chur.lee@samsung.com \
    --cc=jaegeuk@kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=qiwenjie@xiaomi.com \
    --cc=qwjhust@gmail.com \
    --cc=stable@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome