mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Viacheslav Dubeyko <Slava.Dubeyko@ibm.com>
To: "leocstone@gmail.com" <leocstone@gmail.com>,
	"jack@suse.cz" <jack@suse.cz>,
	"penguin-kernel@I-love.SAKURA.ne.jp"
	<penguin-kernel@I-love.SAKURA.ne.jp>,
	"willy@infradead.org" <willy@infradead.org>,
	"brauner@kernel.org" <brauner@kernel.org>
Cc: "glaubitz@physik.fu-berlin.de" <glaubitz@physik.fu-berlin.de>,
	"frank.li@vivo.com" <frank.li@vivo.com>,
	"slava@dubeyko.com" <slava@dubeyko.com>,
	"linux-fsdevel@vger.kernel.org" <linux-fsdevel@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"akpm@linux-foundation.org" <akpm@linux-foundation.org>
Subject: Re:  [PATCH v4] hfs: update sanity check of the root record
Date: Wed, 30 Jul 2025 19:24:54 +0000	[thread overview]
Message-ID: <5498a57ea660b5366ef213acd554aba55a5804d1.camel@ibm.com> (raw)
In-Reply-To: <427fcb57-8424-4e52-9f21-7041b2c4ae5b@I-love.SAKURA.ne.jp>

On Wed, 2025-07-30 at 08:21 +0900, Tetsuo Handa wrote:
> syzbot is reporting that BUG() in hfs_write_inode() fires upon unmount
> operation when the inode number of the record retrieved as a result of
> hfs_cat_find_brec(HFS_ROOT_CNID) is not HFS_ROOT_CNID, for
> commit b905bafdea21 ("hfs: Sanity check the root record") checked
> the record size and the record type but did not check the inode number.
> 
> Reported-by: syzbot+97e301b4b82ae803d21b@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=97e301b4b82ae803d21b  
> Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
> ---
>  fs/hfs/super.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/hfs/super.c b/fs/hfs/super.c
> index fe09c2093a93..d231989b4e23 100644
> --- a/fs/hfs/super.c
> +++ b/fs/hfs/super.c
> @@ -354,7 +354,7 @@ static int hfs_fill_super(struct super_block *sb, struct fs_context *fc)
>  			goto bail_hfs_find;
>  		}
>  		hfs_bnode_read(fd.bnode, &rec, fd.entryoffset, fd.entrylength);
> -		if (rec.type != HFS_CDR_DIR)
> +		if (rec.type != HFS_CDR_DIR || rec.dir.DirID != cpu_to_be32(HFS_ROOT_CNID))
>  			res = -EIO;
>  	}
>  	if (res)

Why do not localize the all checks in hfs_read_inode()?

We will do such logic then [1], even if rec.dir.DirID !=
cpu_to_be32(HFS_ROOT_CNID):

root_inode = hfs_iget(sb, &fd.search_key->cat, &rec);
hfs_find_exit(&fd);
if (!root_inode)
	goto bail_no_root;

The hfs_iget() calls iget5_locked() [2]:

inode = iget5_locked(sb, cnid, hfs_test_inode, hfs_read_inode, &data);

And hfs_read_inode() will be called, finally. If inode ID is wrong, then
make_bad_inode(inode) can be called [3].

If we considering case HFS_CDR_DIR in hfs_read_inode(), then we know that it
could be HFS_POR_CNID, HFS_ROOT_CNID, or >= HFS_FIRSTUSER_CNID. Do you mean that
HFS_POR_CNID could be a problem in hfs_write_inode()?

Thanks,
Slava.

[1] https://elixir.bootlin.com/linux/v6.16-rc6/source/fs/hfs/super.c#L363
[2] https://elixir.bootlin.com/linux/v6.16-rc6/source/fs/hfs/inode.c#L403
[3] 
https://elixir.bootlin.com/linux/v6.16-rc6/source/fs/hfs/inode.c#L373

  reply	other threads:[~2025-07-30 19:25 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-23 13:32 [PATCH] hfs: don't use BUG() when we can continue Tetsuo Handa
2024-12-05 13:45 ` [PATCH (REPOST)] " Tetsuo Handa
2024-12-05 13:59   ` Matthew Wilcox
2024-12-05 14:14     ` Tetsuo Handa
2025-06-25  5:03       ` Tetsuo Handa
2025-07-15  6:51         ` [PATCH v2] hfs: remove BUG() from hfs_release_folio()/hfs_test_inode()/hfs_write_inode() Tetsuo Handa
2025-07-15 19:20           ` Viacheslav Dubeyko
2025-07-17 15:30             ` Tetsuo Handa
2025-07-17 15:32               ` [PATCH v3] " Tetsuo Handa
2025-07-17 18:25                 ` Viacheslav Dubeyko
2025-07-17 19:35                 ` Matthew Wilcox
2025-07-17 19:49                   ` Viacheslav Dubeyko
2025-07-17 22:08                     ` Tetsuo Handa
2025-07-21 17:04                       ` Viacheslav Dubeyko
2025-07-22 10:42                         ` Tetsuo Handa
2025-07-22 13:30                           ` Matthew Wilcox
2025-07-22 14:04                             ` Tetsuo Handa
2025-07-22 14:22                               ` Matthew Wilcox
2025-07-22 18:08                                 ` Viacheslav Dubeyko
2025-07-23  1:07                                   ` Tetsuo Handa
2025-07-23  2:16                                     ` Tetsuo Handa
2025-07-23 18:19                                       ` Viacheslav Dubeyko
2025-07-23 18:43                                         ` Viacheslav Dubeyko
2025-07-24  6:55                                           ` Tetsuo Handa
2025-07-24 19:49                                             ` Viacheslav Dubeyko
2025-07-24 22:05                                               ` Tetsuo Handa
2025-07-24 23:20                                                 ` Tetsuo Handa
2025-07-25  4:16                                                   ` Tetsuo Handa
2025-07-25 17:47                                                     ` Viacheslav Dubeyko
2025-07-25 21:52                                                       ` Tetsuo Handa
2025-07-28 19:37                                                         ` Viacheslav Dubeyko
2025-07-28 21:38                                                           ` Tetsuo Handa
2025-07-29 23:21                                                             ` [PATCH v4] hfs: update sanity check of the root record Tetsuo Handa
2025-07-30 19:24                                                               ` Viacheslav Dubeyko [this message]
2025-07-30 22:02                                                                 ` Tetsuo Handa
2025-07-31 18:03                                                                   ` Viacheslav Dubeyko
2025-07-31 21:12                                                                     ` Tetsuo Handa
2025-08-01 18:26                                                                       ` Viacheslav Dubeyko
2025-08-01 21:52                                                                         ` Tetsuo Handa
2025-08-04 22:00                                                                           ` Viacheslav Dubeyko
2025-08-21 10:57                                                                             ` Tetsuo Handa
2025-07-25 17:45                                                   ` [PATCH v3] hfs: remove BUG() from hfs_release_folio()/hfs_test_inode()/hfs_write_inode() Viacheslav Dubeyko
2025-07-25 22:25                                                     ` Tetsuo Handa
2025-07-27 13:27                                                       ` Tetsuo Handa
2025-07-25 17:42                                                 ` Viacheslav Dubeyko
2025-07-25 22:22                                                   ` Tetsuo Handa

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=5498a57ea660b5366ef213acd554aba55a5804d1.camel@ibm.com \
    --to=slava.dubeyko@ibm.com \
    --cc=akpm@linux-foundation.org \
    --cc=brauner@kernel.org \
    --cc=frank.li@vivo.com \
    --cc=glaubitz@physik.fu-berlin.de \
    --cc=jack@suse.cz \
    --cc=leocstone@gmail.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=penguin-kernel@I-love.SAKURA.ne.jp \
    --cc=slava@dubeyko.com \
    --cc=willy@infradead.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®