From: Viacheslav Dubeyko <slava@dubeyko.com>
To: Kyuwon Cho <kyuwon.cho@skku.edu>,
John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>,
Yangtao Li <frank.li@vivo.com>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] hfs: clamp catalog key name lengths during comparison
Date: Fri, 04 Dec 2026 14:34:42 -0800 [thread overview]
Message-ID: <3e4cc0d3b1a8bf9288fc1ec8218ac67ce69c1f64.camel@dubeyko.com> (raw)
In-Reply-To: <179636379461.1106205.15423253231491526241@skku.edu>
On Fri, 2026-12-04 at 15:35 +0900, Kyuwon Cho wrote:
> The catalog key comparison trusts the embedded Pascal string lengths.
> A corrupt length can make hfs_strcmp() read beyond the fixed-size
> name
> arrays, including on paths that copy keys through
> hfs_bnode_read_key()
> without calling hfs_brec_keylen().
>
> Clamp both operands at the format's HFS_NAMELEN limit at the
> comparison
> boundary. This also preserves valid fixed-size catalog index keys,
> whose
> outer key length does not describe the embedded name length exactly.
Thanks a lot for the quick v2.
Could you please confirm that the reproducer doesn't trigger the KASAN
report anymore with v2 applied?
Also, I think the KASAN trace from v1 is worth keeping in the commit
message, because it helps people searching for the same crash to find
the fix.
The bug goes back to the initial import (Fixes: 1da177e4c3f4), and the
fix is small and self-contained, so a Cc: stable@vger.kernel.org makes
sense.
>
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Suggested-by: Viacheslav Dubeyko <slava@dubeyko.com>
> Signed-off-by: Kyuwon Cho <kyuwon.cho@skku.edu>
> ---
> Changes in v2:
> - Replace the record-size equality check with Viacheslav Dubeyko's
> suggested comparison-boundary fix.
> - Clamp both embedded name lengths to HFS_NAMELEN, covering keys read
> through hfs_bnode_read_key() while preserving fixed-size index
> keys.
>
> v1:
> https://lore.kernel.org/all/179619831256.1663618.8521911735854986516@skku.edu/
>
> The issue was found by an LLM-guided test generator that we are
> developing as a research prototype.
>
> Tested with a multi-leaf catalog created by hformat; mounting,
> listing,
> and looking up files continue to work.
>
> The reproducer is attached to my reply in the v1 thread.
>
> fs/hfs/catalog.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/fs/hfs/catalog.c b/fs/hfs/catalog.c
> index 76924783b136..ef9787d92f5d 100644
> --- a/fs/hfs/catalog.c
> +++ b/fs/hfs/catalog.c
> @@ -171,6 +171,7 @@ int hfs_cat_create(u32 cnid, struct inode *dir,
> const struct qstr *str, struct i
> int hfs_cat_keycmp(const btree_key *key1, const btree_key *key2)
> {
> __be32 k1p, k2p;
> + unsigned int len1, len2;
>
> k1p = key1->cat.ParID;
> k2p = key2->cat.ParID;
> @@ -178,8 +179,10 @@ int hfs_cat_keycmp(const btree_key *key1, const
> btree_key *key2)
> if (k1p != k2p)
> return be32_to_cpu(k1p) < be32_to_cpu(k2p) ? -1 : 1;
>
> - return hfs_strcmp(key1->cat.CName.name, key1->cat.CName.len,
> - key2->cat.CName.name, key2-
> >cat.CName.len);
> + len1 = min_t(unsigned int, key1->cat.CName.len,
> HFS_NAMELEN);
> + len2 = min_t(unsigned int, key2->cat.CName.len,
> HFS_NAMELEN);
min_t(unsigned int, ...) is fine; plain min() would also work with
today's type checks.
I am guessing... We know here that Catalog file record is corrupted.
Should we inform about corruption and recommend to run FSCK tool?
Thanks,
Slava.
> + return hfs_strcmp(key1->cat.CName.name, len1,
> + key2->cat.CName.name, len2);
> }
>
> static int hfs_cat_validate_found_cnid(struct hfs_find_data *fd, u32
> cnid)
next prev parent reply other threads:[~2026-12-04 22:34 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 6:35 Kyuwon Cho
2026-12-04 22:34 ` Viacheslav Dubeyko [this message]
2026-12-05 1:46 ` Kyuwon Cho
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=3e4cc0d3b1a8bf9288fc1ec8218ac67ce69c1f64.camel@dubeyko.com \
--to=slava@dubeyko.com \
--cc=frank.li@vivo.com \
--cc=glaubitz@physik.fu-berlin.de \
--cc=kyuwon.cho@skku.edu \
--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®