Re: [PATCH v4] hfs: Validate CNIDs in hfs_read_inode
From: Tetsuo Handa
Date: Wed Mar 18 2026 - 06:43:43 EST
On 2026/03/17 6:50, Viacheslav Dubeyko wrote:
> It means that, maybe, we need to add the logic of checking the extracted record
> by hfs_cat_find_brec(). But I cannot imagine that this logic can extract the
> record with incorrect CNID. Because, it is the main goal of hfs_cat_find_brec()
> logic to extract the record that contains requested CNID. And if we requested
> the HFS_ROOT_CNID, then this logic should return the record with exactly
> requested CNID or return the error code if such record has not been found.
I can't understand what you are talking about. Since hfs_cat_find_brec() is called
by only hfs_fill_super() with cnid == HFS_ROOT_CNID, we could remove cnid argument
from hfs_cat_find_brec() and rename hfs_cat_find_brec() to something else.
What we should talk about is not hfs_cat_find_brec() but hfs_bnode_read().
Although hfs_write_inode() does nothing if the "rec" contained unexpected values
https://elixir.bootlin.com/linux/v7.0-rc4/source/fs/hfs/inode.c#L499
https://elixir.bootlin.com/linux/v7.0-rc4/source/fs/hfs/inode.c#L522
, it seems that the "check if we can read requested length" => "read the requested
size" => "check if the read data is appropriate" pattern is the expected
hfs_bnode_read() usage. Therefore, I consider that doing the same pattern for
hfs_fill_super() is reasonable.
https://elixir.bootlin.com/linux/v7.0-rc4/source/fs/hfs/super.c#L363