mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Viacheslav Dubeyko <slava@dubeyko.com>
To: David Maximiliano Hermitte <davemadmaxxx@gmail.com>
Cc: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>,
	Yangtao Li <frank.li@vivo.com>,
	linux-fsdevel@vger.kernel.org,  linux-kernel@vger.kernel.org
Subject: Re: HFS syzbot BUG: test patch validating metadata before hfs_write_inode()
Date: Mon, 15 Jun 2026 23:29:50 -0700	[thread overview]
Message-ID: <52bae72d5ca54eed5b4f2218fca124e5bbb0747a.camel@dubeyko.com> (raw)
In-Reply-To: <20260612162043.1524591-1-davemadmaxxx@gmail.com>

Hi David,

On Fri, 2026-06-12 at 16:20 +0000, David Maximiliano Hermitte wrote:
> Hi Slava,
> 
> I followed the direction you pointed out and tested a small HFS
> validation patch for the syzbot crash path.
> 
> This is not intended as a final upstream patch yet. I am sending it
> as a test patch to demonstrate the crash direction and to ask whether
> this is the right validation point. If the direction is correct, I
> would appreciate guidance on the preferred upstream placement and
> syntax before a formal submission.
> 
> My understanding is that the BUG() in hfs_write_inode() is the
> endpoint, not the root cause. This test patch keeps hfs_write_inode()
> intact and rejects corrupted HFS metadata earlier in hfs_read_inode()
> and hfs_brec_read().
> 
> Local QEMU result:
> 
> BEFORE_UNPATCHED:
> - repro_started=true
> - kernel_bug_seen=true
> - verdict=BEFORE_BUG_REPRODUCED
> 
> AFTER_V04_PATCHED:
> - repro_started=true
> - clean_hfs_rejects=50
> - kernel_bug=False
> - oops=False
> - kasan=False
> - hfs_write_inode=False
> - verdict=AFTER_REPRO_RAN_NO_BUG_SEEN
> 
> checkpatch.pl --strict:
> - 0 errors, 0 warnings
> 
> The test patch is included below inline. Full QEMU serial logs are
> available if useful.
> 
> Please let me know whether this validation direction matches what you
> expect, or whether the fix should be placed differently.
> 

Sorry, I am in personal trip right now. And I have not much time and
capabilities for deep review and discussion. I am going to be back to
normal routine around June 26th. I hope our discussion and fix can wait
two weeks. :) Could you please ping me and revive the discussion around
that time?

Thanks,
Slava.

> Best regards,
> David
> 
> --- test patch follows ---
> 
> diff --git a/fs/hfs/bfind.c b/fs/hfs/bfind.c
> index d56e47b..5f56cab 100644
> --- a/fs/hfs/bfind.c
> +++ b/fs/hfs/bfind.c
> @@ -174,8 +174,10 @@ int hfs_brec_read(struct hfs_find_data *fd, void
> *rec, u32 rec_len)
>  	res = hfs_brec_find(fd);
>  	if (res)
>  		return res;
> +	if (fd->entryoffset < 0 || fd->entrylength <= 0)
> +		return -EFSCORRUPTED;
>  	if (fd->entrylength > rec_len)
> -		return -EINVAL;
> +		return -EFSCORRUPTED;
>  	hfs_bnode_read(fd->bnode, rec, fd->entryoffset, fd-
> >entrylength);
>  	return 0;
>  }
> diff --git a/fs/hfs/inode.c b/fs/hfs/inode.c
> index 878535d..beefb47 100644
> --- a/fs/hfs/inode.c
> +++ b/fs/hfs/inode.c
> @@ -369,6 +369,8 @@ static int hfs_read_inode(struct inode *inode,
> void *data)
>  	rec = idata->rec;
>  	switch (rec->type) {
>  	case HFS_CDR_FIL:
> +		if (be32_to_cpu(rec->file.FlNum) <
> HFS_FIRSTUSER_CNID)
> +			return -EFSCORRUPTED;
>  		if (!HFS_IS_RSRC(inode)) {
>  			hfs_inode_read_fork(inode, rec->file.ExtRec,
> rec->file.LgLen,
>  					    rec->file.PyLen,
> be16_to_cpu(rec->file.ClpSize));
> @@ -390,6 +392,9 @@ static int hfs_read_inode(struct inode *inode,
> void *data)
>  		inode->i_mapping->a_ops = &hfs_aops;
>  		break;
>  	case HFS_CDR_DIR:
> +		if (be32_to_cpu(rec->dir.DirID) < HFS_FIRSTUSER_CNID
> &&
> +		    be32_to_cpu(rec->dir.DirID) != HFS_ROOT_CNID)
> +			return -EFSCORRUPTED;
>  		inode->i_ino = be32_to_cpu(rec->dir.DirID);
>  		inode->i_size = be16_to_cpu(rec->dir.Val) + 2;
>  		HFS_I(inode)->fs_blocks = 0;

      reply	other threads:[~2026-06-16  6:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-12 16:20 David Maximiliano Hermitte
2026-06-16  6:29 ` Viacheslav Dubeyko [this message]

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=52bae72d5ca54eed5b4f2218fca124e5bbb0747a.camel@dubeyko.com \
    --to=slava@dubeyko.com \
    --cc=davemadmaxxx@gmail.com \
    --cc=frank.li@vivo.com \
    --cc=glaubitz@physik.fu-berlin.de \
    --cc=linux-fsdevel@vger.kernel.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®