The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Chao Yu <chao@kernel.org>
To: Wenjie Qi <qwjhust@gmail.com>, jaegeuk@kernel.org
Cc: chao@kernel.org, linux-f2fs-devel@lists.sourceforge.net,
	linux-kernel@vger.kernel.org, qiwenjie@xiaomi.com
Subject: Re: [PATCH] f2fs: reject invalid recovered filename lengths
Date: Mon, 3 Aug 2026 16:52:56 +0800	[thread overview]
Message-ID: <08a3a204-e151-4d55-8141-2bdd5ef4fea5@kernel.org> (raw)
In-Reply-To: <20260729114156.3348582-1-qiwenjie@xiaomi.com>

On 7/29/26 19:41, Wenjie Qi wrote:
> Recovery uses raw_inode->i_namelen directly when rebuilding fsynced
> dentries. A zero-length name uses no dentry slots, so recovery can
> report success without recreating the dentry.
> 
> Treat zero-length and oversized recovered names as corruption, mark
> NEED_FSCK, and stop recovery with -EFSCORRUPTED.

Do you have a reproducer for this? maybe using inject.f2fs? It will be
better to cover those bugs w/ xfsqa testcase, could you please consider
to add it?

> 
> Signed-off-by: Wenjie Qi <qiwenjie@xiaomi.com>
> ---
>   fs/f2fs/recovery.c | 14 +++++++++++---
>   1 file changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/f2fs/recovery.c b/fs/f2fs/recovery.c
> index 89af8407b667..70cf99efcb3c 100644
> --- a/fs/f2fs/recovery.c
> +++ b/fs/f2fs/recovery.c
> @@ -126,8 +126,8 @@ static int init_recovered_filename(const struct inode *dir,
>   	fname->disk_name.len = le32_to_cpu(raw_inode->i_namelen);
>   	fname->disk_name.name = raw_inode->i_name;
>   
> -	if (WARN_ON(fname->disk_name.len > F2FS_NAME_LEN))
> -		return -ENAMETOOLONG;
> +	if (!fname->disk_name.len || fname->disk_name.len > F2FS_NAME_LEN)

unlikely?

relocate error handling here?

Thanks,

> +		return -EFSCORRUPTED;
>   
>   	if (!IS_ENCRYPTED(dir)) {
>   		usr_fname->name = fname->disk_name.name;
> @@ -185,8 +185,16 @@ static int recover_dentry(struct inode *inode, struct folio *ifolio,
>   
>   	dir = entry->inode;
>   	err = init_recovered_filename(dir, raw_inode, &fname, &usr_fname);
> -	if (err)
> +	if (err) {
> +		if (err == -EFSCORRUPTED) {
> +			f2fs_err(F2FS_I_SB(inode),
> +				 "invalid recovered filename length %u for ino %llu",
> +				 le32_to_cpu(raw_inode->i_namelen), inode->i_ino);
> +			set_sbi_flag(F2FS_I_SB(inode), SBI_NEED_FSCK);
> +			f2fs_handle_error(F2FS_I_SB(inode), ERROR_CORRUPTED_INODE);
> +		}
>   		goto out;
> +	}
>   retry:
>   	de = __f2fs_find_entry(dir, &fname, &folio);
>   	if (de && inode->i_ino == le32_to_cpu(de->ino))


  reply	other threads:[~2026-08-03  8:52 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-29 11:41 [PATCH] f2fs: reject invalid recovered filename lengths Wenjie Qi
2026-08-03  8:52 ` Chao Yu [this message]
2026-08-03 11:41   ` 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=08a3a204-e151-4d55-8141-2bdd5ef4fea5@kernel.org \
    --to=chao@kernel.org \
    --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 \
    /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