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] hfsplus: validate attribute key name length
Date: Thu, 03 Dec 2026 15:34:03 -0800 [thread overview]
Message-ID: <c2d95803c40af074c4ea04773aef31b6b1fb9d3f.camel@dubeyko.com> (raw)
In-Reply-To: <179619831256.1663618.16544869010167759924@skku.edu>
On Fri, 2026-12-04 at 01:48 +0900, Kyuwon Cho wrote:
> An attributes B-tree key carries both an outer key length and an
> embedded
> Unicode string length. hfs_brec_keylen() bounds the former, but
> hfsplus_attr_bin_cmp_key() trusts the latter. A corrupted attributes
> tree
> can therefore make hfsplus_strcmp() read beyond the key buffer.
>
> Require the embedded name length to fit the format limit and to
> describe
> the same key size as the outer length before copying the key out of
> the
> B-tree node.
Thanks for the report and the patch. The issue is real. The attributes
tree's max_key_len is fixed at HFSPLUS_ATTR_KEYLEN - 2 by
hfs_btree_open(), so the key buffer has room for only 127 Unicode
characters, while hfsplus_strcmp() clamps the length to
HFSPLUS_MAX_STRLEN (255) only.
However, I believe the fix is incomplete. Please, see my comments
below.
>
> Fixes: 3e05ca20fb57 ("hfsplus: add functionality of manipulating by
> records in attributes tree")
> Signed-off-by: Kyuwon Cho <kyuwon.cho@skku.edu>
> ---
> The issue was found by an LLM-guided test generator that we are
> developing as a research prototype.
>
> The reproducer creates and mounts a crafted HFS+ image, then removes
> a
> file whose attribute record has an embedded name length larger than
> its
> key. Mounting the image requires root in the initial namespace.
>
> The decoded trace is:
>
> BUG: KASAN: slab-out-of-bounds in hfsplus_strcmp
> (fs/hfsplus/unicode.c:107)
> Read of size 2 at addr ff11000012fa4a18 by task test/116
> Call Trace:
> hfsplus_strcmp (fs/hfsplus/unicode.c:107)
> hfs_find_rec_by_key (fs/hfsplus/bfind.c:90)
> __hfsplus_brec_find (fs/hfsplus/bfind.c:129)
> hfsplus_brec_remove (fs/hfsplus/brec.c:224)
> __hfsplus_delete_attr (fs/hfsplus/attributes.c:339)
> hfsplus_delete_all_attrs (fs/hfsplus/attributes.c:444)
> hfsplus_delete_cat (fs/hfsplus/catalog.c:415)
> hfsplus_unlink (fs/hfsplus/dir.c:400)
>
> The patch was tested on v7.4-rc5 and rebased onto the HFS tree commit
> a2c27efbbd43 ("hfsplus: fix UAF in hfsplus_cat_write_inode()").
>
> fs/hfsplus/brec.c | 12 ++++++++++++
> 1 file changed, 12 insertions(+)
>
> diff --git a/fs/hfsplus/brec.c b/fs/hfsplus/brec.c
> index f416e562d439..b75dbadbab9b 100644
> --- a/fs/hfsplus/brec.c
> +++ b/fs/hfsplus/brec.c
> @@ -66,6 +66,18 @@ u16 hfs_brec_keylen(struct hfs_bnode *node, u16
> rec)
> retval);
> retval = U16_MAX;
> }
If the outer key length is too large, retval is already U16_MAX here,
but we still fall through into the new check and print a second error
for the same record. Could we return early (or use else if) here?
Frankly speaking, the function becomes grow. We need to refactor the
code. Even now the code looks not very clear.
> + if (node->tree->cnid == HFSPLUS_ATTR_CNID) {
We check tree CNID in multiple places. Probably, we need some helper
function(s).
> + u16 name_len = hfs_bnode_read_u16(node,
> recoff +
> + offsetof(struct hfsplus_attr_key,
> key_name.length));
The record length (len) is not checked against
offsetof(struct hfsplus_attr_key, key_name.unicode) before reading the
name length. hfs_bnode_read_u16() stays within the node, so this is not
a memory safety issue, but for a short record we read the name length
from the next record or from the offset table. I would prefer to reject
such a record explicitly instead of relying on the equality check below
failing by accident.
Frankly speaking, logic looks confusing. I think we need to make the
code more easy to understand.
> +
> + if (name_len > HFSPLUS_ATTR_MAX_STRLEN ||
> + retval != offsetof(struct
> hfsplus_attr_key,
> + key_name.unicode) +
> + name_len *
> sizeof(hfsplus_unichr)) {
It looks like we need a dedicated function for this check.
retval != offsetof(struct hfsplus_attr_key,
+ key_name.unicode) +
+ name_len *
sizeof(hfsplus_unichr)
Are you sure that this is correct? This logic is complicated and
require more clean code.
> + pr_err("invalid attribute name
> length\n");
Could you please make the message more informative? For example,
the name length, key length, node ID and record index. It would help
a lot in analyzing corruption reports.
Thanks,
Slava.
> + return U16_MAX;
> + }
> + }
> }
> return retval;
> }
next prev parent reply other threads:[~2026-12-03 23:34 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 16:48 Kyuwon Cho
2026-12-03 23:34 ` Viacheslav Dubeyko [this message]
2026-12-03 23:51 ` Viacheslav Dubeyko
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=c2d95803c40af074c4ea04773aef31b6b1fb9d3f.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®