mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] hfsplus: validate attribute key name length
@ 2026-12-03 16:48 Kyuwon Cho
  2026-12-03 23:34 ` Viacheslav Dubeyko
  0 siblings, 1 reply; 3+ messages in thread
From: Kyuwon Cho @ 2026-12-03 16:48 UTC (permalink / raw)
  To: Viacheslav Dubeyko, John Paul Adrian Glaubitz, Yangtao Li
  Cc: linux-fsdevel, linux-kernel

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.

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 (node->tree->cnid == HFSPLUS_ATTR_CNID) {
+			u16 name_len = hfs_bnode_read_u16(node, recoff +
+				offsetof(struct hfsplus_attr_key, key_name.length));
+
+			if (name_len > HFSPLUS_ATTR_MAX_STRLEN ||
+			    retval != offsetof(struct hfsplus_attr_key,
+					       key_name.unicode) +
+				      name_len * sizeof(hfsplus_unichr)) {
+				pr_err("invalid attribute name length\n");
+				return U16_MAX;
+			}
+		}
 	}
 	return retval;
 }
-- 
2.43.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-12-03 23:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-03 16:48 [PATCH] hfsplus: validate attribute key name length Kyuwon Cho
2026-12-03 23:34 ` Viacheslav Dubeyko
2026-12-03 23:51   ` Viacheslav Dubeyko

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®