AI Trajectory


Trajectory: (Expand/Collapse All)
Seq Timestamp Type Name Duration
0/0 2026/09/21 03:51 flow patch-triage
7m Args:
null

Results:
{
  "EnableConfigs": [
    "HFSPLUS_FS",
    "BLOCK"
  ],
  "FocusSymbols": [
    "hfsplus_asc2uni",
    "hfsplus_hash_dentry",
    "hfsplus_compare_dentry",
    "hfsplus_combining_class",
    "hfsplus_legacy_decompose",
    "hfsplus_fixup_legacy_sequences"
  ],
  "KMSANReasoning": "The patch adds Unicode canonical combining class reordering and legacy sequence fixups to HFS+ filename processing (in hfsplus_asc2uni, hfsplus_hash_dentry, and hfsplus_compare_dentry). \n\nEvaluating KMSAN applicability:\n1. No structures are copied to user space (no copy_to_user, put_user, netlink, or ioctl info-leaks).\n2. Stack buffers introduced (e.g., `buf[HFSPLUS_MAX_STRLEN]` in `hfsplus_asc2uni` and `run[HFSPLUS_CCC_RUN_MAX]` in `struct hfsplus_decompose_iter`) have strictly bounded lengths tracked by `outlen` and `run_len`. In `hfsplus_decompose_str`, `hfsplus_canonical_reorder`, and `hfsplus_decompose_iter_refill`, only the exact elements that have been written are ever read or manipulated.\n3. The catalog key lengths (`ustr-\u003elength`) accurately represent the number of initialized code units written, preventing surrounding code from reading past initialized bytes.\n4. Any potential issues with array indexing, lookups, or `memmove` boundary conditions in sequence substitution are spatial memory safety bugs (out-of-bounds reads/writes), which are directly detected by standard KASAN.\n\nTherefore, the patch does not introduce or expose uninitialized memory risks, and a dedicated KMSAN fuzzing session is not warranted.",
  "NeedsKMSAN": false,
  "Reasoning": "The patch modifies HFS+ Unicode name handling, introducing canonical combining class (CCC) reordering, legacy decomposition lookups, and in-place buffer fixups. These functions are directly executed during dentry hashing (d_hash), dentry comparison (d_compare), and catalog/xattr key encoding (hfsplus_asc2uni) when accessing an HFS+ filesystem mounted in standard virtual environments via loop/block devices. Fuzzing is warranted to test buffer manipulations, table searching, reordering loops, and string canonicalization consistency.",
  "WorthFuzzing": true
}

1/1 2026/09/21 03:51 action read-patch-diff
0m Args:
null

Results:
{
  "PatchDiff": "commit 9b05d1884d74d63b2810e5bb43da4d00ab799a9c\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate:   Mon Sep 21 03:51:44 2026 +0000\n\n    syz-cluster: applied patch under review\n\ndiff --git a/fs/hfsplus/hfsplus_fs.h b/fs/hfsplus/hfsplus_fs.h\nindex 1e5b58e6a13fc..916e6552e3f0b 100644\n--- a/fs/hfsplus/hfsplus_fs.h\n+++ b/fs/hfsplus/hfsplus_fs.h\n@@ -17,6 +17,7 @@\n #include \u003clinux/blkdev.h\u003e\n #include \u003clinux/fs_context.h\u003e\n #include \"hfsplus_raw.h\"\n+#include \"unicode.h\"\n \n /* Runtime config options */\n #define HFSPLUS_DEF_CR_TYPE    0x3F3F3F3F  /* '????' */\n@@ -486,11 +487,6 @@ void hfsplus_mark_mdb_dirty(struct super_block *sb);\n void hfsplus_prepare_volume_header_for_commit(struct hfsplus_vh *vhdr);\n int hfsplus_commit_superblock(struct super_block *sb);\n \n-/* tables.c */\n-extern u16 hfsplus_case_fold_table[];\n-extern u16 hfsplus_decompose_table[];\n-extern u16 hfsplus_compose_table[];\n-\n /* unicode.c */\n int hfsplus_strcasecmp(const struct hfsplus_unistr *s1,\n \t\t       const struct hfsplus_unistr *s2);\ndiff --git a/fs/hfsplus/tables.c b/fs/hfsplus/tables.c\nindex a5fb8ee7d019d..2101201ab973f 100644\n--- a/fs/hfsplus/tables.c\n+++ b/fs/hfsplus/tables.c\n@@ -3244,3 +3244,499 @@ u16 hfsplus_compose_table[] = {\n \t/* 0x0342 0x0314 0x03c9 0x0345 */\n \t0x1fa7, 0x0000,\n };\n+\n+/*\n+ * Unicode canonical combining class (ccc) table, restricted to the Basic\n+ * Multilingual Plane: HFS+ names are stored as UTF-16 and this kernel's\n+ * wchar_t (see MAX_WCHAR_T in include/linux/nls.h) tops out at U+FFFF, so\n+ * no HFS+ catalog name can contain a code point above the BMP anyway.\n+ *\n+ * Generated from the Unicode Character Database, version 12.1.0\n+ * (https://www.unicode.org/Public/12.1.0/ucd/extracted/DerivedCombiningClass.txt),\n+ * the same UCD version fs/unicode/README.utf8data documents. Class 0\n+ * (\"Not_Reordered\") is the default for every code point not listed here\n+ * and needs no entry.\n+ *\n+ * Used by hfsplus_canonical_reorder() to apply the Unicode Canonical\n+ * Ordering Algorithm to a decomposed name, matching what macOS's own\n+ * fsck_hfs (FixDecomps()) requires of a stored catalog name.\n+ */\n+struct hfsplus_ccc_range hfsplus_ccc_table[] = {\n+\t{ 0x0300, 0x0314, 230 },\n+\t{ 0x0315, 0x0315, 232 },\n+\t{ 0x0316, 0x0319, 220 },\n+\t{ 0x031a, 0x031a, 232 },\n+\t{ 0x031b, 0x031b, 216 },\n+\t{ 0x031c, 0x0320, 220 },\n+\t{ 0x0321, 0x0322, 202 },\n+\t{ 0x0323, 0x0326, 220 },\n+\t{ 0x0327, 0x0328, 202 },\n+\t{ 0x0329, 0x0333, 220 },\n+\t{ 0x0334, 0x0338,   1 },\n+\t{ 0x0339, 0x033c, 220 },\n+\t{ 0x033d, 0x0344, 230 },\n+\t{ 0x0345, 0x0345, 240 },\n+\t{ 0x0346, 0x0346, 230 },\n+\t{ 0x0347, 0x0349, 220 },\n+\t{ 0x034a, 0x034c, 230 },\n+\t{ 0x034d, 0x034e, 220 },\n+\t{ 0x0350, 0x0352, 230 },\n+\t{ 0x0353, 0x0356, 220 },\n+\t{ 0x0357, 0x0357, 230 },\n+\t{ 0x0358, 0x0358, 232 },\n+\t{ 0x0359, 0x035a, 220 },\n+\t{ 0x035b, 0x035b, 230 },\n+\t{ 0x035c, 0x035c, 233 },\n+\t{ 0x035d, 0x035e, 234 },\n+\t{ 0x035f, 0x035f, 233 },\n+\t{ 0x0360, 0x0361, 234 },\n+\t{ 0x0362, 0x0362, 233 },\n+\t{ 0x0363, 0x036f, 230 },\n+\t{ 0x0483, 0x0487, 230 },\n+\t{ 0x0591, 0x0591, 220 },\n+\t{ 0x0592, 0x0595, 230 },\n+\t{ 0x0596, 0x0596, 220 },\n+\t{ 0x0597, 0x0599, 230 },\n+\t{ 0x059a, 0x059a, 222 },\n+\t{ 0x059b, 0x059b, 220 },\n+\t{ 0x059c, 0x05a1, 230 },\n+\t{ 0x05a2, 0x05a7, 220 },\n+\t{ 0x05a8, 0x05a9, 230 },\n+\t{ 0x05aa, 0x05aa, 220 },\n+\t{ 0x05ab, 0x05ac, 230 },\n+\t{ 0x05ad, 0x05ad, 222 },\n+\t{ 0x05ae, 0x05ae, 228 },\n+\t{ 0x05af, 0x05af, 230 },\n+\t{ 0x05b0, 0x05b0,  10 },\n+\t{ 0x05b1, 0x05b1,  11 },\n+\t{ 0x05b2, 0x05b2,  12 },\n+\t{ 0x05b3, 0x05b3,  13 },\n+\t{ 0x05b4, 0x05b4,  14 },\n+\t{ 0x05b5, 0x05b5,  15 },\n+\t{ 0x05b6, 0x05b6,  16 },\n+\t{ 0x05b7, 0x05b7,  17 },\n+\t{ 0x05b8, 0x05b8,  18 },\n+\t{ 0x05b9, 0x05ba,  19 },\n+\t{ 0x05bb, 0x05bb,  20 },\n+\t{ 0x05bc, 0x05bc,  21 },\n+\t{ 0x05bd, 0x05bd,  22 },\n+\t{ 0x05bf, 0x05bf,  23 },\n+\t{ 0x05c1, 0x05c1,  24 },\n+\t{ 0x05c2, 0x05c2,  25 },\n+\t{ 0x05c4, 0x05c4, 230 },\n+\t{ 0x05c5, 0x05c5, 220 },\n+\t{ 0x05c7, 0x05c7,  18 },\n+\t{ 0x0610, 0x0617, 230 },\n+\t{ 0x0618, 0x0618,  30 },\n+\t{ 0x0619, 0x0619,  31 },\n+\t{ 0x061a, 0x061a,  32 },\n+\t{ 0x064b, 0x064b,  27 },\n+\t{ 0x064c, 0x064c,  28 },\n+\t{ 0x064d, 0x064d,  29 },\n+\t{ 0x064e, 0x064e,  30 },\n+\t{ 0x064f, 0x064f,  31 },\n+\t{ 0x0650, 0x0650,  32 },\n+\t{ 0x0651, 0x0651,  33 },\n+\t{ 0x0652, 0x0652,  34 },\n+\t{ 0x0653, 0x0654, 230 },\n+\t{ 0x0655, 0x0656, 220 },\n+\t{ 0x0657, 0x065b, 230 },\n+\t{ 0x065c, 0x065c, 220 },\n+\t{ 0x065d, 0x065e, 230 },\n+\t{ 0x065f, 0x065f, 220 },\n+\t{ 0x0670, 0x0670,  35 },\n+\t{ 0x06d6, 0x06dc, 230 },\n+\t{ 0x06df, 0x06e2, 230 },\n+\t{ 0x06e3, 0x06e3, 220 },\n+\t{ 0x06e4, 0x06e4, 230 },\n+\t{ 0x06e7, 0x06e8, 230 },\n+\t{ 0x06ea, 0x06ea, 220 },\n+\t{ 0x06eb, 0x06ec, 230 },\n+\t{ 0x06ed, 0x06ed, 220 },\n+\t{ 0x0711, 0x0711,  36 },\n+\t{ 0x0730, 0x0730, 230 },\n+\t{ 0x0731, 0x0731, 220 },\n+\t{ 0x0732, 0x0733, 230 },\n+\t{ 0x0734, 0x0734, 220 },\n+\t{ 0x0735, 0x0736, 230 },\n+\t{ 0x0737, 0x0739, 220 },\n+\t{ 0x073a, 0x073a, 230 },\n+\t{ 0x073b, 0x073c, 220 },\n+\t{ 0x073d, 0x073d, 230 },\n+\t{ 0x073e, 0x073e, 220 },\n+\t{ 0x073f, 0x0741, 230 },\n+\t{ 0x0742, 0x0742, 220 },\n+\t{ 0x0743, 0x0743, 230 },\n+\t{ 0x0744, 0x0744, 220 },\n+\t{ 0x0745, 0x0745, 230 },\n+\t{ 0x0746, 0x0746, 220 },\n+\t{ 0x0747, 0x0747, 230 },\n+\t{ 0x0748, 0x0748, 220 },\n+\t{ 0x0749, 0x074a, 230 },\n+\t{ 0x07eb, 0x07f1, 230 },\n+\t{ 0x07f2, 0x07f2, 220 },\n+\t{ 0x07f3, 0x07f3, 230 },\n+\t{ 0x07fd, 0x07fd, 220 },\n+\t{ 0x0816, 0x0819, 230 },\n+\t{ 0x081b, 0x0823, 230 },\n+\t{ 0x0825, 0x0827, 230 },\n+\t{ 0x0829, 0x082d, 230 },\n+\t{ 0x0859, 0x085b, 220 },\n+\t{ 0x08d3, 0x08d3, 220 },\n+\t{ 0x08d4, 0x08e1, 230 },\n+\t{ 0x08e3, 0x08e3, 220 },\n+\t{ 0x08e4, 0x08e5, 230 },\n+\t{ 0x08e6, 0x08e6, 220 },\n+\t{ 0x08e7, 0x08e8, 230 },\n+\t{ 0x08e9, 0x08e9, 220 },\n+\t{ 0x08ea, 0x08ec, 230 },\n+\t{ 0x08ed, 0x08ef, 220 },\n+\t{ 0x08f0, 0x08f0,  27 },\n+\t{ 0x08f1, 0x08f1,  28 },\n+\t{ 0x08f2, 0x08f2,  29 },\n+\t{ 0x08f3, 0x08f5, 230 },\n+\t{ 0x08f6, 0x08f6, 220 },\n+\t{ 0x08f7, 0x08f8, 230 },\n+\t{ 0x08f9, 0x08fa, 220 },\n+\t{ 0x08fb, 0x08ff, 230 },\n+\t{ 0x093c, 0x093c,   7 },\n+\t{ 0x094d, 0x094d,   9 },\n+\t{ 0x0951, 0x0951, 230 },\n+\t{ 0x0952, 0x0952, 220 },\n+\t{ 0x0953, 0x0954, 230 },\n+\t{ 0x09bc, 0x09bc,   7 },\n+\t{ 0x09cd, 0x09cd,   9 },\n+\t{ 0x09fe, 0x09fe, 230 },\n+\t{ 0x0a3c, 0x0a3c,   7 },\n+\t{ 0x0a4d, 0x0a4d,   9 },\n+\t{ 0x0abc, 0x0abc,   7 },\n+\t{ 0x0acd, 0x0acd,   9 },\n+\t{ 0x0b3c, 0x0b3c,   7 },\n+\t{ 0x0b4d, 0x0b4d,   9 },\n+\t{ 0x0bcd, 0x0bcd,   9 },\n+\t{ 0x0c4d, 0x0c4d,   9 },\n+\t{ 0x0c55, 0x0c55,  84 },\n+\t{ 0x0c56, 0x0c56,  91 },\n+\t{ 0x0cbc, 0x0cbc,   7 },\n+\t{ 0x0ccd, 0x0ccd,   9 },\n+\t{ 0x0d3b, 0x0d3c,   9 },\n+\t{ 0x0d4d, 0x0d4d,   9 },\n+\t{ 0x0dca, 0x0dca,   9 },\n+\t{ 0x0e38, 0x0e39, 103 },\n+\t{ 0x0e3a, 0x0e3a,   9 },\n+\t{ 0x0e48, 0x0e4b, 107 },\n+\t{ 0x0eb8, 0x0eb9, 118 },\n+\t{ 0x0eba, 0x0eba,   9 },\n+\t{ 0x0ec8, 0x0ecb, 122 },\n+\t{ 0x0f18, 0x0f19, 220 },\n+\t{ 0x0f35, 0x0f35, 220 },\n+\t{ 0x0f37, 0x0f37, 220 },\n+\t{ 0x0f39, 0x0f39, 216 },\n+\t{ 0x0f71, 0x0f71, 129 },\n+\t{ 0x0f72, 0x0f72, 130 },\n+\t{ 0x0f74, 0x0f74, 132 },\n+\t{ 0x0f7a, 0x0f7d, 130 },\n+\t{ 0x0f80, 0x0f80, 130 },\n+\t{ 0x0f82, 0x0f83, 230 },\n+\t{ 0x0f84, 0x0f84,   9 },\n+\t{ 0x0f86, 0x0f87, 230 },\n+\t{ 0x0fc6, 0x0fc6, 220 },\n+\t{ 0x1037, 0x1037,   7 },\n+\t{ 0x1039, 0x103a,   9 },\n+\t{ 0x108d, 0x108d, 220 },\n+\t{ 0x135d, 0x135f, 230 },\n+\t{ 0x1714, 0x1714,   9 },\n+\t{ 0x1734, 0x1734,   9 },\n+\t{ 0x17d2, 0x17d2,   9 },\n+\t{ 0x17dd, 0x17dd, 230 },\n+\t{ 0x18a9, 0x18a9, 228 },\n+\t{ 0x1939, 0x1939, 222 },\n+\t{ 0x193a, 0x193a, 230 },\n+\t{ 0x193b, 0x193b, 220 },\n+\t{ 0x1a17, 0x1a17, 230 },\n+\t{ 0x1a18, 0x1a18, 220 },\n+\t{ 0x1a60, 0x1a60,   9 },\n+\t{ 0x1a75, 0x1a7c, 230 },\n+\t{ 0x1a7f, 0x1a7f, 220 },\n+\t{ 0x1ab0, 0x1ab4, 230 },\n+\t{ 0x1ab5, 0x1aba, 220 },\n+\t{ 0x1abb, 0x1abc, 230 },\n+\t{ 0x1abd, 0x1abd, 220 },\n+\t{ 0x1b34, 0x1b34,   7 },\n+\t{ 0x1b44, 0x1b44,   9 },\n+\t{ 0x1b6b, 0x1b6b, 230 },\n+\t{ 0x1b6c, 0x1b6c, 220 },\n+\t{ 0x1b6d, 0x1b73, 230 },\n+\t{ 0x1baa, 0x1baa,   9 },\n+\t{ 0x1bab, 0x1bab,   9 },\n+\t{ 0x1be6, 0x1be6,   7 },\n+\t{ 0x1bf2, 0x1bf3,   9 },\n+\t{ 0x1c37, 0x1c37,   7 },\n+\t{ 0x1cd0, 0x1cd2, 230 },\n+\t{ 0x1cd4, 0x1cd4,   1 },\n+\t{ 0x1cd5, 0x1cd9, 220 },\n+\t{ 0x1cda, 0x1cdb, 230 },\n+\t{ 0x1cdc, 0x1cdf, 220 },\n+\t{ 0x1ce0, 0x1ce0, 230 },\n+\t{ 0x1ce2, 0x1ce8,   1 },\n+\t{ 0x1ced, 0x1ced, 220 },\n+\t{ 0x1cf4, 0x1cf4, 230 },\n+\t{ 0x1cf8, 0x1cf9, 230 },\n+\t{ 0x1dc0, 0x1dc1, 230 },\n+\t{ 0x1dc2, 0x1dc2, 220 },\n+\t{ 0x1dc3, 0x1dc9, 230 },\n+\t{ 0x1dca, 0x1dca, 220 },\n+\t{ 0x1dcb, 0x1dcc, 230 },\n+\t{ 0x1dcd, 0x1dcd, 234 },\n+\t{ 0x1dce, 0x1dce, 214 },\n+\t{ 0x1dcf, 0x1dcf, 220 },\n+\t{ 0x1dd0, 0x1dd0, 202 },\n+\t{ 0x1dd1, 0x1df5, 230 },\n+\t{ 0x1df6, 0x1df6, 232 },\n+\t{ 0x1df7, 0x1df8, 228 },\n+\t{ 0x1df9, 0x1df9, 220 },\n+\t{ 0x1dfb, 0x1dfb, 230 },\n+\t{ 0x1dfc, 0x1dfc, 233 },\n+\t{ 0x1dfd, 0x1dfd, 220 },\n+\t{ 0x1dfe, 0x1dfe, 230 },\n+\t{ 0x1dff, 0x1dff, 220 },\n+\t{ 0x20d0, 0x20d1, 230 },\n+\t{ 0x20d2, 0x20d3,   1 },\n+\t{ 0x20d4, 0x20d7, 230 },\n+\t{ 0x20d8, 0x20da,   1 },\n+\t{ 0x20db, 0x20dc, 230 },\n+\t{ 0x20e1, 0x20e1, 230 },\n+\t{ 0x20e5, 0x20e6,   1 },\n+\t{ 0x20e7, 0x20e7, 230 },\n+\t{ 0x20e8, 0x20e8, 220 },\n+\t{ 0x20e9, 0x20e9, 230 },\n+\t{ 0x20ea, 0x20eb,   1 },\n+\t{ 0x20ec, 0x20ef, 220 },\n+\t{ 0x20f0, 0x20f0, 230 },\n+\t{ 0x2cef, 0x2cf1, 230 },\n+\t{ 0x2d7f, 0x2d7f,   9 },\n+\t{ 0x2de0, 0x2dff, 230 },\n+\t{ 0x302a, 0x302a, 218 },\n+\t{ 0x302b, 0x302b, 228 },\n+\t{ 0x302c, 0x302c, 232 },\n+\t{ 0x302d, 0x302d, 222 },\n+\t{ 0x302e, 0x302f, 224 },\n+\t{ 0x3099, 0x309a,   8 },\n+\t{ 0xa66f, 0xa66f, 230 },\n+\t{ 0xa674, 0xa67d, 230 },\n+\t{ 0xa69e, 0xa69f, 230 },\n+\t{ 0xa6f0, 0xa6f1, 230 },\n+\t{ 0xa806, 0xa806,   9 },\n+\t{ 0xa8c4, 0xa8c4,   9 },\n+\t{ 0xa8e0, 0xa8f1, 230 },\n+\t{ 0xa92b, 0xa92d, 220 },\n+\t{ 0xa953, 0xa953,   9 },\n+\t{ 0xa9b3, 0xa9b3,   7 },\n+\t{ 0xa9c0, 0xa9c0,   9 },\n+\t{ 0xaab0, 0xaab0, 230 },\n+\t{ 0xaab2, 0xaab3, 230 },\n+\t{ 0xaab4, 0xaab4, 220 },\n+\t{ 0xaab7, 0xaab8, 230 },\n+\t{ 0xaabe, 0xaabf, 230 },\n+\t{ 0xaac1, 0xaac1, 230 },\n+\t{ 0xaaf6, 0xaaf6,   9 },\n+\t{ 0xabed, 0xabed,   9 },\n+\t{ 0xfb1e, 0xfb1e,  26 },\n+\t{ 0xfe20, 0xfe26, 230 },\n+\t{ 0xfe27, 0xfe2d, 220 },\n+\t{ 0xfe2e, 0xfe2f, 230 },\n+};\n+\n+/*\n+ * Some HFS Plus catalog names contain characters whose canonical\n+ * decomposition either was not yet defined, or was later corrected, in\n+ * the version of Unicode this file's tables above were generated from\n+ * (Apple Technote #1150, itself derived from pre-Unicode-3.0/pre-\"Jaguar\"\n+ * (Mac OS X 10.2) data). macOS's own fsck_hfs has carried a permanent\n+ * \"FixDecomps\" fixup for exactly this since 2002 (see\n+ * fsck_hfs.tproj/dfalib/CatalogCheck.c and DecompData.h in the hfsprogs /\n+ * diskdev_cmds sources) and flags any catalog name it finds still using\n+ * the old form as \"Illegal name\". The two tables and functions below are\n+ * a port of that same fixup data, decoded from hfsprogs 540.1's\n+ * DecompData.h, so this driver stores names the same way macOS has since\n+ * 10.2 rather than the way the original HFS Plus format documentation\n+ * described in 2001.\n+ */\n+\n+/* Category A: single code point -\u003e missing canonical decomposition */\n+/* 44 entries */\n+struct hfsplus_legacy_decomp hfsplus_legacy_decomp_table[] = {\n+\t{ 0x01f8, 2, { 0x004e, 0x0300 } },\n+\t{ 0x01f9, 2, { 0x006e, 0x0300 } },\n+\t{ 0x0218, 2, { 0x0053, 0x0326 } },\n+\t{ 0x0219, 2, { 0x0073, 0x0326 } },\n+\t{ 0x021a, 2, { 0x0054, 0x0326 } },\n+\t{ 0x021b, 2, { 0x0074, 0x0326 } },\n+\t{ 0x021e, 2, { 0x0048, 0x030c } },\n+\t{ 0x021f, 2, { 0x0068, 0x030c } },\n+\t{ 0x0226, 2, { 0x0041, 0x0307 } },\n+\t{ 0x0227, 2, { 0x0061, 0x0307 } },\n+\t{ 0x0228, 2, { 0x0045, 0x0327 } },\n+\t{ 0x0229, 2, { 0x0065, 0x0327 } },\n+\t{ 0x022a, 3, { 0x004f, 0x0308, 0x0304 } },\n+\t{ 0x022b, 3, { 0x006f, 0x0308, 0x0304 } },\n+\t{ 0x022c, 3, { 0x004f, 0x0303, 0x0304 } },\n+\t{ 0x022d, 3, { 0x006f, 0x0303, 0x0304 } },\n+\t{ 0x022e, 2, { 0x004f, 0x0307 } },\n+\t{ 0x022f, 2, { 0x006f, 0x0307 } },\n+\t{ 0x0230, 3, { 0x004f, 0x0307, 0x0304 } },\n+\t{ 0x0231, 3, { 0x006f, 0x0307, 0x0304 } },\n+\t{ 0x0232, 2, { 0x0059, 0x0304 } },\n+\t{ 0x0233, 2, { 0x0079, 0x0304 } },\n+\t{ 0x0400, 2, { 0x0415, 0x0300 } },\n+\t{ 0x040d, 2, { 0x0418, 0x0300 } },\n+\t{ 0x0450, 2, { 0x0435, 0x0300 } },\n+\t{ 0x045d, 2, { 0x0438, 0x0300 } },\n+\t{ 0x04ec, 2, { 0x042d, 0x0308 } },\n+\t{ 0x04ed, 2, { 0x044d, 0x0308 } },\n+\t{ 0x0622, 2, { 0x0627, 0x0653 } },\n+\t{ 0x0623, 2, { 0x0627, 0x0654 } },\n+\t{ 0x0624, 2, { 0x0648, 0x0654 } },\n+\t{ 0x0625, 2, { 0x0627, 0x0655 } },\n+\t{ 0x0626, 2, { 0x064a, 0x0654 } },\n+\t{ 0x06c0, 2, { 0x06d5, 0x0654 } },\n+\t{ 0x06c2, 2, { 0x06c1, 0x0654 } },\n+\t{ 0x06d3, 2, { 0x06d2, 0x0654 } },\n+\t{ 0x0a33, 2, { 0x0a32, 0x0a3c } },\n+\t{ 0x0a36, 2, { 0x0a38, 0x0a3c } },\n+\t{ 0x0dda, 2, { 0x0dd9, 0x0dca } },\n+\t{ 0x0ddc, 2, { 0x0dd9, 0x0dcf } },\n+\t{ 0x0ddd, 3, { 0x0dd9, 0x0dcf, 0x0dca } },\n+\t{ 0x0dde, 2, { 0x0dd9, 0x0ddf } },\n+\t{ 0x1026, 2, { 0x1025, 0x102e } },\n+\t{ 0xfb1d, 2, { 0x05d9, 0x05b4 } },\n+};\n+\n+/* Category B: 2-3 code point sequence -\u003e corrected replacement */\n+/* 25 entries */\n+struct hfsplus_legacy_seq_fixup hfsplus_legacy_seq_fixups[] = {\n+\t{ 2, { 0x00a8, 0x030d }, 2, { 0x00a8, 0x0301 } },\n+\t{ 2, { 0x0306, 0x0307 }, 1, { 0x0310 } },\n+\t{ 2, { 0x0308, 0x030d }, 2, { 0x0308, 0x0301 } },\n+\t{ 2, { 0x0391, 0x030d }, 2, { 0x0391, 0x0301 } },\n+\t{ 2, { 0x0395, 0x030d }, 2, { 0x0395, 0x0301 } },\n+\t{ 2, { 0x0397, 0x030d }, 2, { 0x0397, 0x0301 } },\n+\t{ 2, { 0x0399, 0x030d }, 2, { 0x0399, 0x0301 } },\n+\t{ 2, { 0x039f, 0x030d }, 2, { 0x039f, 0x0301 } },\n+\t{ 2, { 0x03a5, 0x030d }, 2, { 0x03a5, 0x0301 } },\n+\t{ 2, { 0x03a9, 0x030d }, 2, { 0x03a9, 0x0301 } },\n+\t{ 2, { 0x03b1, 0x030d }, 2, { 0x03b1, 0x0301 } },\n+\t{ 2, { 0x03b5, 0x030d }, 2, { 0x03b5, 0x0301 } },\n+\t{ 2, { 0x03b7, 0x030d }, 2, { 0x03b7, 0x0301 } },\n+\t{ 2, { 0x03b9, 0x030d }, 2, { 0x03b9, 0x0301 } },\n+\t{ 2, { 0x03bf, 0x030d }, 2, { 0x03bf, 0x0301 } },\n+\t{ 2, { 0x03c5, 0x030d }, 2, { 0x03c5, 0x0301 } },\n+\t{ 2, { 0x03c9, 0x030d }, 2, { 0x03c9, 0x0301 } },\n+\t{ 2, { 0x03d2, 0x030d }, 2, { 0x03d2, 0x0301 } },\n+\t{ 2, { 0x09ac, 0x09bc }, 1, { 0x09b0 } },\n+\t{ 2, { 0x0a21, 0x0a3c }, 1, { 0x0a5c } },\n+\t{ 2, { 0x0b2f, 0x0b3c }, 1, { 0x0b5f } },\n+\t{ 2, { 0x0e4d, 0x0e32 }, 1, { 0x0e33 } },\n+\t{ 2, { 0x0ecd, 0x0eb2 }, 1, { 0x0eb3 } },\n+\t{ 3, { 0x0fb2, 0x0f80, 0x0f71 }, 1, { 0x0f77 } },\n+\t{ 3, { 0x0fb3, 0x0f80, 0x0f71 }, 1, { 0x0f79 } },\n+};\n+\n+/*\n+ * Look up the Unicode canonical combining class of a BMP code point.\n+ * Returns 0 (\"Not_Reordered\") for any code point not listed in the table,\n+ * which includes every ordinary base character.\n+ */\n+u8 hfsplus_combining_class(u16 c)\n+{\n+\tint lo = 0, hi = ARRAY_SIZE(hfsplus_ccc_table) - 1;\n+\n+\twhile (lo \u003c= hi) {\n+\t\tint mid = (lo + hi) / 2;\n+\t\tconst struct hfsplus_ccc_range *r = \u0026hfsplus_ccc_table[mid];\n+\n+\t\tif (c \u003c r-\u003efirst)\n+\t\t\thi = mid - 1;\n+\t\telse if (c \u003e r-\u003elast)\n+\t\t\tlo = mid + 1;\n+\t\telse\n+\t\t\treturn r-\u003ecombining_class;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * Look up the corrected canonical decomposition for a single BMP code\n+ * point that Apple Technote #1150's own decomposition table (above)\n+ * lacks. Returns NULL (and leaves *size alone) if @uc isn't one of these.\n+ */\n+const u16 *hfsplus_legacy_decompose(u16 uc, int *size)\n+{\n+\tint lo = 0, hi = ARRAY_SIZE(hfsplus_legacy_decomp_table) - 1;\n+\n+\twhile (lo \u003c= hi) {\n+\t\tint mid = (lo + hi) / 2;\n+\t\tconst struct hfsplus_legacy_decomp *e =\n+\t\t\t\t\u0026hfsplus_legacy_decomp_table[mid];\n+\n+\t\tif (uc \u003c e-\u003euc)\n+\t\t\thi = mid - 1;\n+\t\telse if (uc \u003e e-\u003euc)\n+\t\t\tlo = mid + 1;\n+\t\telse {\n+\t\t\t*size = e-\u003elen;\n+\t\t\treturn e-\u003erepl;\n+\t\t}\n+\t}\n+\n+\treturn NULL;\n+}\n+\n+/*\n+ * Scan an already decomposed and canonically-reordered code unit buffer\n+ * for any of the short legacy sequences above and replace them in place\n+ * with their corrected form. @len is updated to the buffer's new length.\n+ */\n+void hfsplus_fixup_legacy_sequences(u16 *buf, int *len)\n+{\n+\tint i = 0;\n+\n+\twhile (i \u003c *len) {\n+\t\tunsigned int j;\n+\t\tbool matched = false;\n+\n+\t\tfor (j = 0; j \u003c ARRAY_SIZE(hfsplus_legacy_seq_fixups); j++) {\n+\t\t\tstruct hfsplus_legacy_seq_fixup *f =\n+\t\t\t\t\t\t\u0026hfsplus_legacy_seq_fixups[j];\n+\t\t\tu16 *src, *dst;\n+\t\t\tsize_t copy_len;\n+\t\t\tint k;\n+\n+\t\t\tif (i + f-\u003ematch_len \u003e *len)\n+\t\t\t\tcontinue;\n+\t\t\tfor (k = 0; k \u003c f-\u003ematch_len; k++)\n+\t\t\t\tif (buf[i + k] != f-\u003ematch[k])\n+\t\t\t\t\tbreak;\n+\t\t\tif (k != f-\u003ematch_len)\n+\t\t\t\tcontinue;\n+\n+\t\t\tdst = \u0026buf[i + f-\u003erepl_len];\n+\t\t\tsrc = \u0026buf[i + f-\u003ematch_len];\n+\t\t\tcopy_len = (*len - i - f-\u003ematch_len) * sizeof(*buf);\n+\t\t\tmemmove(dst, src, copy_len);\n+\n+\t\t\tdst = \u0026buf[i];\n+\t\t\tsrc = f-\u003erepl;\n+\t\t\tcopy_len = f-\u003erepl_len * sizeof(*buf);\n+\t\t\tmemcpy(dst, src, copy_len);\n+\n+\t\t\t*len += f-\u003erepl_len - f-\u003ematch_len;\n+\t\t\tmatched = true;\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tif (!matched)\n+\t\t\ti++;\n+\t}\n+}\ndiff --git a/fs/hfsplus/unicode.c b/fs/hfsplus/unicode.c\nindex 008fec186382b..59b8788a69a9e 100644\n--- a/fs/hfsplus/unicode.c\n+++ b/fs/hfsplus/unicode.c\n@@ -16,6 +16,7 @@\n \n #include \"hfsplus_fs.h\"\n #include \"hfsplus_raw.h\"\n+#include \"unicode.h\"\n \n /* Fold the case of a unicode char, given the 16 bit value */\n /* Returns folded char, or 0 if ignorable */\n@@ -441,45 +442,264 @@ static u16 *decompose_unichar(wchar_t uc, int *size, u16 *hangul_buffer)\n \t*size = hfsplus_try_decompose_hangul(uc, result);\n \tif (*size == 0)\n \t\tresult = hfsplus_decompose_nonhangul(uc, size);\n+\tif (!result) {\n+\t\t/*\n+\t\t * Not every character with a canonical decomposition is in\n+\t\t * Apple Technote #1150's own table above; a small, fixed\n+\t\t * set was only added to the decomposition standard (or had\n+\t\t * its decomposition corrected) after that table was\n+\t\t * generated. hfsplus_legacy_decompose() covers those.\n+\t\t */\n+\t\tconst u16 *legacy = hfsplus_legacy_decompose(uc, size);\n+\n+\t\tif (legacy)\n+\t\t\tresult = memcpy(hangul_buffer, legacy,\n+\t\t\t\t\t*size * sizeof(*legacy));\n+\t}\n \treturn result;\n }\n \n-int hfsplus_asc2uni(struct super_block *sb,\n-\t\t    struct hfsplus_unistr *ustr, int max_unistr_len,\n-\t\t    const char *astr, int len, int name_type)\n+/*\n+ * Apply the Unicode Canonical Ordering Algorithm to a decomposed name held\n+ * as plain host-order code units: within each maximal run of characters\n+ * that have a nonzero combining class, stable-sort the run into ascending\n+ * combining-class order. A character with combining class 0 always starts\n+ * a new run and is never itself reordered.\n+ *\n+ * hfsplus_decompose_table decomposes each source character on its own; it\n+ * says nothing about how the decompositions of two different source\n+ * characters should be ordered relative to each other when both produce\n+ * combining marks that end up adjacent. Without this pass, such a\n+ * sequence can be stored in an order that macOS's own fsck_hfs\n+ * (FixDecomps() in CatalogCheck.c) considers illegal, even though every\n+ * individual character was decomposed correctly.\n+ */\n+static void hfsplus_canonical_reorder(u16 *ustr, int len)\n {\n-\tint size, dsize, decompose;\n-\tu16 *dstr, outlen = 0;\n-\twchar_t c;\n-\tu16 dhangul[3];\n+\tint i;\n+\n+\tfor (i = 1; i \u003c len; i++) {\n+\t\tu8 cls = hfsplus_combining_class(ustr[i]);\n+\t\tint j = i;\n+\n+\t\tif (!cls)\n+\t\t\tcontinue;\n+\n+\t\twhile (j \u003e 0) {\n+\t\t\tu8 prev_cls = hfsplus_combining_class(ustr[j - 1]);\n+\t\t\tu16 tmp;\n+\n+\t\t\tif (!prev_cls || prev_cls \u003c= cls)\n+\t\t\t\tbreak;\n+\n+\t\t\ttmp = ustr[j];\n+\t\t\tustr[j] = ustr[j - 1];\n+\t\t\tustr[j - 1] = tmp;\n+\t\t\tj--;\n+\t\t}\n+\t}\n+}\n+\n+#define HFSPLUS_HANGUL_MAX_JAMO\t\t(3)       /* L + V + optional T */\n+\n+static_assert(HFSPLUS_HANGUL_MAX_JAMO \u003e= HFSPLUS_LEGACY_DECOMP_MAX_LEN,\n+\t\t\"hangul_buffer must fit the longest legacy decomposition too\");\n+\n+/*\n+ * Decompose and canonically reorder an entire Linux name, as plain\n+ * host-order code units. hfsplus_asc2uni(), hfsplus_hash_dentry() and\n+ * hfsplus_compare_dentry() all go through this so that storage, hashing\n+ * and comparison always agree on what a given name canonicalizes to.\n+ *\n+ * @out must hold at least @max_len entries, which must not exceed\n+ * HFSPLUS_MAX_STRLEN. Returns the number of code units written. If\n+ * @consumed is non-NULL, it is set to the number of input bytes actually\n+ * consumed, which is less than @len when @out fills up first.\n+ */\n+static int hfsplus_decompose_str(struct super_block *sb, const char *astr,\n+\t\t\t\t  int len, int max_len, int name_type,\n+\t\t\t\t  u16 *out, int *consumed)\n+{\n+\tint decompose = !test_bit(HFSPLUS_SB_NODECOMPOSE, \u0026HFSPLUS_SB(sb)-\u003eflags);\n+\tconst char *start = astr;\n+\tint outlen = 0;\n+\n+\twhile (outlen \u003c max_len \u0026\u0026 len \u003e 0) {\n+\t\tu16 *dstr;\n+\t\tu16 dhangul[HFSPLUS_HANGUL_MAX_JAMO];\n+\t\tint dsize, size;\n+\t\twchar_t c;\n \n-\tdecompose = !test_bit(HFSPLUS_SB_NODECOMPOSE, \u0026HFSPLUS_SB(sb)-\u003eflags);\n-\twhile (outlen \u003c max_unistr_len \u0026\u0026 len \u003e 0) {\n \t\tsize = asc2unichar(sb, astr, len, \u0026c, name_type);\n \n-\t\tif (decompose)\n-\t\t\tdstr = decompose_unichar(c, \u0026dsize, dhangul);\n-\t\telse\n-\t\t\tdstr = NULL;\n+\t\tdstr = decompose ? decompose_unichar(c, \u0026dsize, dhangul) : NULL;\n \t\tif (dstr) {\n-\t\t\tif (outlen + dsize \u003e max_unistr_len)\n+\t\t\tif (outlen + dsize \u003e max_len)\n \t\t\t\tbreak;\n \t\t\tdo {\n-\t\t\t\tustr-\u003eunicode[outlen++] = cpu_to_be16(*dstr++);\n+\t\t\t\tout[outlen++] = *dstr++;\n \t\t\t} while (--dsize \u003e 0);\n-\t\t} else\n-\t\t\tustr-\u003eunicode[outlen++] = cpu_to_be16(c);\n+\t\t} else {\n+\t\t\tout[outlen++] = c;\n+\t\t}\n \n \t\tastr += size;\n \t\tlen -= size;\n \t}\n+\n+\thfsplus_canonical_reorder(out, outlen);\n+\thfsplus_fixup_legacy_sequences(out, \u0026outlen);\n+\tif (consumed)\n+\t\t*consumed = astr - start;\n+\treturn outlen;\n+}\n+\n+int hfsplus_asc2uni(struct super_block *sb,\n+\t\t    struct hfsplus_unistr *ustr, int max_unistr_len,\n+\t\t    const char *astr, int len, int name_type)\n+{\n+\tu16 buf[HFSPLUS_MAX_STRLEN];\n+\tint outlen, i, consumed;\n+\n+\tif (max_unistr_len \u003e HFSPLUS_MAX_STRLEN)\n+\t\tmax_unistr_len = HFSPLUS_MAX_STRLEN;\n+\n+\toutlen = hfsplus_decompose_str(sb, astr, len, max_unistr_len,\n+\t\t\t\t       name_type, buf, \u0026consumed);\n+\tfor (i = 0; i \u003c outlen; i++)\n+\t\tustr-\u003eunicode[i] = cpu_to_be16(buf[i]);\n \tustr-\u003elength = cpu_to_be16(outlen);\n-\tif (len \u003e 0)\n+\n+\tif (consumed \u003c len)\n \t\treturn -ENAMETOOLONG;\n \treturn 0;\n }\n EXPORT_SYMBOL_IF_KUNIT(hfsplus_asc2uni);\n \n+/*\n+ * Maximum length of a single maximal run of nonzero-combining-class code\n+ * units that hfsplus_decompose_iter_next() below will canonically\n+ * reorder. Every code unit with combining class 0 starts a new run, so\n+ * this only bounds how many *consecutive* combining marks between two\n+ * base characters get sorted - real text, and even deliberately\n+ * adversarial \"Zalgo\" text, essentially never approaches this. Keeping\n+ * it small means hfsplus_hash_dentry() and hfsplus_compare_dentry() only\n+ * ever need a tiny amount of lookahead state, rather than buffering an\n+ * entire (up to 255-unit) name.\n+ */\n+#define HFSPLUS_CCC_RUN_MAX 32\n+\n+/*\n+ * Iterator that produces the canonically-ordered, decomposed code units\n+ * of a Linux name one at a time, without materializing the whole name.\n+ * hfsplus_hash_dentry() and hfsplus_compare_dentry() use this so that\n+ * hashing and comparison always agree with what hfsplus_asc2uni() would\n+ * actually store, while still comparing lazily (stopping at the first\n+ * difference) the way this code did before canonical reordering existed.\n+ */\n+struct hfsplus_decompose_iter {\n+\tstruct super_block *sb;\n+\tconst char *astr;\n+\tint len;\n+\tint name_type;\n+\tint decompose;\n+\n+\tu16 run[HFSPLUS_CCC_RUN_MAX];\n+\tint run_len;\n+\tint run_pos;\n+};\n+\n+static void hfsplus_decompose_iter_init(struct hfsplus_decompose_iter *it,\n+\t\t\t\t\tstruct super_block *sb,\n+\t\t\t\t\tconst char *astr, int len,\n+\t\t\t\t\tint name_type)\n+{\n+\tit-\u003esb = sb;\n+\tit-\u003eastr = astr;\n+\tit-\u003elen = len;\n+\tit-\u003ename_type = name_type;\n+\tit-\u003edecompose = !test_bit(HFSPLUS_SB_NODECOMPOSE, \u0026HFSPLUS_SB(sb)-\u003eflags);\n+\tit-\u003erun_len = 0;\n+\tit-\u003erun_pos = 0;\n+}\n+\n+/*\n+ * Gather the next maximal run of nonzero-combining-class code units\n+ * (starting with whatever character comes next, base or not) and\n+ * canonically reorder just that run. A character is only included once\n+ * we know the class of the first unit it produces, so decoding it is\n+ * speculative until that's decided.\n+ */\n+static bool hfsplus_decompose_iter_refill(struct hfsplus_decompose_iter *it)\n+{\n+\tit-\u003erun_pos = 0;\n+\tit-\u003erun_len = 0;\n+\n+\twhile (it-\u003elen \u003e 0) {\n+\t\tu16 *dstr;\n+\t\tu16 dhangul[HFSPLUS_HANGUL_MAX_JAMO];\n+\t\tint dsize, size;\n+\t\twchar_t c;\n+\n+\t\tsize = asc2unichar(it-\u003esb, it-\u003eastr, it-\u003elen, \u0026c,\n+\t\t\t\t   it-\u003ename_type);\n+\n+\t\tdstr = it-\u003edecompose ?\n+\t\t\tdecompose_unichar(c, \u0026dsize, dhangul) : NULL;\n+\t\tif (!dstr) {\n+\t\t\tdhangul[0] = c;\n+\t\t\tdstr = dhangul;\n+\t\t\tdsize = 1;\n+\t\t}\n+\n+\t\tif (it-\u003erun_len \u003e 0 \u0026\u0026 !hfsplus_combining_class(dstr[0]))\n+\t\t\tbreak;\n+\n+\t\tif (it-\u003erun_len + dsize \u003e HFSPLUS_CCC_RUN_MAX)\n+\t\t\tbreak;\n+\n+\t\tit-\u003eastr += size;\n+\t\tit-\u003elen -= size;\n+\n+\t\tdo {\n+\t\t\tit-\u003erun[it-\u003erun_len++] = *dstr++;\n+\t\t} while (--dsize \u003e 0);\n+\t}\n+\n+\thfsplus_canonical_reorder(it-\u003erun, it-\u003erun_len);\n+\thfsplus_fixup_legacy_sequences(it-\u003erun, \u0026it-\u003erun_len);\n+\treturn it-\u003erun_len \u003e 0;\n+}\n+\n+/* Returns the next code unit, or a negative value once @it is exhausted. */\n+static int hfsplus_decompose_iter_next(struct hfsplus_decompose_iter *it)\n+{\n+\tif (it-\u003erun_pos \u003e= it-\u003erun_len \u0026\u0026 !hfsplus_decompose_iter_refill(it))\n+\t\treturn -1;\n+\treturn it-\u003erun[it-\u003erun_pos++];\n+}\n+\n+/*\n+ * Returns the next code unit that matters for comparison/hashing: folded\n+ * if @casefold, with any character folding to 0 (\"ignorable\") skipped\n+ * entirely. Returns a negative value once @it is exhausted.\n+ */\n+static int hfsplus_decompose_iter_next_folded(struct hfsplus_decompose_iter *it,\n+\t\t\t\t\t      int casefold)\n+{\n+\tint c;\n+\n+\tdo {\n+\t\tc = hfsplus_decompose_iter_next(it);\n+\t\tif (c \u003c 0)\n+\t\t\treturn -1;\n+\t\tif (casefold)\n+\t\t\tc = case_fold(c);\n+\t} while (casefold \u0026\u0026 !c);\n+\n+\treturn c;\n+}\n+\n /*\n  * Hash a string to an integer as appropriate for the HFS+ filesystem.\n  * Composed unicode characters are decomposed and case-folding is performed\n@@ -488,45 +708,17 @@ EXPORT_SYMBOL_IF_KUNIT(hfsplus_asc2uni);\n int hfsplus_hash_dentry(const struct dentry *dentry, struct qstr *str)\n {\n \tstruct super_block *sb = dentry-\u003ed_sb;\n-\tconst char *astr;\n-\tconst u16 *dstr;\n-\tint casefold, decompose, size, len;\n+\tint casefold = test_bit(HFSPLUS_SB_CASEFOLD, \u0026HFSPLUS_SB(sb)-\u003eflags);\n+\tstruct hfsplus_decompose_iter it;\n \tunsigned long hash;\n-\twchar_t c;\n-\tu16 c2;\n-\tu16 dhangul[3];\n+\tint c;\n \n-\tcasefold = test_bit(HFSPLUS_SB_CASEFOLD, \u0026HFSPLUS_SB(sb)-\u003eflags);\n-\tdecompose = !test_bit(HFSPLUS_SB_NODECOMPOSE, \u0026HFSPLUS_SB(sb)-\u003eflags);\n-\thash = init_name_hash(dentry);\n-\tastr = str-\u003ename;\n-\tlen = str-\u003elen;\n-\twhile (len \u003e 0) {\n-\t\tint dsize;\n-\t\tsize = asc2unichar(sb, astr, len, \u0026c, HFS_REGULAR_NAME);\n-\t\tastr += size;\n-\t\tlen -= size;\n+\thfsplus_decompose_iter_init(\u0026it, sb, str-\u003ename, str-\u003elen,\n+\t\t\t\t    HFS_REGULAR_NAME);\n \n-\t\tif (decompose)\n-\t\t\tdstr = decompose_unichar(c, \u0026dsize, dhangul);\n-\t\telse\n-\t\t\tdstr = NULL;\n-\t\tif (dstr) {\n-\t\t\tdo {\n-\t\t\t\tc2 = *dstr++;\n-\t\t\t\tif (casefold)\n-\t\t\t\t\tc2 = case_fold(c2);\n-\t\t\t\tif (!casefold || c2)\n-\t\t\t\t\thash = partial_name_hash(c2, hash);\n-\t\t\t} while (--dsize \u003e 0);\n-\t\t} else {\n-\t\t\tc2 = c;\n-\t\t\tif (casefold)\n-\t\t\t\tc2 = case_fold(c2);\n-\t\t\tif (!casefold || c2)\n-\t\t\t\thash = partial_name_hash(c2, hash);\n-\t\t}\n-\t}\n+\thash = init_name_hash(dentry);\n+\twhile ((c = hfsplus_decompose_iter_next_folded(\u0026it, casefold)) \u003e= 0)\n+\t\thash = partial_name_hash(c, hash);\n \tstr-\u003ehash = end_name_hash(hash);\n \n \treturn 0;\n@@ -542,87 +734,21 @@ int hfsplus_compare_dentry(const struct dentry *dentry,\n \t\tunsigned int len, const char *str, const struct qstr *name)\n {\n \tstruct super_block *sb = dentry-\u003ed_sb;\n-\tint casefold, decompose, size;\n-\tint dsize1, dsize2, len1, len2;\n-\tconst u16 *dstr1, *dstr2;\n-\tconst char *astr1, *astr2;\n-\tu16 c1, c2;\n-\twchar_t c;\n-\tu16 dhangul_1[3], dhangul_2[3];\n-\n-\tcasefold = test_bit(HFSPLUS_SB_CASEFOLD, \u0026HFSPLUS_SB(sb)-\u003eflags);\n-\tdecompose = !test_bit(HFSPLUS_SB_NODECOMPOSE, \u0026HFSPLUS_SB(sb)-\u003eflags);\n-\tastr1 = str;\n-\tlen1 = len;\n-\tastr2 = name-\u003ename;\n-\tlen2 = name-\u003elen;\n-\tdsize1 = dsize2 = 0;\n-\tdstr1 = dstr2 = NULL;\n-\n-\twhile (len1 \u003e 0 \u0026\u0026 len2 \u003e 0) {\n-\t\tif (!dsize1) {\n-\t\t\tsize = asc2unichar(sb, astr1, len1, \u0026c,\n-\t\t\t\t\t   HFS_REGULAR_NAME);\n-\t\t\tastr1 += size;\n-\t\t\tlen1 -= size;\n-\n-\t\t\tif (decompose)\n-\t\t\t\tdstr1 = decompose_unichar(c, \u0026dsize1,\n-\t\t\t\t\t\t\t  dhangul_1);\n-\t\t\tif (!decompose || !dstr1) {\n-\t\t\t\tc1 = c;\n-\t\t\t\tdstr1 = \u0026c1;\n-\t\t\t\tdsize1 = 1;\n-\t\t\t}\n-\t\t}\n+\tint casefold = test_bit(HFSPLUS_SB_CASEFOLD, \u0026HFSPLUS_SB(sb)-\u003eflags);\n+\tstruct hfsplus_decompose_iter it1, it2;\n \n-\t\tif (!dsize2) {\n-\t\t\tsize = asc2unichar(sb, astr2, len2, \u0026c,\n-\t\t\t\t\t   HFS_REGULAR_NAME);\n-\t\t\tastr2 += size;\n-\t\t\tlen2 -= size;\n-\n-\t\t\tif (decompose)\n-\t\t\t\tdstr2 = decompose_unichar(c, \u0026dsize2,\n-\t\t\t\t\t\t\t  dhangul_2);\n-\t\t\tif (!decompose || !dstr2) {\n-\t\t\t\tc2 = c;\n-\t\t\t\tdstr2 = \u0026c2;\n-\t\t\t\tdsize2 = 1;\n-\t\t\t}\n-\t\t}\n+\thfsplus_decompose_iter_init(\u0026it1, sb, str, len, HFS_REGULAR_NAME);\n+\thfsplus_decompose_iter_init(\u0026it2, sb, name-\u003ename, name-\u003elen,\n+\t\t\t\t    HFS_REGULAR_NAME);\n \n-\t\tc1 = *dstr1;\n-\t\tc2 = *dstr2;\n-\t\tif (casefold) {\n-\t\t\tc1 = case_fold(c1);\n-\t\t\tif (!c1) {\n-\t\t\t\tdstr1++;\n-\t\t\t\tdsize1--;\n-\t\t\t\tcontinue;\n-\t\t\t}\n-\t\t\tc2 = case_fold(c2);\n-\t\t\tif (!c2) {\n-\t\t\t\tdstr2++;\n-\t\t\t\tdsize2--;\n-\t\t\t\tcontinue;\n-\t\t\t}\n-\t\t}\n-\t\tif (c1 \u003c c2)\n-\t\t\treturn -1;\n-\t\telse if (c1 \u003e c2)\n-\t\t\treturn 1;\n+\twhile (1) {\n+\t\tint c1 = hfsplus_decompose_iter_next_folded(\u0026it1, casefold);\n+\t\tint c2 = hfsplus_decompose_iter_next_folded(\u0026it2, casefold);\n \n-\t\tdstr1++;\n-\t\tdsize1--;\n-\t\tdstr2++;\n-\t\tdsize2--;\n+\t\tif (c1 \u003c 0 || c2 \u003c 0)\n+\t\t\treturn c1 == c2 ? 0 : (c1 \u003c 0 ? -1 : 1);\n+\t\tif (c1 != c2)\n+\t\t\treturn c1 \u003c c2 ? -1 : 1;\n \t}\n-\n-\tif (len1 \u003c len2)\n-\t\treturn -1;\n-\tif (len1 \u003e len2)\n-\t\treturn 1;\n-\treturn 0;\n }\n EXPORT_SYMBOL_IF_KUNIT(hfsplus_compare_dentry);\ndiff --git a/fs/hfsplus/unicode.h b/fs/hfsplus/unicode.h\nnew file mode 100644\nindex 0000000000000..31cc7691c9162\n--- /dev/null\n+++ b/fs/hfsplus/unicode.h\n@@ -0,0 +1,63 @@\n+/* SPDX-License-Identifier: GPL-2.0 */\n+/*\n+ * Unicode related declarations\n+ */\n+\n+#ifndef _LINUX_HFSPLUS_UNICODE_H\n+#define _LINUX_HFSPLUS_UNICODE_H\n+\n+/*\n+ * struct hfsplus_ccc_range - one run of consecutive BMP code points that\n+ *                            share the same Unicode canonical combining class\n+ * @first: the first UTF-16 code point in the run\n+ * @last: the last code point in the run (inclusive)\n+ * @combining_class: canonical combining class (ccc) shared by @first..@last\n+ */\n+struct hfsplus_ccc_range {\n+\tu16 first;\n+\tu16 last;\n+\tu8 combining_class;\n+};\n+\n+/*\n+ * struct hfsplus_legacy_decomp - corrected canonical decomposition\n+ * @uc: the code point (a UTF-16 code unit) to look up\n+ * @len: number of valid code units in @repl\n+ * @repl: corrected decomposition sequence (base letter + combining marks)\n+ */\n+struct hfsplus_legacy_decomp {\n+\tu16 uc;\n+\tu8 len;\n+#define HFSPLUS_LEGACY_DECOMP_MAX_LEN\t(3)\n+\tu16 repl[HFSPLUS_LEGACY_DECOMP_MAX_LEN];\n+};\n+\n+/*\n+ * struct hfsplus_legacy_seq_fixup - corrected replacement for a short\n+ *                                   sequence of already-decomposed code units\n+ * @match_len: number of valid code units in @match\n+ * @match: decomposed sequence to look for in the buffer\n+ * @repl_len: number of valid code units in @repl\n+ * @repl: corrected sequence to substitute in place of @match\n+ */\n+struct hfsplus_legacy_seq_fixup {\n+\tu8 match_len;\n+#define HFSPLUS_LEGACY_SEQ_MAX_MATCH\t(3)\n+\tu16 match[HFSPLUS_LEGACY_SEQ_MAX_MATCH];\n+\tu8 repl_len;\n+#define HFSPLUS_LEGACY_SEQ_MAX_REPL\t(2)\n+\tu16 repl[HFSPLUS_LEGACY_SEQ_MAX_REPL];\n+};\n+\n+extern u16 hfsplus_case_fold_table[];\n+extern u16 hfsplus_decompose_table[];\n+extern u16 hfsplus_compose_table[];\n+extern struct hfsplus_ccc_range hfsplus_ccc_table[];\n+extern struct hfsplus_legacy_decomp hfsplus_legacy_decomp_table[];\n+extern struct hfsplus_legacy_seq_fixup hfsplus_legacy_seq_fixups[];\n+\n+u8 hfsplus_combining_class(u16 c);\n+const u16 *hfsplus_legacy_decompose(u16 uc, int *size);\n+void hfsplus_fixup_legacy_sequences(u16 *buf, int *len);\n+\n+#endif /* _LINUX_HFSPLUS_UNICODE_H */\ndiff --git a/fs/hfsplus/unicode_test.c b/fs/hfsplus/unicode_test.c\nindex 7f6b2a3c69d9a..a683c6d5fc221 100644\n--- a/fs/hfsplus/unicode_test.c\n+++ b/fs/hfsplus/unicode_test.c\n@@ -10,6 +10,7 @@\n #include \u003clinux/dcache.h\u003e\n #include \u003clinux/stringhash.h\u003e\n #include \"hfsplus_fs.h\"\n+#include \"unicode.h\"\n \n struct test_mock_string_env {\n \tstruct hfsplus_unistr str1;\n@@ -947,6 +948,223 @@ static void hfsplus_asc2uni_decompose_test(struct kunit *test)\n \tfree_mock_sb(mock_sb);\n }\n \n+/*\n+ * Real UTF-8 \u003c-\u003e wchar_t conversion, mirroring what the \"utf8\" NLS table\n+ * actually does (see char2uni()/uni2char() in fs/nls/nls_utf8.c). The\n+ * test_char2uni()/test_uni2char() stand-ins above only handle one raw\n+ * byte per character, which cannot represent the combining marks (e.g.\n+ * U+0301, U+0323) the canonical-reordering tests below need.\n+ */\n+static int test_char2uni_utf8(const unsigned char *rawstring, int boundlen,\n+\t\t\t      wchar_t *uni)\n+{\n+\tunicode_t u;\n+\tint n = utf8_to_utf32(rawstring, boundlen, \u0026u);\n+\n+\tif (n \u003c 0 || u \u003e MAX_WCHAR_T) {\n+\t\t*uni = 0x3f; /* ? */\n+\t\treturn -EINVAL;\n+\t}\n+\t*uni = (wchar_t)u;\n+\treturn n;\n+}\n+\n+static int test_uni2char_utf8(wchar_t uni, unsigned char *out, int boundlen)\n+{\n+\tint n = utf32_to_utf8(uni, out, boundlen);\n+\n+\tif (n \u003c 0) {\n+\t\t*out = '?';\n+\t\treturn -EINVAL;\n+\t}\n+\treturn n;\n+}\n+\n+/*\n+ * Test that hfsplus_asc2uni() brings combining marks contributed by\n+ * different source characters into Unicode canonical (combining-class)\n+ * order, instead of just storing them in whatever order they were typed.\n+ *\n+ * U+0301 (COMBINING ACUTE ACCENT) has combining class 230; U+0323\n+ * (COMBINING DOT BELOW) has combining class 220. Since 220 \u003c 230,\n+ * canonical order requires the dot-below before the acute. A name\n+ * created with them typed in the \"wrong\" order must still end up stored\n+ * in canonical order - this is exactly what macOS's own fsck_hfs\n+ * (FixDecomps() in CatalogCheck.c) requires and flags as \"Illegal name\"\n+ * when it isn't true.\n+ */\n+static void hfsplus_asc2uni_combining_reorder_test(struct kunit *test)\n+{\n+\tstruct test_mock_sb *mock_sb;\n+\tstruct hfsplus_unistr ustr;\n+\t/* \"e\" + COMBINING ACUTE ACCENT (U+0301) + COMBINING DOT BELOW (U+0323) */\n+\tstatic const char wrong_order[] = \"e\\xcc\\x81\\xcc\\xa3\";\n+\t/* \"e\" + COMBINING DOT BELOW (U+0323) + COMBINING ACUTE ACCENT (U+0301) */\n+\tstatic const char canonical_order[] = \"e\\xcc\\xa3\\xcc\\x81\";\n+\t/* Two class-230 marks: GRAVE (U+0300) then ACUTE (U+0301) */\n+\tstatic const char same_class[] = \"e\\xcc\\x80\\xcc\\x81\";\n+\tint result;\n+\n+\tmock_sb = setup_mock_sb();\n+\tKUNIT_ASSERT_NOT_NULL(test, mock_sb);\n+\n+\tmock_sb-\u003enls.char2uni = test_char2uni_utf8;\n+\n+\t/* Typed out of canonical order: must be reordered on storage. */\n+\tresult = hfsplus_asc2uni(\u0026mock_sb-\u003esb, \u0026ustr, HFSPLUS_MAX_STRLEN,\n+\t\t\t\t wrong_order, strlen(wrong_order),\n+\t\t\t\t HFS_REGULAR_NAME);\n+\n+\tKUNIT_EXPECT_EQ(test, 0, result);\n+\tKUNIT_EXPECT_EQ(test, 3, be16_to_cpu(ustr.length));\n+\tKUNIT_EXPECT_EQ(test, 'e', be16_to_cpu(ustr.unicode[0]));\n+\tKUNIT_EXPECT_EQ(test, 0x0323, be16_to_cpu(ustr.unicode[1]));\n+\tKUNIT_EXPECT_EQ(test, 0x0301, be16_to_cpu(ustr.unicode[2]));\n+\n+\t/* Already in canonical order: must come out unchanged. */\n+\tresult = hfsplus_asc2uni(\u0026mock_sb-\u003esb, \u0026ustr, HFSPLUS_MAX_STRLEN,\n+\t\t\t\t canonical_order, strlen(canonical_order),\n+\t\t\t\t HFS_REGULAR_NAME);\n+\n+\tKUNIT_EXPECT_EQ(test, 0, result);\n+\tKUNIT_EXPECT_EQ(test, 3, be16_to_cpu(ustr.length));\n+\tKUNIT_EXPECT_EQ(test, 'e', be16_to_cpu(ustr.unicode[0]));\n+\tKUNIT_EXPECT_EQ(test, 0x0323, be16_to_cpu(ustr.unicode[1]));\n+\tKUNIT_EXPECT_EQ(test, 0x0301, be16_to_cpu(ustr.unicode[2]));\n+\n+\t/* Two marks of equal combining class must keep their relative\n+\t * (input) order - the sort must be stable, not just \"sorted\".\n+\t */\n+\tresult = hfsplus_asc2uni(\u0026mock_sb-\u003esb, \u0026ustr, HFSPLUS_MAX_STRLEN,\n+\t\t\t\t same_class, strlen(same_class),\n+\t\t\t\t HFS_REGULAR_NAME);\n+\n+\tKUNIT_EXPECT_EQ(test, 0, result);\n+\tKUNIT_EXPECT_EQ(test, 3, be16_to_cpu(ustr.length));\n+\tKUNIT_EXPECT_EQ(test, 'e', be16_to_cpu(ustr.unicode[0]));\n+\tKUNIT_EXPECT_EQ(test, 0x0300, be16_to_cpu(ustr.unicode[1]));\n+\tKUNIT_EXPECT_EQ(test, 0x0301, be16_to_cpu(ustr.unicode[2]));\n+\n+\tfree_mock_sb(mock_sb);\n+}\n+\n+/*\n+ * Test that a name written with combining marks in non-canonical order\n+ * still reads back as valid, correct UTF-8 once reordered - i.e. that\n+ * hfsplus_asc2uni() and hfsplus_uni2asc_str() stay consistent with each\n+ * other across the reordering.\n+ *\n+ * NODECOMPOSE is set so hfsplus_uni2asc_str() doesn't also recompose\n+ * \"e\" + COMBINING DOT BELOW back into the precomposed U+1EB9 (\"e\"): that\n+ * composition behavior is real (and already covered elsewhere), but it\n+ * would obscure what this test is actually checking.\n+ */\n+static void hfsplus_unicode_combining_reorder_roundtrip_test(struct kunit *test)\n+{\n+\tstruct test_mock_sb *mock_sb;\n+\tstruct hfsplus_unistr ustr;\n+\tstatic const char wrong_order[] = \"e\\xcc\\x81\\xcc\\xa3\";\n+\tstatic const char expected[] = \"e\\xcc\\xa3\\xcc\\x81\"; /* canonical order */\n+\tchar buf[32];\n+\tint len = sizeof(buf);\n+\tint result;\n+\n+\tmock_sb = setup_mock_sb();\n+\tKUNIT_ASSERT_NOT_NULL(test, mock_sb);\n+\n+\tset_bit(HFSPLUS_SB_NODECOMPOSE, \u0026mock_sb-\u003esb_info.flags);\n+\tmock_sb-\u003enls.char2uni = test_char2uni_utf8;\n+\tmock_sb-\u003enls.uni2char = test_uni2char_utf8;\n+\n+\tresult = hfsplus_asc2uni(\u0026mock_sb-\u003esb, \u0026ustr, HFSPLUS_MAX_STRLEN,\n+\t\t\t\t wrong_order, strlen(wrong_order),\n+\t\t\t\t HFS_REGULAR_NAME);\n+\tKUNIT_EXPECT_EQ(test, 0, result);\n+\n+\tresult = hfsplus_uni2asc_str(\u0026mock_sb-\u003esb, \u0026ustr, buf, \u0026len);\n+\n+\tKUNIT_EXPECT_EQ(test, 0, result);\n+\tKUNIT_EXPECT_EQ(test, (int)strlen(expected), len);\n+\tKUNIT_EXPECT_MEMEQ(test, expected, buf, len);\n+\n+\tfree_mock_sb(mock_sb);\n+}\n+\n+/*\n+ * Test that hfsplus_asc2uni() decomposes a character using the corrected\n+ * (post-2002/\"Jaguar\") canonical decomposition even when Apple Technote\n+ * #1150's own decomposition table doesn't have an entry for it.\n+ *\n+ * U+01F8 (LATIN CAPITAL LETTER N WITH GRAVE) is exactly one of the\n+ * characters macOS's own fsck_hfs (FixDecomps() in CatalogCheck.c) has\n+ * flagged \"Illegal name\" for since 2002 when found stored undecomposed.\n+ */\n+static void hfsplus_asc2uni_legacy_decomp_test(struct kunit *test)\n+{\n+\tstruct test_mock_sb *mock_sb;\n+\tstruct hfsplus_unistr ustr;\n+\tstatic const char input[] = \"\\xc7\\xb8\"; /* U+01F8 */\n+\tint result;\n+\n+\tmock_sb = setup_mock_sb();\n+\tKUNIT_ASSERT_NOT_NULL(test, mock_sb);\n+\n+\tmock_sb-\u003enls.char2uni = test_char2uni_utf8;\n+\n+\tresult = hfsplus_asc2uni(\u0026mock_sb-\u003esb, \u0026ustr, HFSPLUS_MAX_STRLEN,\n+\t\t\t\t input, strlen(input), HFS_REGULAR_NAME);\n+\n+\tKUNIT_EXPECT_EQ(test, 0, result);\n+\tKUNIT_EXPECT_EQ(test, 2, be16_to_cpu(ustr.length));\n+\tKUNIT_EXPECT_EQ(test, 'N', be16_to_cpu(ustr.unicode[0]));\n+\tKUNIT_EXPECT_EQ(test, 0x0300, be16_to_cpu(ustr.unicode[1]));\n+\n+\tfree_mock_sb(mock_sb);\n+}\n+\n+/*\n+ * Test that hfsplus_asc2uni() corrects two more of fsck_hfs's known\n+ * legacy decomposition sequences once combining marks from independently\n+ * typed characters end up adjacent:\n+ *\n+ *  - GREEK SMALL LETTER ALPHA (U+03B1) + COMBINING VERTICAL LINE ABOVE\n+ *    (U+030D) must become U+03B1 + COMBINING ACUTE ACCENT (U+0301).\n+ *  - BENGALI LETTER BA (U+09AC) + BENGALI SIGN NUKTA (U+09BC) must become\n+ *    the single character BENGALI LETTER RA WITH MIDDLE DIAGONAL (U+09B0).\n+ */\n+static void hfsplus_asc2uni_legacy_seq_fixup_test(struct kunit *test)\n+{\n+\tstruct test_mock_sb *mock_sb;\n+\tstruct hfsplus_unistr ustr;\n+\tstatic const char greek_input[] = \"\\xce\\xb1\\xcc\\x8d\"; /* U+03B1 U+030D */\n+\tstatic const char bengali_input[] = \"\\xe0\\xa6\\xac\\xe0\\xa6\\xbc\"; /* U+09AC U+09BC */\n+\tint result;\n+\n+\tmock_sb = setup_mock_sb();\n+\tKUNIT_ASSERT_NOT_NULL(test, mock_sb);\n+\n+\tmock_sb-\u003enls.char2uni = test_char2uni_utf8;\n+\n+\tresult = hfsplus_asc2uni(\u0026mock_sb-\u003esb, \u0026ustr, HFSPLUS_MAX_STRLEN,\n+\t\t\t\t greek_input, strlen(greek_input),\n+\t\t\t\t HFS_REGULAR_NAME);\n+\n+\tKUNIT_EXPECT_EQ(test, 0, result);\n+\tKUNIT_EXPECT_EQ(test, 2, be16_to_cpu(ustr.length));\n+\tKUNIT_EXPECT_EQ(test, 0x03b1, be16_to_cpu(ustr.unicode[0]));\n+\tKUNIT_EXPECT_EQ(test, 0x0301, be16_to_cpu(ustr.unicode[1]));\n+\n+\tresult = hfsplus_asc2uni(\u0026mock_sb-\u003esb, \u0026ustr, HFSPLUS_MAX_STRLEN,\n+\t\t\t\t bengali_input, strlen(bengali_input),\n+\t\t\t\t HFS_REGULAR_NAME);\n+\n+\tKUNIT_EXPECT_EQ(test, 0, result);\n+\tKUNIT_EXPECT_EQ(test, 1, be16_to_cpu(ustr.length));\n+\tKUNIT_EXPECT_EQ(test, 0x09b0, be16_to_cpu(ustr.unicode[0]));\n+\n+\tfree_mock_sb(mock_sb);\n+}\n+\n /* Mock dentry for testing hfsplus_hash_dentry */\n static struct dentry test_dentry;\n \n@@ -1230,6 +1448,37 @@ static void hfsplus_hash_dentry_edge_cases_test(struct kunit *test)\n \tfree_mock_sb(mock_sb);\n }\n \n+/*\n+ * Test that hfsplus_hash_dentry() hashes two names identically when they\n+ * differ only in the (non-canonical) typed order of the same combining\n+ * marks - both must canonicalize to the same stored form, so they must\n+ * hash the same or dcache lookups would spuriously miss.\n+ */\n+static void hfsplus_hash_dentry_combining_reorder_test(struct kunit *test)\n+{\n+\tstruct test_mock_sb *mock_sb;\n+\tstruct qstr str1, str2;\n+\tint result;\n+\n+\tmock_sb = setup_mock_sb();\n+\tKUNIT_ASSERT_NOT_NULL(test, mock_sb);\n+\n+\tsetup_mock_dentry(\u0026mock_sb-\u003esb);\n+\tmock_sb-\u003enls.char2uni = test_char2uni_utf8;\n+\n+\tcreate_qstr(\u0026str1, \"e\\xcc\\x81\\xcc\\xa3\"); /* acute, then dot-below */\n+\tresult = hfsplus_hash_dentry(\u0026test_dentry, \u0026str1);\n+\tKUNIT_EXPECT_EQ(test, 0, result);\n+\n+\tcreate_qstr(\u0026str2, \"e\\xcc\\xa3\\xcc\\x81\"); /* dot-below, then acute */\n+\tresult = hfsplus_hash_dentry(\u0026test_dentry, \u0026str2);\n+\tKUNIT_EXPECT_EQ(test, 0, result);\n+\n+\tKUNIT_EXPECT_EQ(test, str1.hash, str2.hash);\n+\n+\tfree_mock_sb(mock_sb);\n+}\n+\n /* Test hfsplus_compare_dentry basic functionality */\n static void hfsplus_compare_dentry_basic_test(struct kunit *test)\n {\n@@ -1552,6 +1801,59 @@ static void hfsplus_compare_dentry_combined_flags_test(struct kunit *test)\n \tfree_mock_sb(mock_sb);\n }\n \n+/*\n+ * Test that hfsplus_compare_dentry() treats two names as equal when they\n+ * differ only in the (non-canonical) typed order of the same combining\n+ * marks, since both refer to the same canonically-ordered catalog entry.\n+ */\n+static void hfsplus_compare_dentry_combining_reorder_test(struct kunit *test)\n+{\n+\tstruct test_mock_sb *mock_sb;\n+\tstruct qstr name;\n+\tint result;\n+\n+\tmock_sb = setup_mock_sb();\n+\tKUNIT_ASSERT_NOT_NULL(test, mock_sb);\n+\n+\tsetup_mock_dentry(\u0026mock_sb-\u003esb);\n+\tmock_sb-\u003enls.char2uni = test_char2uni_utf8;\n+\n+\tcreate_qstr(\u0026name, \"e\\xcc\\xa3\\xcc\\x81\"); /* dot-below, then acute */\n+\tresult = hfsplus_compare_dentry(\u0026test_dentry, 5, \"e\\xcc\\x81\\xcc\\xa3\",\n+\t\t\t\t\t\u0026name); /* acute, then dot-below */\n+\tKUNIT_EXPECT_EQ(test, 0, result);\n+\n+\tfree_mock_sb(mock_sb);\n+}\n+\n+/*\n+ * Test that a precomposed character using one of fsck_hfs's known legacy\n+ * decompositions compares equal to the already-decomposed form of the\n+ * same character - i.e. that hfsplus_compare_dentry() applies the same\n+ * legacy-decomposition correction as hfsplus_asc2uni() does on storage,\n+ * so a lookup finds the entry regardless of which form was typed.\n+ */\n+static void hfsplus_compare_dentry_legacy_decomp_test(struct kunit *test)\n+{\n+\tstruct test_mock_sb *mock_sb;\n+\tstruct qstr name;\n+\tint result;\n+\n+\tmock_sb = setup_mock_sb();\n+\tKUNIT_ASSERT_NOT_NULL(test, mock_sb);\n+\n+\tsetup_mock_dentry(\u0026mock_sb-\u003esb);\n+\tmock_sb-\u003enls.char2uni = test_char2uni_utf8;\n+\n+\t/* \"N\" + COMBINING GRAVE ACCENT (U+0300), already decomposed */\n+\tcreate_qstr(\u0026name, \"N\\xcc\\x80\");\n+\t/* U+01F8, precomposed */\n+\tresult = hfsplus_compare_dentry(\u0026test_dentry, 2, \"\\xc7\\xb8\", \u0026name);\n+\tKUNIT_EXPECT_EQ(test, 0, result);\n+\n+\tfree_mock_sb(mock_sb);\n+}\n+\n static struct kunit_case hfsplus_unicode_test_cases[] = {\n \tKUNIT_CASE(hfsplus_strcasecmp_test),\n \tKUNIT_CASE(hfsplus_strcmp_test),\n@@ -1567,12 +1869,17 @@ static struct kunit_case hfsplus_unicode_test_cases[] = {\n \tKUNIT_CASE(hfsplus_asc2uni_buffer_limits_test),\n \tKUNIT_CASE(hfsplus_asc2uni_edge_cases_test),\n \tKUNIT_CASE(hfsplus_asc2uni_decompose_test),\n+\tKUNIT_CASE(hfsplus_asc2uni_combining_reorder_test),\n+\tKUNIT_CASE(hfsplus_unicode_combining_reorder_roundtrip_test),\n+\tKUNIT_CASE(hfsplus_asc2uni_legacy_decomp_test),\n+\tKUNIT_CASE(hfsplus_asc2uni_legacy_seq_fixup_test),\n \tKUNIT_CASE(hfsplus_hash_dentry_basic_test),\n \tKUNIT_CASE(hfsplus_hash_dentry_casefold_test),\n \tKUNIT_CASE(hfsplus_hash_dentry_special_chars_test),\n \tKUNIT_CASE(hfsplus_hash_dentry_decompose_test),\n \tKUNIT_CASE(hfsplus_hash_dentry_consistency_test),\n \tKUNIT_CASE(hfsplus_hash_dentry_edge_cases_test),\n+\tKUNIT_CASE(hfsplus_hash_dentry_combining_reorder_test),\n \tKUNIT_CASE(hfsplus_compare_dentry_basic_test),\n \tKUNIT_CASE(hfsplus_compare_dentry_casefold_test),\n \tKUNIT_CASE(hfsplus_compare_dentry_special_chars_test),\n@@ -1580,6 +1887,8 @@ static struct kunit_case hfsplus_unicode_test_cases[] = {\n \tKUNIT_CASE(hfsplus_compare_dentry_decompose_test),\n \tKUNIT_CASE(hfsplus_compare_dentry_edge_cases_test),\n \tKUNIT_CASE(hfsplus_compare_dentry_combined_flags_test),\n+\tKUNIT_CASE(hfsplus_compare_dentry_combining_reorder_test),\n+\tKUNIT_CASE(hfsplus_compare_dentry_legacy_decomp_test),\n \t{}\n };\n \n"
}

2/1 2026/09/21 03:51 agent patch-evaluator
5m Model:
core

Args:
null

Results:
{
  "EnableConfigs": [
    "HFSPLUS_FS",
    "BLOCK"
  ],
  "FocusSymbols": [
    "hfsplus_asc2uni",
    "hfsplus_hash_dentry",
    "hfsplus_compare_dentry",
    "hfsplus_combining_class",
    "hfsplus_legacy_decompose",
    "hfsplus_fixup_legacy_sequences"
  ],
  "Reasoning": "The patch modifies HFS+ Unicode name handling, introducing canonical combining class (CCC) reordering, legacy decomposition lookups, and in-place buffer fixups. These functions are directly executed during dentry hashing (d_hash), dentry comparison (d_compare), and catalog/xattr key encoding (hfsplus_asc2uni) when accessing an HFS+ filesystem mounted in standard virtual environments via loop/block devices. Fuzzing is warranted to test buffer manipulations, table searching, reordering loops, and string canonicalization consistency.",
  "WorthFuzzing": true
}

Instruction:
You are an expert Linux kernel maintainer and security engineer.
Your job is to review a provided patch series and evaluate whether it warrants fuzzing with syzkaller.

IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in
your workspace. Do NOT rely on internal assumptions. You must actively use your code access
tools to inspect the actual source code, callers, and surrounding context.

================================================================================
1. CORE TRIAGE PHILOSOPHY
================================================================================
The goal of patch fuzzing is to discover crashes, regressions, exposed latent bugs,
and newly triggered assertions introduced by the patch series.

- REACHABILITY IS THE PRIMARY GATE:
  Fuzzing can only discover bugs in code that can actually execute in standard virtualized
  environments (GCE or QEMU, utilizing software-emulated devices like USB gadgets, netdev, tun/tap).
  If the modified code is structurally unreachable (see Section 2), it MUST NOT be fuzzed,
  regardless of whether it adds assertions or complex logic.

- DO NOT BLINDLY TRUST "NO FUNCTIONAL CHANGE" (NFCI) OR "REFACTORING" CLAIMS:
  Patch authors routinely label changes as "cleanups", "refactorings", or state
  "No functional change intended". Do NOT take these claims at face value.
  Code refactorings that rearrange logic, introduce helper functions, or alter state management
  in core subsystems frequently introduce subtle semantic shifts or uncover latent kernel bugs.
  If reachable executable code is modified or refactored, it MUST be fuzzed.

- NEW OR MODIFIED ASSERTIONS IN REACHABLE CODE MUST BE FUZZED:
  When a patch introduces or modifies runtime checks or assertions (e.g., WARN_ON*, VM_WARN_ON*,
  BUG_ON*, lockdep_assert*) in reachable code paths, it enforces new or stricter invariants.
  Even if the author believes the invariant always holds, fuzzing is essential to verify whether
  an unusual sequence of operations can violate it.

================================================================================
2. WHEN TO RETURN WorthFuzzing=false (NEGATIVE CRITERIA)
================================================================================
Return WorthFuzzing=false ONLY IF all modified code falls strictly into one or more of these categories:

- Non-kernel and non-executable changes:
  * Modifications to Documentation/, comments, or spelling fixes.
  * User-space directories, self-tests, samples, or scripts (e.g., tools/, samples/, scripts/, usr/)
    that do not affect the compiled kernel image (vmlinux) or kernel modules.
  * Purely decorative logging (e.g., message strings in pr_err, printk, dev_info) or tracepoints
    that do not alter control flow or data structures.
  * Build system or Kconfig changes that do not alter compiled C logic.
- Structurally unreachable hardware:
  * Vendor-specific PCIe switches, SmartNICs, or GPU drivers (e.g., mlxsw, pds_core, qed,
    ionic, amdgpu) requiring physical ASIC/PCIe cards not emulated in standard QEMU.
- Unreachable execution paths:
  * Driver teardown callbacks (.remove, .shutdown, pci_unregister_driver) executed only during
    physical PCI hot-unplug or manual sysfs driver unbinding.
  * Code paths exclusive to architectures other than the target architecture.

================================================================================
3. WHEN TO RETURN WorthFuzzing=true (POSITIVE CRITERIA)
================================================================================
Return WorthFuzzing=true whenever the patch touches reachable executable code, including:
- Core Subsystems:
  * Any logic modifications in memory management (mm/), synchronization/locking (kernel/locking/),
    BPF, scheduler, core networking, VFS, or syscall handling.
- Refactorings and Code Cleanups:
  * Any restructuring of reachable data structures, helper abstractions, or algorithm flows.
- Runtime Assertions and Defensive Checks:
  * Any introduction or alteration of assertions (WARN_ON*, VM_WARN_ON*, BUG_ON*, etc.) in reachable paths.
- Reachable Drivers and Protocols:
  * Drivers accessible via virtual buses (virtio, USB gadget, loopback, netlink, binder, sockets, etc.).

================================================================================
4. EXTRACTING FocusSymbols (PREVENTING DILUTION)
================================================================================
When WorthFuzzing=true, you must extract specific kernel functions into FocusSymbols to guide the fuzzer:

- AVOID UBIQUITOUS LIFECYCLE HOT-PATHS:
  Do NOT list generic, ubiquitous functions called by almost every program in the corpus
  (including, but not limited to: general memory allocators and deallocators, page fault
  and trap handlers, or core synchronization primitives; this is not an exhaustive list).
  Listing ubiquitous functions causes the fuzzer to classify thousands of unrelated tests as "focused",
  which severely dilutes fuzzing effort away from the actual changes.

- TARGET SPECIFIC FEATURE LOGIC AND ENTRYPOINTS:
  List functions that specifically implement the logic being added or altered, or direct API entrypoints
  for the subsystem feature under review.

- HANDLING STATIC INLINE FUNCTIONS IN HEADERS (.h):
  Compiler-inlined static functions (such as static inlines in mm/*.h or include/linux/*.h) lack
  distinct symbol addresses in vmlinux and cannot be targeted directly by symbol coverage filters.
  If the changes are primarily in static inline helpers, identify non-static, feature-specific caller
  functions in .c files that exercise them (avoiding ubiquitous lifecycle wrappers).

================================================================================
5. IDENTIFYING EnableConfigs
================================================================================
Identify any specific CONFIG_ options required to properly compile and reach the modified code:
- Inspect Kconfig files and #ifdef guards; do not make assumptions.
- Check "depends on" lines in Kconfig to include any non-standard parent subsystem configs needed.
- Strip any 'CONFIG_' prefix (e.g., return "NET_IPV4" instead of "CONFIG_NET_IPV4").
Prefer calling several tools at the same time to save round-trips.


Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.

Prompt:
Target architecture: amd64

For your convenience, here is the diff of the changes:
commit 9b05d1884d74d63b2810e5bb43da4d00ab799a9c
Author: syz-cluster <triage@syzkaller.com>
Date:   Mon Sep 21 03:51:44 2026 +0000

    syz-cluster: applied patch under review

diff --git a/fs/hfsplus/hfsplus_fs.h b/fs/hfsplus/hfsplus_fs.h
index 1e5b58e6a13fc..916e6552e3f0b 100644
--- a/fs/hfsplus/hfsplus_fs.h
+++ b/fs/hfsplus/hfsplus_fs.h
@@ -17,6 +17,7 @@
 #include <linux/blkdev.h>
 #include <linux/fs_context.h>
 #include "hfsplus_raw.h"
+#include "unicode.h"
 
 /* Runtime config options */
 #define HFSPLUS_DEF_CR_TYPE    0x3F3F3F3F  /* '????' */
@@ -486,11 +487,6 @@ void hfsplus_mark_mdb_dirty(struct super_block *sb);
 void hfsplus_prepare_volume_header_for_commit(struct hfsplus_vh *vhdr);
 int hfsplus_commit_superblock(struct super_block *sb);
 
-/* tables.c */
-extern u16 hfsplus_case_fold_table[];
-extern u16 hfsplus_decompose_table[];
-extern u16 hfsplus_compose_table[];
-
 /* unicode.c */
 int hfsplus_strcasecmp(const struct hfsplus_unistr *s1,
 		       const struct hfsplus_unistr *s2);
diff --git a/fs/hfsplus/tables.c b/fs/hfsplus/tables.c
index a5fb8ee7d019d..2101201ab973f 100644
--- a/fs/hfsplus/tables.c
+++ b/fs/hfsplus/tables.c
@@ -3244,3 +3244,499 @@ u16 hfsplus_compose_table[] = {
 	/* 0x0342 0x0314 0x03c9 0x0345 */
 	0x1fa7, 0x0000,
 };
+
+/*
+ * Unicode canonical combining class (ccc) table, restricted to the Basic
+ * Multilingual Plane: HFS+ names are stored as UTF-16 and this kernel's
+ * wchar_t (see MAX_WCHAR_T in include/linux/nls.h) tops out at U+FFFF, so
+ * no HFS+ catalog name can contain a code point above the BMP anyway.
+ *
+ * Generated from the Unicode Character Database, version 12.1.0
+ * (https://www.unicode.org/Public/12.1.0/ucd/extracted/DerivedCombiningClass.txt),
+ * the same UCD version fs/unicode/README.utf8data documents. Class 0
+ * ("Not_Reordered") is the default for every code point not listed here
+ * and needs no entry.
+ *
+ * Used by hfsplus_canonical_reorder() to apply the Unicode Canonical
+ * Ordering Algorithm to a decomposed name, matching what macOS's own
+ * fsck_hfs (FixDecomps()) requires of a stored catalog name.
+ */
+struct hfsplus_ccc_range hfsplus_ccc_table[] = {
+	{ 0x0300, 0x0314, 230 },
+	{ 0x0315, 0x0315, 232 },
+	{ 0x0316, 0x0319, 220 },
+	{ 0x031a, 0x031a, 232 },
+	{ 0x031b, 0x031b, 216 },
+	{ 0x031c, 0x0320, 220 },
+	{ 0x0321, 0x0322, 202 },
+	{ 0x0323, 0x0326, 220 },
+	{ 0x0327, 0x0328, 202 },
+	{ 0x0329, 0x0333, 220 },
+	{ 0x0334, 0x0338,   1 },
+	{ 0x0339, 0x033c, 220 },
+	{ 0x033d, 0x0344, 230 },
+	{ 0x0345, 0x0345, 240 },
+	{ 0x0346, 0x0346, 230 },
+	{ 0x0347, 0x0349, 220 },
+	{ 0x034a, 0x034c, 230 },
+	{ 0x034d, 0x034e, 220 },
+	{ 0x0350, 0x0352, 230 },
+	{ 0x0353, 0x0356, 220 },
+	{ 0x0357, 0x0357, 230 },
+	{ 0x0358, 0x0358, 232 },
+	{ 0x0359, 0x035a, 220 },
+	{ 0x035b, 0x035b, 230 },
+	{ 0x035c, 0x035c, 233 },
+	{ 0x035d, 0x035e, 234 },
+	{ 0x035f, 0x035f, 233 },
+	{ 0x0360, 0x0361, 234 },
+	{ 0x0362, 0x0362, 233 },
+	{ 0x0363, 0x036f, 230 },
+	{ 0x0483, 0x0487, 230 },
+	{ 0x0591, 0x0591, 220 },
+	{ 0x0592, 0x0595, 230 },
+	{ 0x0596, 0x0596, 220 },
+	{ 0x0597, 0x0599, 230 },
+	{ 0x059a, 0x059a, 222 },
+	{ 0x059b, 0x059b, 220 },
+	{ 0x059c, 0x05a1, 230 },
+	{ 0x05a2, 0x05a7, 220 },
+	{ 0x05a8, 0x05a9, 230 },
+	{ 0x05aa, 0x05aa, 220 },
+	{ 0x05ab, 0x05ac, 230 },
+	{ 0x05ad, 0x05ad, 222 },
+	{ 0x05ae, 0x05ae, 228 },
+	{ 0x05af, 0x05af, 230 },
+	{ 0x05b0, 0x05b0,  10 },
+	{ 0x05b1, 0x05b1,  11 },
+	{ 0x05b2, 0x05b2,  12 },
+	{ 0x05b3, 0x05b3,  13 },
+	{ 0x05b4, 0x05b4,  14 },
+	{ 0x05b5, 0x05b5,  15 },
+	{ 0x05b6, 0x05b6,  16 },
+	{ 0x05b7, 0x05b7,  17 },
+	{ 0x05b8, 0x05b8,  18 },
+	{ 0x05b9, 0x05ba,  19 },
+	{ 0x05bb, 0x05bb,  20 },
+	{ 0x05bc, 0x05bc,  21 },
+	{ 0x05bd, 0x05bd,  22 },
+	{ 0x05bf, 0x05bf,  23 },
+	{ 0x05c1, 0x05c1,  24 },
+	{ 0x05c2, 0x05c2,  25 },
+	{ 0x05c4, 0x05c4, 230 },
+	{ 0x05c5, 0x05c5, 220 },
+	{ 0x05c7, 0x05c7,  18 },
+	{ 0x0610, 0x0617, 230 },
+	{ 0x0618, 0x0618,  30 },
+	{ 0x0619, 0x0619,  31 },
+	{ 0x061a, 0x061a,  32 },
+	{ 0x064b, 0x064b,  27 },
+	{ 0x064c, 0x064c,  28 },
+	{ 0x064d, 0x064d,  29 },
+	{ 0x064e, 0x064e,  30 },
+	{ 0x064f, 0x064f,  31 },
+	{ 0x0650, 0x0650,  32 },
+	{ 0x0651, 0x0651,  33 },
+	{ 0x0652, 0x0652,  34 },
+	{ 0x0653, 0x0654, 230 },
+	{ 0x0655, 0x0656, 220 },
+	{ 0x0657, 0x065b, 230 },
+	{ 0x065c, 0x065c, 220 },
+	{ 0x065d, 0x065e, 230 },
+	{ 0x065f, 0x065f, 220 },
+	{ 0x0670, 0x0670,  35 },
+	{ 0x06d6, 0x06dc, 230 },
+	{ 0x06df, 0x06e2, 230 },
+	{ 0x06e3, 0x06e3, 220 },
+	{ 0x06e4, 0x06e4, 230 },
+	{ 0x06e7, 0x06e8, 230 },
+	{ 0x06ea, 0x06ea, 220 },
+	{ 0x06eb, 0x06ec, 230 },
+	{ 0x06ed, 0x06ed, 220 },
+	{ 0x0711, 0x0711,  36 },
+	{ 0x0730, 0x0730, 230 },
+	{ 0x0731, 0x0731, 220 },
+	{ 0x0732, 0x0733, 230 },
+	{ 0x0734, 0x0734, 220 },
+	{ 0x0735, 0x0736, 230 },
+	{ 0x0737, 0x0739, 220 },
+	{ 0x073a, 0x073a, 230 },
+	{ 0x073b, 0x073c, 220 },
+	{ 0x073d, 0x073d, 230 },
+	{ 0x073e, 0x073e, 220 },
+	{ 0x073f, 0x0741, 230 },
+	{ 0x0742, 0x0742, 220 },
+	{ 0x0743, 0x0743, 230 },
+	{ 0x0744, 0x0744, 220 },
+	{ 0x0745, 0x0745, 230 },
+	{ 0x0746, 0x0746, 220 },
+	{ 0x0747, 0x0747, 230 },
+	{ 0x0748, 0x0748, 220 },
+	{ 0x0749, 0x074a, 230 },
+	{ 0x07eb, 0x07f1, 230 },
+	{ 0x07f2, 0x07f2, 220 },
+	{ 0x07f3, 0x07f3, 230 },
+	{ 0x07fd, 0x07fd, 220 },
+	{ 0x0816, 0x0819, 230 },
+	{ 0x081b, 0x0823, 230 },
+	{ 0x0825, 0x0827, 230 },
+	{ 0x0829, 0x082d, 230 },
+	{ 0x0859, 0x085b, 220 },
+	{ 0x08d3, 0x08d3, 220 },
+	{ 0x08d4, 0x08e1, 230 },
+	{ 0x08e3, 0x08e3, 220 },
+	{ 0x08e4, 0x08e5, 230 },
+	{ 0x08e6, 0x08e6, 220 },
+	{ 0x08e7, 0x08e8, 230 },
+	{ 0x08e9, 0x08e9, 220 },
+	{ 0x08ea, 0x08ec, 230 },
+	{ 0x08ed, 0x08ef, 220 },
+	{ 0x08f0, 0x08f0,  27 },
+	{ 0x08f1, 0x08f1,  28 },
+	{ 0x08f2, 0x08f2,  29 },
+	{ 0x08f3, 0x08f5, 230 },
+	{ 0x08f6, 0x08f6, 220 },
+	{ 0x08f7, 0x08f8, 230 },
+	{ 0x08f9, 0x08fa, 220 },
+	{ 0x08fb, 0x08ff, 230 },
+	{ 0x093c, 0x093c,   7 },
+	{ 0x094d, 0x094d,   9 },
+	{ 0x0951, 0x0951, 230 },
+	{ 0x0952, 0x0952, 220 },
+	{ 0x0953, 0x0954, 230 },
+	{ 0x09bc, 0x09bc,   7 },
+	{ 0x09cd, 0x09cd,   9 },
+	{ 0x09fe, 0x09fe, 230 },
+	{ 0x0a3c, 0x0a3c,   7 },
+	{ 0x0a4d, 0x0a4d,   9 },
+	{ 0x0abc, 0x0abc,   7 },
+	{ 0x0acd, 0x0acd,   9 },
+	{ 0x0b3c, 0x0b3c,   7 },
+	{ 0x0b4d, 0x0b4d,   9 },
+	{ 0x0bcd, 0x0bcd,   9 },
+	{ 0x0c4d, 0x0c4d,   9 },
+	{ 0x0c55, 0x0c55,  84 },
+	{ 0x0c56, 0x0c56,  91 },
+	{ 0x0cbc, 0x0cbc,   7 },
+	{ 0x0ccd, 0x0ccd,   9 },
+	{ 0x0d3b, 0x0d3c,   9 },
+	{ 0x0d4d, 0x0d4d,   9 },
+	{ 0x0dca, 0x0dca,   9 },
+	{ 0x0e38, 0x0e39, 103 },
+	{ 0x0e3a, 0x0e3a,   9 },
+	{ 0x0e48, 0x0e4b, 107 },
+	{ 0x0eb8, 0x0eb9, 118 },
+	{ 0x0eba, 0x0eba,   9 },
+	{ 0x0ec8, 0x0ecb, 122 },
+	{ 0x0f18, 0x0f19, 220 },
+	{ 0x0f35, 0x0f35, 220 },
+	{ 0x0f37, 0x0f37, 220 },
+	{ 0x0f39, 0x0f39, 216 },
+	{ 0x0f71, 0x0f71, 129 },
+	{ 0x0f72, 0x0f72, 130 },
+	{ 0x0f74, 0x0f74, 132 },
+	{ 0x0f7a, 0x0f7d, 130 },
+	{ 0x0f80, 0x0f80, 130 },
+	{ 0x0f82, 0x0f83, 230 },
+	{ 0x0f84, 0x0f84,   9 },
+	{ 0x0f86, 0x0f87, 230 },
+	{ 0x0fc6, 0x0fc6, 220 },
+	{ 0x1037, 0x1037,   7 },
+	{ 0x1039, 0x103a,   9 },
+	{ 0x108d, 0x108d, 220 },
+	{ 0x135d, 0x135f, 230 },
+	{ 0x1714, 0x1714,   9 },
+	{ 0x1734, 0x1734,   9 },
+	{ 0x17d2, 0x17d2,   9 },
+	{ 0x17dd, 0x17dd, 230 },
+	{ 0x18a9, 0x18a9, 228 },
+	{ 0x1939, 0x1939, 222 },
+	{ 0x193a, 0x193a, 230 },
+	{ 0x193b, 0x193b, 220 },
+	{ 0x1a17, 0x1a17, 230 },
+	{ 0x1a18, 0x1a18, 220 },
+	{ 0x1a60, 0x1a60,   9 },
+	{ 0x1a75, 0x1a7c, 230 },
+	{ 0x1a7f, 0x1a7f, 220 },
+	{ 0x1ab0, 0x1ab4, 230 },
+	{ 0x1ab5, 0x1aba, 220 },
+	{ 0x1abb, 0x1abc, 230 },
+	{ 0x1abd, 0x1abd, 220 },
+	{ 0x1b34, 0x1b34,   7 },
+	{ 0x1b44, 0x1b44,   9 },
+	{ 0x1b6b, 0x1b6b, 230 },
+	{ 0x1b6c, 0x1b6c, 220 },
+	{ 0x1b6d, 0x1b73, 230 },
+	{ 0x1baa, 0x1baa,   9 },
+	{ 0x1bab, 0x1bab,   9 },
+	{ 0x1be6, 0x1be6,   7 },
+	{ 0x1bf2, 0x1bf3,   9 },
+	{ 0x1c37, 0x1c37,   7 },
+	{ 0x1cd0, 0x1cd2, 230 },
+	{ 0x1cd4, 0x1cd4,   1 },
+	{ 0x1cd5, 0x1cd9, 220 },
+	{ 0x1cda, 0x1cdb, 230 },
+	{ 0x1cdc, 0x1cdf, 220 },
+	{ 0x1ce0, 0x1ce0, 230 },
+	{ 0x1ce2, 0x1ce8,   1 },
+	{ 0x1ced, 0x1ced, 220 },
+	{ 0x1cf4, 0x1cf4, 230 },
+	{ 0x1cf8, 0x1cf9, 230 },
+	{ 0x1dc0, 0x1dc1, 230 },
+	{ 0x1dc2, 0x1dc2, 220 },
+	{ 0x1dc3, 0x1dc9, 230 },
+	{ 0x1dca, 0x1dca, 220 },
+	{ 0x1dcb, 0x1dcc, 230 },
+	{ 0x1dcd, 0x1dcd, 234 },
+	{ 0x1dce, 0x1dce, 214 },
+	{ 0x1dcf, 0x1dcf, 220 },
+	{ 0x1dd0, 0x1dd0, 202 },
+	{ 0x1dd1, 0x1df5, 230 },
+	{ 0x1df6, 0x1df6, 232 },
+	{ 0x1df7, 0x1df8, 228 },
+	{ 0x1df9, 0x1df9, 220 },
+	{ 0x1dfb, 0x1dfb, 230 },
+	{ 0x1dfc, 0x1dfc, 233 },
+	{ 0x1dfd, 0x1dfd, 220 },
+	{ 0x1dfe, 0x1dfe, 230 },
+	{ 0x1dff, 0x1dff, 220 },
+	{ 0x20d0, 0x20d1, 230 },
+	{ 0x20d2, 0x20d3,   1 },
+	{ 0x20d4, 0x20d7, 230 },
+	{ 0x20d8, 0x20da,   1 },
+	{ 0x20db, 0x20dc, 230 },
+	{ 0x20e1, 0x20e1, 230 },
+	{ 0x20e5, 0x20e6,   1 },
+	{ 0x20e7, 0x20e7, 230 },
+	{ 0x20e8, 0x20e8, 220 },
+	{ 0x20e9, 0x20e9, 230 },
+	{ 0x20ea, 0x20eb,   1 },
+	{ 0x20ec, 0x20ef, 220 },
+	{ 0x20f0, 0x20f0, 230 },
+	{ 0x2cef, 0x2cf1, 230 },
+	{ 0x2d7f, 0x2d7f,   9 },
+	{ 0x2de0, 0x2dff, 230 },
+	{ 0x302a, 0x302a, 218 },
+	{ 0x302b, 0x302b, 228 },
+	{ 0x302c, 0x302c, 232 },
+	{ 0x302d, 0x302d, 222 },
+	{ 0x302e, 0x302f, 224 },
+	{ 0x3099, 0x309a,   8 },
+	{ 0xa66f, 0xa66f, 230 },
+	{ 0xa674, 0xa67d, 230 },
+	{ 0xa69e, 0xa69f, 230 },
+	{ 0xa6f0, 0xa6f1, 230 },
+	{ 0xa806, 0xa806,   9 },
+	{ 0xa8c4, 0xa8c4,   9 },
+	{ 0xa8e0, 0xa8f1, 230 },
+	{ 0xa92b, 0xa92d, 220 },
+	{ 0xa953, 0xa953,   9 },
+	{ 0xa9b3, 0xa9b3,   7 },
+	{ 0xa9c0, 0xa9c0,   9 },
+	{ 0xaab0, 0xaab0, 230 },
+	{ 0xaab2, 0xaab3, 230 },
+	{ 0xaab4, 0xaab4, 220 },
+	{ 0xaab7, 0xaab8, 230 },
+	{ 0xaabe, 0xaabf, 230 },
+	{ 0xaac1, 0xaac1, 230 },
+	{ 0xaaf6, 0xaaf6,   9 },
+	{ 0xabed, 0xabed,   9 },
+	{ 0xfb1e, 0xfb1e,  26 },
+	{ 0xfe20, 0xfe26, 230 },
+	{ 0xfe27, 0xfe2d, 220 },
+	{ 0xfe2e, 0xfe2f, 230 },
+};
+
+/*
+ * Some HFS Plus catalog names contain characters whose canonical
+ * decomposition either was not yet defined, or was later corrected, in
+ * the version of Unicode this file's tables above were generated from
+ * (Apple Technote #1150, itself derived from pre-Unicode-3.0/pre-"Jaguar"
+ * (Mac OS X 10.2) data). macOS's own fsck_hfs has carried a permanent
+ * "FixDecomps" fixup for exactly this since 2002 (see
+ * fsck_hfs.tproj/dfalib/CatalogCheck.c and DecompData.h in the hfsprogs /
+ * diskdev_cmds sources) and flags any catalog name it finds still using
+ * the old form as "Illegal name". The two tables and functions below are
+ * a port of that same fixup data, decoded from hfsprogs 540.1's
+ * DecompData.h, so this driver stores names the same way macOS has since
+ * 10.2 rather than the way the original HFS Plus format documentation
+ * described in 2001.
+ */
+
+/* Category A: single code point -> missing canonical decomposition */
+/* 44 entries */
+struct hfsplus_legacy_decomp hfsplus_legacy_decomp_table[] = {
+	{ 0x01f8, 2, { 0x004e, 0x0300 } },
+	{ 0x01f9, 2, { 0x006e, 0x0300 } },
+	{ 0x0218, 2, { 0x0053, 0x0326 } },
+	{ 0x0219, 2, { 0x0073, 0x0326 } },
+	{ 0x021a, 2, { 0x0054, 0x0326 } },
+	{ 0x021b, 2, { 0x0074, 0x0326 } },
+	{ 0x021e, 2, { 0x0048, 0x030c } },
+	{ 0x021f, 2, { 0x0068, 0x030c } },
+	{ 0x0226, 2, { 0x0041, 0x0307 } },
+	{ 0x0227, 2, { 0x0061, 0x0307 } },
+	{ 0x0228, 2, { 0x0045, 0x0327 } },
+	{ 0x0229, 2, { 0x0065, 0x0327 } },
+	{ 0x022a, 3, { 0x004f, 0x0308, 0x0304 } },
+	{ 0x022b, 3, { 0x006f, 0x0308, 0x0304 } },
+	{ 0x022c, 3, { 0x004f, 0x0303, 0x0304 } },
+	{ 0x022d, 3, { 0x006f, 0x0303, 0x0304 } },
+	{ 0x022e, 2, { 0x004f, 0x0307 } },
+	{ 0x022f, 2, { 0x006f, 0x0307 } },
+	{ 0x0230, 3, { 0x004f, 0x0307, 0x0304 } },
+	{ 0x0231, 3, { 0x006f, 0x0307, 0x0304 } },
+	{ 0x0232, 2, { 0x0059, 0x0304 } },
+	{ 0x0233, 2, { 0x0079, 0x0304 } },
+	{ 0x0400, 2, { 0x0415, 0x0300 } },
+	{ 0x040d, 2, { 0x0418, 0x0300 } },
+	{ 0x0450, 2, { 0x0435, 0x0300 } },
+	{ 0x045d, 2, { 0x0438, 0x0300 } },
+	{ 0x04ec, 2, { 0x042d, 0x0308 } },
+	{ 0x04ed, 2, { 0x044d, 0x0308 } },
+	{ 0x0622, 2, { 0x0627, 0x0653 } },
+	{ 0x0623, 2, { 0x0627, 0x0654 } },
+	{ 0x0624, 2, { 0x0648, 0x0654 } },
+	{ 0x0625, 2, { 0x0627, 0x0655 } },
+	{ 0x0626, 2, { 0x064a, 0x0654 } },
+	{ 0x06c0, 2, { 0x06d5, 0x0654 } },
+	{ 0x06c2, 2, { 0x06c1, 0x0654 } },
+	{ 0x06d3, 2, { 0x06d2, 0x0654 } },
+	{ 0x0a33, 2, { 0x0a32, 0x0a3c } },
+	{ 0x0a36, 2, { 0x0a38, 0x0a3c } },
+	{ 0x0dda, 2, { 0x0dd9, 0x0dca } },
+	{ 0x0ddc, 2, { 0x0dd9, 0x0dcf } },
+	{ 0x0ddd, 3, { 0x0dd9, 0x0dcf, 0x0dca } },
+	{ 0x0dde, 2, { 0x0dd9, 0x0ddf } },
+	{ 0x1026, 2, { 0x1025, 0x102e } },
+	{ 0xfb1d, 2, { 0x05d9, 0x05b4 } },
+};
+
+/* Category B: 2-3 code point sequence -> corrected replacement */
+/* 25 entries */
+struct hfsplus_legacy_seq_fixup hfsplus_legacy_seq_fixups[] = {
+	{ 2, { 0x00a8, 0x030d }, 2, { 0x00a8, 0x0301 } },
+	{ 2, { 0x0306, 0x0307 }, 1, { 0x0310 } },
+	{ 2, { 0x0308, 0x030d }, 2, { 0x0308, 0x0301 } },
+	{ 2, { 0x0391, 0x030d }, 2, { 0x0391, 0x0301 } },
+	{ 2, { 0x0395, 0x030d }, 2, { 0x0395, 0x0301 } },
+	{ 2, { 0x0397, 0x030d }, 2, { 0x0397, 0x0301 } },
+	{ 2, { 0x0399, 0x030d }, 2, { 0x0399, 0x0301 } },
+	{ 2, { 0x039f, 0x030d }, 2, { 0x039f, 0x0301 } },
+	{ 2, { 0x03a5, 0x030d }, 2, { 0x03a5, 0x0301 } },
+	{ 2, { 0x03a9, 0x030d }, 2, { 0x03a9, 0x0301 } },
+	{ 2, { 0x03b1, 0x030d }, 2, { 0x03b1, 0x0301 } },
+	{ 2, { 0x03b5, 0x030d }, 2, { 0x03b5, 0x0301 } },
+	{ 2, { 0x03b7, 0x030d }, 2, { 0x03b7, 0x0301 } },
+	{ 2, { 0x03b9, 0x030d }, 2, { 0x03b9, 0x0301 } },
+	{ 2, { 0x03bf, 0x030d }, 2, { 0x03bf, 0x0301 } },
+	{ 2, { 0x03c5, 0x030d }, 2, { 0x03c5, 0x0301 } },
+	{ 2, { 0x03c9, 0x030d }, 2, { 0x03c9, 0x0301 } },
+	{ 2, { 0x03d2, 0x030d }, 2, { 0x03d2, 0x0301 } },
+	{ 2, { 0x09ac, 0x09bc }, 1, { 0x09b0 } },
+	{ 2, { 0x0a21, 0x0a3c }, 1, { 0x0a5c } },
+	{ 2, { 0x0b2f, 0x0b3c }, 1, { 0x0b5f } },
+	{ 2, { 0x0e4d, 0x0e32 }, 1, { 0x0e33 } },
+	{ 2, { 0x0ecd, 0x0eb2 }, 1, { 0x0eb3 } },
+	{ 3, { 0x0fb2, 0x0f80, 0x0f71 }, 1, { 0x0f77 } },
+	{ 3, { 0x0fb3, 0x0f80, 0x0f71 }, 1, { 0x0f79 } },
+};
+
+/*
+ * Look up the Unicode canonical combining class of a BMP code point.
+ * Returns 0 ("Not_Reordered") for any code point not listed in the table,
+ * which includes every ordinary base character.
+ */
+u8 hfsplus_combining_class(u16 c)
+{
+	int lo = 0, hi = ARRAY_SIZE(hfsplus_ccc_table) - 1;
+
+	while (lo <= hi) {
+		int mid = (lo + hi) / 2;
+		const struct hfsplus_ccc_range *r = &hfsplus_ccc_table[mid];
+
+		if (c < r->first)
+			hi = mid - 1;
+		else if (c > r->last)
+			lo = mid + 1;
+		else
+			return r->combining_class;
+	}
+
+	return 0;
+}
+
+/*
+ * Look up the corrected canonical decomposition for a single BMP code
+ * point that Apple Technote #1150's own decomposition table (above)
+ * lacks. Returns NULL (and leaves *size alone) if @uc isn't one of these.
+ */
+const u16 *hfsplus_legacy_decompose(u16 uc, int *size)
+{
+	int lo = 0, hi = ARRAY_SIZE(hfsplus_legacy_decomp_table) - 1;
+
+	while (lo <= hi) {
+		int mid = (lo + hi) / 2;
+		const struct hfsplus_legacy_decomp *e =
+				&hfsplus_legacy_decomp_table[mid];
+
+		if (uc < e->uc)
+			hi = mid - 1;
+		else if (uc > e->uc)
+			lo = mid + 1;
+		else {
+			*size = e->len;
+			return e->repl;
+		}
+	}
+
+	return NULL;
+}
+
+/*
+ * Scan an already decomposed and canonically-reordered code unit buffer
+ * for any of the short legacy sequences above and replace them in place
+ * with their corrected form. @len is updated to the buffer's new length.
+ */
+void hfsplus_fixup_legacy_sequences(u16 *buf, int *len)
+{
+	int i = 0;
+
+	while (i < *len) {
+		unsigned int j;
+		bool matched = false;
+
+		for (j = 0; j < ARRAY_SIZE(hfsplus_legacy_seq_fixups); j++) {
+			struct hfsplus_legacy_seq_fixup *f =
+						&hfsplus_legacy_seq_fixups[j];
+			u16 *src, *dst;
+			size_t copy_len;
+			int k;
+
+			if (i + f->match_len > *len)
+				continue;
+			for (k = 0; k < f->match_len; k++)
+				if (buf[i + k] != f->match[k])
+					break;
+			if (k != f->match_len)
+				continue;
+
+			dst = &buf[i + f->repl_len];
+			src = &buf[i + f->match_len];
+			copy_len = (*len - i - f->match_len) * sizeof(*buf);
+			memmove(dst, src, copy_len);
+
+			dst = &buf[i];
+			src = f->repl;
+			copy_len = f->repl_len * sizeof(*buf);
+			memcpy(dst, src, copy_len);
+
+			*len += f->repl_len - f->match_len;
+			matched = true;
+			break;
+		}
+
+		if (!matched)
+			i++;
+	}
+}
diff --git a/fs/hfsplus/unicode.c b/fs/hfsplus/unicode.c
index 008fec186382b..59b8788a69a9e 100644
--- a/fs/hfsplus/unicode.c
+++ b/fs/hfsplus/unicode.c
@@ -16,6 +16,7 @@
 
 #include "hfsplus_fs.h"
 #include "hfsplus_raw.h"
+#include "unicode.h"
 
 /* Fold the case of a unicode char, given the 16 bit value */
 /* Returns folded char, or 0 if ignorable */
@@ -441,45 +442,264 @@ static u16 *decompose_unichar(wchar_t uc, int *size, u16 *hangul_buffer)
 	*size = hfsplus_try_decompose_hangul(uc, result);
 	if (*size == 0)
 		result = hfsplus_decompose_nonhangul(uc, size);
+	if (!result) {
+		/*
+		 * Not every character with a canonical decomposition is in
+		 * Apple Technote #1150's own table above; a small, fixed
+		 * set was only added to the decomposition standard (or had
+		 * its decomposition corrected) after that table was
+		 * generated. hfsplus_legacy_decompose() covers those.
+		 */
+		const u16 *legacy = hfsplus_legacy_decompose(uc, size);
+
+		if (legacy)
+			result = memcpy(hangul_buffer, legacy,
+					*size * sizeof(*legacy));
+	}
 	return result;
 }
 
-int hfsplus_asc2uni(struct super_block *sb,
-		    struct hfsplus_unistr *ustr, int max_unistr_len,
-		    const char *astr, int len, int name_type)
+/*
+ * Apply the Unicode Canonical Ordering Algorithm to a decomposed name held
+ * as plain host-order code units: within each maximal run of characters
+ * that have a nonzero combining class, stable-sort the run into ascending
+ * combining-class order. A character with combining class 0 always starts
+ * a new run and is never itself reordered.
+ *
+ * hfsplus_decompose_table decomposes each source character on its own; it
+ * says nothing about how the decompositions of two different source
+ * characters should be ordered relative to each other when both produce
+ * combining marks that end up adjacent. Without this pass, such a
+ * sequence can be stored in an order that macOS's own fsck_hfs
+ * (FixDecomps() in CatalogCheck.c) considers illegal, even though every
+ * individual character was decomposed correctly.
+ */
+static void hfsplus_canonical_reorder(u16 *ustr, int len)
 {
-	int size, dsize, decompose;
-	u16 *dstr, outlen = 0;
-	wchar_t c;
-	u16 dhangul[3];
+	int i;
+
+	for (i = 1; i < len; i++) {
+		u8 cls = hfsplus_combining_class(ustr[i]);
+		int j = i;
+
+		if (!cls)
+			continue;
+
+		while (j > 0) {
+			u8 prev_cls = hfsplus_combining_class(ustr[j - 1]);
+			u16 tmp;
+
+			if (!prev_cls || prev_cls <= cls)
+				break;
+
+			tmp = ustr[j];
+			ustr[j] = ustr[j - 1];
+			ustr[j - 1] = tmp;
+			j--;
+		}
+	}
+}
+
+#define HFSPLUS_HANGUL_MAX_JAMO		(3)       /* L + V + optional T */
+
+static_assert(HFSPLUS_HANGUL_MAX_JAMO >= HFSPLUS_LEGACY_DECOMP_MAX_LEN,
+		"hangul_buffer must fit the longest legacy decomposition too");
+
+/*
+ * Decompose and canonically reorder an entire Linux name, as plain
+ * host-order code units. hfsplus_asc2uni(), hfsplus_hash_dentry() and
+ * hfsplus_compare_dentry() all go through this so that storage, hashing
+ * and comparison always agree on what a given name canonicalizes to.
+ *
+ * @out must hold at least @max_len entries, which must not exceed
+ * HFSPLUS_MAX_STRLEN. Returns the number of code units written. If
+ * @consumed is non-NULL, it is set to the number of input bytes actually
+ * consumed, which is less than @len when @out fills up first.
+ */
+static int hfsplus_decompose_str(struct super_block *sb, const char *astr,
+				  int len, int max_len, int name_type,
+				  u16 *out, int *consumed)
+{
+	int decompose = !test_bit(HFSPLUS_SB_NODECOMPOSE, &HFSPLUS_SB(sb)->flags);
+	const char *start = astr;
+	int outlen = 0;
+
+	while (outlen < max_len && len > 0) {
+		u16 *dstr;
+		u16 dhangul[HFSPLUS_HANGUL_MAX_JAMO];
+		int dsize, size;
+		wchar_t c;
 
-	decompose = !test_bit(HFSPLUS_SB_NODECOMPOSE, &HFSPLUS_SB(sb)->flags);
-	while (outlen < max_unistr_len && len > 0) {
 		size = asc2unichar(sb, astr, len, &c, name_type);
 
-		if (decompose)
-			dstr = decompose_unichar(c, &dsize, dhangul);
-		else
-			dstr = NULL;
+		dstr = decompose ? decompose_unichar(c, &dsize, dhangul) : NULL;
 		if (dstr) {
-			if (outlen + dsize > max_unistr_len)
+			if (outlen + dsize > max_len)
 				break;
 			do {
-				ustr->unicode[outlen++] = cpu_to_be16(*dstr++);
+				out[outlen++] = *dstr++;
 			} while (--dsize > 0);
-		} else
-			ustr->unicode[outlen++] = cpu_to_be16(c);
+		} else {
+			out[outlen++] = c;
+		}
 
 		astr += size;
 		len -= size;
 	}
+
+	hfsplus_canonical_reorder(out, outlen);
+	hfsplus_fixup_legacy_sequences(out, &outlen);
+	if (consumed)
+		*consumed = astr - start;
+	return outlen;
+}
+
+int hfsplus_asc2uni(struct super_block *sb,
+		    struct hfsplus_unistr *ustr, int max_unistr_len,
+		    const char *astr, int len, int name_type)
+{
+	u16 buf[HFSPLUS_MAX_STRLEN];
+	int outlen, i, consumed;
+
+	if (max_unistr_len > HFSPLUS_MAX_STRLEN)
+		max_unistr_len = HFSPLUS_MAX_STRLEN;
+
+	outlen = hfsplus_decompose_str(sb, astr, len, max_unistr_len,
+				       name_type, buf, &consumed);
+	for (i = 0; i < outlen; i++)
+		ustr->unicode[i] = cpu_to_be16(buf[i]);
 	ustr->length = cpu_to_be16(outlen);
-	if (len > 0)
+
+	if (consumed < len)
 		return -ENAMETOOLONG;
 	return 0;
 }
 EXPORT_SYMBOL_IF_KUNIT(hfsplus_asc2uni);
 
+/*
+ * Maximum length of a single maximal run of nonzero-combining-class code
+ * units that hfsplus_decompose_iter_next() below will canonically
+ * reorder. Every code unit with combining class 0 starts a new run, so
+ * this only bounds how many *consecutive* combining marks between two
+ * base characters get sorted - real text, and even deliberately
+ * adversarial "Zalgo" text, essentially never approaches this. Keeping
+ * it small means hfsplus_hash_dentry() and hfsplus_compare_dentry() only
+ * ever need a tiny amount of lookahead state, rather than buffering an
+ * entire (up to 255-unit) name.
+ */
+#define HFSPLUS_CCC_RUN_MAX 32
+
+/*
+ * Iterator that produces the canonically-ordered, decomposed code units
+ * of a Linux name one at a time, without materializing the whole name.
+ * hfsplus_hash_dentry() and hfsplus_compare_dentry() use this so that
+ * hashing and comparison always agree with what hfsplus_asc2uni() would
+ * actually store, while still comparing lazily (stopping at the first
+ * difference) the way this code did before canonical reordering existed.
+ */
+struct hfsplus_decompose_iter {
+	struct super_block *sb;
+	const char *astr;
+	int len;
+	int name_type;
+	int decompose;
+
+	u16 run[HFSPLUS_CCC_RUN_MAX];
+	int run_len;
+	int run_pos;
+};
+
+static void hfsplus_decompose_iter_init(struct hfsplus_decompose_iter *it,
+					struct super_block *sb,
+					const char *astr, int len,
+					int name_type)
+{
+	it->sb = sb;
+	it->astr = astr;
+	it->len = len;
+	it->name_type = name_type;
+	it->decompose = !test_bit(HFSPLUS_SB_NODECOMPOSE, &HFSPLUS_SB(sb)->flags);
+	it->run_len = 0;
+	it->run_pos = 0;
+}
+
+/*
+ * Gather the next maximal run of nonzero-combining-class code units
+ * (starting with whatever character comes next, base or not) and
+ * canonically reorder just that run. A character is only included once
+ * we know the class of the first unit it produces, so decoding it is
+ * speculative until that's decided.
+ */
+static bool hfsplus_decompose_iter_refill(struct hfsplus_decompose_iter *it)
+{
+	it->run_pos = 0;
+	it->run_len = 0;
+
+	while (it->len > 0) {
+		u16 *dstr;
+		u16 dhangul[HFSPLUS_HANGUL_MAX_JAMO];
+		int dsize, size;
+		wchar_t c;
+
+		size = asc2unichar(it->sb, it->astr, it->len, &c,
+				   it->name_type);
+
+		dstr = it->decompose ?
+			decompose_unichar(c, &dsize, dhangul) : NULL;
+		if (!dstr) {
+			dhangul[0] = c;
+			dstr = dhangul;
+			dsize = 1;
+		}
+
+		if (it->run_len > 0 && !hfsplus_combining_class(dstr[0]))
+			break;
+
+		if (it->run_len + dsize > HFSPLUS_CCC_RUN_MAX)
+			break;
+
+		it->astr += size;
+		it->len -= size;
+
+		do {
+			it->run[it->run_len++] = *dstr++;
+		} while (--dsize > 0);
+	}
+
+	hfsplus_canonical_reorder(it->run, it->run_len);
+	hfsplus_fixup_legacy_sequences(it->run, &it->run_len);
+	return it->run_len > 0;
+}
+
+/* Returns the next code unit, or a negative value once @it is exhausted. */
+static int hfsplus_decompose_iter_next(struct hfsplus_decompose_iter *it)
+{
+	if (it->run_pos >= it->run_len && !hfsplus_decompose_iter_refill(it))
+		return -1;
+	return it->run[it->run_pos++];
+}
+
+/*
+ * Returns the next code unit that matters for comparison/hashing: folded
+ * if @casefold, with any character folding to 0 ("ignorable") skipped
+ * entirely. Returns a negative value once @it is exhausted.
+ */
+static int hfsplus_decompose_iter_next_folded(struct hfsplus_decompose_iter *it,
+					      int casefold)
+{
+	int c;
+
+	do {
+		c = hfsplus_decompose_iter_next(it);
+		if (c < 0)
+			return -1;
+		if (casefold)
+			c = case_fold(c);
+	} while (casefold && !c);
+
+	return c;
+}
+
 /*
  * Hash a string to an integer as appropriate for the HFS+ filesystem.
  * Composed unicode characters are decomposed and case-folding is performed
@@ -488,45 +708,17 @@ EXPORT_SYMBOL_IF_KUNIT(hfsplus_asc2uni);
 int hfsplus_hash_dentry(const struct dentry *dentry, struct qstr *str)
 {
 	struct super_block *sb = dentry->d_sb;
-	const char *astr;
-	const u16 *dstr;
-	int casefold, decompose, size, len;
+	int casefold = test_bit(HFSPLUS_SB_CASEFOLD, &HFSPLUS_SB(sb)->flags);
+	struct hfsplus_decompose_iter it;
 	unsigned long hash;
-	wchar_t c;
-	u16 c2;
-	u16 dhangul[3];
+	int c;
 
-	casefold = test_bit(HFSPLUS_SB_CASEFOLD, &HFSPLUS_SB(sb)->flags);
-	decompose = !test_bit(HFSPLUS_SB_NODECOMPOSE, &HFSPLUS_SB(sb)->flags);
-	hash = init_name_hash(dentry);
-	astr = str->name;
-	len = str->len;
-	while (len > 0) {
-		int dsize;
-		size = asc2unichar(sb, astr, len, &c, HFS_REGULAR_NAME);
-		astr += size;
-		len -= size;
+	hfsplus_decompose_iter_init(&it, sb, str->name, str->len,
+				    HFS_REGULAR_NAME);
 
-		if (decompose)
-			dstr = decompose_unichar(c, &dsize, dhangul);
-		else
-			dstr = NULL;
-		if (dstr) {
-			do {
-				c2 = *dstr++;
-				if (casefold)
-					c2 = case_fold(c2);
-				if (!casefold || c2)
-					hash = partial_name_hash(c2, hash);
-			} while (--dsize > 0);
-		} else {
-			c2 = c;
-			if (casefold)
-				c2 = case_fold(c2);
-			if (!casefold || c2)
-				hash = partial_name_hash(c2, hash);
-		}
-	}
+	hash = init_name_hash(dentry);
+	while ((c = hfsplus_decompose_iter_next_folded(&it, casefold)) >= 0)
+		hash = partial_name_hash(c, hash);
 	str->hash = end_name_hash(hash);
 
 	return 0;
@@ -542,87 +734,21 @@ int hfsplus_compare_dentry(const struct dentry *dentry,
 		unsigned int len, const char *str, const struct qstr *name)
 {
 	struct super_block *sb = dentry->d_sb;
-	int casefold, decompose, size;
-	int dsize1, dsize2, len1, len2;
-	const u16 *dstr1, *dstr2;
-	const char *astr1, *astr2;
-	u16 c1, c2;
-	wchar_t c;
-	u16 dhangul_1[3], dhangul_2[3];
-
-	casefold = test_bit(HFSPLUS_SB_CASEFOLD, &HFSPLUS_SB(sb)->flags);
-	decompose = !test_bit(HFSPLUS_SB_NODECOMPOSE, &HFSPLUS_SB(sb)->flags);
-	astr1 = str;
-	len1 = len;
-	astr2 = name->name;
-	len2 = name->len;
-	dsize1 = dsize2 = 0;
-	dstr1 = dstr2 = NULL;
-
-	while (len1 > 0 && len2 > 0) {
-		if (!dsize1) {
-			size = asc2unichar(sb, astr1, len1, &c,
-					   HFS_REGULAR_NAME);
-			astr1 += size;
-			len1 -= size;
-
-			if (decompose)
-				dstr1 = decompose_unichar(c, &dsize1,
-							  dhangul_1);
-			if (!decompose || !dstr1) {
-				c1 = c;
-				dstr1 = &c1;
-				dsize1 = 1;
-			}
-		}
+	int casefold = test_bit(HFSPLUS_SB_CASEFOLD, &HFSPLUS_SB(sb)->flags);
+	struct hfsplus_decompose_iter it1, it2;
 
-		if (!dsize2) {
-			size = asc2unichar(sb, astr2, len2, &c,
-					   HFS_REGULAR_NAME);
-			astr2 += size;
-			len2 -= size;
-
-			if (decompose)
-				dstr2 = decompose_unichar(c, &dsize2,
-							  dhangul_2);
-			if (!decompose || !dstr2) {
-				c2 = c;
-				dstr2 = &c2;
-				dsize2 = 1;
-			}
-		}
+	hfsplus_decompose_iter_init(&it1, sb, str, len, HFS_REGULAR_NAME);
+	hfsplus_decompose_iter_init(&it2, sb, name->name, name->len,
+				    HFS_REGULAR_NAME);
 
-		c1 = *dstr1;
-		c2 = *dstr2;
-		if (casefold) {
-			c1 = case_fold(c1);
-			if (!c1) {
-				dstr1++;
-				dsize1--;
-				continue;
-			}
-			c2 = case_fold(c2);
-			if (!c2) {
-				dstr2++;
-				dsize2--;
-				continue;
-			}
-		}
-		if (c1 < c2)
-			return -1;
-		else if (c1 > c2)
-			return 1;
+	while (1) {
+		int c1 = hfsplus_decompose_iter_next_folded(&it1, casefold);
+		int c2 = hfsplus_decompose_iter_next_folded(&it2, casefold);
 
-		dstr1++;
-		dsize1--;
-		dstr2++;
-		dsize2--;
+		if (c1 < 0 || c2 < 0)
+			return c1 == c2 ? 0 : (c1 < 0 ? -1 : 1);
+		if (c1 != c2)
+			return c1 < c2 ? -1 : 1;
 	}
-
-	if (len1 < len2)
-		return -1;
-	if (len1 > len2)
-		return 1;
-	return 0;
 }
 EXPORT_SYMBOL_IF_KUNIT(hfsplus_compare_dentry);
diff --git a/fs/hfsplus/unicode.h b/fs/hfsplus/unicode.h
new file mode 100644
index 0000000000000..31cc7691c9162
--- /dev/null
+++ b/fs/hfsplus/unicode.h
@@ -0,0 +1,63 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Unicode related declarations
+ */
+
+#ifndef _LINUX_HFSPLUS_UNICODE_H
+#define _LINUX_HFSPLUS_UNICODE_H
+
+/*
+ * struct hfsplus_ccc_range - one run of consecutive BMP code points that
+ *                            share the same Unicode canonical combining class
+ * @first: the first UTF-16 code point in the run
+ * @last: the last code point in the run (inclusive)
+ * @combining_class: canonical combining class (ccc) shared by @first..@last
+ */
+struct hfsplus_ccc_range {
+	u16 first;
+	u16 last;
+	u8 combining_class;
+};
+
+/*
+ * struct hfsplus_legacy_decomp - corrected canonical decomposition
+ * @uc: the code point (a UTF-16 code unit) to look up
+ * @len: number of valid code units in @repl
+ * @repl: corrected decomposition sequence (base letter + combining marks)
+ */
+struct hfsplus_legacy_decomp {
+	u16 uc;
+	u8 len;
+#define HFSPLUS_LEGACY_DECOMP_MAX_LEN	(3)
+	u16 repl[HFSPLUS_LEGACY_DECOMP_MAX_LEN];
+};
+
+/*
+ * struct hfsplus_legacy_seq_fixup - corrected replacement for a short
+ *                                   sequence of already-decomposed code units
+ * @match_len: number of valid code units in @match
+ * @match: decomposed sequence to look for in the buffer
+ * @repl_len: number of valid code units in @repl
+ * @repl: corrected sequence to substitute in place of @match
+ */
+struct hfsplus_legacy_seq_fixup {
+	u8 match_len;
+#define HFSPLUS_LEGACY_SEQ_MAX_MATCH	(3)
+	u16 match[HFSPLUS_LEGACY_SEQ_MAX_MATCH];
+	u8 repl_len;
+#define HFSPLUS_LEGACY_SEQ_MAX_REPL	(2)
+	u16 repl[HFSPLUS_LEGACY_SEQ_MAX_REPL];
+};
+
+extern u16 hfsplus_case_fold_table[];
+extern u16 hfsplus_decompose_table[];
+extern u16 hfsplus_compose_table[];
+extern struct hfsplus_ccc_range hfsplus_ccc_table[];
+extern struct hfsplus_legacy_decomp hfsplus_legacy_decomp_table[];
+extern struct hfsplus_legacy_seq_fixup hfsplus_legacy_seq_fixups[];
+
+u8 hfsplus_combining_class(u16 c);
+const u16 *hfsplus_legacy_decompose(u16 uc, int *size);
+void hfsplus_fixup_legacy_sequences(u16 *buf, int *len);
+
+#endif /* _LINUX_HFSPLUS_UNICODE_H */
diff --git a/fs/hfsplus/unicode_test.c b/fs/hfsplus/unicode_test.c
index 7f6b2a3c69d9a..a683c6d5fc221 100644
--- a/fs/hfsplus/unicode_test.c
+++ b/fs/hfsplus/unicode_test.c
@@ -10,6 +10,7 @@
 #include <linux/dcache.h>
 #include <linux/stringhash.h>
 #include "hfsplus_fs.h"
+#include "unicode.h"
 
 struct test_mock_string_env {
 	struct hfsplus_unistr str1;
@@ -947,6 +948,223 @@ static void hfsplus_asc2uni_decompose_test(struct kunit *test)
 	free_mock_sb(mock_sb);
 }
 
+/*
+ * Real UTF-8 <-> wchar_t conversion, mirroring what the "utf8" NLS table
+ * actually does (see char2uni()/uni2char() in fs/nls/nls_utf8.c). The
+ * test_char2uni()/test_uni2char() stand-ins above only handle one raw
+ * byte per character, which cannot represent the combining marks (e.g.
+ * U+0301, U+0323) the canonical-reordering tests below need.
+ */
+static int test_char2uni_utf8(const unsigned char *rawstring, int boundlen,
+			      wchar_t *uni)
+{
+	unicode_t u;
+	int n = utf8_to_utf32(rawstring, boundlen, &u);
+
+	if (n < 0 || u > MAX_WCHAR_T) {
+		*uni = 0x3f; /* ? */
+		return -EINVAL;
+	}
+	*uni = (wchar_t)u;
+	return n;
+}
+
+static int test_uni2char_utf8(wchar_t uni, unsigned char *out, int boundlen)
+{
+	int n = utf32_to_utf8(uni, out, boundlen);
+
+	if (n < 0) {
+		*out = '?';
+		return -EINVAL;
+	}
+	return n;
+}
+
+/*
+ * Test that hfsplus_asc2uni() brings combining marks contributed by
+ * different source characters into Unicode canonical (combining-class)
+ * order, instead of just storing them in whatever order they were typed.
+ *
+ * U+0301 (COMBINING ACUTE ACCENT) has combining class 230; U+0323
+ * (COMBINING DOT BELOW) has combining class 220. Since 220 < 230,
+ * canonical order requires the dot-below before the acute. A name
+ * created with them typed in the "wrong" order must still end up stored
+ * in canonical order - this is exactly what macOS's own fsck_hfs
+ * (FixDecomps() in CatalogCheck.c) requires and flags as "Illegal name"
+ * when it isn't true.
+ */
+static void hfsplus_asc2uni_combining_reorder_test(struct kunit *test)
+{
+	struct test_mock_sb *mock_sb;
+	struct hfsplus_unistr ustr;
+	/* "e" + COMBINING ACUTE ACCENT (U+0301) + COMBINING DOT BELOW (U+0323) */
+	static const char wrong_order[] = "e\xcc\x81\xcc\xa3";
+	/* "e" + COMBINING DOT BELOW (U+0323) + COMBINING ACUTE ACCENT (U+0301) */
+	static const char canonical_order[] = "e\xcc\xa3\xcc\x81";
+	/* Two class-230 marks: GRAVE (U+0300) then ACUTE (U+0301) */
+	static const char same_class[] = "e\xcc\x80\xcc\x81";
+	int result;
+
+	mock_sb = setup_mock_sb();
+	KUNIT_ASSERT_NOT_NULL(test, mock_sb);
+
+	mock_sb->nls.char2uni = test_char2uni_utf8;
+
+	/* Typed out of canonical order: must be reordered on storage. */
+	result = hfsplus_asc2uni(&mock_sb->sb, &ustr, HFSPLUS_MAX_STRLEN,
+				 wrong_order, strlen(wrong_order),
+				 HFS_REGULAR_NAME);
+
+	KUNIT_EXPECT_EQ(test, 0, result);
+	KUNIT_EXPECT_EQ(test, 3, be16_to_cpu(ustr.length));
+	KUNIT_EXPECT_EQ(test, 'e', be16_to_cpu(ustr.unicode[0]));
+	KUNIT_EXPECT_EQ(test, 0x0323, be16_to_cpu(ustr.unicode[1]));
+	KUNIT_EXPECT_EQ(test, 0x0301, be16_to_cpu(ustr.unicode[2]));
+
+	/* Already in canonical order: must come out unchanged. */
+	result = hfsplus_asc2uni(&mock_sb->sb, &ustr, HFSPLUS_MAX_STRLEN,
+				 canonical_order, strlen(canonical_order),
+				 HFS_REGULAR_NAME);
+
+	KUNIT_EXPECT_EQ(test, 0, result);
+	KUNIT_EXPECT_EQ(test, 3, be16_to_cpu(ustr.length));
+	KUNIT_EXPECT_EQ(test, 'e', be16_to_cpu(ustr.unicode[0]));
+	KUNIT_EXPECT_EQ(test, 0x0323, be16_to_cpu(ustr.unicode[1]));
+	KUNIT_EXPECT_EQ(test, 0x0301, be16_to_cpu(ustr.unicode[2]));
+
+	/* Two marks of equal combining class must keep their relative
+	 * (input) order - the sort must be stable, not just "sorted".
+	 */
+	result = hfsplus_asc2uni(&mock_sb->sb, &ustr, HFSPLUS_MAX_STRLEN,
+				 same_class, strlen(same_class),
+				 HFS_REGULAR_NAME);
+
+	KUNIT_EXPECT_EQ(test, 0, result);
+	KUNIT_EXPECT_EQ(test, 3, be16_to_cpu(ustr.length));
+	KUNIT_EXPECT_EQ(test, 'e', be16_to_cpu(ustr.unicode[0]));
+	KUNIT_EXPECT_EQ(test, 0x0300, be16_to_cpu(ustr.unicode[1]));
+	KUNIT_EXPECT_EQ(test, 0x0301, be16_to_cpu(ustr.unicode[2]));
+
+	free_mock_sb(mock_sb);
+}
+
+/*
+ * Test that a name written with combining marks in non-canonical order
+ * still reads back as valid, correct UTF-8 once reordered - i.e. that
+ * hfsplus_asc2uni() and hfsplus_uni2asc_str() stay consistent with each
+ * other across the reordering.
+ *
+ * NODECOMPOSE is set so hfsplus_uni2asc_str() doesn't also recompose
+ * "e" + COMBINING DOT BELOW back into the precomposed U+1EB9 ("e"): that
+ * composition behavior is real (and already covered elsewhere), but it
+ * would obscure what this test is actually checking.
+ */
+static void hfsplus_unicode_combining_reorder_roundtrip_test(struct kunit *test)
+{
+	struct test_mock_sb *mock_sb;
+	struct hfsplus_unistr ustr;
+	static const char wrong_order[] = "e\xcc\x81\xcc\xa3";
+	static const char expected[] = "e\xcc\xa3\xcc\x81"; /* canonical order */
+	char buf[32];
+	int len = sizeof(buf);
+	int result;
+
+	mock_sb = setup_mock_sb();
+	KUNIT_ASSERT_NOT_NULL(test, mock_sb);
+
+	set_bit(HFSPLUS_SB_NODECOMPOSE, &mock_sb->sb_info.flags);
+	mock_sb->nls.char2uni = test_char2uni_utf8;
+	mock_sb->nls.uni2char = test_uni2char_utf8;
+
+	result = hfsplus_asc2uni(&mock_sb->sb, &ustr, HFSPLUS_MAX_STRLEN,
+				 wrong_order, strlen(wrong_order),
+				 HFS_REGULAR_NAME);
+	KUNIT_EXPECT_EQ(test, 0, result);
+
+	result = hfsplus_uni2asc_str(&mock_sb->sb, &ustr, buf, &len);
+
+	KUNIT_EXPECT_EQ(test, 0, result);
+	KUNIT_EXPECT_EQ(test, (int)strlen(expected), len);
+	KUNIT_EXPECT_MEMEQ(test, expected, buf, len);
+
+	free_mock_sb(mock_sb);
+}
+
+/*
+ * Test that hfsplus_asc2uni() decomposes a character using the corrected
+ * (post-2002/"Jaguar") canonical decomposition even when Apple Technote
+ * #1150's own decomposition table doesn't have an entry for it.
+ *
+ * U+01F8 (LATIN CAPITAL LETTER N WITH GRAVE) is exactly one of the
+ * characters macOS's own fsck_hfs (FixDecomps() in CatalogCheck.c) has
+ * flagged "Illegal name" for since 2002 when found stored undecomposed.
+ */
+static void hfsplus_asc2uni_legacy_decomp_test(struct kunit *test)
+{
+	struct test_mock_sb *mock_sb;
+	struct hfsplus_unistr ustr;
+	static const char input[] = "\xc7\xb8"; /* U+01F8 */
+	int result;
+
+	mock_sb = setup_mock_sb();
+	KUNIT_ASSERT_NOT_NULL(test, mock_sb);
+
+	mock_sb->nls.char2uni = test_char2uni_utf8;
+
+	result = hfsplus_asc2uni(&mock_sb->sb, &ustr, HFSPLUS_MAX_STRLEN,
+				 input, strlen(input), HFS_REGULAR_NAME);
+
+	KUNIT_EXPECT_EQ(test, 0, result);
+	KUNIT_EXPECT_EQ(test, 2, be16_to_cpu(ustr.length));
+	KUNIT_EXPECT_EQ(test, 'N', be16_to_cpu(ustr.unicode[0]));
+	KUNIT_EXPECT_EQ(test, 0x0300, be16_to_cpu(ustr.unicode[1]));
+
+	free_mock_sb(mock_sb);
+}
+
+/*
+ * Test that hfsplus_asc2uni() corrects two more of fsck_hfs's known
+ * legacy decomposition sequences once combining marks from independently
+ * typed characters end up adjacent:
+ *
+ *  - GREEK SMALL LETTER ALPHA (U+03B1) + COMBINING VERTICAL LINE ABOVE
+ *    (U+030D) must become U+03B1 + COMBINING ACUTE ACCENT (U+0301).
+ *  - BENGALI LETTER BA (U+09AC) + BENGALI SIGN NUKTA (U+09BC) must become
+ *    the single character BENGALI LETTER RA WITH MIDDLE DIAGONAL (U+09B0).
+ */
+static void hfsplus_asc2uni_legacy_seq_fixup_test(struct kunit *test)
+{
+	struct test_mock_sb *mock_sb;
+	struct hfsplus_unistr ustr;
+	static const char greek_input[] = "\xce\xb1\xcc\x8d"; /* U+03B1 U+030D */
+	static const char bengali_input[] = "\xe0\xa6\xac\xe0\xa6\xbc"; /* U+09AC U+09BC */
+	int result;
+
+	mock_sb = setup_mock_sb();
+	KUNIT_ASSERT_NOT_NULL(test, mock_sb);
+
+	mock_sb->nls.char2uni = test_char2uni_utf8;
+
+	result = hfsplus_asc2uni(&mock_sb->sb, &ustr, HFSPLUS_MAX_STRLEN,
+				 greek_input, strlen(greek_input),
+				 HFS_REGULAR_NAME);
+
+	KUNIT_EXPECT_EQ(test, 0, result);
+	KUNIT_EXPECT_EQ(test, 2, be16_to_cpu(ustr.length));
+	KUNIT_EXPECT_EQ(test, 0x03b1, be16_to_cpu(ustr.unicode[0]));
+	KUNIT_EXPECT_EQ(test, 0x0301, be16_to_cpu(ustr.unicode[1]));
+
+	result = hfsplus_asc2uni(&mock_sb->sb, &ustr, HFSPLUS_MAX_STRLEN,
+				 bengali_input, strlen(bengali_input),
+				 HFS_REGULAR_NAME);
+
+	KUNIT_EXPECT_EQ(test, 0, result);
+	KUNIT_EXPECT_EQ(test, 1, be16_to_cpu(ustr.length));
+	KUNIT_EXPECT_EQ(test, 0x09b0, be16_to_cpu(ustr.unicode[0]));
+
+	free_mock_sb(mock_sb);
+}
+
 /* Mock dentry for testing hfsplus_hash_dentry */
 static struct dentry test_dentry;
 
@@ -1230,6 +1448,37 @@ static void hfsplus_hash_dentry_edge_cases_test(struct kunit *test)
 	free_mock_sb(mock_sb);
 }
 
+/*
+ * Test that hfsplus_hash_dentry() hashes two names identically when they
+ * differ only in the (non-canonical) typed order of the same combining
+ * marks - both must canonicalize to the same stored form, so they must
+ * hash the same or dcache lookups would spuriously miss.
+ */
+static void hfsplus_hash_dentry_combining_reorder_test(struct kunit *test)
+{
+	struct test_mock_sb *mock_sb;
+	struct qstr str1, str2;
+	int result;
+
+	mock_sb = setup_mock_sb();
+	KUNIT_ASSERT_NOT_NULL(test, mock_sb);
+
+	setup_mock_dentry(&mock_sb->sb);
+	mock_sb->nls.char2uni = test_char2uni_utf8;
+
+	create_qstr(&str1, "e\xcc\x81\xcc\xa3"); /* acute, then dot-below */
+	result = hfsplus_hash_dentry(&test_dentry, &str1);
+	KUNIT_EXPECT_EQ(test, 0, result);
+
+	create_qstr(&str2, "e\xcc\xa3\xcc\x81"); /* dot-below, then acute */
+	result = hfsplus_hash_dentry(&test_dentry, &str2);
+	KUNIT_EXPECT_EQ(test, 0, result);
+
+	KUNIT_EXPECT_EQ(test, str1.hash, str2.hash);
+
+	free_mock_sb(mock_sb);
+}
+
 /* Test hfsplus_compare_dentry basic functionality */
 static void hfsplus_compare_dentry_basic_test(struct kunit *test)
 {
@@ -1552,6 +1801,59 @@ static void hfsplus_compare_dentry_combined_flags_test(struct kunit *test)
 	free_mock_sb(mock_sb);
 }
 
+/*
+ * Test that hfsplus_compare_dentry() treats two names as equal when they
+ * differ only in the (non-canonical) typed order of the same combining
+ * marks, since both refer to the same canonically-ordered catalog entry.
+ */
+static void hfsplus_compare_dentry_combining_reorder_test(struct kunit *test)
+{
+	struct test_mock_sb *mock_sb;
+	struct qstr name;
+	int result;
+
+	mock_sb = setup_mock_sb();
+	KUNIT_ASSERT_NOT_NULL(test, mock_sb);
+
+	setup_mock_dentry(&mock_sb->sb);
+	mock_sb->nls.char2uni = test_char2uni_utf8;
+
+	create_qstr(&name, "e\xcc\xa3\xcc\x81"); /* dot-below, then acute */
+	result = hfsplus_compare_dentry(&test_dentry, 5, "e\xcc\x81\xcc\xa3",
+					&name); /* acute, then dot-below */
+	KUNIT_EXPECT_EQ(test, 0, result);
+
+	free_mock_sb(mock_sb);
+}
+
+/*
+ * Test that a precomposed character using one of fsck_hfs's known legacy
+ * decompositions compares equal to the already-decomposed form of the
+ * same character - i.e. that hfsplus_compare_dentry() applies the same
+ * legacy-decomposition correction as hfsplus_asc2uni() does on storage,
+ * so a lookup finds the entry regardless of which form was typed.
+ */
+static void hfsplus_compare_dentry_legacy_decomp_test(struct kunit *test)
+{
+	struct test_mock_sb *mock_sb;
+	struct qstr name;
+	int result;
+
+	mock_sb = setup_mock_sb();
+	KUNIT_ASSERT_NOT_NULL(test, mock_sb);
+
+	setup_mock_dentry(&mock_sb->sb);
+	mock_sb->nls.char2uni = test_char2uni_utf8;
+
+	/* "N" + COMBINING GRAVE ACCENT (U+0300), already decomposed */
+	create_qstr(&name, "N\xcc\x80");
+	/* U+01F8, precomposed */
+	result = hfsplus_compare_dentry(&test_dentry, 2, "\xc7\xb8", &name);
+	KUNIT_EXPECT_EQ(test, 0, result);
+
+	free_mock_sb(mock_sb);
+}
+
 static struct kunit_case hfsplus_unicode_test_cases[] = {
 	KUNIT_CASE(hfsplus_strcasecmp_test),
 	KUNIT_CASE(hfsplus_strcmp_test),
@@ -1567,12 +1869,17 @@ static struct kunit_case hfsplus_unicode_test_cases[] = {
 	KUNIT_CASE(hfsplus_asc2uni_buffer_limits_test),
 	KUNIT_CASE(hfsplus_asc2uni_edge_cases_test),
 	KUNIT_CASE(hfsplus_asc2uni_decompose_test),
+	KUNIT_CASE(hfsplus_asc2uni_combining_reorder_test),
+	KUNIT_CASE(hfsplus_unicode_combining_reorder_roundtrip_test),
+	KUNIT_CASE(hfsplus_asc2uni_legacy_decomp_test),
+	KUNIT_CASE(hfsplus_asc2uni_legacy_seq_fixup_test),
 	KUNIT_CASE(hfsplus_hash_dentry_basic_test),
 	KUNIT_CASE(hfsplus_hash_dentry_casefold_test),
 	KUNIT_CASE(hfsplus_hash_dentry_special_chars_test),
 	KUNIT_CASE(hfsplus_hash_dentry_decompose_test),
 	KUNIT_CASE(hfsplus_hash_dentry_consistency_test),
 	KUNIT_CASE(hfsplus_hash_dentry_edge_cases_test),
+	KUNIT_CASE(hfsplus_hash_dentry_combining_reorder_test),
 	KUNIT_CASE(hfsplus_compare_dentry_basic_test),
 	KUNIT_CASE(hfsplus_compare_dentry_casefold_test),
 	KUNIT_CASE(hfsplus_compare_dentry_special_chars_test),
@@ -1580,6 +1887,8 @@ static struct kunit_case hfsplus_unicode_test_cases[] = {
 	KUNIT_CASE(hfsplus_compare_dentry_decompose_test),
 	KUNIT_CASE(hfsplus_compare_dentry_edge_cases_test),
 	KUNIT_CASE(hfsplus_compare_dentry_combined_flags_test),
+	KUNIT_CASE(hfsplus_compare_dentry_combining_reorder_test),
+	KUNIT_CASE(hfsplus_compare_dentry_legacy_decomp_test),
 	{}
 };
 

3/2 2026/09/21 03:51 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 25649
							output: 28
							thoughts: 132
						

Thoughts:
**Reviewing a HFS+ Filesystem Patch for Fuzzing Suitability**

Okay, so I've been asked to take a look at this patch and decide if it's worth targeting with syzkaller. First, let's dive into the code. Right, it's modifying HFS+ filesystem code, which is always interesting. I see changes across `fs/hfsplus/hfsplus_fs.h`, `fs/hfsplus/tables.c`, `fs/hfsplus/unicode.c`, `fs/hfsplus/unicode.h`, and `fs/hfsplus/unicode_test.c`. That's a good spread, touching on core structures, tables, Unicode handling, and a test file. That indicates a potential for a decent impact, which is a good sign for potential fuzzing efforts.

Before going deeper into the patch, let me quickly confirm what configurations are involved, I'll check `fs/hfsplus/Kconfig`. It's important to understand the build configurations to see the dependencies for a proper assessment.



4/2 2026/09/21 03:51 tool grepper
0m Args:
{
  "Expression": "HFSPLUS",
  "PathPrefix": "fs/hfsplus"
}

Results:
{
  "Output": "\nFull output is too long, showing 500 out of 2284 lines.\nUse more precise expression if possible.\n\nfs/hfsplus/.kunitconfig=1=CONFIG_KUNIT=y\nfs/hfsplus/.kunitconfig:2:CONFIG_HFSPLUS_FS=y\nfs/hfsplus/.kunitconfig:3:CONFIG_HFSPLUS_KUNIT_TEST=y\nfs/hfsplus/.kunitconfig-4-CONFIG_BLOCK=y\n--\nfs/hfsplus/Kconfig-1-# SPDX-License-Identifier: GPL-2.0-only\nfs/hfsplus/Kconfig:2:config HFSPLUS_FS\nfs/hfsplus/Kconfig-3-\ttristate \"Apple Extended HFS file system support\"\n--\nfs/hfsplus/Kconfig-17-\nfs/hfsplus/Kconfig:18:config HFSPLUS_KUNIT_TEST\nfs/hfsplus/Kconfig-19-\ttristate \"KUnit tests for HFS+ filesystem\" if !KUNIT_ALL_TESTS\nfs/hfsplus/Kconfig:20:\tdepends on HFSPLUS_FS \u0026\u0026 KUNIT\nfs/hfsplus/Kconfig-21-\tdefault KUNIT_ALL_TESTS\n--\nfs/hfsplus/Makefile-5-\nfs/hfsplus/Makefile:6:obj-$(CONFIG_HFSPLUS_FS) += hfsplus.o\nfs/hfsplus/Makefile-7-\nfs/hfsplus/Makefile=8=hfsplus-objs := super.o options.o inode.o ioctl.o extents.o catalog.o dir.o btree.o \\\n--\nfs/hfsplus/Makefile-12-# KUnit tests\nfs/hfsplus/Makefile:13:obj-$(CONFIG_HFSPLUS_KUNIT_TEST) += unicode_test.o\n--\nfs/hfsplus/attributes.c=50=int hfsplus_attr_build_key(struct super_block *sb, hfsplus_btree_key *key,\n--\nfs/hfsplus/attributes.c-59-\t\t\t\t(struct hfsplus_unistr *)\u0026key-\u003eattr.key_name,\nfs/hfsplus/attributes.c:60:\t\t\t\tHFSPLUS_ATTR_MAX_STRLEN, name, strlen(name),\nfs/hfsplus/attributes.c-61-\t\t\t\tHFS_XATTR_NAME);\n--\nfs/hfsplus/attributes.c=89=void hfsplus_destroy_attr_entry(hfsplus_attr_entry *entry)\n--\nfs/hfsplus/attributes.c-94-\nfs/hfsplus/attributes.c:95:#define HFSPLUS_INVALID_ATTR_RECORD -1\nfs/hfsplus/attributes.c-96-\nfs/hfsplus/attributes.c=97=static int hfsplus_attr_build_record(hfsplus_attr_entry *entry, int record_type,\n--\nfs/hfsplus/attributes.c-99-{\nfs/hfsplus/attributes.c:100:\tif (record_type == HFSPLUS_ATTR_FORK_DATA) {\nfs/hfsplus/attributes.c-101-\t\t/*\n--\nfs/hfsplus/attributes.c-106-\t\treturn sizeof(struct hfsplus_attr_fork_data);\nfs/hfsplus/attributes.c:107:\t} else if (record_type == HFSPLUS_ATTR_EXTENTS) {\nfs/hfsplus/attributes.c-108-\t\t/*\n--\nfs/hfsplus/attributes.c-113-\t\treturn sizeof(struct hfsplus_attr_extents);\nfs/hfsplus/attributes.c:114:\t} else if (record_type == HFSPLUS_ATTR_INLINE_DATA) {\nfs/hfsplus/attributes.c-115-\t\tu16 len;\n--\nfs/hfsplus/attributes.c-118-\t\tentry-\u003einline_data.record_type = cpu_to_be32(record_type);\nfs/hfsplus/attributes.c:119:\t\tif (size \u003c= HFSPLUS_MAX_INLINE_DATA_SIZE)\nfs/hfsplus/attributes.c-120-\t\t\tlen = size;\n--\nfs/hfsplus/attributes.c-122-\t\t\thfs_dbg(\"value size %zu is too big\\n\", size);\nfs/hfsplus/attributes.c:123:\t\t\treturn HFSPLUS_INVALID_ATTR_RECORD;\nfs/hfsplus/attributes.c-124-\t\t}\n--\nfs/hfsplus/attributes.c-136-\nfs/hfsplus/attributes.c:137:\treturn HFSPLUS_INVALID_ATTR_RECORD;\nfs/hfsplus/attributes.c-138-}\n--\nfs/hfsplus/attributes.c=140=int hfsplus_find_attr(struct super_block *sb, u32 cnid,\n--\nfs/hfsplus/attributes.c-146-\nfs/hfsplus/attributes.c:147:\tif (!HFSPLUS_SB(sb)-\u003eattr_tree) {\nfs/hfsplus/attributes.c-148-\t\tpr_err(\"attributes file doesn't exist\\n\");\n--\nfs/hfsplus/attributes.c=180=int hfsplus_attr_exists(struct inode *inode, const char *name)\n--\nfs/hfsplus/attributes.c-188-\nfs/hfsplus/attributes.c:189:\tif (!HFSPLUS_SB(sb)-\u003eattr_tree)\nfs/hfsplus/attributes.c-190-\t\treturn 0;\nfs/hfsplus/attributes.c-191-\nfs/hfsplus/attributes.c:192:\terr = hfs_find_init(HFSPLUS_SB(sb)-\u003eattr_tree, \u0026fd);\nfs/hfsplus/attributes.c-193-\tif (err)\n--\nfs/hfsplus/attributes.c=209=int hfsplus_create_attr_nolock(struct inode *inode, const char *name,\n--\nfs/hfsplus/attributes.c-230-\tentry_size = hfsplus_attr_build_record(entry_ptr,\nfs/hfsplus/attributes.c:231:\t\t\t\t\tHFSPLUS_ATTR_INLINE_DATA,\nfs/hfsplus/attributes.c-232-\t\t\t\t\tinode-\u003ei_ino,\nfs/hfsplus/attributes.c-233-\t\t\t\t\tvalue, size);\nfs/hfsplus/attributes.c:234:\tif (entry_size == HFSPLUS_INVALID_ATTR_RECORD) {\nfs/hfsplus/attributes.c:235:\t\tif (size \u003e HFSPLUS_MAX_INLINE_DATA_SIZE)\nfs/hfsplus/attributes.c-236-\t\t\terr = -E2BIG;\n--\nfs/hfsplus/attributes.c-255-\nfs/hfsplus/attributes.c:256:\thfsplus_mark_inode_dirty(HFSPLUS_ATTR_TREE_I(sb), HFSPLUS_I_ATTR_DIRTY);\nfs/hfsplus/attributes.c:257:\thfsplus_mark_inode_dirty(inode, HFSPLUS_I_ATTR_DIRTY);\nfs/hfsplus/attributes.c-258-\n--\nfs/hfsplus/attributes.c=262=int hfsplus_create_attr(struct inode *inode,\n--\nfs/hfsplus/attributes.c-273-\nfs/hfsplus/attributes.c:274:\tif (!HFSPLUS_SB(sb)-\u003eattr_tree) {\nfs/hfsplus/attributes.c-275-\t\tpr_err(\"attributes file doesn't exist\\n\");\n--\nfs/hfsplus/attributes.c-282-\nfs/hfsplus/attributes.c:283:\terr = hfs_find_init(HFSPLUS_SB(sb)-\u003eattr_tree, \u0026fd);\nfs/hfsplus/attributes.c-284-\tif (err)\n--\nfs/hfsplus/attributes.c=305=static int __hfsplus_delete_attr(struct inode *inode, u32 cnid,\n--\nfs/hfsplus/attributes.c-322-\tswitch (be32_to_cpu(record_type)) {\nfs/hfsplus/attributes.c:323:\tcase HFSPLUS_ATTR_INLINE_DATA:\nfs/hfsplus/attributes.c-324-\t\t/* All is OK. Do nothing. */\nfs/hfsplus/attributes.c-325-\t\tbreak;\nfs/hfsplus/attributes.c:326:\tcase HFSPLUS_ATTR_FORK_DATA:\nfs/hfsplus/attributes.c:327:\tcase HFSPLUS_ATTR_EXTENTS:\nfs/hfsplus/attributes.c-328-\t\tpr_err(\"only inline data xattr are supported\\n\");\n--\nfs/hfsplus/attributes.c-342-\nfs/hfsplus/attributes.c:343:\thfsplus_mark_inode_dirty(HFSPLUS_ATTR_TREE_I(inode-\u003ei_sb),\nfs/hfsplus/attributes.c:344:\t\t\t\t HFSPLUS_I_ATTR_DIRTY);\nfs/hfsplus/attributes.c:345:\thfsplus_mark_inode_dirty(inode, HFSPLUS_I_ATTR_DIRTY);\nfs/hfsplus/attributes.c-346-\treturn 0;\n--\nfs/hfsplus/attributes.c=383=int hfsplus_delete_attr(struct inode *inode, const char *name)\n--\nfs/hfsplus/attributes.c-391-\nfs/hfsplus/attributes.c:392:\tif (!HFSPLUS_SB(sb)-\u003eattr_tree) {\nfs/hfsplus/attributes.c-393-\t\tpr_err(\"attributes file doesn't exist\\n\");\n--\nfs/hfsplus/attributes.c-396-\nfs/hfsplus/attributes.c:397:\terr = hfs_find_init(HFSPLUS_SB(sb)-\u003eattr_tree, \u0026fd);\nfs/hfsplus/attributes.c-398-\tif (err)\n--\nfs/hfsplus/attributes.c=415=int hfsplus_delete_all_attrs(struct inode *dir, u32 cnid)\n--\nfs/hfsplus/attributes.c-421-\nfs/hfsplus/attributes.c:422:\tif (!HFSPLUS_SB(dir-\u003ei_sb)-\u003eattr_tree) {\nfs/hfsplus/attributes.c-423-\t\tpr_err(\"attributes file doesn't exist\\n\");\n--\nfs/hfsplus/attributes.c-426-\nfs/hfsplus/attributes.c:427:\terr = hfs_find_init(HFSPLUS_SB(dir-\u003ei_sb)-\u003eattr_tree, \u0026fd);\nfs/hfsplus/attributes.c-428-\tif (err)\n--\nfs/hfsplus/attributes.c=454=int hfsplus_replace_attr(struct inode *inode,\n--\nfs/hfsplus/attributes.c-465-\nfs/hfsplus/attributes.c:466:\tif (!HFSPLUS_SB(sb)-\u003eattr_tree) {\nfs/hfsplus/attributes.c-467-\t\tpr_err(\"attributes file doesn't exist\\n\");\n--\nfs/hfsplus/attributes.c-474-\nfs/hfsplus/attributes.c:475:\terr = hfs_find_init(HFSPLUS_SB(sb)-\u003eattr_tree, \u0026fd);\nfs/hfsplus/attributes.c-476-\tif (err)\n--\nfs/hfsplus/bfind.c=44=int hfs_find_1st_rec_by_cnid(struct hfs_bnode *bnode,\n--\nfs/hfsplus/bfind.c-52-\nfs/hfsplus/bfind.c:53:\tif (bnode-\u003etree-\u003ecnid == HFSPLUS_EXT_CNID) {\nfs/hfsplus/bfind.c-54-\t\tcur_cnid = fd-\u003ekey-\u003eext.cnid;\nfs/hfsplus/bfind.c-55-\t\tsearch_cnid = fd-\u003esearch_key-\u003eext.cnid;\nfs/hfsplus/bfind.c:56:\t} else if (bnode-\u003etree-\u003ecnid == HFSPLUS_CAT_CNID) {\nfs/hfsplus/bfind.c-57-\t\tcur_cnid = fd-\u003ekey-\u003ecat.parent;\nfs/hfsplus/bfind.c-58-\t\tsearch_cnid = fd-\u003esearch_key-\u003ecat.parent;\nfs/hfsplus/bfind.c:59:\t} else if (bnode-\u003etree-\u003ecnid == HFSPLUS_ATTR_CNID) {\nfs/hfsplus/bfind.c-60-\t\tcur_cnid = fd-\u003ekey-\u003eattr.cnid;\n--\nfs/hfsplus/bfind.c=304=int hfsplus_brec_read_cat(struct hfs_find_data *fd, hfsplus_cat_entry *entry)\n--\nfs/hfsplus/bfind.c-314-\tswitch (be16_to_cpu(entry-\u003etype)) {\nfs/hfsplus/bfind.c:315:\tcase HFSPLUS_FOLDER:\nfs/hfsplus/bfind.c-316-\t\texpected_size = sizeof(struct hfsplus_cat_folder);\nfs/hfsplus/bfind.c-317-\t\tbreak;\nfs/hfsplus/bfind.c:318:\tcase HFSPLUS_FILE:\nfs/hfsplus/bfind.c-319-\t\texpected_size = sizeof(struct hfsplus_cat_file);\nfs/hfsplus/bfind.c-320-\t\tbreak;\nfs/hfsplus/bfind.c:321:\tcase HFSPLUS_FOLDER_THREAD:\nfs/hfsplus/bfind.c:322:\tcase HFSPLUS_FILE_THREAD:\nfs/hfsplus/bfind.c-323-\t\t/* Ensure we have at least the fixed fields before reading nodeName.length */\nfs/hfsplus/bfind.c:324:\t\tif (fd-\u003eentrylength \u003c HFSPLUS_MIN_THREAD_SZ) {\nfs/hfsplus/bfind.c-325-\t\t\tpr_err(\"thread record too short (got %u)\\n\", fd-\u003eentrylength);\n--\nfs/hfsplus/bitmap.c=19=int hfsplus_block_allocate(struct super_block *sb, u32 size,\n--\nfs/hfsplus/bitmap.c-21-{\nfs/hfsplus/bitmap.c:22:\tstruct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);\nfs/hfsplus/bitmap.c-23-\tstruct page *page;\n--\nfs/hfsplus/bitmap.c=164=int hfsplus_block_free(struct super_block *sb, u32 offset, u32 count)\nfs/hfsplus/bitmap.c-165-{\nfs/hfsplus/bitmap.c:166:\tstruct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);\nfs/hfsplus/bitmap.c-167-\tstruct page *page;\n--\nfs/hfsplus/bnode.c=74=void hfs_bnode_read_key(struct hfs_bnode *node, void *key, u32 off)\n--\nfs/hfsplus/bnode.c-81-\t    tree-\u003eattributes \u0026 HFS_TREE_VARIDXKEYS ||\nfs/hfsplus/bnode.c:82:\t    node-\u003etree-\u003ecnid == HFSPLUS_ATTR_CNID)\nfs/hfsplus/bnode.c-83-\t\tkey_len = hfs_bnode_read_u16(node, off) + 2;\n--\nfs/hfsplus/bnode.c=350=void hfs_bnode_dump(struct hfs_bnode *node)\n--\nfs/hfsplus/bnode.c-376-\t\t\tif (node-\u003etree-\u003eattributes \u0026 HFS_TREE_VARIDXKEYS ||\nfs/hfsplus/bnode.c:377:\t\t\t\t\tnode-\u003etree-\u003ecnid == HFSPLUS_ATTR_CNID)\nfs/hfsplus/bnode.c-378-\t\t\t\ttmp = hfs_bnode_read_u16(node, key_off) + 2;\n--\nfs/hfsplus/bnode.c=713=bool hfs_bnode_need_zeroout(struct hfs_btree *tree)\n--\nfs/hfsplus/bnode.c-715-\tstruct super_block *sb = tree-\u003einode-\u003ei_sb;\nfs/hfsplus/bnode.c:716:\tstruct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);\nfs/hfsplus/bnode.c-717-\tconst u32 volume_attr = be32_to_cpu(sbi-\u003es_vhdr-\u003eattributes);\nfs/hfsplus/bnode.c-718-\nfs/hfsplus/bnode.c:719:\treturn volume_attr \u0026 HFSPLUS_VOL_UNUSED_NODE_FIX;\nfs/hfsplus/bnode.c-720-}\n--\nfs/hfsplus/brec.c=45=u16 hfs_brec_keylen(struct hfs_bnode *node, u16 rec)\n--\nfs/hfsplus/brec.c-55-\t   !(node-\u003etree-\u003eattributes \u0026 HFS_TREE_VARIDXKEYS) \u0026\u0026\nfs/hfsplus/brec.c:56:\t   (node-\u003etree-\u003ecnid != HFSPLUS_ATTR_CNID)) {\nfs/hfsplus/brec.c-57-\t\tretval = node-\u003etree-\u003emax_key_len + 2;\n--\nfs/hfsplus/brec.c=73=int hfs_brec_insert(struct hfs_find_data *fd, void *entry, u32 entry_len)\n--\nfs/hfsplus/brec.c-175-\t\tif ((tree-\u003eattributes \u0026 HFS_TREE_VARIDXKEYS) ||\nfs/hfsplus/brec.c:176:\t\t\t\t(tree-\u003ecnid == HFSPLUS_ATTR_CNID))\nfs/hfsplus/brec.c-177-\t\t\tkey_len = be16_to_cpu(fd-\u003esearch_key-\u003ekey_len) + 2;\n--\nfs/hfsplus/brec.c=382=static int hfs_brec_update_parent(struct hfs_find_data *fd)\n--\nfs/hfsplus/brec.c-410-\tif ((tree-\u003eattributes \u0026 HFS_TREE_VARIDXKEYS) ||\nfs/hfsplus/brec.c:411:\t\t\t\t(tree-\u003ecnid == HFSPLUS_ATTR_CNID))\nfs/hfsplus/brec.c-412-\t\tnewkeylen = hfs_bnode_read_u16(node, 14) + 2;\n--\nfs/hfsplus/brec.c=491=static int hfs_btree_inc_height(struct hfs_btree *tree)\n--\nfs/hfsplus/brec.c-539-\t\t\t\ttree-\u003eattributes \u0026 HFS_TREE_VARIDXKEYS ||\nfs/hfsplus/brec.c:540:\t\t\t\ttree-\u003ecnid == HFSPLUS_ATTR_CNID)\nfs/hfsplus/brec.c-541-\t\t\tkey_size = hfs_bnode_read_u16(node, 14) + 2;\n--\nfs/hfsplus/brec.c-546-\t\tif (!(tree-\u003eattributes \u0026 HFS_TREE_VARIDXKEYS) \u0026\u0026\nfs/hfsplus/brec.c:547:\t\t\t\t(tree-\u003ecnid != HFSPLUS_ATTR_CNID)) {\nfs/hfsplus/brec.c-548-\t\t\tkey_size = tree-\u003emax_key_len + 2;\n--\nfs/hfsplus/btree.c=75=u32 hfsplus_calc_btree_clump_size(u32 block_size, u32 node_size,\n--\nfs/hfsplus/btree.c-84-\tswitch (file_id) {\nfs/hfsplus/btree.c:85:\tcase HFSPLUS_ATTR_CNID:\nfs/hfsplus/btree.c-86-\t\tcolumn = 0;\nfs/hfsplus/btree.c-87-\t\tbreak;\nfs/hfsplus/btree.c:88:\tcase HFSPLUS_CAT_CNID:\nfs/hfsplus/btree.c-89-\t\tcolumn = 1;\n--\nfs/hfsplus/btree.c=149=static struct page *hfs_bmap_get_map_page(struct hfs_bnode *node,\n--\nfs/hfsplus/btree.c-155-\nfs/hfsplus/btree.c:156:\tif (node-\u003ethis == HFSPLUS_TREE_HEAD) {\nfs/hfsplus/btree.c-157-\t\tif (node-\u003etype != HFS_NODE_HEADER) {\n--\nfs/hfsplus/btree.c-160-\t\t}\nfs/hfsplus/btree.c:161:\t\trec_idx = HFSPLUS_BTREE_HDR_MAP_REC_INDEX;\nfs/hfsplus/btree.c-162-\t} else {\n--\nfs/hfsplus/btree.c-166-\t\t}\nfs/hfsplus/btree.c:167:\t\trec_idx = HFSPLUS_BTREE_MAP_NODE_REC_INDEX;\nfs/hfsplus/btree.c-168-\t}\n--\nfs/hfsplus/btree.c=253=static const char *hfs_btree_name(u32 cnid)\n--\nfs/hfsplus/btree.c-255-\tswitch (cnid) {\nfs/hfsplus/btree.c:256:\tcase HFSPLUS_EXT_CNID:\nfs/hfsplus/btree.c-257-\t\treturn HFS_EXTENT_TREE_NAME;\nfs/hfsplus/btree.c:258:\tcase HFSPLUS_CAT_CNID:\nfs/hfsplus/btree.c-259-\t\treturn HFS_CATALOG_TREE_NAME;\nfs/hfsplus/btree.c:260:\tcase HFSPLUS_ATTR_CNID:\nfs/hfsplus/btree.c-261-\t\treturn HFS_ATTR_TREE_NAME;\n--\nfs/hfsplus/btree.c=268=struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id)\n--\nfs/hfsplus/btree.c-290-\nfs/hfsplus/btree.c:291:\tif (!HFSPLUS_I(tree-\u003einode)-\u003efirst_blocks) {\nfs/hfsplus/btree.c-292-\t\tpr_err(\"invalid btree extent records (0 size)\\n\");\n--\nfs/hfsplus/btree.c-316-\tswitch (id) {\nfs/hfsplus/btree.c:317:\tcase HFSPLUS_EXT_CNID:\nfs/hfsplus/btree.c:318:\t\tif (tree-\u003emax_key_len != HFSPLUS_EXT_KEYLEN - sizeof(u16)) {\nfs/hfsplus/btree.c-319-\t\t\tpr_err(\"invalid extent max_key_len %d\\n\",\n--\nfs/hfsplus/btree.c-329-\t\tbreak;\nfs/hfsplus/btree.c:330:\tcase HFSPLUS_CAT_CNID:\nfs/hfsplus/btree.c:331:\t\tif (tree-\u003emax_key_len != HFSPLUS_CAT_KEYLEN - sizeof(u16)) {\nfs/hfsplus/btree.c-332-\t\t\tpr_err(\"invalid catalog max_key_len %d\\n\",\n--\nfs/hfsplus/btree.c-340-\nfs/hfsplus/btree.c:341:\t\tif (test_bit(HFSPLUS_SB_HFSX, \u0026HFSPLUS_SB(sb)-\u003eflags) \u0026\u0026\nfs/hfsplus/btree.c:342:\t\t    (head-\u003ekey_type == HFSPLUS_KEY_BINARY))\nfs/hfsplus/btree.c-343-\t\t\ttree-\u003ekeycmp = hfsplus_cat_bin_cmp_key;\n--\nfs/hfsplus/btree.c-345-\t\t\ttree-\u003ekeycmp = hfsplus_cat_case_cmp_key;\nfs/hfsplus/btree.c:346:\t\t\tset_bit(HFSPLUS_SB_CASEFOLD, \u0026HFSPLUS_SB(sb)-\u003eflags);\nfs/hfsplus/btree.c-347-\t\t}\nfs/hfsplus/btree.c-348-\t\tbreak;\nfs/hfsplus/btree.c:349:\tcase HFSPLUS_ATTR_CNID:\nfs/hfsplus/btree.c:350:\t\tif (tree-\u003emax_key_len != HFSPLUS_ATTR_KEYLEN - sizeof(u16)) {\nfs/hfsplus/btree.c-351-\t\t\tpr_err(\"invalid attributes max_key_len %d\\n\",\n--\nfs/hfsplus/btree.c-367-\tsize = tree-\u003enode_size;\nfs/hfsplus/btree.c:368:\tif (size \u003c HFSPLUS_NODE_MINSZ || size \u003e HFSPLUS_NODE_MXSZ)\nfs/hfsplus/btree.c-369-\t\tgoto fail_page;\n--\nfs/hfsplus/btree.c-383-\nfs/hfsplus/btree.c:384:\tnode = hfs_bnode_find(tree, HFSPLUS_TREE_HEAD);\nfs/hfsplus/btree.c-385-\tif (IS_ERR(node))\n--\nfs/hfsplus/btree.c=499=int hfs_bmap_reserve(struct hfs_btree *tree, u32 rsvd_nodes)\n--\nfs/hfsplus/btree.c-501-\tstruct inode *inode = tree-\u003einode;\nfs/hfsplus/btree.c:502:\tstruct hfsplus_inode_info *hip = HFSPLUS_I(inode);\nfs/hfsplus/btree.c-503-\tu32 count;\n--\nfs/hfsplus/btree.c-516-\t\t\t(loff_t)hip-\u003ealloc_blocks \u003c\u003c\nfs/hfsplus/btree.c:517:\t\t\t\tHFSPLUS_SB(tree-\u003esb)-\u003ealloc_blksz_shift;\nfs/hfsplus/btree.c-518-\t\thip-\u003efs_blocks =\nfs/hfsplus/btree.c:519:\t\t\thip-\u003ealloc_blocks \u003c\u003c HFSPLUS_SB(tree-\u003esb)-\u003efs_shift;\nfs/hfsplus/btree.c-520-\t\tinode_set_bytes(inode, inode-\u003ei_size);\n--\nfs/hfsplus/catalog.c=43=int hfsplus_cat_build_key(struct super_block *sb,\n--\nfs/hfsplus/catalog.c-48-\tkey-\u003ecat.parent = cpu_to_be32(parent);\nfs/hfsplus/catalog.c:49:\terr = hfsplus_asc2uni(sb, \u0026key-\u003ecat.name, HFSPLUS_MAX_STRLEN,\nfs/hfsplus/catalog.c-50-\t\t\t      str-\u003ename, str-\u003elen, HFS_REGULAR_NAME);\n--\nfs/hfsplus/catalog.c=81=void hfsplus_cat_set_perms(struct inode *inode, struct hfsplus_perm *perms)\n--\nfs/hfsplus/catalog.c-83-\tif (inode-\u003ei_flags \u0026 S_IMMUTABLE)\nfs/hfsplus/catalog.c:84:\t\tperms-\u003erootflags |= HFSPLUS_FLG_IMMUTABLE;\nfs/hfsplus/catalog.c-85-\telse\nfs/hfsplus/catalog.c:86:\t\tperms-\u003erootflags \u0026= ~HFSPLUS_FLG_IMMUTABLE;\nfs/hfsplus/catalog.c-87-\tif (inode-\u003ei_flags \u0026 S_APPEND)\nfs/hfsplus/catalog.c:88:\t\tperms-\u003erootflags |= HFSPLUS_FLG_APPEND;\nfs/hfsplus/catalog.c-89-\telse\nfs/hfsplus/catalog.c:90:\t\tperms-\u003erootflags \u0026= ~HFSPLUS_FLG_APPEND;\nfs/hfsplus/catalog.c-91-\nfs/hfsplus/catalog.c:92:\tperms-\u003euserflags = HFSPLUS_I(inode)-\u003euserflags;\nfs/hfsplus/catalog.c-93-\tperms-\u003emode = cpu_to_be16(inode-\u003ei_mode);\n--\nfs/hfsplus/catalog.c=105=static int hfsplus_cat_build_record(hfsplus_cat_entry *entry,\n--\nfs/hfsplus/catalog.c-107-{\nfs/hfsplus/catalog.c:108:\tstruct hfsplus_sb_info *sbi = HFSPLUS_SB(inode-\u003ei_sb);\nfs/hfsplus/catalog.c-109-\n--\nfs/hfsplus/catalog.c-114-\t\tmemset(folder, 0, sizeof(*folder));\nfs/hfsplus/catalog.c:115:\t\tfolder-\u003etype = cpu_to_be16(HFSPLUS_FOLDER);\nfs/hfsplus/catalog.c:116:\t\tif (test_bit(HFSPLUS_SB_HFSX, \u0026sbi-\u003eflags))\nfs/hfsplus/catalog.c:117:\t\t\tfolder-\u003eflags |= cpu_to_be16(HFSPLUS_HAS_FOLDER_COUNT);\nfs/hfsplus/catalog.c-118-\t\tfolder-\u003eid = cpu_to_be32(inode-\u003ei_ino);\nfs/hfsplus/catalog.c:119:\t\tHFSPLUS_I(inode)-\u003ecreate_date =\nfs/hfsplus/catalog.c-120-\t\t\tfolder-\u003ecreate_date =\n--\nfs/hfsplus/catalog.c-133-\t\tmemset(file, 0, sizeof(*file));\nfs/hfsplus/catalog.c:134:\t\tfile-\u003etype = cpu_to_be16(HFSPLUS_FILE);\nfs/hfsplus/catalog.c:135:\t\tfile-\u003eflags = cpu_to_be16(HFSPLUS_FILE_THREAD_EXISTS);\nfs/hfsplus/catalog.c-136-\t\tfile-\u003eid = cpu_to_be32(cnid);\nfs/hfsplus/catalog.c:137:\t\tHFSPLUS_I(inode)-\u003ecreate_date =\nfs/hfsplus/catalog.c-138-\t\t\tfile-\u003ecreate_date =\n--\nfs/hfsplus/catalog.c-154-\t\t\t}\nfs/hfsplus/catalog.c:155:\t\t\tif (HFSPLUS_FLG_IMMUTABLE \u0026\nfs/hfsplus/catalog.c-156-\t\t\t\t\t(file-\u003epermissions.rootflags |\n--\nfs/hfsplus/catalog.c-158-\t\t\t\tfile-\u003eflags |=\nfs/hfsplus/catalog.c:159:\t\t\t\t\tcpu_to_be16(HFSPLUS_FILE_LOCKED);\nfs/hfsplus/catalog.c-160-\t\t} else {\n--\nfs/hfsplus/catalog.c-163-\t\t\tfile-\u003euser_info.fdCreator =\nfs/hfsplus/catalog.c:164:\t\t\t\tcpu_to_be32(HFSP_HFSPLUS_CREATOR);\nfs/hfsplus/catalog.c-165-\t\t\tfile-\u003euser_info.fdFlags =\n--\nfs/hfsplus/catalog.c-167-\t\t\tfile-\u003ecreate_date =\nfs/hfsplus/catalog.c:168:\t\t\t\tHFSPLUS_I(sbi-\u003ehidden_dir)-\u003ecreate_date;\nfs/hfsplus/catalog.c-169-\t\t\tfile-\u003epermissions.dev =\nfs/hfsplus/catalog.c:170:\t\t\t\tcpu_to_be32(HFSPLUS_I(inode)-\u003elinkid);\nfs/hfsplus/catalog.c-171-\t\t}\n--\nfs/hfsplus/catalog.c=176=static int hfsplus_fill_cat_thread(struct super_block *sb,\n--\nfs/hfsplus/catalog.c-184-\tentry-\u003ethread.parentID = cpu_to_be32(parentid);\nfs/hfsplus/catalog.c:185:\terr = hfsplus_asc2uni(sb, \u0026entry-\u003ethread.nodeName, HFSPLUS_MAX_STRLEN,\nfs/hfsplus/catalog.c-186-\t\t\t\tstr-\u003ename, str-\u003elen, HFS_REGULAR_NAME);\n--\nfs/hfsplus/catalog.c=223=static void hfsplus_subfolders_inc(struct inode *dir)\nfs/hfsplus/catalog.c-224-{\nfs/hfsplus/catalog.c:225:\tstruct hfsplus_sb_info *sbi = HFSPLUS_SB(dir-\u003ei_sb);\nfs/hfsplus/catalog.c-226-\nfs/hfsplus/catalog.c:227:\tif (test_bit(HFSPLUS_SB_HFSX, \u0026sbi-\u003eflags)) {\nfs/hfsplus/catalog.c-228-\t\t/*\nfs/hfsplus/catalog.c-229-\t\t * Increment subfolder count. Note, the value is only meaningful\nfs/hfsplus/catalog.c:230:\t\t * for folders with HFSPLUS_HAS_FOLDER_COUNT flag set.\nfs/hfsplus/catalog.c-231-\t\t */\nfs/hfsplus/catalog.c:232:\t\tHFSPLUS_I(dir)-\u003esubfolders++;\nfs/hfsplus/catalog.c-233-\t}\n--\nfs/hfsplus/catalog.c=236=static void hfsplus_subfolders_dec(struct inode *dir)\nfs/hfsplus/catalog.c-237-{\nfs/hfsplus/catalog.c:238:\tstruct hfsplus_sb_info *sbi = HFSPLUS_SB(dir-\u003ei_sb);\nfs/hfsplus/catalog.c-239-\nfs/hfsplus/catalog.c:240:\tif (test_bit(HFSPLUS_SB_HFSX, \u0026sbi-\u003eflags)) {\nfs/hfsplus/catalog.c-241-\t\t/*\nfs/hfsplus/catalog.c-242-\t\t * Decrement subfolder count. Note, the value is only meaningful\nfs/hfsplus/catalog.c:243:\t\t * for folders with HFSPLUS_HAS_FOLDER_COUNT flag set.\nfs/hfsplus/catalog.c-244-\t\t *\n--\nfs/hfsplus/catalog.c-247-\t\t */\nfs/hfsplus/catalog.c:248:\t\tif (HFSPLUS_I(dir)-\u003esubfolders)\nfs/hfsplus/catalog.c:249:\t\t\tHFSPLUS_I(dir)-\u003esubfolders--;\nfs/hfsplus/catalog.c-250-\t}\n--\nfs/hfsplus/catalog.c=253=int hfsplus_create_cat(u32 cnid, struct inode *dir,\n--\nfs/hfsplus/catalog.c-263-\t\tstr-\u003ename, cnid, inode-\u003ei_nlink);\nfs/hfsplus/catalog.c:264:\terr = hfs_find_init(HFSPLUS_SB(sb)-\u003ecat_tree, \u0026fd);\nfs/hfsplus/catalog.c-265-\tif (err)\n--\nfs/hfsplus/catalog.c-278-\t\tS_ISDIR(inode-\u003ei_mode) ?\nfs/hfsplus/catalog.c:279:\t\t\tHFSPLUS_FOLDER_THREAD : HFSPLUS_FILE_THREAD,\nfs/hfsplus/catalog.c-280-\t\tdir-\u003ei_ino, str);\n--\nfs/hfsplus/catalog.c-315-\tinode_set_mtime_to_ts(dir, inode_set_ctime_current(dir));\nfs/hfsplus/catalog.c:316:\thfsplus_mark_inode_dirty(HFSPLUS_CAT_TREE_I(sb), HFSPLUS_I_CAT_DIRTY);\nfs/hfsplus/catalog.c:317:\thfsplus_mark_inode_dirty(dir, HFSPLUS_I_CAT_DIRTY);\nfs/hfsplus/catalog.c-318-\n--\nfs/hfsplus/catalog.c=331=int hfsplus_delete_cat(u32 cnid, struct inode *dir, const struct qstr *str)\n--\nfs/hfsplus/catalog.c-339-\thfs_dbg(\"name %s, cnid %u\\n\", str ? str-\u003ename : NULL, cnid);\nfs/hfsplus/catalog.c:340:\terr = hfs_find_init(HFSPLUS_SB(sb)-\u003ecat_tree, \u0026fd);\nfs/hfsplus/catalog.c-341-\tif (err)\n--\nfs/hfsplus/catalog.c-379-\ttype = hfs_bnode_read_u16(fd.bnode, fd.entryoffset);\nfs/hfsplus/catalog.c:380:\tif (type == HFSPLUS_FILE) {\nfs/hfsplus/catalog.c-381-#if 0\n--\nfs/hfsplus/catalog.c-383-\t\thfs_bnode_read(fd.bnode, \u0026fork, off, sizeof(fork));\nfs/hfsplus/catalog.c:384:\t\thfsplus_free_fork(sb, cnid, \u0026fork, HFSPLUS_TYPE_DATA);\nfs/hfsplus/catalog.c-385-#endif\n--\nfs/hfsplus/catalog.c-389-\t\thfs_bnode_read(fd.bnode, \u0026fork, off, sizeof(fork));\nfs/hfsplus/catalog.c:390:\t\thfsplus_free_fork(sb, cnid, \u0026fork, HFSPLUS_TYPE_RSRC);\nfs/hfsplus/catalog.c-391-\t}\n--\nfs/hfsplus/catalog.c-406-\tdir-\u003ei_size--;\nfs/hfsplus/catalog.c:407:\tif (type == HFSPLUS_FOLDER)\nfs/hfsplus/catalog.c-408-\t\thfsplus_subfolders_dec(dir);\nfs/hfsplus/catalog.c-409-\tinode_set_mtime_to_ts(dir, inode_set_ctime_current(dir));\nfs/hfsplus/catalog.c:410:\thfsplus_mark_inode_dirty(HFSPLUS_CAT_TREE_I(sb), HFSPLUS_I_CAT_DIRTY);\nfs/hfsplus/catalog.c:411:\thfsplus_mark_inode_dirty(dir, HFSPLUS_I_CAT_DIRTY);\nfs/hfsplus/catalog.c-412-\nfs/hfsplus/catalog.c:413:\tif (type == HFSPLUS_FILE || type == HFSPLUS_FOLDER) {\nfs/hfsplus/catalog.c:414:\t\tif (HFSPLUS_SB(sb)-\u003eattr_tree)\nfs/hfsplus/catalog.c-415-\t\t\thfsplus_delete_all_attrs(dir, cnid);\n--\nfs/hfsplus/catalog.c=424=int hfsplus_rename_cat(u32 cnid,\n--\nfs/hfsplus/catalog.c-436-\t\tdst_dir-\u003ei_ino, dst_name-\u003ename);\nfs/hfsplus/catalog.c:437:\terr = hfs_find_init(HFSPLUS_SB(sb)-\u003ecat_tree, \u0026src_fd);\nfs/hfsplus/catalog.c-438-\tif (err)\n--\nfs/hfsplus/catalog.c-484-\tdst_dir-\u003ei_size++;\nfs/hfsplus/catalog.c:485:\tif (type == HFSPLUS_FOLDER)\nfs/hfsplus/catalog.c-486-\t\thfsplus_subfolders_inc(dst_dir);\n--\nfs/hfsplus/catalog.c-501-\tsrc_dir-\u003ei_size--;\nfs/hfsplus/catalog.c:502:\tif (type == HFSPLUS_FOLDER)\nfs/hfsplus/catalog.c-503-\t\thfsplus_subfolders_dec(src_dir);\n--\nfs/hfsplus/catalog.c-532-\nfs/hfsplus/catalog.c:533:\thfsplus_mark_inode_dirty(HFSPLUS_CAT_TREE_I(sb), HFSPLUS_I_CAT_DIRTY);\nfs/hfsplus/catalog.c:534:\thfsplus_mark_inode_dirty(dst_dir, HFSPLUS_I_CAT_DIRTY);\nfs/hfsplus/catalog.c:535:\thfsplus_mark_inode_dirty(src_dir, HFSPLUS_I_CAT_DIRTY);\nfs/hfsplus/catalog.c-536-out:\n--\nfs/hfsplus/dir.c=30=static struct dentry *hfsplus_lookup(struct inode *dir, struct dentry *dentry,\n--\nfs/hfsplus/dir.c-43-\tdentry-\u003ed_fsdata = NULL;\nfs/hfsplus/dir.c:44:\terr = hfs_find_init(HFSPLUS_SB(sb)-\u003ecat_tree, \u0026fd);\nfs/hfsplus/dir.c-45-\tif (err)\n--\nfs/hfsplus/dir.c-62-\ttype = be16_to_cpu(entry.type);\nfs/hfsplus/dir.c:63:\tif (type == HFSPLUS_FOLDER) {\nfs/hfsplus/dir.c-64-\t\tif (fd.entrylength \u003c sizeof(struct hfsplus_cat_folder)) {\n--\nfs/hfsplus/dir.c-69-\t\tdentry-\u003ed_fsdata = (void *)(unsigned long)cnid;\nfs/hfsplus/dir.c:70:\t} else if (type == HFSPLUS_FILE) {\nfs/hfsplus/dir.c-71-\t\tif (fd.entrylength \u003c sizeof(struct hfsplus_cat_file)) {\n--\nfs/hfsplus/dir.c-78-\t\t\t\tentry.file.user_info.fdCreator ==\nfs/hfsplus/dir.c:79:\t\t\t\tcpu_to_be32(HFSP_HFSPLUS_CREATOR) \u0026\u0026\nfs/hfsplus/dir.c:80:\t\t\t\tHFSPLUS_SB(sb)-\u003ehidden_dir \u0026\u0026\nfs/hfsplus/dir.c-81-\t\t\t\t(entry.file.create_date ==\nfs/hfsplus/dir.c:82:\t\t\t\t\tHFSPLUS_I(HFSPLUS_SB(sb)-\u003ehidden_dir)-\u003e\nfs/hfsplus/dir.c-83-\t\t\t\t\t\tcreate_date ||\nfs/hfsplus/dir.c-84-\t\t\t\tentry.file.create_date ==\nfs/hfsplus/dir.c:85:\t\t\t\t\tHFSPLUS_I(d_inode(sb-\u003es_root))-\u003e\nfs/hfsplus/dir.c-86-\t\t\t\t\t\tcreate_date)) {\n--\nfs/hfsplus/dir.c-103-\t\t\t\terr = hfsplus_cat_build_key(sb, fd.search_key,\nfs/hfsplus/dir.c:104:\t\t\t\t\tHFSPLUS_SB(sb)-\u003ehidden_dir-\u003ei_ino,\nfs/hfsplus/dir.c-105-\t\t\t\t\t\u0026str);\n--\nfs/hfsplus/dir.c-121-\tif (S_ISREG(inode-\u003ei_mode))\n\n"
}

5/2 2026/09/21 03:51 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 37307
							output: 29
							thoughts: 23
						

Thoughts:
Okay, here's my take on those thoughts, tailored for an expert audience:

**Quick Check: Recent Commit Details**

Right, so I need a refresher on the very last change I made in this repository. My go-to moves here are usually `git log -1` to get the most recent commit details in a concise format. That's usually enough. But if I need a more granular view, including the full diff, I'll switch to `git show`. It really depends on how much information I need at this point. I'm aiming for the quickest way to confirm the context and intent of the last modification without diving into a full-blown investigation. What's the best option to quickly jog my memory: a `git log -1` call, or a `git show` call?



6/2 2026/09/21 03:51 tool grepper
0m Args:
{
  "Expression": ".*",
  "PathPrefix": "fs/hfsplus/Kconfig"
}

Results:
{
  "Output": "fs/hfsplus/Kconfig:1:# SPDX-License-Identifier: GPL-2.0-only\nfs/hfsplus/Kconfig:2:config HFSPLUS_FS\nfs/hfsplus/Kconfig:3:\ttristate \"Apple Extended HFS file system support\"\nfs/hfsplus/Kconfig:4:\tdepends on BLOCK\nfs/hfsplus/Kconfig:5:\tselect BUFFER_HEAD\nfs/hfsplus/Kconfig:6:\tselect NLS\nfs/hfsplus/Kconfig:7:\tselect NLS_UTF8\nfs/hfsplus/Kconfig:8:\tselect LEGACY_DIRECT_IO\nfs/hfsplus/Kconfig:9:\thelp\nfs/hfsplus/Kconfig:10:\t  If you say Y here, you will be able to mount extended format\nfs/hfsplus/Kconfig:11:\t  Macintosh-formatted hard drive partitions with full read-write access.\nfs/hfsplus/Kconfig:12:\nfs/hfsplus/Kconfig:13:\t  This file system is often called HFS+ and was introduced with\nfs/hfsplus/Kconfig:14:\t  MacOS 8. It includes all Mac specific filesystem data such as\nfs/hfsplus/Kconfig:15:\t  data forks and creator codes, but it also has several UNIX\nfs/hfsplus/Kconfig:16:\t  style features such as file ownership and permissions.\nfs/hfsplus/Kconfig:17:\nfs/hfsplus/Kconfig:18:config HFSPLUS_KUNIT_TEST\nfs/hfsplus/Kconfig:19:\ttristate \"KUnit tests for HFS+ filesystem\" if !KUNIT_ALL_TESTS\nfs/hfsplus/Kconfig:20:\tdepends on HFSPLUS_FS \u0026\u0026 KUNIT\nfs/hfsplus/Kconfig:21:\tdefault KUNIT_ALL_TESTS\nfs/hfsplus/Kconfig:22:\thelp\nfs/hfsplus/Kconfig:23:\t  This builds KUnit tests for the HFS+ filesystem.\nfs/hfsplus/Kconfig:24:\nfs/hfsplus/Kconfig:25:\t  KUnit tests run during boot and output the results to the debug\nfs/hfsplus/Kconfig:26:\t  log in TAP format (https://testanything.org/). Only useful for\nfs/hfsplus/Kconfig:27:\t  kernel devs running KUnit test harness and are not for inclusion\nfs/hfsplus/Kconfig:28:\t  into a production build.\nfs/hfsplus/Kconfig:29:\nfs/hfsplus/Kconfig:30:\t  For more information on KUnit and unit tests in general please\nfs/hfsplus/Kconfig:31:\t  refer to the KUnit documentation in Documentation/dev-tools/kunit/.\n"
}

7/2 2026/09/21 03:51 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 38237
							output: 43
							thoughts: 51
						

Thoughts:
Okay, let's dive into this code. I need to understand the impact of these changes. My first thought is to trace the usage of the modified functions. I'll need to see the callers, the specific locations where `hfsplus_asc2uni`, `hfsplus_hash_dentry`, and `hfsplus_compare_dentry` are being used. This isn't just about finding *where* they're called, but how they're integrated into the broader HFS+ system.

I'll reach for grep. Specifically, I'll search the codebase using grep for these function names. This should provide the cross-references I need to begin tracing the call chains. Identifying the key call sites quickly is critical.



8/2 2026/09/21 03:51 tool grepper
0m Args:
{
  "Expression": "hfsplus_(asc2uni|hash_dentry|compare_dentry)",
  "PathPrefix": "fs/hfsplus"
}

Results:
{
  "Output": "\nFull output is too long, showing 500 out of 587 lines.\nUse more precise expression if possible.\n\nfs/hfsplus/attributes.c=50=int hfsplus_attr_build_key(struct super_block *sb, hfsplus_btree_key *key,\n--\nfs/hfsplus/attributes.c-57-\tif (name) {\nfs/hfsplus/attributes.c:58:\t\tint res = hfsplus_asc2uni(sb,\nfs/hfsplus/attributes.c-59-\t\t\t\t(struct hfsplus_unistr *)\u0026key-\u003eattr.key_name,\n--\nfs/hfsplus/catalog.c=43=int hfsplus_cat_build_key(struct super_block *sb,\n--\nfs/hfsplus/catalog.c-48-\tkey-\u003ecat.parent = cpu_to_be32(parent);\nfs/hfsplus/catalog.c:49:\terr = hfsplus_asc2uni(sb, \u0026key-\u003ecat.name, HFSPLUS_MAX_STRLEN,\nfs/hfsplus/catalog.c-50-\t\t\t      str-\u003ename, str-\u003elen, HFS_REGULAR_NAME);\n--\nfs/hfsplus/catalog.c=176=static int hfsplus_fill_cat_thread(struct super_block *sb,\n--\nfs/hfsplus/catalog.c-184-\tentry-\u003ethread.parentID = cpu_to_be32(parentid);\nfs/hfsplus/catalog.c:185:\terr = hfsplus_asc2uni(sb, \u0026entry-\u003ethread.nodeName, HFSPLUS_MAX_STRLEN,\nfs/hfsplus/catalog.c-186-\t\t\t\tstr-\u003ename, str-\u003elen, HFS_REGULAR_NAME);\n--\nfs/hfsplus/hfsplus_fs.h=498=int hfsplus_uni2asc_xattr_str(struct super_block *sb,\n--\nfs/hfsplus/hfsplus_fs.h-500-\t\t\t      char *astr, int *len_p);\nfs/hfsplus/hfsplus_fs.h:501:int hfsplus_asc2uni(struct super_block *sb, struct hfsplus_unistr *ustr,\nfs/hfsplus/hfsplus_fs.h-502-\t\t    int max_unistr_len, const char *astr, int len,\nfs/hfsplus/hfsplus_fs.h-503-\t\t    int name_type);\nfs/hfsplus/hfsplus_fs.h:504:int hfsplus_hash_dentry(const struct dentry *dentry, struct qstr *str);\nfs/hfsplus/hfsplus_fs.h:505:int hfsplus_compare_dentry(const struct dentry *dentry, unsigned int len,\nfs/hfsplus/hfsplus_fs.h-506-\t\t\t   const char *str, const struct qstr *name);\n--\nfs/hfsplus/inode.c=220=const struct dentry_operations hfsplus_dentry_operations = {\nfs/hfsplus/inode.c:221:\t.d_hash       = hfsplus_hash_dentry,\nfs/hfsplus/inode.c:222:\t.d_compare    = hfsplus_compare_dentry,\nfs/hfsplus/inode.c-223-};\n--\nfs/hfsplus/unicode.c=505=static_assert(HFSPLUS_HANGUL_MAX_JAMO \u003e= HFSPLUS_LEGACY_DECOMP_MAX_LEN,\n--\nfs/hfsplus/unicode.c-509- * Decompose and canonically reorder an entire Linux name, as plain\nfs/hfsplus/unicode.c:510: * host-order code units. hfsplus_asc2uni(), hfsplus_hash_dentry() and\nfs/hfsplus/unicode.c:511: * hfsplus_compare_dentry() all go through this so that storage, hashing\nfs/hfsplus/unicode.c-512- * and comparison always agree on what a given name canonicalizes to.\n--\nfs/hfsplus/unicode.c=519=static int hfsplus_decompose_str(struct super_block *sb, const char *astr,\n--\nfs/hfsplus/unicode.c-556-\nfs/hfsplus/unicode.c:557:int hfsplus_asc2uni(struct super_block *sb,\nfs/hfsplus/unicode.c-558-\t\t    struct hfsplus_unistr *ustr, int max_unistr_len,\n--\nfs/hfsplus/unicode.c-576-}\nfs/hfsplus/unicode.c:577:EXPORT_SYMBOL_IF_KUNIT(hfsplus_asc2uni);\nfs/hfsplus/unicode.c-578-\n--\nfs/hfsplus/unicode.c-585- * adversarial \"Zalgo\" text, essentially never approaches this. Keeping\nfs/hfsplus/unicode.c:586: * it small means hfsplus_hash_dentry() and hfsplus_compare_dentry() only\nfs/hfsplus/unicode.c-587- * ever need a tiny amount of lookahead state, rather than buffering an\n--\nfs/hfsplus/unicode.c-594- * of a Linux name one at a time, without materializing the whole name.\nfs/hfsplus/unicode.c:595: * hfsplus_hash_dentry() and hfsplus_compare_dentry() use this so that\nfs/hfsplus/unicode.c:596: * hashing and comparison always agree with what hfsplus_asc2uni() would\nfs/hfsplus/unicode.c-597- * actually store, while still comparing lazily (stopping at the first\n--\nfs/hfsplus/unicode.c=687=static int hfsplus_decompose_iter_next_folded(struct hfsplus_decompose_iter *it,\n--\nfs/hfsplus/unicode.c-707- */\nfs/hfsplus/unicode.c:708:int hfsplus_hash_dentry(const struct dentry *dentry, struct qstr *str)\nfs/hfsplus/unicode.c-709-{\n--\nfs/hfsplus/unicode.c-725-}\nfs/hfsplus/unicode.c:726:EXPORT_SYMBOL_IF_KUNIT(hfsplus_hash_dentry);\nfs/hfsplus/unicode.c-727-\n--\nfs/hfsplus/unicode.c-732- */\nfs/hfsplus/unicode.c:733:int hfsplus_compare_dentry(const struct dentry *dentry,\nfs/hfsplus/unicode.c-734-\t\tunsigned int len, const char *str, const struct qstr *name)\n--\nfs/hfsplus/unicode.c-753-}\nfs/hfsplus/unicode.c:754:EXPORT_SYMBOL_IF_KUNIT(hfsplus_compare_dentry);\n--\nfs/hfsplus/unicode_test.c=683=static void check_unistr_content(struct kunit *test,\n--\nfs/hfsplus/unicode_test.c-700-\nfs/hfsplus/unicode_test.c:701:/* Test hfsplus_asc2uni basic functionality */\nfs/hfsplus/unicode_test.c:702:static void hfsplus_asc2uni_basic_test(struct kunit *test)\nfs/hfsplus/unicode_test.c-703-{\n--\nfs/hfsplus/unicode_test.c-716-\t/* Test simple ASCII string conversion */\nfs/hfsplus/unicode_test.c:717:\tresult = hfsplus_asc2uni(\u0026mock_sb-\u003esb, \u0026mock_env-\u003estr1,\nfs/hfsplus/unicode_test.c-718-\t\t\t\t HFSPLUS_MAX_STRLEN, \"hello\", 5,\n--\nfs/hfsplus/unicode_test.c-724-\t/* Test empty string */\nfs/hfsplus/unicode_test.c:725:\tresult = hfsplus_asc2uni(\u0026mock_sb-\u003esb, \u0026mock_env-\u003estr1,\nfs/hfsplus/unicode_test.c-726-\t\t\t\t HFSPLUS_MAX_STRLEN, \"\", 0,\n--\nfs/hfsplus/unicode_test.c-732-\t/* Test single character */\nfs/hfsplus/unicode_test.c:733:\tresult = hfsplus_asc2uni(\u0026mock_sb-\u003esb, \u0026mock_env-\u003estr1,\nfs/hfsplus/unicode_test.c-734-\t\t\t\t HFSPLUS_MAX_STRLEN, \"A\", 1,\n--\nfs/hfsplus/unicode_test.c-740-\t/* Test null-terminated string with explicit length */\nfs/hfsplus/unicode_test.c:741:\tresult = hfsplus_asc2uni(\u0026mock_sb-\u003esb, \u0026mock_env-\u003estr1,\nfs/hfsplus/unicode_test.c-742-\t\t\t\t HFSPLUS_MAX_STRLEN, \"test\\0extra\", 4,\n--\nfs/hfsplus/unicode_test.c-752-/* Test special character handling in asc2uni */\nfs/hfsplus/unicode_test.c:753:static void hfsplus_asc2uni_special_chars_test(struct kunit *test)\nfs/hfsplus/unicode_test.c-754-{\n--\nfs/hfsplus/unicode_test.c-767-\t/* Test colon conversion (should become forward slash) */\nfs/hfsplus/unicode_test.c:768:\tresult = hfsplus_asc2uni(\u0026mock_sb-\u003esb, \u0026mock_env-\u003estr1,\nfs/hfsplus/unicode_test.c-769-\t\t\t\t HFSPLUS_MAX_STRLEN, \":\", 1,\n--\nfs/hfsplus/unicode_test.c-776-\t/* Test string with mixed special characters */\nfs/hfsplus/unicode_test.c:777:\tresult = hfsplus_asc2uni(\u0026mock_sb-\u003esb, \u0026mock_env-\u003estr1,\nfs/hfsplus/unicode_test.c-778-\t\t\t\t HFSPLUS_MAX_STRLEN, \"a:b\", 3,\n--\nfs/hfsplus/unicode_test.c-787-\t/* Test multiple special characters */\nfs/hfsplus/unicode_test.c:788:\tresult = hfsplus_asc2uni(\u0026mock_sb-\u003esb, \u0026mock_env-\u003estr1,\nfs/hfsplus/unicode_test.c-789-\t\t\t\t HFSPLUS_MAX_STRLEN, \":::\", 3,\n--\nfs/hfsplus/unicode_test.c-802-/* Test buffer length limits */\nfs/hfsplus/unicode_test.c:803:static void hfsplus_asc2uni_buffer_limits_test(struct kunit *test)\nfs/hfsplus/unicode_test.c-804-{\n--\nfs/hfsplus/unicode_test.c-818-\tmemset(mock_env-\u003ebuf, 'a', HFSPLUS_MAX_STRLEN);\nfs/hfsplus/unicode_test.c:819:\tresult = hfsplus_asc2uni(\u0026mock_sb-\u003esb,\nfs/hfsplus/unicode_test.c-820-\t\t\t\t \u0026mock_env-\u003estr1, HFSPLUS_MAX_STRLEN,\n--\nfs/hfsplus/unicode_test.c-829-\tmemset(mock_env-\u003ebuf, 'a', HFSPLUS_MAX_STRLEN + 5);\nfs/hfsplus/unicode_test.c:830:\tresult = hfsplus_asc2uni(\u0026mock_sb-\u003esb,\nfs/hfsplus/unicode_test.c-831-\t\t\t\t \u0026mock_env-\u003estr1, HFSPLUS_MAX_STRLEN,\n--\nfs/hfsplus/unicode_test.c-839-\t/* Test with smaller max_unistr_len */\nfs/hfsplus/unicode_test.c:840:\tresult = hfsplus_asc2uni(\u0026mock_sb-\u003esb,\nfs/hfsplus/unicode_test.c-841-\t\t\t\t \u0026mock_env-\u003estr1, 5, \"toolongstring\", 13,\n--\nfs/hfsplus/unicode_test.c-847-\t/* Test zero max length */\nfs/hfsplus/unicode_test.c:848:\tresult = hfsplus_asc2uni(\u0026mock_sb-\u003esb, \u0026mock_env-\u003estr1, 0, \"test\", 4,\nfs/hfsplus/unicode_test.c-849-\t\t\t\t HFS_REGULAR_NAME);\n--\nfs/hfsplus/unicode_test.c-858-/* Test error handling and edge cases */\nfs/hfsplus/unicode_test.c:859:static void hfsplus_asc2uni_edge_cases_test(struct kunit *test)\nfs/hfsplus/unicode_test.c-860-{\n--\nfs/hfsplus/unicode_test.c-871-\t/* Test zero length input */\nfs/hfsplus/unicode_test.c:872:\tresult = hfsplus_asc2uni(\u0026mock_sb-\u003esb,\nfs/hfsplus/unicode_test.c-873-\t\t\t\t \u0026ustr, HFSPLUS_MAX_STRLEN, \"test\", 0,\n--\nfs/hfsplus/unicode_test.c-879-\t/* Test input with length mismatch */\nfs/hfsplus/unicode_test.c:880:\tresult = hfsplus_asc2uni(\u0026mock_sb-\u003esb,\nfs/hfsplus/unicode_test.c-881-\t\t\t\t \u0026ustr, HFSPLUS_MAX_STRLEN, \"hello\", 3,\n--\nfs/hfsplus/unicode_test.c-887-\t/* Test with various printable ASCII characters */\nfs/hfsplus/unicode_test.c:888:\tresult = hfsplus_asc2uni(\u0026mock_sb-\u003esb,\nfs/hfsplus/unicode_test.c-889-\t\t\t\t \u0026ustr, HFSPLUS_MAX_STRLEN, \"ABC123!@#\", 9,\n--\nfs/hfsplus/unicode_test.c-895-\t/* Test null character in the middle */\nfs/hfsplus/unicode_test.c:896:\tresult = hfsplus_asc2uni(\u0026mock_sb-\u003esb,\nfs/hfsplus/unicode_test.c-897-\t\t\t\t \u0026ustr, HFSPLUS_MAX_STRLEN, test_str, 3,\n--\nfs/hfsplus/unicode_test.c-909-/* Test decomposition flag behavior */\nfs/hfsplus/unicode_test.c:910:static void hfsplus_asc2uni_decompose_test(struct kunit *test)\nfs/hfsplus/unicode_test.c-911-{\n--\nfs/hfsplus/unicode_test.c-925-\tclear_bit(HFSPLUS_SB_NODECOMPOSE, \u0026mock_sb-\u003esb_info.flags);\nfs/hfsplus/unicode_test.c:926:\tresult = hfsplus_asc2uni(\u0026mock_sb-\u003esb, \u0026mock_env-\u003estr1,\nfs/hfsplus/unicode_test.c-927-\t\t\t\t HFSPLUS_MAX_STRLEN, \"test\", 4,\n--\nfs/hfsplus/unicode_test.c-934-\tset_bit(HFSPLUS_SB_NODECOMPOSE, \u0026mock_sb-\u003esb_info.flags);\nfs/hfsplus/unicode_test.c:935:\tresult = hfsplus_asc2uni(\u0026mock_sb-\u003esb, \u0026mock_env-\u003estr2,\nfs/hfsplus/unicode_test.c-936-\t\t\t\t HFSPLUS_MAX_STRLEN, \"test\", 4,\n--\nfs/hfsplus/unicode_test.c=972=static int test_uni2char_utf8(wchar_t uni, unsigned char *out, int boundlen)\n--\nfs/hfsplus/unicode_test.c-983-/*\nfs/hfsplus/unicode_test.c:984: * Test that hfsplus_asc2uni() brings combining marks contributed by\nfs/hfsplus/unicode_test.c-985- * different source characters into Unicode canonical (combining-class)\n--\nfs/hfsplus/unicode_test.c-995- */\nfs/hfsplus/unicode_test.c:996:static void hfsplus_asc2uni_combining_reorder_test(struct kunit *test)\nfs/hfsplus/unicode_test.c-997-{\n--\nfs/hfsplus/unicode_test.c-1013-\t/* Typed out of canonical order: must be reordered on storage. */\nfs/hfsplus/unicode_test.c:1014:\tresult = hfsplus_asc2uni(\u0026mock_sb-\u003esb, \u0026ustr, HFSPLUS_MAX_STRLEN,\nfs/hfsplus/unicode_test.c-1015-\t\t\t\t wrong_order, strlen(wrong_order),\n--\nfs/hfsplus/unicode_test.c-1024-\t/* Already in canonical order: must come out unchanged. */\nfs/hfsplus/unicode_test.c:1025:\tresult = hfsplus_asc2uni(\u0026mock_sb-\u003esb, \u0026ustr, HFSPLUS_MAX_STRLEN,\nfs/hfsplus/unicode_test.c-1026-\t\t\t\t canonical_order, strlen(canonical_order),\n--\nfs/hfsplus/unicode_test.c-1037-\t */\nfs/hfsplus/unicode_test.c:1038:\tresult = hfsplus_asc2uni(\u0026mock_sb-\u003esb, \u0026ustr, HFSPLUS_MAX_STRLEN,\nfs/hfsplus/unicode_test.c-1039-\t\t\t\t same_class, strlen(same_class),\n--\nfs/hfsplus/unicode_test.c-1053- * still reads back as valid, correct UTF-8 once reordered - i.e. that\nfs/hfsplus/unicode_test.c:1054: * hfsplus_asc2uni() and hfsplus_uni2asc_str() stay consistent with each\nfs/hfsplus/unicode_test.c-1055- * other across the reordering.\n--\nfs/hfsplus/unicode_test.c=1062=static void hfsplus_unicode_combining_reorder_roundtrip_test(struct kunit *test)\n--\nfs/hfsplus/unicode_test.c-1078-\nfs/hfsplus/unicode_test.c:1079:\tresult = hfsplus_asc2uni(\u0026mock_sb-\u003esb, \u0026ustr, HFSPLUS_MAX_STRLEN,\nfs/hfsplus/unicode_test.c-1080-\t\t\t\t wrong_order, strlen(wrong_order),\n--\nfs/hfsplus/unicode_test.c-1093-/*\nfs/hfsplus/unicode_test.c:1094: * Test that hfsplus_asc2uni() decomposes a character using the corrected\nfs/hfsplus/unicode_test.c-1095- * (post-2002/\"Jaguar\") canonical decomposition even when Apple Technote\n--\nfs/hfsplus/unicode_test.c-1101- */\nfs/hfsplus/unicode_test.c:1102:static void hfsplus_asc2uni_legacy_decomp_test(struct kunit *test)\nfs/hfsplus/unicode_test.c-1103-{\n--\nfs/hfsplus/unicode_test.c-1113-\nfs/hfsplus/unicode_test.c:1114:\tresult = hfsplus_asc2uni(\u0026mock_sb-\u003esb, \u0026ustr, HFSPLUS_MAX_STRLEN,\nfs/hfsplus/unicode_test.c-1115-\t\t\t\t input, strlen(input), HFS_REGULAR_NAME);\n--\nfs/hfsplus/unicode_test.c-1125-/*\nfs/hfsplus/unicode_test.c:1126: * Test that hfsplus_asc2uni() corrects two more of fsck_hfs's known\nfs/hfsplus/unicode_test.c-1127- * legacy decomposition sequences once combining marks from independently\n--\nfs/hfsplus/unicode_test.c-1134- */\nfs/hfsplus/unicode_test.c:1135:static void hfsplus_asc2uni_legacy_seq_fixup_test(struct kunit *test)\nfs/hfsplus/unicode_test.c-1136-{\n--\nfs/hfsplus/unicode_test.c-1147-\nfs/hfsplus/unicode_test.c:1148:\tresult = hfsplus_asc2uni(\u0026mock_sb-\u003esb, \u0026ustr, HFSPLUS_MAX_STRLEN,\nfs/hfsplus/unicode_test.c-1149-\t\t\t\t greek_input, strlen(greek_input),\n--\nfs/hfsplus/unicode_test.c-1156-\nfs/hfsplus/unicode_test.c:1157:\tresult = hfsplus_asc2uni(\u0026mock_sb-\u003esb, \u0026ustr, HFSPLUS_MAX_STRLEN,\nfs/hfsplus/unicode_test.c-1158-\t\t\t\t bengali_input, strlen(bengali_input),\n--\nfs/hfsplus/unicode_test.c-1167-\nfs/hfsplus/unicode_test.c:1168:/* Mock dentry for testing hfsplus_hash_dentry */\nfs/hfsplus/unicode_test.c-1169-static struct dentry test_dentry;\n--\nfs/hfsplus/unicode_test.c=1178=static void create_qstr(struct qstr *str, const char *name)\n--\nfs/hfsplus/unicode_test.c-1184-\nfs/hfsplus/unicode_test.c:1185:/* Test hfsplus_hash_dentry basic functionality */\nfs/hfsplus/unicode_test.c:1186:static void hfsplus_hash_dentry_basic_test(struct kunit *test)\nfs/hfsplus/unicode_test.c-1187-{\n--\nfs/hfsplus/unicode_test.c-1199-\tcreate_qstr(\u0026str1, \"hello\");\nfs/hfsplus/unicode_test.c:1200:\tresult = hfsplus_hash_dentry(\u0026test_dentry, \u0026str1);\nfs/hfsplus/unicode_test.c-1201-\n--\nfs/hfsplus/unicode_test.c-1206-\tcreate_qstr(\u0026str2, \"hello\");\nfs/hfsplus/unicode_test.c:1207:\tresult = hfsplus_hash_dentry(\u0026test_dentry, \u0026str2);\nfs/hfsplus/unicode_test.c-1208-\n--\nfs/hfsplus/unicode_test.c-1213-\tcreate_qstr(\u0026str1, \"\");\nfs/hfsplus/unicode_test.c:1214:\tresult = hfsplus_hash_dentry(\u0026test_dentry, \u0026str1);\nfs/hfsplus/unicode_test.c-1215-\n--\nfs/hfsplus/unicode_test.c-1220-\tcreate_qstr(\u0026str1, \"A\");\nfs/hfsplus/unicode_test.c:1221:\tresult = hfsplus_hash_dentry(\u0026test_dentry, \u0026str1);\nfs/hfsplus/unicode_test.c-1222-\n--\nfs/hfsplus/unicode_test.c-1229-/* Test case folding behavior in hash */\nfs/hfsplus/unicode_test.c:1230:static void hfsplus_hash_dentry_casefold_test(struct kunit *test)\nfs/hfsplus/unicode_test.c-1231-{\n--\nfs/hfsplus/unicode_test.c-1245-\tcreate_qstr(\u0026str1, \"Hello\");\nfs/hfsplus/unicode_test.c:1246:\tresult = hfsplus_hash_dentry(\u0026test_dentry, \u0026str1);\nfs/hfsplus/unicode_test.c-1247-\tKUNIT_EXPECT_EQ(test, 0, result);\n--\nfs/hfsplus/unicode_test.c-1249-\tcreate_qstr(\u0026str2, \"hello\");\nfs/hfsplus/unicode_test.c:1250:\tresult = hfsplus_hash_dentry(\u0026test_dentry, \u0026str2);\nfs/hfsplus/unicode_test.c-1251-\tKUNIT_EXPECT_EQ(test, 0, result);\n--\nfs/hfsplus/unicode_test.c-1262-\tcreate_qstr(\u0026str1, \"Hello\");\nfs/hfsplus/unicode_test.c:1263:\tresult = hfsplus_hash_dentry(\u0026test_dentry, \u0026str1);\nfs/hfsplus/unicode_test.c-1264-\tKUNIT_EXPECT_EQ(test, 0, result);\n--\nfs/hfsplus/unicode_test.c-1266-\tcreate_qstr(\u0026str2, \"hello\");\nfs/hfsplus/unicode_test.c:1267:\tresult = hfsplus_hash_dentry(\u0026test_dentry, \u0026str2);\nfs/hfsplus/unicode_test.c-1268-\tKUNIT_EXPECT_EQ(test, 0, result);\n--\nfs/hfsplus/unicode_test.c-1274-\tcreate_qstr(\u0026str1, \"HeLLo\");\nfs/hfsplus/unicode_test.c:1275:\tresult = hfsplus_hash_dentry(\u0026test_dentry, \u0026str1);\nfs/hfsplus/unicode_test.c-1276-\tKUNIT_EXPECT_EQ(test, 0, result);\n--\nfs/hfsplus/unicode_test.c-1282-/* Test special character handling in hash */\nfs/hfsplus/unicode_test.c:1283:static void hfsplus_hash_dentry_special_chars_test(struct kunit *test)\nfs/hfsplus/unicode_test.c-1284-{\n--\nfs/hfsplus/unicode_test.c-1296-\tcreate_qstr(\u0026str1, \"file:name\");\nfs/hfsplus/unicode_test.c:1297:\tresult = hfsplus_hash_dentry(\u0026test_dentry, \u0026str1);\nfs/hfsplus/unicode_test.c-1298-\tKUNIT_EXPECT_EQ(test, 0, result);\n--\nfs/hfsplus/unicode_test.c-1300-\tcreate_qstr(\u0026str2, \"file/name\");\nfs/hfsplus/unicode_test.c:1301:\tresult = hfsplus_hash_dentry(\u0026test_dentry, \u0026str2);\nfs/hfsplus/unicode_test.c-1302-\tKUNIT_EXPECT_EQ(test, 0, result);\n--\nfs/hfsplus/unicode_test.c-1308-\tcreate_qstr(\u0026str1, \":::\");\nfs/hfsplus/unicode_test.c:1309:\tresult = hfsplus_hash_dentry(\u0026test_dentry, \u0026str1);\nfs/hfsplus/unicode_test.c-1310-\tKUNIT_EXPECT_EQ(test, 0, result);\n--\nfs/hfsplus/unicode_test.c-1312-\tcreate_qstr(\u0026str2, \"///\");\nfs/hfsplus/unicode_test.c:1313:\tresult = hfsplus_hash_dentry(\u0026test_dentry, \u0026str2);\nfs/hfsplus/unicode_test.c-1314-\tKUNIT_EXPECT_EQ(test, 0, result);\n--\nfs/hfsplus/unicode_test.c-1321-/* Test decomposition flag behavior in hash */\nfs/hfsplus/unicode_test.c:1322:static void hfsplus_hash_dentry_decompose_test(struct kunit *test)\nfs/hfsplus/unicode_test.c-1323-{\n--\nfs/hfsplus/unicode_test.c-1337-\tcreate_qstr(\u0026str1, \"test\");\nfs/hfsplus/unicode_test.c:1338:\tresult = hfsplus_hash_dentry(\u0026test_dentry, \u0026str1);\nfs/hfsplus/unicode_test.c-1339-\tKUNIT_EXPECT_EQ(test, 0, result);\n--\nfs/hfsplus/unicode_test.c-1344-\tcreate_qstr(\u0026str2, \"test\");\nfs/hfsplus/unicode_test.c:1345:\tresult = hfsplus_hash_dentry(\u0026test_dentry, \u0026str2);\nfs/hfsplus/unicode_test.c-1346-\tKUNIT_EXPECT_EQ(test, 0, result);\n--\nfs/hfsplus/unicode_test.c-1357-/* Test hash consistency and distribution */\nfs/hfsplus/unicode_test.c:1358:static void hfsplus_hash_dentry_consistency_test(struct kunit *test)\nfs/hfsplus/unicode_test.c-1359-{\n--\nfs/hfsplus/unicode_test.c-1372-\tcreate_qstr(\u0026str1, \"consistent\");\nfs/hfsplus/unicode_test.c:1373:\tresult = hfsplus_hash_dentry(\u0026test_dentry, \u0026str1);\nfs/hfsplus/unicode_test.c-1374-\tKUNIT_EXPECT_EQ(test, 0, result);\n--\nfs/hfsplus/unicode_test.c-1377-\tcreate_qstr(\u0026str2, \"consistent\");\nfs/hfsplus/unicode_test.c:1378:\tresult = hfsplus_hash_dentry(\u0026test_dentry, \u0026str2);\nfs/hfsplus/unicode_test.c-1379-\tKUNIT_EXPECT_EQ(test, 0, result);\n--\nfs/hfsplus/unicode_test.c-1384-\tcreate_qstr(\u0026str3, \"different\");\nfs/hfsplus/unicode_test.c:1385:\tresult = hfsplus_hash_dentry(\u0026test_dentry, \u0026str3);\nfs/hfsplus/unicode_test.c-1386-\tKUNIT_EXPECT_EQ(test, 0, result);\n--\nfs/hfsplus/unicode_test.c-1391-\tcreate_qstr(\u0026str1, \"file1\");\nfs/hfsplus/unicode_test.c:1392:\tresult = hfsplus_hash_dentry(\u0026test_dentry, \u0026str1);\nfs/hfsplus/unicode_test.c-1393-\tKUNIT_EXPECT_EQ(test, 0, result);\n--\nfs/hfsplus/unicode_test.c-1395-\tcreate_qstr(\u0026str2, \"file2\");\nfs/hfsplus/unicode_test.c:1396:\tresult = hfsplus_hash_dentry(\u0026test_dentry, \u0026str2);\nfs/hfsplus/unicode_test.c-1397-\tKUNIT_EXPECT_EQ(test, 0, result);\n--\nfs/hfsplus/unicode_test.c-1404-/* Test edge cases and boundary conditions */\nfs/hfsplus/unicode_test.c:1405:static void hfsplus_hash_dentry_edge_cases_test(struct kunit *test)\nfs/hfsplus/unicode_test.c-1406-{\n--\nfs/hfsplus/unicode_test.c-1425-\tcreate_qstr(\u0026str, mock_env-\u003ebuf);\nfs/hfsplus/unicode_test.c:1426:\tresult = hfsplus_hash_dentry(\u0026test_dentry, \u0026str);\nfs/hfsplus/unicode_test.c-1427-\n--\nfs/hfsplus/unicode_test.c-1432-\tcreate_qstr(\u0026str, \"!@#$%^\u0026*()_+-=[]{}|;':\\\",./\u003c\u003e?\");\nfs/hfsplus/unicode_test.c:1433:\tresult = hfsplus_hash_dentry(\u0026test_dentry, \u0026str);\nfs/hfsplus/unicode_test.c-1434-\n--\nfs/hfsplus/unicode_test.c-1441-\tstr.hash = 0;\nfs/hfsplus/unicode_test.c:1442:\tresult = hfsplus_hash_dentry(\u0026test_dentry, \u0026str);\nfs/hfsplus/unicode_test.c-1443-\n--\nfs/hfsplus/unicode_test.c-1451-/*\nfs/hfsplus/unicode_test.c:1452: * Test that hfsplus_hash_dentry() hashes two names identically when they\nfs/hfsplus/unicode_test.c-1453- * differ only in the (non-canonical) typed order of the same combining\n--\nfs/hfsplus/unicode_test.c-1456- */\nfs/hfsplus/unicode_test.c:1457:static void hfsplus_hash_dentry_combining_reorder_test(struct kunit *test)\nfs/hfsplus/unicode_test.c-1458-{\n--\nfs/hfsplus/unicode_test.c-1469-\tcreate_qstr(\u0026str1, \"e\\xcc\\x81\\xcc\\xa3\"); /* acute, then dot-below */\nfs/hfsplus/unicode_test.c:1470:\tresult = hfsplus_hash_dentry(\u0026test_dentry, \u0026str1);\nfs/hfsplus/unicode_test.c-1471-\tKUNIT_EXPECT_EQ(test, 0, result);\n--\nfs/hfsplus/unicode_test.c-1473-\tcreate_qstr(\u0026str2, \"e\\xcc\\xa3\\xcc\\x81\"); /* dot-below, then acute */\nfs/hfsplus/unicode_test.c:1474:\tresult = hfsplus_hash_dentry(\u0026test_dentry, \u0026str2);\nfs/hfsplus/unicode_test.c-1475-\tKUNIT_EXPECT_EQ(test, 0, result);\n--\nfs/hfsplus/unicode_test.c-1481-\nfs/hfsplus/unicode_test.c:1482:/* Test hfsplus_compare_dentry basic functionality */\nfs/hfsplus/unicode_test.c:1483:static void hfsplus_compare_dentry_basic_test(struct kunit *test)\nfs/hfsplus/unicode_test.c-1484-{\n--\nfs/hfsplus/unicode_test.c-1496-\tcreate_qstr(\u0026name, \"hello\");\nfs/hfsplus/unicode_test.c:1497:\tresult = hfsplus_compare_dentry(\u0026test_dentry, 5, \"hello\", \u0026name);\nfs/hfsplus/unicode_test.c-1498-\tKUNIT_EXPECT_EQ(test, 0, result);\n--\nfs/hfsplus/unicode_test.c-1501-\tcreate_qstr(\u0026name, \"world\");\nfs/hfsplus/unicode_test.c:1502:\tresult = hfsplus_compare_dentry(\u0026test_dentry, 5, \"hello\", \u0026name);\nfs/hfsplus/unicode_test.c-1503-\tKUNIT_EXPECT_LT(test, result, 0); /* \"hello\" \u003c \"world\" */\nfs/hfsplus/unicode_test.c-1504-\nfs/hfsplus/unicode_test.c:1505:\tresult = hfsplus_compare_dentry(\u0026test_dentry, 5, \"world\", \u0026name);\nfs/hfsplus/unicode_test.c-1506-\tKUNIT_EXPECT_EQ(test, 0, result);\n--\nfs/hfsplus/unicode_test.c-1508-\tcreate_qstr(\u0026name, \"hello\");\nfs/hfsplus/unicode_test.c:1509:\tresult = hfsplus_compare_dentry(\u0026test_dentry, 5, \"world\", \u0026name);\nfs/hfsplus/unicode_test.c-1510-\tKUNIT_EXPECT_GT(test, result, 0); /* \"world\" \u003e \"hello\" */\n--\nfs/hfsplus/unicode_test.c-1513-\tcreate_qstr(\u0026name, \"\");\nfs/hfsplus/unicode_test.c:1514:\tresult = hfsplus_compare_dentry(\u0026test_dentry, 0, \"\", \u0026name);\nfs/hfsplus/unicode_test.c-1515-\tKUNIT_EXPECT_EQ(test, 0, result);\n--\nfs/hfsplus/unicode_test.c-1518-\tcreate_qstr(\u0026name, \"test\");\nfs/hfsplus/unicode_test.c:1519:\tresult = hfsplus_compare_dentry(\u0026test_dentry, 0, \"\", \u0026name);\nfs/hfsplus/unicode_test.c-1520-\tKUNIT_EXPECT_LT(test, result, 0); /* \"\" \u003c \"test\" */\n--\nfs/hfsplus/unicode_test.c-1522-\tcreate_qstr(\u0026name, \"\");\nfs/hfsplus/unicode_test.c:1523:\tresult = hfsplus_compare_dentry(\u0026test_dentry, 4, \"test\", \u0026name);\nfs/hfsplus/unicode_test.c-1524-\tKUNIT_EXPECT_GT(test, result, 0); /* \"test\" \u003e \"\" */\n--\nfs/hfsplus/unicode_test.c-1529-/* Test case folding behavior in comparison */\nfs/hfsplus/unicode_test.c:1530:static void hfsplus_compare_dentry_casefold_test(struct kunit *test)\nfs/hfsplus/unicode_test.c-1531-{\n--\nfs/hfsplus/unicode_test.c-1545-\tcreate_qstr(\u0026name, \"hello\");\nfs/hfsplus/unicode_test.c:1546:\tresult = hfsplus_compare_dentry(\u0026test_dentry, 5, \"Hello\", \u0026name);\nfs/hfsplus/unicode_test.c-1547-\t/* Case sensitive: \"Hello\" != \"hello\" */\n--\nfs/hfsplus/unicode_test.c-1550-\tcreate_qstr(\u0026name, \"Hello\");\nfs/hfsplus/unicode_test.c:1551:\tresult = hfsplus_compare_dentry(\u0026test_dentry, 5, \"hello\", \u0026name);\nfs/hfsplus/unicode_test.c-1552-\t/* Case sensitive: \"hello\" != \"Hello\" */\n--\nfs/hfsplus/unicode_test.c-1558-\tcreate_qstr(\u0026name, \"hello\");\nfs/hfsplus/unicode_test.c:1559:\tresult = hfsplus_compare_dentry(\u0026test_dentry, 5, \"Hello\", \u0026name);\nfs/hfsplus/unicode_test.c-1560-\t/* Case insensitive: \"Hello\" == \"hello\" */\n--\nfs/hfsplus/unicode_test.c-1563-\tcreate_qstr(\u0026name, \"Hello\");\nfs/hfsplus/unicode_test.c:1564:\tresult = hfsplus_compare_dentry(\u0026test_dentry, 5, \"hello\", \u0026name);\nfs/hfsplus/unicode_test.c-1565-\t/* Case insensitive: \"hello\" == \"Hello\" */\n--\nfs/hfsplus/unicode_test.c-1569-\tcreate_qstr(\u0026name, \"TeSt\");\nfs/hfsplus/unicode_test.c:1570:\tresult = hfsplus_compare_dentry(\u0026test_dentry, 4, \"test\", \u0026name);\nfs/hfsplus/unicode_test.c-1571-\tKUNIT_EXPECT_EQ(test, 0, result);\n--\nfs/hfsplus/unicode_test.c-1573-\tcreate_qstr(\u0026name, \"test\");\nfs/hfsplus/unicode_test.c:1574:\tresult = hfsplus_compare_dentry(\u0026test_dentry, 4, \"TEST\", \u0026name);\nfs/hfsplus/unicode_test.c-1575-\tKUNIT_EXPECT_EQ(test, 0, result);\n--\nfs/hfsplus/unicode_test.c-1580-/* Test special character handling in comparison */\nfs/hfsplus/unicode_test.c:1581:static void hfsplus_compare_dentry_special_chars_test(struct kunit *test)\nfs/hfsplus/unicode_test.c-1582-{\n--\nfs/hfsplus/unicode_test.c-1594-\tcreate_qstr(\u0026name, \"file/name\");\nfs/hfsplus/unicode_test.c:1595:\tresult = hfsplus_compare_dentry(\u0026test_dentry, 9, \"file:name\", \u0026name);\nfs/hfsplus/unicode_test.c-1596-\t/* \"file:name\" == \"file/name\" after conversion */\n--\nfs/hfsplus/unicode_test.c-1599-\tcreate_qstr(\u0026name, \"file:name\");\nfs/hfsplus/unicode_test.c:1600:\tresult = hfsplus_compare_dentry(\u0026test_dentry, 9, \"file/name\", \u0026name);\nfs/hfsplus/unicode_test.c-1601-\t/* \"file/name\" == \"file:name\" after conversion */\n--\nfs/hfsplus/unicode_test.c-1605-\tcreate_qstr(\u0026name, \"///\");\nfs/hfsplus/unicode_test.c:1606:\tresult = hfsplus_compare_dentry(\u0026test_dentry, 3, \":::\", \u0026name);\nfs/hfsplus/unicode_test.c-1607-\tKUNIT_EXPECT_EQ(test, 0, result);\n--\nfs/hfsplus/unicode_test.c-1610-\tcreate_qstr(\u0026name, \"a/b:c\");\nfs/hfsplus/unicode_test.c:1611:\tresult = hfsplus_compare_dentry(\u0026test_dentry, 5, \"a:b/c\", \u0026name);\nfs/hfsplus/unicode_test.c-1612-\t/* Both become \"a/b/c\" after conversion */\n--\nfs/hfsplus/unicode_test.c-1618-/* Test length differences */\nfs/hfsplus/unicode_test.c:1619:static void hfsplus_compare_dentry_length_test(struct kunit *test)\nfs/hfsplus/unicode_test.c-1620-{\n--\nfs/hfsplus/unicode_test.c-1632-\tcreate_qstr(\u0026name, \"testing\");\nfs/hfsplus/unicode_test.c:1633:\tresult = hfsplus_compare_dentry(\u0026test_dentry, 4, \"test\", \u0026name);\nfs/hfsplus/unicode_test.c-1634-\tKUNIT_EXPECT_LT(test, result, 0); /* \"test\" \u003c \"testing\" */\n--\nfs/hfsplus/unicode_test.c-1636-\tcreate_qstr(\u0026name, \"test\");\nfs/hfsplus/unicode_test.c:1637:\tresult = hfsplus_compare_dentry(\u0026test_dentry, 7, \"testing\", \u0026name);\nfs/hfsplus/unicode_test.c-1638-\tKUNIT_EXPECT_GT(test, result, 0); /* \"testing\" \u003e \"test\" */\n--\nfs/hfsplus/unicode_test.c-1641-\tcreate_qstr(\u0026name, \"exact\");\nfs/hfsplus/unicode_test.c:1642:\tresult = hfsplus_compare_dentry(\u0026test_dentry, 5, \"exact\", \u0026name);\nfs/hfsplus/unicode_test.c-1643-\tKUNIT_EXPECT_EQ(test, 0, result);\n--\nfs/hfsplus/unicode_test.c-1646-\tcreate_qstr(\u0026name, \"hello\");\nfs/hfsplus/unicode_test.c:1647:\tresult = hfsplus_compare_dentry(\u0026test_dentry, 3, \"hel\", \u0026name);\nfs/hfsplus/unicode_test.c-1648-\tKUNIT_EXPECT_LT(test, result, 0); /* \"hel\" \u003c \"hello\" */\n--\nfs/hfsplus/unicode_test.c-1651-\tcreate_qstr(\u0026name, \"hi\");\nfs/hfsplus/unicode_test.c:1652:\tresult = hfsplus_compare_dentry(\u0026test_dentry, 2, \"hello\", \u0026name);\nfs/hfsplus/unicode_test.c-1653-\t/* \"he\" \u003c \"hi\" (only first 2 chars compared) */\n--\nfs/hfsplus/unicode_test.c-1659-/* Test decomposition flag behavior */\nfs/hfsplus/unicode_test.c:1660:static void hfsplus_compare_dentry_decompose_test(struct kunit *test)\nfs/hfsplus/unicode_test.c-1661-{\n--\nfs/hfsplus/unicode_test.c-1675-\tcreate_qstr(\u0026name, \"test\");\nfs/hfsplus/unicode_test.c:1676:\tresult = hfsplus_compare_dentry(\u0026test_dentry, 4, \"test\", \u0026name);\nfs/hfsplus/unicode_test.c-1677-\tKUNIT_EXPECT_EQ(test, 0, result);\n--\nfs/hfsplus/unicode_test.c-1682-\tcreate_qstr(\u0026name, \"test\");\nfs/hfsplus/unicode_test.c:1683:\tresult = hfsplus_compare_dentry(\u0026test_dentry, 4, \"test\", \u0026name);\nfs/hfsplus/unicode_test.c-1684-\tKUNIT_EXPECT_EQ(test, 0, result);\n--\nfs/hfsplus/unicode_test.c-1687-\tcreate_qstr(\u0026name, \"different\");\nfs/hfsplus/unicode_test.c:1688:\tresult = hfsplus_compare_dentry(\u0026test_dentry, 4, \"test\", \u0026name);\nfs/hfsplus/unicode_test.c-1689-\tKUNIT_EXPECT_NE(test, 0, result);\n--\nfs/hfsplus/unicode_test.c-1694-/* Test edge cases and boundary conditions */\nfs/hfsplus/unicode_test.c:1695:static void hfsplus_compare_dentry_edge_cases_test(struct kunit *test)\nfs/hfsplus/unicode_test.c-1696-{\n--\nfs/hfsplus/unicode_test.c-1725-\tcreate_qstr(\u0026name, long_str);\nfs/hfsplus/unicode_test.c:1726:\tresult = hfsplus_compare_dentry(\u0026test_dentry, str_size - 1,\nfs/hfsplus/unicode_test.c-1727-\t\t\t\t\tlong_str, \u0026name);\n--\nfs/hfsplus/unicode_test.c-1734-\tcreate_qstr(\u0026name, long_str2);\nfs/hfsplus/unicode_test.c:1735:\tresult = hfsplus_compare_dentry(\u0026test_dentry, str_size - 1,\nfs/hfsplus/unicode_test.c-1736-\t\t\t\t\tlong_str, \u0026name);\n--\nfs/hfsplus/unicode_test.c-1740-\tcreate_qstr(\u0026name, \"b\");\nfs/hfsplus/unicode_test.c:1741:\tresult = hfsplus_compare_dentry(\u0026test_dentry, 1, \"a\", \u0026name);\n\n"
}

9/2 2026/09/21 03:51 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 50903
							output: 38
							thoughts: 335
						

Thoughts:
**HFS+ Vulnerability Hunt**

Okay, let's break this down. First, I'm noting the key functions within the HFS+ filesystem implementation in the Linux kernel: `hfsplus_dentry_operations` with its hashing and comparison functions, and `hfsplus_asc2uni`, which is critical for character conversion in various operations. HFS+ is definitely supported, that's good. Syzkaller can, in theory, interact with it through images and system calls like `syz_mount_image`, or even loop devices. That's a significant point.

But the real question is whether HFS+ is readily accessible within common virtualization environments like QEMU or GCE for Syzkaller to interact with and test. And yes, it is. Ext4, btrfs, HFS+, f2fs, and NTFS are all mountable, opening up the possibility of fuzzing this thing. This is important: now the hunt begins for vulnerabilities.

Now, it's time to dive into the code. I need to scrutinize any code changes, looking for subtle issues. Things like subtle bugs, out-of-bounds reads or writes, buffer overflows, or even potential infinite loops are what I'm looking for. This needs to be a detailed, line-by-line inspection. I'll start with the string manipulation routines: `hfsplus_decompose_str`, `hfsplus_canonical_reorder`, `hfsplus_fixup_legacy_sequences`, and the `hfsplus_decompose_iter_*` functions. I'll focus my attention on `fs/hfsplus/tables.c` and `fs/hfsplus/unicode.c` because they are likely the source of character handling issues.



10/2 2026/09/21 03:52 tool read-file
0m Args:
{
  "File": "fs/hfsplus/tables.c",
  "FirstLine": 3690,
  "LineCount": 60
}

Results:
{
  "Contents": "3690:\t\t\t}\n3691:\t\t}\n3692:\t\n3693:\t\treturn NULL;\n3694:\t}\n3695:\t\n3696:\t/*\n3697:\t * Scan an already decomposed and canonically-reordered code unit buffer\n3698:\t * for any of the short legacy sequences above and replace them in place\n3699:\t * with their corrected form. @len is updated to the buffer's new length.\n3700:\t */\n3701:\tvoid hfsplus_fixup_legacy_sequences(u16 *buf, int *len)\n3702:\t{\n3703:\t\tint i = 0;\n3704:\t\n3705:\t\twhile (i \u003c *len) {\n3706:\t\t\tunsigned int j;\n3707:\t\t\tbool matched = false;\n3708:\t\n3709:\t\t\tfor (j = 0; j \u003c ARRAY_SIZE(hfsplus_legacy_seq_fixups); j++) {\n3710:\t\t\t\tstruct hfsplus_legacy_seq_fixup *f =\n3711:\t\t\t\t\t\t\t\u0026hfsplus_legacy_seq_fixups[j];\n3712:\t\t\t\tu16 *src, *dst;\n3713:\t\t\t\tsize_t copy_len;\n3714:\t\t\t\tint k;\n3715:\t\n3716:\t\t\t\tif (i + f-\u003ematch_len \u003e *len)\n3717:\t\t\t\t\tcontinue;\n3718:\t\t\t\tfor (k = 0; k \u003c f-\u003ematch_len; k++)\n3719:\t\t\t\t\tif (buf[i + k] != f-\u003ematch[k])\n3720:\t\t\t\t\t\tbreak;\n3721:\t\t\t\tif (k != f-\u003ematch_len)\n3722:\t\t\t\t\tcontinue;\n3723:\t\n3724:\t\t\t\tdst = \u0026buf[i + f-\u003erepl_len];\n3725:\t\t\t\tsrc = \u0026buf[i + f-\u003ematch_len];\n3726:\t\t\t\tcopy_len = (*len - i - f-\u003ematch_len) * sizeof(*buf);\n3727:\t\t\t\tmemmove(dst, src, copy_len);\n3728:\t\n3729:\t\t\t\tdst = \u0026buf[i];\n3730:\t\t\t\tsrc = f-\u003erepl;\n3731:\t\t\t\tcopy_len = f-\u003erepl_len * sizeof(*buf);\n3732:\t\t\t\tmemcpy(dst, src, copy_len);\n3733:\t\n3734:\t\t\t\t*len += f-\u003erepl_len - f-\u003ematch_len;\n3735:\t\t\t\tmatched = true;\n3736:\t\t\t\tbreak;\n3737:\t\t\t}\n3738:\t\n3739:\t\t\tif (!matched)\n3740:\t\t\t\ti++;\n3741:\t\t}\n3742:\t}\n"
}

11/2 2026/09/21 03:52 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 52393
							output: 37
							thoughts: 857
						

Thoughts:
**Analyzing the hfsplus_fixup_legacy_sequences Function**

Okay, let's break this down. I'm focusing on `hfsplus_fixup_legacy_sequences`.  The core logic revolves around this `matched = true` condition and how `i` isn't always incremented.  The key is that if `f->repl_len < f->match_len`, then the buffer length gets *decreased*.  What happens when they're equal? *len* stays the same.

Looking at `hfsplus_legacy_seq_fixups` themselves, the entry `{ 2, { 0x00a8, 0x030d }, 2, { 0x00a8, 0x0301 } }` comes to mind.  If my buffer `buf[i]` holds 0x00a8 and 0x030d, it's *replaced* with 0x00a8, 0x0301. Then, because match_len and repl_len are equal, *len* doesn't change.  The problem is, the loop continues from the *same* `i`! That's a red flag!

In the next iteration, with the same starting index `i`, it will try to match *again*. `buf[i]` will be 0x00a8, and buf[i+1] is now 0x0301. The entry won't match.

My thought is, does *any* other entry now match the *replacement* `0x00a8, 0x0301`?  What if one replacement matches another entry, or even itself?  A self-match means an infinite loop, even though it replaces with something different.  What if the replacment matches the *match* of another entry?

But the real issue is that `i` *should* advance when `matched = true`, shouldn't it?  If `f->match` is replaced by `f->repl`, why isn't `i` incremented by `f->repl_len` or something?  The design is flawed! We need `i += f->repl_len`! I'm concerned that a loop is *intended* as part of this process. This means there's the possibility of a cycle.

Let's look at the C code snippet.  `dst = &buf[i + f->repl_len]`... `src = &buf[i + f->match_len]`...  The `memmove` and `memcpy` operations... Ah, so it's shifting data within the buffer to accommodate the replacement. *len* is updated!

Wait, looking at all the entries in `hfsplus_legacy_seq_fixups`, I see `f->repl_len <= f->match_len` in *every* single one!  This *won't* grow the buffer! That simplifies things.

Now, I need to check `hfsplus_decompose_iter_refill` in `unicode.c`. This might give me the full picture. Time to read this code carefully!



12/2 2026/09/21 03:52 tool read-file
0m Args:
{
  "File": "fs/hfsplus/unicode.c",
  "FirstLine": 600,
  "LineCount": 90
}

Results:
{
  "Contents": " 600:\tstruct hfsplus_decompose_iter {\n 601:\t\tstruct super_block *sb;\n 602:\t\tconst char *astr;\n 603:\t\tint len;\n 604:\t\tint name_type;\n 605:\t\tint decompose;\n 606:\t\n 607:\t\tu16 run[HFSPLUS_CCC_RUN_MAX];\n 608:\t\tint run_len;\n 609:\t\tint run_pos;\n 610:\t};\n 611:\t\n 612:\tstatic void hfsplus_decompose_iter_init(struct hfsplus_decompose_iter *it,\n 613:\t\t\t\t\t\tstruct super_block *sb,\n 614:\t\t\t\t\t\tconst char *astr, int len,\n 615:\t\t\t\t\t\tint name_type)\n 616:\t{\n 617:\t\tit-\u003esb = sb;\n 618:\t\tit-\u003eastr = astr;\n 619:\t\tit-\u003elen = len;\n 620:\t\tit-\u003ename_type = name_type;\n 621:\t\tit-\u003edecompose = !test_bit(HFSPLUS_SB_NODECOMPOSE, \u0026HFSPLUS_SB(sb)-\u003eflags);\n 622:\t\tit-\u003erun_len = 0;\n 623:\t\tit-\u003erun_pos = 0;\n 624:\t}\n 625:\t\n 626:\t/*\n 627:\t * Gather the next maximal run of nonzero-combining-class code units\n 628:\t * (starting with whatever character comes next, base or not) and\n 629:\t * canonically reorder just that run. A character is only included once\n 630:\t * we know the class of the first unit it produces, so decoding it is\n 631:\t * speculative until that's decided.\n 632:\t */\n 633:\tstatic bool hfsplus_decompose_iter_refill(struct hfsplus_decompose_iter *it)\n 634:\t{\n 635:\t\tit-\u003erun_pos = 0;\n 636:\t\tit-\u003erun_len = 0;\n 637:\t\n 638:\t\twhile (it-\u003elen \u003e 0) {\n 639:\t\t\tu16 *dstr;\n 640:\t\t\tu16 dhangul[HFSPLUS_HANGUL_MAX_JAMO];\n 641:\t\t\tint dsize, size;\n 642:\t\t\twchar_t c;\n 643:\t\n 644:\t\t\tsize = asc2unichar(it-\u003esb, it-\u003eastr, it-\u003elen, \u0026c,\n 645:\t\t\t\t\t   it-\u003ename_type);\n 646:\t\n 647:\t\t\tdstr = it-\u003edecompose ?\n 648:\t\t\t\tdecompose_unichar(c, \u0026dsize, dhangul) : NULL;\n 649:\t\t\tif (!dstr) {\n 650:\t\t\t\tdhangul[0] = c;\n 651:\t\t\t\tdstr = dhangul;\n 652:\t\t\t\tdsize = 1;\n 653:\t\t\t}\n 654:\t\n 655:\t\t\tif (it-\u003erun_len \u003e 0 \u0026\u0026 !hfsplus_combining_class(dstr[0]))\n 656:\t\t\t\tbreak;\n 657:\t\n 658:\t\t\tif (it-\u003erun_len + dsize \u003e HFSPLUS_CCC_RUN_MAX)\n 659:\t\t\t\tbreak;\n 660:\t\n 661:\t\t\tit-\u003eastr += size;\n 662:\t\t\tit-\u003elen -= size;\n 663:\t\n 664:\t\t\tdo {\n 665:\t\t\t\tit-\u003erun[it-\u003erun_len++] = *dstr++;\n 666:\t\t\t} while (--dsize \u003e 0);\n 667:\t\t}\n 668:\t\n 669:\t\thfsplus_canonical_reorder(it-\u003erun, it-\u003erun_len);\n 670:\t\thfsplus_fixup_legacy_sequences(it-\u003erun, \u0026it-\u003erun_len);\n 671:\t\treturn it-\u003erun_len \u003e 0;\n 672:\t}\n 673:\t\n 674:\t/* Returns the next code unit, or a negative value once @it is exhausted. */\n 675:\tstatic int hfsplus_decompose_iter_next(struct hfsplus_decompose_iter *it)\n 676:\t{\n 677:\t\tif (it-\u003erun_pos \u003e= it-\u003erun_len \u0026\u0026 !hfsplus_decompose_iter_refill(it))\n 678:\t\t\treturn -1;\n 679:\t\treturn it-\u003erun[it-\u003erun_pos++];\n 680:\t}\n 681:\t\n 682:\t/*\n 683:\t * Returns the next code unit that matters for comparison/hashing: folded\n 684:\t * if @casefold, with any character folding to 0 (\"ignorable\") skipped\n 685:\t * entirely. Returns a negative value once @it is exhausted.\n 686:\t */\n 687:\tstatic int hfsplus_decompose_iter_next_folded(struct hfsplus_decompose_iter *it,\n 688:\t\t\t\t\t\t      int casefold)\n 689:\t{\n"
}

13/2 2026/09/21 03:52 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 55352
							output: 37
							thoughts: 642
						

Thoughts:
**Deconstructing `hfsplus_decompose_iter_refill`**

Okay, hold on a second. Let's really look at this `hfsplus_decompose_iter_refill` function. Specifically, let's step through it and consider a critical edge case. I see that there is a `while` loop, and inside is where the important stuff happens.

The code's purpose appears to be filling a buffer `it->run` with decomposed Unicode characters, subject to some length constraints.  I see that it uses `asc2unichar` to get the current character and decompose it if needed using `decompose_unichar`. Okay, got it.

But, hang on, what if `it->run_len` is initially zero? This is an important case to consider when analyzing any buffer filling.

So, let's say the first character is a simple ASCII character, like 'a'. The `asc2unichar` call gets me `c = 'a'`.  The code bypasses the decomposition since it is just ASCII. So `dstr[0] = 'a'`. `hfsplus_combining_class(dstr[0])` returns false. Crucially, because `it->run_len` is zero initially, the check `it->run_len > 0 && !hfsplus_combining_class(dstr[0])` evaluates to `false` in this first iteration. The next conditional `it->run_len + dsize > HFSPLUS_CCC_RUN_MAX` is then considered. `it->run_len + dsize` is 1, so the condition is also false.

So, the first ASCII character 'a' gets added to `it->run`, and `it->run_len` becomes 1. The code then loops again.

Now, let's say the *next* character is also 'b', another simple ASCII character. The important observation: `it->run_len > 0 && !hfsplus_combining_class(dstr[0])` is NOW `true`. So the `while` loop will break! That means `hfsplus_canonical_reorder` will be called on a buffer of length one, followed by `hfsplus_fixup_legacy_sequences`, also on a buffer of length one. And the function returns `true`.

Wait! A potential optimization comes to mind... Let's think through what happens if the *first* character *decomposes* into multiple code units. I should go examine the code for `decompose_unichar` now and see what it is doing.



14/2 2026/09/21 03:52 tool read-file
0m Args:
{
  "File": "fs/hfsplus/unicode.c",
  "FirstLine": 430,
  "LineCount": 40
}

Results:
{
  "Contents": " 430:\t\t\treturn 3;\n 431:\t\t}\n 432:\t\treturn 2;\n 433:\t}\n 434:\t\n 435:\t/* Decomposes a single unicode character. */\n 436:\tstatic u16 *decompose_unichar(wchar_t uc, int *size, u16 *hangul_buffer)\n 437:\t{\n 438:\t\tu16 *result;\n 439:\t\n 440:\t\t/* Hangul is handled separately */\n 441:\t\tresult = hangul_buffer;\n 442:\t\t*size = hfsplus_try_decompose_hangul(uc, result);\n 443:\t\tif (*size == 0)\n 444:\t\t\tresult = hfsplus_decompose_nonhangul(uc, size);\n 445:\t\tif (!result) {\n 446:\t\t\t/*\n 447:\t\t\t * Not every character with a canonical decomposition is in\n 448:\t\t\t * Apple Technote #1150's own table above; a small, fixed\n 449:\t\t\t * set was only added to the decomposition standard (or had\n 450:\t\t\t * its decomposition corrected) after that table was\n 451:\t\t\t * generated. hfsplus_legacy_decompose() covers those.\n 452:\t\t\t */\n 453:\t\t\tconst u16 *legacy = hfsplus_legacy_decompose(uc, size);\n 454:\t\n 455:\t\t\tif (legacy)\n 456:\t\t\t\tresult = memcpy(hangul_buffer, legacy,\n 457:\t\t\t\t\t\t*size * sizeof(*legacy));\n 458:\t\t}\n 459:\t\treturn result;\n 460:\t}\n 461:\t\n 462:\t/*\n 463:\t * Apply the Unicode Canonical Ordering Algorithm to a decomposed name held\n 464:\t * as plain host-order code units: within each maximal run of characters\n 465:\t * that have a nonzero combining class, stable-sort the run into ascending\n 466:\t * combining-class order. A character with combining class 0 always starts\n 467:\t * a new run and is never itself reordered.\n 468:\t *\n 469:\t * hfsplus_decompose_table decomposes each source character on its own; it\n"
}

15/2 2026/09/21 03:52 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 57202
							output: 37
							thoughts: 26
						

Thoughts:
Here's my take on the thought process, summarized as you requested:

**Deconstructing Non-Hangul Characters in HFS+**

Okay, hold on a second. Something just clicked. I need to zero in on this `hfsplus_decompose_nonhangul` function. My gut tells me this is where the action is regarding how the system handles non-Hangul characters. I need to understand how *exactly* non-Hangul characters are being decomposed within this context. I need to thoroughly examine the decomposition logic here. This could be the key.



16/2 2026/09/21 03:52 tool read-file
0m Args:
{
  "File": "fs/hfsplus/unicode.c",
  "FirstLine": 400,
  "LineCount": 35
}

Results:
{
  "Contents": " 400:\t\treturn hfsplus_decompose_table + (off / 4);\n 401:\t}\n 402:\t\n 403:\t/*\n 404:\t * Try to decompose a unicode character as Hangul. Return 0 if @uc is not\n 405:\t * precomposed Hangul, otherwise return the length of the decomposition.\n 406:\t *\n 407:\t * This function was adapted from sample code from the Unicode Standard\n 408:\t * Annex #15: Unicode Normalization Forms, version 3.2.0.\n 409:\t *\n 410:\t * Copyright (C) 1991-2018 Unicode, Inc.  All rights reserved.  Distributed\n 411:\t * under the Terms of Use in http://www.unicode.org/copyright.html.\n 412:\t */\n 413:\tstatic int hfsplus_try_decompose_hangul(wchar_t uc, u16 *result)\n 414:\t{\n 415:\t\tint index;\n 416:\t\tint l, v, t;\n 417:\t\n 418:\t\tindex = uc - Hangul_SBase;\n 419:\t\tif (index \u003c 0 || index \u003e= Hangul_SCount)\n 420:\t\t\treturn 0;\n 421:\t\n 422:\t\tl = Hangul_LBase + index / Hangul_NCount;\n 423:\t\tv = Hangul_VBase + (index % Hangul_NCount) / Hangul_TCount;\n 424:\t\tt = Hangul_TBase + index % Hangul_TCount;\n 425:\t\n 426:\t\tresult[0] = l;\n 427:\t\tresult[1] = v;\n 428:\t\tif (t != Hangul_TBase) {\n 429:\t\t\tresult[2] = t;\n 430:\t\t\treturn 3;\n 431:\t\t}\n 432:\t\treturn 2;\n 433:\t}\n 434:\t\n"
}

17/2 2026/09/21 03:52 llm patch-evaluator
1m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 57933
							output: 37
							thoughts: 41
						

Thoughts:
Here's my attempt at summarizing the thought process, as if I were an expert:

**Diving into `hfsplus_decompose_nonhangul`**

Okay, hold on a second. I need to take a closer look at that function, `hfsplus_decompose_nonhangul`. Specifically, let's jump over to `fs/hfsplus/unicode.c` – lines 370 to 405. I need to refresh my memory on the intricacies of the non-Hangul decomposition logic within the HFS+ filesystem. I'm expecting to see the usual suspects: perhaps some table lookups for precomposed characters, the handling of combining marks, and the overall algorithm for normalization. I want to see how they're handling edge cases. I'm especially interested in how they tackle situations that could potentially lead to hangs or infinite loops – it’s a common pitfall in Unicode normalization routines. Let’s see what cleverness (or lack thereof) is implemented there. This section is key for interoperability with other systems.



18/2 2026/09/21 03:53 tool read-file
0m Args:
{
  "File": "fs/hfsplus/unicode.c",
  "FirstLine": 370,
  "LineCount": 35
}

Results:
{
  "Contents": " 370:\t\tif (size \u003c= 0) {\n 371:\t\t\t*uc = '?';\n 372:\t\t\tsize = 1;\n 373:\t\t}\n 374:\t\n 375:\t\thfsplus_linux2mac_compatibility_check(uc, name_type);\n 376:\t\treturn size;\n 377:\t}\n 378:\t\n 379:\t/* Decomposes a non-Hangul unicode character. */\n 380:\tstatic u16 *hfsplus_decompose_nonhangul(wchar_t uc, int *size)\n 381:\t{\n 382:\t\tint off;\n 383:\t\n 384:\t\toff = hfsplus_decompose_table[(uc \u003e\u003e 12) \u0026 0xf];\n 385:\t\tif (off == 0 || off == 0xffff)\n 386:\t\t\treturn NULL;\n 387:\t\n 388:\t\toff = hfsplus_decompose_table[off + ((uc \u003e\u003e 8) \u0026 0xf)];\n 389:\t\tif (!off)\n 390:\t\t\treturn NULL;\n 391:\t\n 392:\t\toff = hfsplus_decompose_table[off + ((uc \u003e\u003e 4) \u0026 0xf)];\n 393:\t\tif (!off)\n 394:\t\t\treturn NULL;\n 395:\t\n 396:\t\toff = hfsplus_decompose_table[off + (uc \u0026 0xf)];\n 397:\t\t*size = off \u0026 3;\n 398:\t\tif (*size == 0)\n 399:\t\t\treturn NULL;\n 400:\t\treturn hfsplus_decompose_table + (off / 4);\n 401:\t}\n 402:\t\n 403:\t/*\n 404:\t * Try to decompose a unicode character as Hangul. Return 0 if @uc is not\n"
}

19/2 2026/09/21 03:53 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 58746
							output: 36
							thoughts: 3300
						

Thoughts:
**Deep Dive into HFS+ String Decomposition and Canonical Reordering**

Okay, so I've been tracing the logic for decomposing and reordering Unicode strings within the HFS+ filesystem implementation. It's clear that there are some subtle but critical differences in how this is handled, depending on whether we're dealing with an entire string (like when converting a filename) or processing it incrementally (like during directory hashing or comparison).

I've zeroed in on the `hfsplus_decompose_iter_refill` function, which is used for the iterative approach. It looks like the code attempts to decompose each character, and then reorder the combining marks. Specifically, it uses `decompose_unichar` to decompose a character into a base character and combining marks. The crucial part is how it handles a sequence like "é" (U+00E9, "e" with acute accent) or sequences with multiple combining characters.

The code seems to buffer a "run" of code units, and there's a limit (`HFSPLUS_CCC_RUN_MAX = 32`) on the number of combining characters it will accumulate within a single run *before* reordering them using `hfsplus_canonical_reorder`. However, a key observation is that if `it->run_len + dsize > HFSPLUS_CCC_RUN_MAX` (where `dsize` is the number of code units the decomposed character expands to), the loop breaks *before* consuming the full decomposed character. This is where it gets interesting...

If a character decomposes into *more* than 32 code units, only the first 32 are reordered. What happens to the remaining units? They're handled in the *next* iteration, without any consideration for the initial combining marks, which might be an issue. Basically, each chunk of 32 characters or less are sorted independently. This also applies when the `hfsplus_combining_class` check is `true`, and it encounters another combining mark.

Now, consider `hfsplus_canonical_reorder`. It's a standard bubble sort where it puts combining characters after non-combining characters. It correctly reorders the run, ensuring that combining marks are in the correct canonical order. So if we have "e" (class 0), acute (class 230), and dot below (class 220), `hfsplus_canonical_reorder` will swap the acute and the dot, so that the order is "e" , dot below, and then acute.

But here's the kicker: The `hfsplus_decompose_str` function, used by `hfsplus_asc2uni` for *full* string conversion, reorders the *entire* string after the decomposition process, regardless of the number of combining marks. This function is called by `hfsplus_attr_build_key`. So it is called when setting extended attributes on a file.

This suggests a potential inconsistency. If a string has more than 32 combining marks, the iterative approach in `hfsplus_compare_dentry` or `hfsplus_hash_dentry` will sort the string in chunks (32 marks at a time), while the full conversion in `hfsplus_asc2uni` will reorder the whole string. Because of this, two names could hash to different values or could be considered unequal during directory traversal and file name comparison! This is a *significant* potential bug. What if someone has a really long sequence of combining marks? `hfsplus_asc2uni` gets it right. But the other parts only work up to 32.

Finally, I need to check the callers of `hfsplus_asc2uni` because the `max_unistr_len` parameter might be limited in various places. It calls `hfsplus_attr_build_key` for extended attributes. So, now, I need to see what `HFSPLUS_ATTR_MAX_STRLEN` is!



20/2 2026/09/21 03:54 tool grepper
0m Args:
{
  "Expression": "HFSPLUS_ATTR_MAX_STRLEN",
  "PathPrefix": "fs/hfsplus"
}

Results:
{
  "Output": "fs/hfsplus/attributes.c=50=int hfsplus_attr_build_key(struct super_block *sb, hfsplus_btree_key *key,\n--\nfs/hfsplus/attributes.c-59-\t\t\t\t(struct hfsplus_unistr *)\u0026key-\u003eattr.key_name,\nfs/hfsplus/attributes.c:60:\t\t\t\tHFSPLUS_ATTR_MAX_STRLEN, name, strlen(name),\nfs/hfsplus/attributes.c-61-\t\t\t\tHFS_XATTR_NAME);\n--\nfs/hfsplus/unicode.c=320=inline int hfsplus_uni2asc_xattr_str(struct super_block *sb,\n--\nfs/hfsplus/unicode.c-324-\treturn hfsplus_uni2asc(sb, (const struct hfsplus_unistr *)ustr,\nfs/hfsplus/unicode.c:325:\t\t\t\tHFSPLUS_ATTR_MAX_STRLEN, astr, len_p,\nfs/hfsplus/unicode.c-326-\t\t\t\tHFS_XATTR_NAME);\n--\nfs/hfsplus/xattr.c=534=int hfsplus_setxattr(struct inode *inode, const char *name,\n--\nfs/hfsplus/xattr.c-539-\tsize_t xattr_name_len =\nfs/hfsplus/xattr.c:540:\t\tNLS_MAX_CHARSET_SIZE * HFSPLUS_ATTR_MAX_STRLEN + 1;\nfs/hfsplus/xattr.c-541-\tint res;\n--\nfs/hfsplus/xattr.c=696=ssize_t hfsplus_getxattr(struct inode *inode, const char *name,\n--\nfs/hfsplus/xattr.c-706-\nfs/hfsplus/xattr.c:707:\txattr_name = kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATTR_MAX_STRLEN + 1,\nfs/hfsplus/xattr.c-708-\t\t\t     GFP_KERNEL);\n--\nfs/hfsplus/xattr.c=802=ssize_t hfsplus_listxattr(struct dentry *dentry, char *buffer, size_t size)\n--\nfs/hfsplus/xattr.c-829-\nfs/hfsplus/xattr.c:830:\tstrbuf_size = NLS_MAX_CHARSET_SIZE * HFSPLUS_ATTR_MAX_STRLEN +\nfs/hfsplus/xattr.c-831-\t\t\tXATTR_MAC_OSX_PREFIX_LEN + 1;\n--\nfs/hfsplus/xattr.c-863-\nfs/hfsplus/xattr.c:864:\t\txattr_name_len = NLS_MAX_CHARSET_SIZE * HFSPLUS_ATTR_MAX_STRLEN;\nfs/hfsplus/xattr.c-865-\t\tif (hfsplus_uni2asc_xattr_str(inode-\u003ei_sb,\n--\nfs/hfsplus/xattr_security.c=36=static int hfsplus_initxattrs(struct inode *inode,\n--\nfs/hfsplus/xattr_security.c-43-\nfs/hfsplus/xattr_security.c:44:\txattr_name = kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATTR_MAX_STRLEN + 1,\nfs/hfsplus/xattr_security.c-45-\t\tGFP_KERNEL);\n"
}

21/2 2026/09/21 03:54 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 63844
							output: 28
							thoughts: 35
						

Thoughts:
Okay, here's my interpretation of those thoughts, tailored for an expert audience, presented in the first person:

**Decoding that Attribute Access**

Alright, let's dive in. I'm looking at this expression, `key->attr.key_name`, and my immediate thought is, "What precisely is that `key_name` attribute pointing to within the broader context of the system?". It's a standard pattern for attribute access, but I need to understand its specific meaning here.

My next step is clear: I need to locate where `key_name` is defined, and how it's being used. Given the context, the most likely place to start looking is within the HFS+ filesystem implementation, specifically within the `fs/hfsplus` directory. That's where I'll find the structures and definitions related to the filesystem's internal data structures, and hopefully, I'll find the definition and meaning of `key_name` there. I'll need to know what kind of value it is, what data it is associated with and what the data signifies. Then I'll be able to trace its usage to understand the code that is being worked on.



22/2 2026/09/21 03:54 tool grepper
0m Args:
{
  "Expression": "key_name",
  "PathPrefix": "fs/hfsplus"
}

Results:
{
  "Output": "fs/hfsplus/attributes.c=35=int hfsplus_attr_bin_cmp_key(const hfsplus_btree_key *k1,\n--\nfs/hfsplus/attributes.c-45-\treturn hfsplus_strcmp(\nfs/hfsplus/attributes.c:46:\t\t\t(const struct hfsplus_unistr *)\u0026k1-\u003eattr.key_name,\nfs/hfsplus/attributes.c:47:\t\t\t(const struct hfsplus_unistr *)\u0026k2-\u003eattr.key_name);\nfs/hfsplus/attributes.c-48-}\n--\nfs/hfsplus/attributes.c=50=int hfsplus_attr_build_key(struct super_block *sb, hfsplus_btree_key *key,\n--\nfs/hfsplus/attributes.c-58-\t\tint res = hfsplus_asc2uni(sb,\nfs/hfsplus/attributes.c:59:\t\t\t\t(struct hfsplus_unistr *)\u0026key-\u003eattr.key_name,\nfs/hfsplus/attributes.c-60-\t\t\t\tHFSPLUS_ATTR_MAX_STRLEN, name, strlen(name),\n--\nfs/hfsplus/attributes.c-63-\t\t\treturn res;\nfs/hfsplus/attributes.c:64:\t\tlen = be16_to_cpu(key-\u003eattr.key_name.length);\nfs/hfsplus/attributes.c-65-\t} else {\nfs/hfsplus/attributes.c:66:\t\tkey-\u003eattr.key_name.length = 0;\nfs/hfsplus/attributes.c-67-\t\tlen = 0;\n--\nfs/hfsplus/attributes.c-71-\t * the size of the key_len field itself.\nfs/hfsplus/attributes.c:72:\t * So, offsetof(hfsplus_attr_key, key_name) is a trick because\nfs/hfsplus/attributes.c-73-\t * it takes into consideration key_len field (__be16) of\n--\nfs/hfsplus/attributes.c-77-\tkey-\u003ekey_len =\nfs/hfsplus/attributes.c:78:\t\tcpu_to_be16(offsetof(struct hfsplus_attr_key, key_name) +\nfs/hfsplus/attributes.c-79-\t\t\t\t2 * len);\n--\nfs/hfsplus/xattr.c=802=ssize_t hfsplus_listxattr(struct dentry *dentry, char *buffer, size_t size)\n--\nfs/hfsplus/xattr.c-865-\t\tif (hfsplus_uni2asc_xattr_str(inode-\u003ei_sb,\nfs/hfsplus/xattr.c:866:\t\t\t\t\t      \u0026fd.key-\u003eattr.key_name, strbuf,\nfs/hfsplus/xattr.c-867-\t\t\t\t\t      \u0026xattr_name_len)) {\n--\nfs/hfsplus/xattr.c-887-\nfs/hfsplus/xattr.c:888:\t\tmemset(fd.key-\u003eattr.key_name.unicode, 0,\nfs/hfsplus/xattr.c:889:\t\t\tsizeof(fd.key-\u003eattr.key_name.unicode));\nfs/hfsplus/xattr.c-890-\t\tmemset(strbuf, 0, strbuf_size);\n"
}

23/2 2026/09/21 03:54 llm patch-evaluator
1m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 65008
							output: 33
							thoughts: 17
						

Thoughts:
Here's my attempt at summarizing the thought process, tailored for an expert audience:

**Diving into the hfsplus_attr_key Declaration**

Okay, let's get down to brass tacks. My initial thought process is centered on dissecting the `hfsplus_attr_key` struct declaration. I'm immediately interested in the structure and the field definitions within it. I want to understand how this key is constructed because it's the fundamental building block for attribute management within the HFS+ filesystem. I'm focusing on the data layout: the order of the fields, their sizes, and their individual meanings. I'm immediately thinking, are there any potential alignment issues that I need to be aware of? This matters when considering the performance of attribute lookup and storage. Beyond that, I will be assessing how the key is used in comparisons or indexing: is it a compound key? If so, what is the ordering and significance of the sub-keys within the compound? How does the size of the key compare to other keys within the HFS+ architecture? I am also considering the implications in terms of on-disk structures. Does this key directly map to an on-disk representation, or is it an abstraction? If abstraction, what are the layers of translation? Knowing this will significantly affect how I analyze any related code. Let's delve into the specifics and get a real feel for it.



24/2 2026/09/21 03:55 tool grepper
0m Args:
{
  "Expression": "struct hfsplus_attr_key",
  "PathPrefix": "fs/hfsplus"
}

Results:
{
  "Output": "fs/hfsplus/attributes.c=50=int hfsplus_attr_build_key(struct super_block *sb, hfsplus_btree_key *key,\n--\nfs/hfsplus/attributes.c-54-\nfs/hfsplus/attributes.c:55:\tmemset(key, 0, sizeof(struct hfsplus_attr_key));\nfs/hfsplus/attributes.c-56-\tkey-\u003eattr.cnid = cpu_to_be32(cnid);\n--\nfs/hfsplus/attributes.c-77-\tkey-\u003ekey_len =\nfs/hfsplus/attributes.c:78:\t\tcpu_to_be16(offsetof(struct hfsplus_attr_key, key_name) +\nfs/hfsplus/attributes.c-79-\t\t\t\t2 * len);\n--\nfs/hfsplus/attributes.c=305=static int __hfsplus_delete_attr(struct inode *inode, u32 cnid,\n--\nfs/hfsplus/attributes.c-313-\t\t\tfd-\u003ekeyoffset +\nfs/hfsplus/attributes.c:314:\t\t\toffsetof(struct hfsplus_attr_key, cnid),\nfs/hfsplus/attributes.c-315-\t\t\tsizeof(__be32));\n--\nfs/hfsplus/xattr.c=802=ssize_t hfsplus_listxattr(struct dentry *dentry, char *buffer, size_t size)\n--\nfs/hfsplus/xattr.c-807-\tstruct hfs_find_data fd;\nfs/hfsplus/xattr.c:808:\tstruct hfsplus_attr_key attr_key;\nfs/hfsplus/xattr.c-809-\tchar *strbuf;\n"
}

25/2 2026/09/21 03:55 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 65807
							output: 35
							thoughts: 27
						

Thoughts:
Here's my take on the thought process, summarized as you requested:

**Deconstructing the HFS+ Attribute Key**

Okay, so I need to get a handle on `struct hfsplus_attr_key`. Right, time to dig into the source. Let's see... I'll pull up `hfsplus_raw.h` and immediately focus on that definition. I want to understand its structure, the components that make it up, and how it's used within the broader HFS+ file system context. No need to waste time with other definitions for now, I need to understand this key specifically. This will inform my next steps, whatever they might be.



26/2 2026/09/21 03:55 tool grepper
0m Args:
{
  "Expression": "struct hfsplus_attr_key\\b",
  "PathPrefix": "fs/hfsplus"
}

Results:
{
  "Output": "fs/hfsplus/attributes.c=50=int hfsplus_attr_build_key(struct super_block *sb, hfsplus_btree_key *key,\n--\nfs/hfsplus/attributes.c-54-\nfs/hfsplus/attributes.c:55:\tmemset(key, 0, sizeof(struct hfsplus_attr_key));\nfs/hfsplus/attributes.c-56-\tkey-\u003eattr.cnid = cpu_to_be32(cnid);\n--\nfs/hfsplus/attributes.c-77-\tkey-\u003ekey_len =\nfs/hfsplus/attributes.c:78:\t\tcpu_to_be16(offsetof(struct hfsplus_attr_key, key_name) +\nfs/hfsplus/attributes.c-79-\t\t\t\t2 * len);\n--\nfs/hfsplus/attributes.c=305=static int __hfsplus_delete_attr(struct inode *inode, u32 cnid,\n--\nfs/hfsplus/attributes.c-313-\t\t\tfd-\u003ekeyoffset +\nfs/hfsplus/attributes.c:314:\t\t\toffsetof(struct hfsplus_attr_key, cnid),\nfs/hfsplus/attributes.c-315-\t\t\tsizeof(__be32));\n--\nfs/hfsplus/xattr.c=802=ssize_t hfsplus_listxattr(struct dentry *dentry, char *buffer, size_t size)\n--\nfs/hfsplus/xattr.c-807-\tstruct hfs_find_data fd;\nfs/hfsplus/xattr.c:808:\tstruct hfsplus_attr_key attr_key;\nfs/hfsplus/xattr.c-809-\tchar *strbuf;\n"
}

27/2 2026/09/21 03:55 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 66469
							output: 32
							thoughts: 16
						

Thoughts:
Here's my attempt at summarizing the thought process, tailored for an expert audience:

**Investigating the `hfsplus_attr_key` Definition**

Alright, let's zero in on this `hfsplus_attr_key`. I need to solidify my understanding of exactly what this refers to. It's a key within the HFS+ attribute structure, so, given its name, I'm already assuming it's probably related to extended attributes. My immediate thought is to check the HFS+ specification or relevant source code – likely the Apple File System documentation or perhaps the Darwin kernel headers if I'm looking for a low-level definition. I'm going to look for details on its structure, the data it contains, and its role in indexing or locating specific extended attribute data within an HFS+ volume. Is it a unique identifier? Part of a key-value pair? Or perhaps used in hashing or b-tree structures? Knowing its format is crucial for analyzing and potentially manipulating HFS+ attributes. I need to understand its relationship to the other fields in the HFS+ catalog and attribute file. My goal is a precise understanding of its structure and purpose, and I'll need to know where it is used.



28/2 2026/09/21 03:55 tool grepper
0m Args:
{
  "Expression": "hfsplus_attr_key",
  "PathPrefix": "fs/hfsplus"
}

Results:
{
  "Output": "fs/hfsplus/attributes.c=50=int hfsplus_attr_build_key(struct super_block *sb, hfsplus_btree_key *key,\n--\nfs/hfsplus/attributes.c-54-\nfs/hfsplus/attributes.c:55:\tmemset(key, 0, sizeof(struct hfsplus_attr_key));\nfs/hfsplus/attributes.c-56-\tkey-\u003eattr.cnid = cpu_to_be32(cnid);\n--\nfs/hfsplus/attributes.c-71-\t * the size of the key_len field itself.\nfs/hfsplus/attributes.c:72:\t * So, offsetof(hfsplus_attr_key, key_name) is a trick because\nfs/hfsplus/attributes.c-73-\t * it takes into consideration key_len field (__be16) of\nfs/hfsplus/attributes.c:74:\t * hfsplus_attr_key structure instead of length field (__be16) of\nfs/hfsplus/attributes.c-75-\t * hfsplus_attr_unistr structure.\n--\nfs/hfsplus/attributes.c-77-\tkey-\u003ekey_len =\nfs/hfsplus/attributes.c:78:\t\tcpu_to_be16(offsetof(struct hfsplus_attr_key, key_name) +\nfs/hfsplus/attributes.c-79-\t\t\t\t2 * len);\n--\nfs/hfsplus/attributes.c=305=static int __hfsplus_delete_attr(struct inode *inode, u32 cnid,\n--\nfs/hfsplus/attributes.c-313-\t\t\tfd-\u003ekeyoffset +\nfs/hfsplus/attributes.c:314:\t\t\toffsetof(struct hfsplus_attr_key, cnid),\nfs/hfsplus/attributes.c-315-\t\t\tsizeof(__be32));\n--\nfs/hfsplus/xattr.c=802=ssize_t hfsplus_listxattr(struct dentry *dentry, char *buffer, size_t size)\n--\nfs/hfsplus/xattr.c-807-\tstruct hfs_find_data fd;\nfs/hfsplus/xattr.c:808:\tstruct hfsplus_attr_key attr_key;\nfs/hfsplus/xattr.c-809-\tchar *strbuf;\n"
}

29/2 2026/09/21 03:55 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 67386
							output: 32
							thoughts: 37
						

Thoughts:
Okay, here's my take on those thoughts, framed as an expert's internal monologue:

**Diving into the Data Structures**

Right, before I go any further with this, I need to get a crystal-clear understanding of the underlying data structures. Specifically, I need to make sure I have a solid grip on how `key->attr.key_name` and `hfsplus_unistr` are *actually* defined. I'll need to drill down into `hfsplus_raw.h` to see the declarations, the underlying representations and their implications. I'll be looking for nuances that could affect my interpretation or manipulations of these elements later on. Gotta be precise here; HFS+ is notoriously sensitive.



30/2 2026/09/21 03:55 tool grepper
0m Args:
{
  "Expression": "struct hfsplus_unistr",
  "PathPrefix": "fs/hfsplus"
}

Results:
{
  "Output": "fs/hfsplus/attributes.c=35=int hfsplus_attr_bin_cmp_key(const hfsplus_btree_key *k1,\n--\nfs/hfsplus/attributes.c-45-\treturn hfsplus_strcmp(\nfs/hfsplus/attributes.c:46:\t\t\t(const struct hfsplus_unistr *)\u0026k1-\u003eattr.key_name,\nfs/hfsplus/attributes.c:47:\t\t\t(const struct hfsplus_unistr *)\u0026k2-\u003eattr.key_name);\nfs/hfsplus/attributes.c-48-}\n--\nfs/hfsplus/attributes.c=50=int hfsplus_attr_build_key(struct super_block *sb, hfsplus_btree_key *key,\n--\nfs/hfsplus/attributes.c-58-\t\tint res = hfsplus_asc2uni(sb,\nfs/hfsplus/attributes.c:59:\t\t\t\t(struct hfsplus_unistr *)\u0026key-\u003eattr.key_name,\nfs/hfsplus/attributes.c-60-\t\t\t\tHFSPLUS_ATTR_MAX_STRLEN, name, strlen(name),\n--\nfs/hfsplus/catalog.c=68=static void hfsplus_cat_build_key_uni(hfsplus_btree_key *key, u32 parent,\nfs/hfsplus/catalog.c:69:\t\t\t\t      struct hfsplus_unistr *name)\nfs/hfsplus/catalog.c-70-{\n--\nfs/hfsplus/hfsplus_fs.h=488=int hfsplus_commit_superblock(struct super_block *sb);\n--\nfs/hfsplus/hfsplus_fs.h-490-/* unicode.c */\nfs/hfsplus/hfsplus_fs.h:491:int hfsplus_strcasecmp(const struct hfsplus_unistr *s1,\nfs/hfsplus/hfsplus_fs.h:492:\t\t       const struct hfsplus_unistr *s2);\nfs/hfsplus/hfsplus_fs.h:493:int hfsplus_strcmp(const struct hfsplus_unistr *s1,\nfs/hfsplus/hfsplus_fs.h:494:\t\t   const struct hfsplus_unistr *s2);\nfs/hfsplus/hfsplus_fs.h-495-int hfsplus_uni2asc_str(struct super_block *sb,\nfs/hfsplus/hfsplus_fs.h:496:\t\t\tconst struct hfsplus_unistr *ustr, char *astr,\nfs/hfsplus/hfsplus_fs.h-497-\t\t\tint *len_p);\nfs/hfsplus/hfsplus_fs.h=498=int hfsplus_uni2asc_xattr_str(struct super_block *sb,\n--\nfs/hfsplus/hfsplus_fs.h-500-\t\t\t      char *astr, int *len_p);\nfs/hfsplus/hfsplus_fs.h:501:int hfsplus_asc2uni(struct super_block *sb, struct hfsplus_unistr *ustr,\nfs/hfsplus/hfsplus_fs.h-502-\t\t    int max_unistr_len, const char *astr, int len,\n--\nfs/hfsplus/hfsplus_fs.h=513=static inline u32 hfsplus_cat_thread_size(const struct hfsplus_cat_thread *thread)\n--\nfs/hfsplus/hfsplus_fs.h-515-\treturn offsetof(struct hfsplus_cat_thread, nodeName) +\nfs/hfsplus/hfsplus_fs.h:516:\t       offsetof(struct hfsplus_unistr, unicode) +\nfs/hfsplus/hfsplus_fs.h-517-\t       be16_to_cpu(thread-\u003enodeName.length) * sizeof(hfsplus_unichr);\n--\nfs/hfsplus/unicode.c=23=static inline u16 case_fold(u16 c)\n--\nfs/hfsplus/unicode.c-35-/* Compare unicode strings, return values like normal strcmp */\nfs/hfsplus/unicode.c:36:int hfsplus_strcasecmp(const struct hfsplus_unistr *s1,\nfs/hfsplus/unicode.c:37:\t\t       const struct hfsplus_unistr *s2)\nfs/hfsplus/unicode.c-38-{\n--\nfs/hfsplus/unicode.c=79=EXPORT_SYMBOL_IF_KUNIT(hfsplus_strcasecmp);\n--\nfs/hfsplus/unicode.c-81-/* Compare names as a sequence of 16-bit unsigned integers */\nfs/hfsplus/unicode.c:82:int hfsplus_strcmp(const struct hfsplus_unistr *s1,\nfs/hfsplus/unicode.c:83:\t\t   const struct hfsplus_unistr *s2)\nfs/hfsplus/unicode.c-84-{\n--\nfs/hfsplus/unicode.c=185=static int hfsplus_uni2asc(struct super_block *sb,\nfs/hfsplus/unicode.c:186:\t\t\t   const struct hfsplus_unistr *ustr,\nfs/hfsplus/unicode.c-187-\t\t\t   int max_len, char *astr, int *len_p,\n--\nfs/hfsplus/unicode.c=309=inline int hfsplus_uni2asc_str(struct super_block *sb,\nfs/hfsplus/unicode.c:310:\t\t\t       const struct hfsplus_unistr *ustr, char *astr,\nfs/hfsplus/unicode.c-311-\t\t\t       int *len_p)\n--\nfs/hfsplus/unicode.c=320=inline int hfsplus_uni2asc_xattr_str(struct super_block *sb,\n--\nfs/hfsplus/unicode.c-323-{\nfs/hfsplus/unicode.c:324:\treturn hfsplus_uni2asc(sb, (const struct hfsplus_unistr *)ustr,\nfs/hfsplus/unicode.c-325-\t\t\t\tHFSPLUS_ATTR_MAX_STRLEN, astr, len_p,\n--\nfs/hfsplus/unicode.c=557=int hfsplus_asc2uni(struct super_block *sb,\nfs/hfsplus/unicode.c:558:\t\t    struct hfsplus_unistr *ustr, int max_unistr_len,\nfs/hfsplus/unicode.c-559-\t\t    const char *astr, int len, int name_type)\n--\nfs/hfsplus/unicode_test.c=15=struct test_mock_string_env {\nfs/hfsplus/unicode_test.c:16:\tstruct hfsplus_unistr str1;\nfs/hfsplus/unicode_test.c:17:\tstruct hfsplus_unistr str2;\nfs/hfsplus/unicode_test.c-18-\tchar *buf;\n--\nfs/hfsplus/unicode_test.c=41=static void free_mock_str_env(struct test_mock_string_env *env)\n--\nfs/hfsplus/unicode_test.c-47-/* Helper function to create hfsplus_unistr */\nfs/hfsplus/unicode_test.c:48:static void create_unistr(struct hfsplus_unistr *ustr, const char *ascii_str)\nfs/hfsplus/unicode_test.c-49-{\n--\nfs/hfsplus/unicode_test.c-59-\nfs/hfsplus/unicode_test.c:60:static void corrupt_unistr(struct hfsplus_unistr *ustr)\nfs/hfsplus/unicode_test.c-61-{\n--\nfs/hfsplus/unicode_test.c=683=static void check_unistr_content(struct kunit *test,\nfs/hfsplus/unicode_test.c:684:\t\t\t\t struct hfsplus_unistr *ustr,\nfs/hfsplus/unicode_test.c-685-\t\t\t\t const char *expected_ascii)\n--\nfs/hfsplus/unicode_test.c=859=static void hfsplus_asc2uni_edge_cases_test(struct kunit *test)\n--\nfs/hfsplus/unicode_test.c-861-\tstruct test_mock_sb *mock_sb;\nfs/hfsplus/unicode_test.c:862:\tstruct hfsplus_unistr ustr;\nfs/hfsplus/unicode_test.c-863-\tchar test_str[] = {'a', '\\0', 'b'};\n--\nfs/hfsplus/unicode_test.c=996=static void hfsplus_asc2uni_combining_reorder_test(struct kunit *test)\n--\nfs/hfsplus/unicode_test.c-998-\tstruct test_mock_sb *mock_sb;\nfs/hfsplus/unicode_test.c:999:\tstruct hfsplus_unistr ustr;\nfs/hfsplus/unicode_test.c-1000-\t/* \"e\" + COMBINING ACUTE ACCENT (U+0301) + COMBINING DOT BELOW (U+0323) */\n--\nfs/hfsplus/unicode_test.c=1062=static void hfsplus_unicode_combining_reorder_roundtrip_test(struct kunit *test)\n--\nfs/hfsplus/unicode_test.c-1064-\tstruct test_mock_sb *mock_sb;\nfs/hfsplus/unicode_test.c:1065:\tstruct hfsplus_unistr ustr;\nfs/hfsplus/unicode_test.c-1066-\tstatic const char wrong_order[] = \"e\\xcc\\x81\\xcc\\xa3\";\n--\nfs/hfsplus/unicode_test.c=1102=static void hfsplus_asc2uni_legacy_decomp_test(struct kunit *test)\n--\nfs/hfsplus/unicode_test.c-1104-\tstruct test_mock_sb *mock_sb;\nfs/hfsplus/unicode_test.c:1105:\tstruct hfsplus_unistr ustr;\nfs/hfsplus/unicode_test.c-1106-\tstatic const char input[] = \"\\xc7\\xb8\"; /* U+01F8 */\n--\nfs/hfsplus/unicode_test.c=1135=static void hfsplus_asc2uni_legacy_seq_fixup_test(struct kunit *test)\n--\nfs/hfsplus/unicode_test.c-1137-\tstruct test_mock_sb *mock_sb;\nfs/hfsplus/unicode_test.c:1138:\tstruct hfsplus_unistr ustr;\nfs/hfsplus/unicode_test.c-1139-\tstatic const char greek_input[] = \"\\xce\\xb1\\xcc\\x8d\"; /* U+03B1 U+030D */\n"
}

31/2 2026/09/21 03:55 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 70434
							output: 31
							thoughts: 25
						

Thoughts:
Here's my take on those thoughts:

**Peering into the Core: `hfsplus_unistr`**

Alright, let's get down to brass tacks. I need to understand this `hfsplus_unistr` structure. That means diving straight into the source. No beating around the bush; I'm going to pull up the definition. I'm thinking, "hfsplus_raw.h" is the likely place to find it, given the context. Time to see what we're actually dealing with here. Understanding the low-level data structures is key to properly working with any file system.



32/2 2026/09/21 03:55 tool grepper
0m Args:
{
  "Expression": "hfsplus_unistr",
  "PathPrefix": "fs/hfsplus"
}

Results:
{
  "Output": "fs/hfsplus/attributes.c=35=int hfsplus_attr_bin_cmp_key(const hfsplus_btree_key *k1,\n--\nfs/hfsplus/attributes.c-45-\treturn hfsplus_strcmp(\nfs/hfsplus/attributes.c:46:\t\t\t(const struct hfsplus_unistr *)\u0026k1-\u003eattr.key_name,\nfs/hfsplus/attributes.c:47:\t\t\t(const struct hfsplus_unistr *)\u0026k2-\u003eattr.key_name);\nfs/hfsplus/attributes.c-48-}\n--\nfs/hfsplus/attributes.c=50=int hfsplus_attr_build_key(struct super_block *sb, hfsplus_btree_key *key,\n--\nfs/hfsplus/attributes.c-58-\t\tint res = hfsplus_asc2uni(sb,\nfs/hfsplus/attributes.c:59:\t\t\t\t(struct hfsplus_unistr *)\u0026key-\u003eattr.key_name,\nfs/hfsplus/attributes.c-60-\t\t\t\tHFSPLUS_ATTR_MAX_STRLEN, name, strlen(name),\n--\nfs/hfsplus/catalog.c=68=static void hfsplus_cat_build_key_uni(hfsplus_btree_key *key, u32 parent,\nfs/hfsplus/catalog.c:69:\t\t\t\t      struct hfsplus_unistr *name)\nfs/hfsplus/catalog.c-70-{\n--\nfs/hfsplus/hfsplus_fs.h=488=int hfsplus_commit_superblock(struct super_block *sb);\n--\nfs/hfsplus/hfsplus_fs.h-490-/* unicode.c */\nfs/hfsplus/hfsplus_fs.h:491:int hfsplus_strcasecmp(const struct hfsplus_unistr *s1,\nfs/hfsplus/hfsplus_fs.h:492:\t\t       const struct hfsplus_unistr *s2);\nfs/hfsplus/hfsplus_fs.h:493:int hfsplus_strcmp(const struct hfsplus_unistr *s1,\nfs/hfsplus/hfsplus_fs.h:494:\t\t   const struct hfsplus_unistr *s2);\nfs/hfsplus/hfsplus_fs.h-495-int hfsplus_uni2asc_str(struct super_block *sb,\nfs/hfsplus/hfsplus_fs.h:496:\t\t\tconst struct hfsplus_unistr *ustr, char *astr,\nfs/hfsplus/hfsplus_fs.h-497-\t\t\tint *len_p);\nfs/hfsplus/hfsplus_fs.h=498=int hfsplus_uni2asc_xattr_str(struct super_block *sb,\n--\nfs/hfsplus/hfsplus_fs.h-500-\t\t\t      char *astr, int *len_p);\nfs/hfsplus/hfsplus_fs.h:501:int hfsplus_asc2uni(struct super_block *sb, struct hfsplus_unistr *ustr,\nfs/hfsplus/hfsplus_fs.h-502-\t\t    int max_unistr_len, const char *astr, int len,\n--\nfs/hfsplus/hfsplus_fs.h=513=static inline u32 hfsplus_cat_thread_size(const struct hfsplus_cat_thread *thread)\n--\nfs/hfsplus/hfsplus_fs.h-515-\treturn offsetof(struct hfsplus_cat_thread, nodeName) +\nfs/hfsplus/hfsplus_fs.h:516:\t       offsetof(struct hfsplus_unistr, unicode) +\nfs/hfsplus/hfsplus_fs.h-517-\t       be16_to_cpu(thread-\u003enodeName.length) * sizeof(hfsplus_unichr);\n--\nfs/hfsplus/unicode.c=23=static inline u16 case_fold(u16 c)\n--\nfs/hfsplus/unicode.c-35-/* Compare unicode strings, return values like normal strcmp */\nfs/hfsplus/unicode.c:36:int hfsplus_strcasecmp(const struct hfsplus_unistr *s1,\nfs/hfsplus/unicode.c:37:\t\t       const struct hfsplus_unistr *s2)\nfs/hfsplus/unicode.c-38-{\n--\nfs/hfsplus/unicode.c=79=EXPORT_SYMBOL_IF_KUNIT(hfsplus_strcasecmp);\n--\nfs/hfsplus/unicode.c-81-/* Compare names as a sequence of 16-bit unsigned integers */\nfs/hfsplus/unicode.c:82:int hfsplus_strcmp(const struct hfsplus_unistr *s1,\nfs/hfsplus/unicode.c:83:\t\t   const struct hfsplus_unistr *s2)\nfs/hfsplus/unicode.c-84-{\n--\nfs/hfsplus/unicode.c=185=static int hfsplus_uni2asc(struct super_block *sb,\nfs/hfsplus/unicode.c:186:\t\t\t   const struct hfsplus_unistr *ustr,\nfs/hfsplus/unicode.c-187-\t\t\t   int max_len, char *astr, int *len_p,\n--\nfs/hfsplus/unicode.c=309=inline int hfsplus_uni2asc_str(struct super_block *sb,\nfs/hfsplus/unicode.c:310:\t\t\t       const struct hfsplus_unistr *ustr, char *astr,\nfs/hfsplus/unicode.c-311-\t\t\t       int *len_p)\n--\nfs/hfsplus/unicode.c=320=inline int hfsplus_uni2asc_xattr_str(struct super_block *sb,\n--\nfs/hfsplus/unicode.c-323-{\nfs/hfsplus/unicode.c:324:\treturn hfsplus_uni2asc(sb, (const struct hfsplus_unistr *)ustr,\nfs/hfsplus/unicode.c-325-\t\t\t\tHFSPLUS_ATTR_MAX_STRLEN, astr, len_p,\n--\nfs/hfsplus/unicode.c=557=int hfsplus_asc2uni(struct super_block *sb,\nfs/hfsplus/unicode.c:558:\t\t    struct hfsplus_unistr *ustr, int max_unistr_len,\nfs/hfsplus/unicode.c-559-\t\t    const char *astr, int len, int name_type)\n--\nfs/hfsplus/unicode_test.c=15=struct test_mock_string_env {\nfs/hfsplus/unicode_test.c:16:\tstruct hfsplus_unistr str1;\nfs/hfsplus/unicode_test.c:17:\tstruct hfsplus_unistr str2;\nfs/hfsplus/unicode_test.c-18-\tchar *buf;\n--\nfs/hfsplus/unicode_test.c=41=static void free_mock_str_env(struct test_mock_string_env *env)\n--\nfs/hfsplus/unicode_test.c-46-\nfs/hfsplus/unicode_test.c:47:/* Helper function to create hfsplus_unistr */\nfs/hfsplus/unicode_test.c:48:static void create_unistr(struct hfsplus_unistr *ustr, const char *ascii_str)\nfs/hfsplus/unicode_test.c-49-{\n--\nfs/hfsplus/unicode_test.c-59-\nfs/hfsplus/unicode_test.c:60:static void corrupt_unistr(struct hfsplus_unistr *ustr)\nfs/hfsplus/unicode_test.c-61-{\n--\nfs/hfsplus/unicode_test.c=683=static void check_unistr_content(struct kunit *test,\nfs/hfsplus/unicode_test.c:684:\t\t\t\t struct hfsplus_unistr *ustr,\nfs/hfsplus/unicode_test.c-685-\t\t\t\t const char *expected_ascii)\n--\nfs/hfsplus/unicode_test.c=859=static void hfsplus_asc2uni_edge_cases_test(struct kunit *test)\n--\nfs/hfsplus/unicode_test.c-861-\tstruct test_mock_sb *mock_sb;\nfs/hfsplus/unicode_test.c:862:\tstruct hfsplus_unistr ustr;\nfs/hfsplus/unicode_test.c-863-\tchar test_str[] = {'a', '\\0', 'b'};\n--\nfs/hfsplus/unicode_test.c=996=static void hfsplus_asc2uni_combining_reorder_test(struct kunit *test)\n--\nfs/hfsplus/unicode_test.c-998-\tstruct test_mock_sb *mock_sb;\nfs/hfsplus/unicode_test.c:999:\tstruct hfsplus_unistr ustr;\nfs/hfsplus/unicode_test.c-1000-\t/* \"e\" + COMBINING ACUTE ACCENT (U+0301) + COMBINING DOT BELOW (U+0323) */\n--\nfs/hfsplus/unicode_test.c=1062=static void hfsplus_unicode_combining_reorder_roundtrip_test(struct kunit *test)\n--\nfs/hfsplus/unicode_test.c-1064-\tstruct test_mock_sb *mock_sb;\nfs/hfsplus/unicode_test.c:1065:\tstruct hfsplus_unistr ustr;\nfs/hfsplus/unicode_test.c-1066-\tstatic const char wrong_order[] = \"e\\xcc\\x81\\xcc\\xa3\";\n--\nfs/hfsplus/unicode_test.c=1102=static void hfsplus_asc2uni_legacy_decomp_test(struct kunit *test)\n--\nfs/hfsplus/unicode_test.c-1104-\tstruct test_mock_sb *mock_sb;\nfs/hfsplus/unicode_test.c:1105:\tstruct hfsplus_unistr ustr;\nfs/hfsplus/unicode_test.c-1106-\tstatic const char input[] = \"\\xc7\\xb8\"; /* U+01F8 */\n--\nfs/hfsplus/unicode_test.c=1135=static void hfsplus_asc2uni_legacy_seq_fixup_test(struct kunit *test)\n--\nfs/hfsplus/unicode_test.c-1137-\tstruct test_mock_sb *mock_sb;\nfs/hfsplus/unicode_test.c:1138:\tstruct hfsplus_unistr ustr;\nfs/hfsplus/unicode_test.c-1139-\tstatic const char greek_input[] = \"\\xce\\xb1\\xcc\\x8d\"; /* U+03B1 U+030D */\n"
}

33/2 2026/09/21 03:55 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 73464
							output: 34
							thoughts: 25
						

Thoughts:
Here's my summary, as though I'm thinking it:

**Digging into the `hfsplus_unistr` Definition**

Okay, time to get to the core of this. I need to understand what `hfsplus_unistr` actually *is*. Let's go straight to the source – the `hfsplus_raw.h` header file. That's the logical place to start digging for the raw definition. I'm expecting to find the structure defined there, along with all its members. Understanding this structure is fundamental to understanding the data it represents and how it's handled. Hopefully, the comments are helpful too. Time to open that file and get started.



34/2 2026/09/21 03:55 tool grepper
0m Args:
{
  "Expression": "struct hfsplus_unistr\\b",
  "PathPrefix": "fs/hfsplus"
}

Results:
{
  "Output": "fs/hfsplus/attributes.c=35=int hfsplus_attr_bin_cmp_key(const hfsplus_btree_key *k1,\n--\nfs/hfsplus/attributes.c-45-\treturn hfsplus_strcmp(\nfs/hfsplus/attributes.c:46:\t\t\t(const struct hfsplus_unistr *)\u0026k1-\u003eattr.key_name,\nfs/hfsplus/attributes.c:47:\t\t\t(const struct hfsplus_unistr *)\u0026k2-\u003eattr.key_name);\nfs/hfsplus/attributes.c-48-}\n--\nfs/hfsplus/attributes.c=50=int hfsplus_attr_build_key(struct super_block *sb, hfsplus_btree_key *key,\n--\nfs/hfsplus/attributes.c-58-\t\tint res = hfsplus_asc2uni(sb,\nfs/hfsplus/attributes.c:59:\t\t\t\t(struct hfsplus_unistr *)\u0026key-\u003eattr.key_name,\nfs/hfsplus/attributes.c-60-\t\t\t\tHFSPLUS_ATTR_MAX_STRLEN, name, strlen(name),\n--\nfs/hfsplus/catalog.c=68=static void hfsplus_cat_build_key_uni(hfsplus_btree_key *key, u32 parent,\nfs/hfsplus/catalog.c:69:\t\t\t\t      struct hfsplus_unistr *name)\nfs/hfsplus/catalog.c-70-{\n--\nfs/hfsplus/hfsplus_fs.h=488=int hfsplus_commit_superblock(struct super_block *sb);\n--\nfs/hfsplus/hfsplus_fs.h-490-/* unicode.c */\nfs/hfsplus/hfsplus_fs.h:491:int hfsplus_strcasecmp(const struct hfsplus_unistr *s1,\nfs/hfsplus/hfsplus_fs.h:492:\t\t       const struct hfsplus_unistr *s2);\nfs/hfsplus/hfsplus_fs.h:493:int hfsplus_strcmp(const struct hfsplus_unistr *s1,\nfs/hfsplus/hfsplus_fs.h:494:\t\t   const struct hfsplus_unistr *s2);\nfs/hfsplus/hfsplus_fs.h-495-int hfsplus_uni2asc_str(struct super_block *sb,\nfs/hfsplus/hfsplus_fs.h:496:\t\t\tconst struct hfsplus_unistr *ustr, char *astr,\nfs/hfsplus/hfsplus_fs.h-497-\t\t\tint *len_p);\nfs/hfsplus/hfsplus_fs.h=498=int hfsplus_uni2asc_xattr_str(struct super_block *sb,\n--\nfs/hfsplus/hfsplus_fs.h-500-\t\t\t      char *astr, int *len_p);\nfs/hfsplus/hfsplus_fs.h:501:int hfsplus_asc2uni(struct super_block *sb, struct hfsplus_unistr *ustr,\nfs/hfsplus/hfsplus_fs.h-502-\t\t    int max_unistr_len, const char *astr, int len,\n--\nfs/hfsplus/hfsplus_fs.h=513=static inline u32 hfsplus_cat_thread_size(const struct hfsplus_cat_thread *thread)\n--\nfs/hfsplus/hfsplus_fs.h-515-\treturn offsetof(struct hfsplus_cat_thread, nodeName) +\nfs/hfsplus/hfsplus_fs.h:516:\t       offsetof(struct hfsplus_unistr, unicode) +\nfs/hfsplus/hfsplus_fs.h-517-\t       be16_to_cpu(thread-\u003enodeName.length) * sizeof(hfsplus_unichr);\n--\nfs/hfsplus/unicode.c=23=static inline u16 case_fold(u16 c)\n--\nfs/hfsplus/unicode.c-35-/* Compare unicode strings, return values like normal strcmp */\nfs/hfsplus/unicode.c:36:int hfsplus_strcasecmp(const struct hfsplus_unistr *s1,\nfs/hfsplus/unicode.c:37:\t\t       const struct hfsplus_unistr *s2)\nfs/hfsplus/unicode.c-38-{\n--\nfs/hfsplus/unicode.c=79=EXPORT_SYMBOL_IF_KUNIT(hfsplus_strcasecmp);\n--\nfs/hfsplus/unicode.c-81-/* Compare names as a sequence of 16-bit unsigned integers */\nfs/hfsplus/unicode.c:82:int hfsplus_strcmp(const struct hfsplus_unistr *s1,\nfs/hfsplus/unicode.c:83:\t\t   const struct hfsplus_unistr *s2)\nfs/hfsplus/unicode.c-84-{\n--\nfs/hfsplus/unicode.c=185=static int hfsplus_uni2asc(struct super_block *sb,\nfs/hfsplus/unicode.c:186:\t\t\t   const struct hfsplus_unistr *ustr,\nfs/hfsplus/unicode.c-187-\t\t\t   int max_len, char *astr, int *len_p,\n--\nfs/hfsplus/unicode.c=309=inline int hfsplus_uni2asc_str(struct super_block *sb,\nfs/hfsplus/unicode.c:310:\t\t\t       const struct hfsplus_unistr *ustr, char *astr,\nfs/hfsplus/unicode.c-311-\t\t\t       int *len_p)\n--\nfs/hfsplus/unicode.c=320=inline int hfsplus_uni2asc_xattr_str(struct super_block *sb,\n--\nfs/hfsplus/unicode.c-323-{\nfs/hfsplus/unicode.c:324:\treturn hfsplus_uni2asc(sb, (const struct hfsplus_unistr *)ustr,\nfs/hfsplus/unicode.c-325-\t\t\t\tHFSPLUS_ATTR_MAX_STRLEN, astr, len_p,\n--\nfs/hfsplus/unicode.c=557=int hfsplus_asc2uni(struct super_block *sb,\nfs/hfsplus/unicode.c:558:\t\t    struct hfsplus_unistr *ustr, int max_unistr_len,\nfs/hfsplus/unicode.c-559-\t\t    const char *astr, int len, int name_type)\n--\nfs/hfsplus/unicode_test.c=15=struct test_mock_string_env {\nfs/hfsplus/unicode_test.c:16:\tstruct hfsplus_unistr str1;\nfs/hfsplus/unicode_test.c:17:\tstruct hfsplus_unistr str2;\nfs/hfsplus/unicode_test.c-18-\tchar *buf;\n--\nfs/hfsplus/unicode_test.c=41=static void free_mock_str_env(struct test_mock_string_env *env)\n--\nfs/hfsplus/unicode_test.c-47-/* Helper function to create hfsplus_unistr */\nfs/hfsplus/unicode_test.c:48:static void create_unistr(struct hfsplus_unistr *ustr, const char *ascii_str)\nfs/hfsplus/unicode_test.c-49-{\n--\nfs/hfsplus/unicode_test.c-59-\nfs/hfsplus/unicode_test.c:60:static void corrupt_unistr(struct hfsplus_unistr *ustr)\nfs/hfsplus/unicode_test.c-61-{\n--\nfs/hfsplus/unicode_test.c=683=static void check_unistr_content(struct kunit *test,\nfs/hfsplus/unicode_test.c:684:\t\t\t\t struct hfsplus_unistr *ustr,\nfs/hfsplus/unicode_test.c-685-\t\t\t\t const char *expected_ascii)\n--\nfs/hfsplus/unicode_test.c=859=static void hfsplus_asc2uni_edge_cases_test(struct kunit *test)\n--\nfs/hfsplus/unicode_test.c-861-\tstruct test_mock_sb *mock_sb;\nfs/hfsplus/unicode_test.c:862:\tstruct hfsplus_unistr ustr;\nfs/hfsplus/unicode_test.c-863-\tchar test_str[] = {'a', '\\0', 'b'};\n--\nfs/hfsplus/unicode_test.c=996=static void hfsplus_asc2uni_combining_reorder_test(struct kunit *test)\n--\nfs/hfsplus/unicode_test.c-998-\tstruct test_mock_sb *mock_sb;\nfs/hfsplus/unicode_test.c:999:\tstruct hfsplus_unistr ustr;\nfs/hfsplus/unicode_test.c-1000-\t/* \"e\" + COMBINING ACUTE ACCENT (U+0301) + COMBINING DOT BELOW (U+0323) */\n--\nfs/hfsplus/unicode_test.c=1062=static void hfsplus_unicode_combining_reorder_roundtrip_test(struct kunit *test)\n--\nfs/hfsplus/unicode_test.c-1064-\tstruct test_mock_sb *mock_sb;\nfs/hfsplus/unicode_test.c:1065:\tstruct hfsplus_unistr ustr;\nfs/hfsplus/unicode_test.c-1066-\tstatic const char wrong_order[] = \"e\\xcc\\x81\\xcc\\xa3\";\n--\nfs/hfsplus/unicode_test.c=1102=static void hfsplus_asc2uni_legacy_decomp_test(struct kunit *test)\n--\nfs/hfsplus/unicode_test.c-1104-\tstruct test_mock_sb *mock_sb;\nfs/hfsplus/unicode_test.c:1105:\tstruct hfsplus_unistr ustr;\nfs/hfsplus/unicode_test.c-1106-\tstatic const char input[] = \"\\xc7\\xb8\"; /* U+01F8 */\n--\nfs/hfsplus/unicode_test.c=1135=static void hfsplus_asc2uni_legacy_seq_fixup_test(struct kunit *test)\n--\nfs/hfsplus/unicode_test.c-1137-\tstruct test_mock_sb *mock_sb;\nfs/hfsplus/unicode_test.c:1138:\tstruct hfsplus_unistr ustr;\nfs/hfsplus/unicode_test.c-1139-\tstatic const char greek_input[] = \"\\xce\\xb1\\xcc\\x8d\"; /* U+03B1 U+030D */\n"
}

35/2 2026/09/21 03:55 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 76495
							output: 22
							thoughts: 22
						

Thoughts:
Here's my thought process, as if I were considering this myself:

**Locating the `hfsplus_unistr` Structure Definition**

Okay, so I need to track down the definition of the `hfsplus_unistr` structure. Given my familiarity with the HFS+ file system, I know it's a critical data structure, likely involved in Unicode string handling. Since I'm working with a large codebase (probably a kernel or file system implementation), manually browsing would be incredibly inefficient. The best approach is to leverage a tool specifically designed for this purpose. Grepping the entire tree is the obvious and most effective way to locate it. I need to be precise, so I will start by searching for exactly `struct hfsplus_unistr` using the right tool like `grep` or `ag`. Once I've found it, I can see where it's declared and how it is defined. From there, I can determine which header file contains the declaration and begin an analysis.



36/2 2026/09/21 03:55 tool grepper
0m Args:
{
  "Expression": "struct hfsplus_unistr \\{"
}

Results:
{
  "Output": "include/linux/hfs_common.h=149=struct hfs_name {\n--\ninclude/linux/hfs_common.h-154-/* A \"string\" as used in filenames, etc. */\ninclude/linux/hfs_common.h:155:struct hfsplus_unistr {\ninclude/linux/hfs_common.h-156-\t__be16 length;\n"
}

37/2 2026/09/21 03:55 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 76862
							output: 38
							thoughts: 23
						

Thoughts:
Here's my summary, as if I were thinking these thoughts:

**Diving into the HFS+ Code**

Okay, time to dig into the HFS+ kernel code again. I'm going to start by looking at `include/linux/hfs_common.h`. I seem to remember something specific around line 155, so let's jump right to that area. I need to refresh my memory on the data structures and maybe understand the implications of the layout in that area. Hopefully, this will shed some light on the issue I am currently trying to troubleshoot.



38/2 2026/09/21 03:55 tool read-file
0m Args:
{
  "File": "include/linux/hfs_common.h",
  "FirstLine": 150,
  "LineCount": 40
}

Results:
{
  "Contents": " 150:\t\tu8 len;\n 151:\t\tu8 name[HFS_NAMELEN];\n 152:\t} __packed;\n 153:\t\n 154:\t/* A \"string\" as used in filenames, etc. */\n 155:\tstruct hfsplus_unistr {\n 156:\t\t__be16 length;\n 157:\t\thfsplus_unichr unicode[HFSPLUS_MAX_STRLEN];\n 158:\t} __packed;\n 159:\t\n 160:\t/*\n 161:\t * A \"string\" is used in attributes file\n 162:\t * for name of extended attribute\n 163:\t */\n 164:\tstruct hfsplus_attr_unistr {\n 165:\t\t__be16 length;\n 166:\t\thfsplus_unichr unicode[HFSPLUS_ATTR_MAX_STRLEN];\n 167:\t} __packed;\n 168:\t\n 169:\tenum {\n 170:\t\tHFS_REGULAR_NAME,\n 171:\t\tHFS_XATTR_NAME,\n 172:\t};\n 173:\t\n 174:\tstruct hfs_extent {\n 175:\t\t__be16 block;\n 176:\t\t__be16 count;\n 177:\t};\n 178:\ttypedef struct hfs_extent hfs_extent_rec[3];\n 179:\t\n 180:\t/* A single contiguous area of a file */\n 181:\tstruct hfsplus_extent {\n 182:\t\t__be32 start_block;\n 183:\t\t__be32 block_count;\n 184:\t} __packed;\n 185:\ttypedef struct hfsplus_extent hfsplus_extent_rec[8];\n 186:\t\n 187:\t/* Information for a \"Fork\" in a file */\n 188:\tstruct hfsplus_fork_raw {\n 189:\t\t__be64 total_size;\n"
}

39/2 2026/09/21 03:55 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 77602
							output: 33
							thoughts: 313
						

Thoughts:
**Analyzing HFS+ Attribute Key Construction**

Okay, here we go. Let's dig into this HFS+ attribute key structure. First, I see these definitions: `hfsplus_unistr` and `hfsplus_attr_unistr`. Right, standard Unicode strings, the latter specifically for extended attributes, presumably with a defined maximum length, as expected.

Now, let's see how `hfsplus_attr_build_key` actually works. Ah, here we are... it uses `hfsplus_asc2uni` to convert an ASCII name into a Unicode representation for the attribute key. The key part is `key->attr.key_name`. *That's* the important piece I need to understand. What exactly is `key->attr.key_name`? Let's check `hfsplus_raw.h` to see how that's defined, so I can see what type of structure we are converting this name to.



40/2 2026/09/21 03:55 tool grepper
0m Args:
{
  "Expression": "struct hfsplus_attr_key",
  "PathPrefix": "fs/hfsplus"
}

Results:
{
  "Output": "fs/hfsplus/attributes.c=50=int hfsplus_attr_build_key(struct super_block *sb, hfsplus_btree_key *key,\n--\nfs/hfsplus/attributes.c-54-\nfs/hfsplus/attributes.c:55:\tmemset(key, 0, sizeof(struct hfsplus_attr_key));\nfs/hfsplus/attributes.c-56-\tkey-\u003eattr.cnid = cpu_to_be32(cnid);\n--\nfs/hfsplus/attributes.c-77-\tkey-\u003ekey_len =\nfs/hfsplus/attributes.c:78:\t\tcpu_to_be16(offsetof(struct hfsplus_attr_key, key_name) +\nfs/hfsplus/attributes.c-79-\t\t\t\t2 * len);\n--\nfs/hfsplus/attributes.c=305=static int __hfsplus_delete_attr(struct inode *inode, u32 cnid,\n--\nfs/hfsplus/attributes.c-313-\t\t\tfd-\u003ekeyoffset +\nfs/hfsplus/attributes.c:314:\t\t\toffsetof(struct hfsplus_attr_key, cnid),\nfs/hfsplus/attributes.c-315-\t\t\tsizeof(__be32));\n--\nfs/hfsplus/xattr.c=802=ssize_t hfsplus_listxattr(struct dentry *dentry, char *buffer, size_t size)\n--\nfs/hfsplus/xattr.c-807-\tstruct hfs_find_data fd;\nfs/hfsplus/xattr.c:808:\tstruct hfsplus_attr_key attr_key;\nfs/hfsplus/xattr.c-809-\tchar *strbuf;\n"
}

41/2 2026/09/21 03:55 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 78611
							output: 36
							thoughts: 26
						

Thoughts:
Here's my take on those thoughts:

**Peering into the Core: Unpacking `hfsplus_attr_key`**

Okay, time to get down to brass tacks. I need to refresh my memory on the specifics of `hfsplus_attr_key`. Let's dive right into the `hfsplus_raw.h` header file. It's the definitive source, I'm sure it will be much clearer to see the actual definition, not just rely on vague recollections. I want to see precisely how it's structured, what fields it contains, and how that key is designed to work in the underlying HFS+ architecture. It's often the small details in the raw data structures that reveal important aspects of how a file system *really* functions. Time to crack open that header and take a look.



42/2 2026/09/21 03:56 tool grepper
0m Error:
no matches

Args:
{
  "Expression": "key_name",
  "PathPrefix": "fs/hfsplus/hfsplus_raw.h"
}

Results:
{
  "error": "no matches"
}

43/2 2026/09/21 03:56 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 78865
							output: 25
							thoughts: 24
						

Thoughts:
Here's my attempt at summarizing the thought process, tailored for an expert audience:

**Hunting Down a Key Variable**

Okay, so I need to track down where this `key_name` is actually defined. Given the context, it's highly likely to be in either `include/` or, because we're probably dealing with a file system-specific key, `fs/hfsplus`. My instinct tells me to start the hunt there because anything related to keys is likely to be defined at a low level. It's the first step in debugging or trying to track down where a variable is being changed, or what its initial value is set to. Time to start digging through those directories.



44/2 2026/09/21 03:56 tool grepper
0m Args:
{
  "Expression": "key_name",
  "PathPrefix": "include/"
}

Results:
{
  "Output": "include/linux/fscrypt.h=43=struct fscrypt_name {\n--\ninclude/linux/fscrypt.h-48-\tstruct fscrypt_str crypto_buf;\ninclude/linux/fscrypt.h:49:\tbool is_nokey_name;\ninclude/linux/fscrypt.h-50-};\n--\ninclude/linux/fscrypt.h=271=static inline void fscrypt_handle_d_move(struct dentry *dentry)\n--\ninclude/linux/fscrypt.h-289-/**\ninclude/linux/fscrypt.h:290: * fscrypt_is_nokey_name() - test whether a dentry is a no-key name\ninclude/linux/fscrypt.h-291- * @dentry: the dentry to check\n--\ninclude/linux/fscrypt.h-312- */\ninclude/linux/fscrypt.h:313:static inline bool fscrypt_is_nokey_name(const struct dentry *dentry)\ninclude/linux/fscrypt.h-314-{\n--\ninclude/linux/fscrypt.h=318=static inline void fscrypt_prepare_dentry(struct dentry *dentry,\ninclude/linux/fscrypt.h:319:\t\t\t\t\t  bool is_nokey_name)\ninclude/linux/fscrypt.h-320-{\n--\ninclude/linux/fscrypt.h-328-\t */\ninclude/linux/fscrypt.h:329:\tif (is_nokey_name) {\ninclude/linux/fscrypt.h-330-\t\tspin_lock(\u0026dentry-\u003ed_lock);\n--\ninclude/linux/fscrypt.h=492=static inline void fscrypt_handle_d_move(struct dentry *dentry)\n--\ninclude/linux/fscrypt.h-495-\ninclude/linux/fscrypt.h:496:static inline bool fscrypt_is_nokey_name(const struct dentry *dentry)\ninclude/linux/fscrypt.h-497-{\n--\ninclude/linux/fscrypt.h=501=static inline void fscrypt_prepare_dentry(struct dentry *dentry,\ninclude/linux/fscrypt.h:502:\t\t\t\t\t  bool is_nokey_name)\ninclude/linux/fscrypt.h-503-{\n--\ninclude/linux/hfs_common.h=619=struct hfsplus_attr_key {\n--\ninclude/linux/hfs_common.h-623-\t__be32 start_block;\ninclude/linux/hfs_common.h:624:\tstruct hfsplus_attr_unistr key_name;\ninclude/linux/hfs_common.h-625-} __packed;\n--\ninclude/linux/tpm.h=108=struct tpm_chip {\n--\ninclude/linux/tpm.h-168-\t /* name of NULL seed */\ninclude/linux/tpm.h:169:\tu8 null_key_name[TPM2_NAME_SIZE];\ninclude/linux/tpm.h-170-\tu8 null_ec_key_x[EC_PT_SZ];\n"
}

45/2 2026/09/21 03:56 llm patch-evaluator
1m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 79888
							output: 28
							thoughts: 3192
						

Thoughts:
**Deep Dive into HFS+ String Handling and Potential Vulnerabilities**

Alright, let's break this down systematically. I'm examining this code because I need to be *absolutely* certain of its integrity, especially regarding potential vulnerabilities related to string manipulation and buffer overflows. My initial concern is always around the size of allocated buffers and how they interact with external data.

First, I see the structure `hfsplus_attr_key` and its `key_name` member, which is a `hfsplus_attr_unistr`. The key part here is the conversion from ASCII to Unicode: `hfsplus_asc2uni`. This function takes the source ASCII string (`name`) and converts it to a Unicode string, storing the result in `key->attr.key_name`. The critical piece of information I need to confirm is how the length of the string is handled during the conversion, and what limits are in place.

`hfsplus_asc2uni` calls `hfsplus_decompose_str`.  `outlen` in `hfsplus_decompose_str` is important, because this value determines how much data is written into the buffer. The loop condition `while (outlen < max_len && len > 0)` is reassuring; however, I need to confirm that `outlen` can never exceed `max_len`, which has a hard limit.

I am now looking at the loop in `hfsplus_decompose_str`. Specifically, I was worried about what happens when `dstr` is `NULL`. If `dstr` is `NULL`, then `out[outlen++] = c;` is executed. In this case, `outlen` is incremented. However, as the loop condition is `outlen < max_len`, I'm comfortable that this write will not overflow `out`. The maximum value for `outlen` is `max_len`. This is because the loop always exits when `outlen` is equal to `max_len`.  `out` is a `u16` buffer with the size `HFSPLUS_MAX_STRLEN`, so as long as `max_len` is appropriately constrained, I am safe. I see that `max_len` is initially set to  `HFSPLUS_ATTR_MAX_STRLEN`, and my earlier code checks that `max_unistr_len` is never greater than this. Thus, `max_len` is `HFSPLUS_ATTR_MAX_STRLEN` at the `hfsplus_asc2uni` level. The write to the buffer therefore will never overflow, given that we have the proper checks in place.

However, `hfsplus_decompose_str` also calls `hfsplus_canonical_reorder` and `hfsplus_fixup_legacy_sequences`. I need to confirm that neither of these functions can *increase* the value of `outlen` and cause a buffer overflow after the initial size check.

Looking at `hfsplus_canonical_reorder`, it reorders characters based on combining classes. It can only swap existing elements, so the *number* of elements in the buffer cannot increase.

`hfsplus_fixup_legacy_sequences` could be problematic, but I see that all replacements have lengths `f->repl_len <= f->match_len`. So this can *only* decrease or keep the same the amount of `outlen`.

Now, focusing on the decomposition logic itself, the `decompose_unichar` function is the next point of interest. This function tries to decompose a Unicode character into multiple characters, for example, for composed characters. `decompose_unichar` calls `hfsplus_try_decompose_hangul` and `hfsplus_decompose_nonhangul`. If decomposition is not possible, it calls `hfsplus_legacy_decompose`, which returns a pointer to a replacement sequence. I note the use of `hangul_buffer`.  The code uses `memcpy` to copy the `legacy` decomposition into `hangul_buffer`. I see that `hangul_buffer` is an array of size `HFSPLUS_HANGUL_MAX_JAMO` which is equal to 3. The entries in `hfsplus_legacy_decomp_table` have a `len` field that is either 2 or 3. Importantly, there is a `static_assert` that verifies that the `hangul_buffer` will not overflow, and can hold at least the maximum length of these decomposed sequences. I am comfortable that the `memcpy` is safe.

Finally, I examined `hfsplus_compare_dentry`, as it uses similar decomposition logic, and could be a source of potential issues if it mishandles string comparison. Since it seems to be iterating and decomposing strings,


46/2 2026/09/21 03:57 tool grepper
0m Args:
{
  "Expression": "\\.d_compare\\b",
  "PathPrefix": "fs/"
}

Results:
{
  "Output": "fs/adfs/dir.c=425=const struct dentry_operations adfs_dentry_operations = {\nfs/adfs/dir.c-426-\t.d_hash\t\t= adfs_hash,\nfs/adfs/dir.c:427:\t.d_compare\t= adfs_compare,\nfs/adfs/dir.c-428-};\n--\nfs/affs/namei.c=574=const struct dentry_operations affs_dentry_operations = {\nfs/affs/namei.c-575-\t.d_hash\t\t= affs_hash_dentry,\nfs/affs/namei.c:576:\t.d_compare\t= affs_compare_dentry,\nfs/affs/namei.c-577-};\n--\nfs/affs/namei.c=579=const struct dentry_operations affs_intl_dentry_operations = {\nfs/affs/namei.c-580-\t.d_hash\t\t= affs_intl_hash_dentry,\nfs/affs/namei.c:581:\t.d_compare\t= affs_intl_compare_dentry,\nfs/affs/namei.c-582-};\n--\nfs/efivarfs/super.c=205=static const struct dentry_operations efivarfs_d_ops = {\nfs/efivarfs/super.c:206:\t.d_compare = efivarfs_d_compare,\nfs/efivarfs/super.c-207-\t.d_hash = efivarfs_d_hash,\n--\nfs/exfat/namei.c=130=const struct dentry_operations exfat_dentry_ops = {\n--\nfs/exfat/namei.c-132-\t.d_hash\t\t= exfat_d_hash,\nfs/exfat/namei.c:133:\t.d_compare\t= exfat_d_cmp,\nfs/exfat/namei.c-134-};\n--\nfs/exfat/namei.c=196=const struct dentry_operations exfat_utf8_dentry_ops = {\n--\nfs/exfat/namei.c-198-\t.d_hash\t\t= exfat_utf8_d_hash,\nfs/exfat/namei.c:199:\t.d_compare\t= exfat_utf8_d_cmp,\nfs/exfat/namei.c-200-};\n--\nfs/fat/namei_msdos.c=194=static const struct dentry_operations msdos_dentry_operations = {\nfs/fat/namei_msdos.c-195-\t.d_hash\t\t= msdos_hash,\nfs/fat/namei_msdos.c:196:\t.d_compare\t= msdos_cmp,\nfs/fat/namei_msdos.c-197-};\n--\nfs/fat/namei_vfat.c=187=static const struct dentry_operations vfat_ci_dentry_ops = {\n--\nfs/fat/namei_vfat.c-189-\t.d_hash\t\t= vfat_hashi,\nfs/fat/namei_vfat.c:190:\t.d_compare\t= vfat_cmpi,\nfs/fat/namei_vfat.c-191-};\n--\nfs/fat/namei_vfat.c=193=static const struct dentry_operations vfat_dentry_ops = {\n--\nfs/fat/namei_vfat.c-195-\t.d_hash\t\t= vfat_hash,\nfs/fat/namei_vfat.c:196:\t.d_compare\t= vfat_cmp,\nfs/fat/namei_vfat.c-197-};\n--\nfs/hfs/sysdep.c=44=const struct dentry_operations hfs_dentry_operations =\n--\nfs/hfs/sysdep.c-47-\t.d_hash\t\t= hfs_hash_dentry,\nfs/hfs/sysdep.c:48:\t.d_compare\t= hfs_compare_dentry,\nfs/hfs/sysdep.c-49-};\n--\nfs/hfsplus/inode.c=220=const struct dentry_operations hfsplus_dentry_operations = {\nfs/hfsplus/inode.c-221-\t.d_hash       = hfsplus_hash_dentry,\nfs/hfsplus/inode.c:222:\t.d_compare    = hfsplus_compare_dentry,\nfs/hfsplus/inode.c-223-};\n--\nfs/hpfs/dentry.c=59=const struct dentry_operations hpfs_dentry_operations = {\nfs/hpfs/dentry.c-60-\t.d_hash\t\t= hpfs_hash_dentry,\nfs/hpfs/dentry.c:61:\t.d_compare\t= hpfs_compare_dentry,\nfs/hpfs/dentry.c-62-};\n--\nfs/isofs/inode.c=131=static const struct dentry_operations isofs_dentry_ops[] = {\n--\nfs/isofs/inode.c-133-\t\t.d_hash\t\t= isofs_hashi,\nfs/isofs/inode.c:134:\t\t.d_compare\t= isofs_dentry_cmpi,\nfs/isofs/inode.c-135-\t},\n--\nfs/isofs/inode.c-138-\t\t.d_hash\t\t= isofs_hash_ms,\nfs/isofs/inode.c:139:\t\t.d_compare\t= isofs_dentry_cmp_ms,\nfs/isofs/inode.c-140-\t},\n--\nfs/isofs/inode.c-142-\t\t.d_hash\t\t= isofs_hashi_ms,\nfs/isofs/inode.c:143:\t\t.d_compare\t= isofs_dentry_cmpi_ms,\nfs/isofs/inode.c-144-\t},\n--\nfs/jfs/namei.c=1616=const struct dentry_operations jfs_ci_dentry_operations =\n--\nfs/jfs/namei.c-1618-\t.d_hash = jfs_ci_hash,\nfs/jfs/namei.c:1619:\t.d_compare = jfs_ci_compare,\nfs/jfs/namei.c-1620-\t.d_revalidate = jfs_ci_revalidate,\n--\nfs/libfs.c=1870=static const struct dentry_operations generic_ci_dentry_ops = {\nfs/libfs.c-1871-\t.d_hash = generic_ci_d_hash,\nfs/libfs.c:1872:\t.d_compare = generic_ci_d_compare,\nfs/libfs.c-1873-#ifdef CONFIG_FS_ENCRYPTION\n--\nfs/ntfs3/namei.c=559=const struct dentry_operations ntfs_dentry_ops = {\nfs/ntfs3/namei.c-560-\t.d_hash\t\t= ntfs_d_hash,\nfs/ntfs3/namei.c:561:\t.d_compare\t= ntfs_d_compare,\nfs/ntfs3/namei.c-562-};\n--\nfs/overlayfs/super.c=173=static const struct dentry_operations ovl_dentry_ci_operations = {\n--\nfs/overlayfs/super.c-177-\t.d_hash = generic_ci_d_hash,\nfs/overlayfs/super.c:178:\t.d_compare = generic_ci_d_compare,\nfs/overlayfs/super.c-179-};\n--\nfs/proc/proc_sysctl.c=937=static const struct dentry_operations proc_sys_dentry_operations = {\n--\nfs/proc/proc_sysctl.c-939-\t.d_delete\t= proc_sys_delete,\nfs/proc/proc_sysctl.c:940:\t.d_compare\t= proc_sys_compare,\nfs/proc/proc_sysctl.c-941-};\n--\nfs/smb/client/dir.c=1205=const struct dentry_operations cifs_ci_dentry_ops = {\n--\nfs/smb/client/dir.c-1207-\t.d_hash = cifs_ci_hash,\nfs/smb/client/dir.c:1208:\t.d_compare = cifs_ci_compare,\nfs/smb/client/dir.c-1209-\t.d_automount = cifs_d_automount,\n"
}

47/2 2026/09/21 03:57 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 86398
							output: 37
							thoughts: 3774
						

Thoughts:
**Deep Dive into HFS+ String Decomposition and Iteration**

Okay, so I've been dissecting the string comparison and decomposition logic in the HFS+ filesystem code, specifically focusing on how it handles Unicode normalization and iteration. The initial comparison (`d_compare`) is straightforward: 0 for match, positive or negative for mismatch, mirroring the standard `strcmp` conventions.

My focus now is on `hfsplus_decompose_iter_refill` and how it interacts with the decomposition table. I've realized there's a crucial interplay between characters that decompose to multiple code points and the combining class logic. The primary loop in `hfsplus_decompose_iter_refill` extracts characters, potentially decomposes them, and then adds them to `it->run`.

The core logic revolves around these key points: if the initial character decomposes to several codepoints, those are added in sequence to the run, until a base character that is not a combining class. The loop breaks when a "base" character is encountered. But the real problem comes if, for instance, a character `c` decomposes to multiple units *and* a subsequent character is a "base" character. It correctly adds the first part of the decomposed character, but the iteration continues with the next source character without advancing the source pointer, `it->astr`. It's possible that decomposed sequences get "truncated".

Then, I started tracing scenarios with combining marks, and how they reorder. The canonical reordering seems to work correctly: combining marks are moved to the correct position (after the base character) based on their combining class, which is good. But this is happening *within* the `it->run` buffer, which is filled up at each call to `refill`. Then, I considered the scenario where the very *first* character is a combining mark. The logic *correctly* reorders the combining marks, too! Good.

The next thing I noticed is how the iteration progresses, especially when handling sequences of single characters. If the input is just single "base" characters like 'a', 'b', 'c', the refill function correctly breaks the loop after the first character is added to the run buffer. And the iteration goes to the next character in subsequent calls to the `next` function.

Now, I'm concerned about the `hfsplus_fixup_legacy_sequences`. This table seems to hold special fixups for certain character sequences to handle legacy issues. My main concern is, how does this fixup interact when a "fixable" sequence is split across calls to `refill`? This is a question because `refill` returns data and updates state. My plan now is to look at some entries in the fixup table and verify their combining class. This requires an understanding of how these special character sequences are handled.



48/2 2026/09/21 03:57 tool grepper
0m Args:
{
  "Expression": "0x0e[34]",
  "PathPrefix": "fs/hfsplus/tables.c"
}

Results:
{
  "Output": "fs/hfsplus/tables.c=411=u16 hfsplus_decompose_table[] = {\n--\nfs/hfsplus/tables.c-606-\t0x0000, 0x0000, 0x0000, 0x0420, 0x0000, 0x0000, 0x0000, 0x0000,\nfs/hfsplus/tables.c:607:\t/* char values 0x0e3_ */\nfs/hfsplus/tables.c-608-\t0x0000, 0x0000, 0x0000, 0x2b76, 0x0000, 0x0000, 0x0000, 0x0000,\n--\nfs/hfsplus/tables.c-888-\t0x0cc6, 0x0cd6, 0x0cc6, 0x0cc2, 0x0cc6, 0x0cc2, 0x0cd5, 0x0d46,\nfs/hfsplus/tables.c:889:\t0x0d3e, 0x0d47, 0x0d3e, 0x0d46, 0x0d57, 0x0e4d, 0x0e32, 0x0ecd,\nfs/hfsplus/tables.c-890-\t0x0eb2, 0x0f42, 0x0fb7, 0x0f4c, 0x0fb7, 0x0f51, 0x0fb7, 0x0f56,\n--\nfs/hfsplus/tables.c=1072=u16 hfsplus_compose_table[] = {\n--\nfs/hfsplus/tables.c-1086-\t0x0c56, 0x05a6,  0x0cc2, 0x05aa,  0x0cd5, 0x05ae,  0x0cd6, 0x05b4,\nfs/hfsplus/tables.c:1087:\t0x0d3e, 0x05b8,  0x0d57, 0x05be,  0x0e32, 0x05c2,  0x0eb2, 0x05c6,\nfs/hfsplus/tables.c-1088-\t0x0f71, 0x05ca,  0x0f80, 0x05d2,  0x0fb5, 0x05d8,  0x0fb7, 0x05de,\n--\nfs/hfsplus/tables.c-1334-\t0x0000, 0x0001,  0x0d46, 0x0cc8,\nfs/hfsplus/tables.c:1335:\t/* 0x0e32 */\nfs/hfsplus/tables.c:1336:\t0x0000, 0x0001,  0x0e4d, 0x0cca,\nfs/hfsplus/tables.c-1337-\t/* 0x0eb2 */\n--\nfs/hfsplus/tables.c-2139-\t/* 0x03b9 0x0313 */\nfs/hfsplus/tables.c:2140:\t0x1f30, 0x0003,  0x0300, 0x0e30,  0x0301, 0x0e32,  0x0342, 0x0e34,\nfs/hfsplus/tables.c-2141-\t/* 0x03bf 0x0313 */\nfs/hfsplus/tables.c:2142:\t0x1f40, 0x0002,  0x0300, 0x0e36,  0x0301, 0x0e38,\nfs/hfsplus/tables.c-2143-\t/* 0x03c1 0x0313 */\n--\nfs/hfsplus/tables.c-2145-\t/* 0x03c5 0x0313 */\nfs/hfsplus/tables.c:2146:\t0x1f50, 0x0003,  0x0300, 0x0e3a,  0x0301, 0x0e3c,  0x0342, 0x0e3e,\nfs/hfsplus/tables.c-2147-\t/* 0x03c9 0x0313 */\nfs/hfsplus/tables.c:2148:\t0x1f60, 0x0003,  0x0300, 0x0e40,  0x0301, 0x0e42,  0x0342, 0x0e44,\nfs/hfsplus/tables.c-2149-\t/* 0x0391 0x0314 */\nfs/hfsplus/tables.c:2150:\t0x1f09, 0x0003,  0x0300, 0x0e46,  0x0301, 0x0e48,  0x0342, 0x0e4a,\nfs/hfsplus/tables.c-2151-\t/* 0x0395 0x0314 */\nfs/hfsplus/tables.c:2152:\t0x1f19, 0x0002,  0x0300, 0x0e4c,  0x0301, 0x0e4e,\nfs/hfsplus/tables.c-2153-\t/* 0x0397 0x0314 */\n--\nfs/hfsplus/tables.c-2589-\t0x0d4c, 0x0000,\nfs/hfsplus/tables.c:2590:\t/* 0x0e4d 0x0e32 */\nfs/hfsplus/tables.c:2591:\t0x0e33, 0x0000,\nfs/hfsplus/tables.c-2592-\t/* 0x0ecd 0x0eb2 */\n--\nfs/hfsplus/tables.c=3264=struct hfsplus_ccc_range hfsplus_ccc_table[] = {\n--\nfs/hfsplus/tables.c-3424-\t{ 0x0dca, 0x0dca,   9 },\nfs/hfsplus/tables.c:3425:\t{ 0x0e38, 0x0e39, 103 },\nfs/hfsplus/tables.c:3426:\t{ 0x0e3a, 0x0e3a,   9 },\nfs/hfsplus/tables.c:3427:\t{ 0x0e48, 0x0e4b, 107 },\nfs/hfsplus/tables.c-3428-\t{ 0x0eb8, 0x0eb9, 118 },\n--\nfs/hfsplus/tables.c=3617=struct hfsplus_legacy_seq_fixup hfsplus_legacy_seq_fixups[] = {\n--\nfs/hfsplus/tables.c-3638-\t{ 2, { 0x0b2f, 0x0b3c }, 1, { 0x0b5f } },\nfs/hfsplus/tables.c:3639:\t{ 2, { 0x0e4d, 0x0e32 }, 1, { 0x0e33 } },\nfs/hfsplus/tables.c-3640-\t{ 2, { 0x0ecd, 0x0eb2 }, 1, { 0x0eb3 } },\n"
}

49/2 2026/09/21 03:57 llm patch-evaluator-compressor
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Reply:
### 1. Approaches Tried and Their Results

1. **Analyzed Git Patch and Scope**:
   - Inspected HEAD commit `9b05d1884d74d63b2810e5bb43da4d00ab799a9c`: "syz-cluster: applied patch under review".
   - Touched files:
     - `fs/hfsplus/hfsplus_fs.h`
     - `fs/hfsplus/tables.c`
     - `fs/hfsplus/unicode.c`
     - `fs/hfsplus/unicode.h` (new header)
     - `fs/hfsplus/unicode_test.c`
   - Purpose of patch: Adds Unicode Canonical Combining Class (CCC) table (`hfsplus_ccc_table`), legacy decomposition table (`hfsplus_legacy_decomp_table`), sequence fixup table (`hfsplus_legacy_seq_fixups`), and applies the Unicode Canonical Ordering Algorithm and legacy fixups in HFS+ filename decomposition, hashing, and comparison (`hfsplus_canonical_reorder`, `hfsplus_fixup_legacy_sequences`, `hfsplus_decompose_str`, `hfsplus_decompose_iter_*`, `hfsplus_hash_dentry`, `hfsplus_compare_dentry`).

2. **Kconfig and Build System Inspection**:
   - Inspected `fs/hfsplus/Kconfig`.
   - `CONFIG_HFSPLUS_FS`:
     - Depends on: `BLOCK`
     - Selects: `BUFFER_HEAD`, `NLS`, `NLS_UTF8`, `LEGACY_DIRECT_IO`
   - `CONFIG_HFSPLUS_KUNIT_TEST`:
     - Depends on: `HFSPLUS_FS && KUNIT`
   - Requisite config for the core code is `HFSPLUS_FS` (and dependency `BLOCK`).

3. **Call-Chain and Usage Tracing**:
   - `hfsplus_hash_dentry` and `hfsplus_compare_dentry` are registered in `hfsplus_dentry_operations` (`inode.c`).
   - `hfsplus_asc2uni` is invoked in:
     - `hfsplus_cat_build_key` (catalog key creation)
     - `hfsplus_fill_cat_thread` (catalog thread record creation)
     - `hfsplus_attr_build_key` (extended attribute key creation)
   - These are reachable during standard filesystem operations (lookup, create, mkdir, setxattr, etc.) on mounted HFS+ filesystems (e.g. via loop device or syzkaller mount).

4. **Detailed Code Audits**:
   - Examined `hfsplus_fixup_legacy_sequences` in `fs/hfsplus/tables.c`:
     - Checked for infinite loops: replacements have `repl_len <= match_len` in all entries. Replacements do not trigger successive matches resulting in cycles.
   - Examined `hfsplus_decompose_iter_refill` and iterators in `fs/hfsplus/unicode.c`:
     - Discovered potential behavioral mismatch:
       - `hfsplus_decompose_str` (used by `hfsplus_asc2uni`) buffers and canonical-reorders the *entire* decomposed string in memory (`buf[HFSPLUS_MAX_STRLEN]`, up to 255 code units), then runs sequence fixups.
       - `hfsplus_decompose_iter_refill` (used by `hfsplus_hash_dentry` and `hfsplus_compare_dentry`) reorders in chunks bounded by `HFSPLUS_CCC_RUN_MAX` (32 code units). If consecutive combining marks exceed 32, sorting across the boundary differs from `hfsplus_asc2uni`.
   - Traced `HFSPLUS_ATTR_MAX_STRLEN` and attribute key manipulation to verify buffer bounds when `hfsplus_asc2uni` is called with max lengths other than `HFSPLUS_MAX_STRLEN`.
     - In `hfsplus_asc2uni`:
       ```c
       u16 buf[HFSPLUS_MAX_STRLEN];
       if (max_unistr_len > HFSPLUS_MAX_STRLEN)
           max_unistr_len = HFSPLUS_MAX_STRLEN;
       outlen = hfsplus_decompose_str(sb, astr, len, max_unistr_len, ...);
       ```
       Buffer sizing is safe from stack overflow since `buf` is `HFSPLUS_MAX_STRLEN`.

---

### 2. Current Hypotheses and Lines of Investigation

- **WorthFuzzing Decision**:
  - Code touches reachable core filesystem logic (`fs/hfsplus/`): dentry operations (`d_hash`, `d_compare`), catalog key construction (`hfsplus_asc2uni`), and character decomposition algorithms.
  - HFS+ filesystems are fully supported and can be mounted via disk images or loop devices inside standard QEMU/KVM VMs in syzkaller.
  - Major logic modifications to string parsing, buffer scanning/replacements (`memmove`/`memcpy` in `hfsplus_fixup_legacy_sequences`), sorting (`hfsplus_canonical_reorder`), and iterator lookaheads (`hfsplus_decompose_iter_*`).
  - Conclusion: `WorthFuzzing=true`.

- **FocusSymbols Candidate List**:
  - `hfsplus_asc2uni`
  - `hfsplus_hash_dentry`
  - `hfsplus_compare_dentry`
  - `hfsplus_combining_class`
  - `hfsplus_legacy_decompose`
  - `hfsplus_fixup_legacy_sequences`
  - (Note: `hfsplus_canonical_reorder`, `hfsplus_decompose_str`, `hfsplus_decompose_iter_*` are static; external entry points and non-static helpers in tables.c are the primary exported/global symbols).

- **EnableConfigs**:
  - `HFSPLUS_FS`
  - `BLOCK` (dependency of `HFSPLUS_FS`)

---

### 3. Critical Code Snippets, Structs, and Paths

- **`fs/hfsplus/tables.c`**:
  ```c
  u8 hfsplus_combining_class(u16 c);
  const u16 *hfsplus_legacy_decompose(u16 uc, int *size);
  void hfsplus_fixup_legacy_sequences(u16 *buf, int *len);
  ```

- **`fs/hfsplus/unicode.c`**:
  ```c
  int hfsplus_asc2uni(struct super_block *sb,
                      struct hfsplus_unistr *ustr, int max_unistr_len,
                      const char *astr, int len, int name_type);

  int hfsplus_hash_dentry(const struct dentry *dentry, struct qstr *str);

  int hfsplus_compare_dentry(const struct dentry *dentry,
                             unsigned int len, const char *str,
                             const struct qstr *name);
  ```

- **`fs/hfsplus/unicode.h`**:
  - `struct hfsplus_ccc_range`
  - `struct hfsplus_legacy_decomp`
  - `struct hfsplus_legacy_seq_fixup`

- **Key Dentry Hook**:
  - `fs/hfsplus/inode.c:220`:
    ```c
    const struct dentry_operations hfsplus_dentry_operations = {
        .d_hash       = hfsplus_hash_dentry,
        .d_compare    = hfsplus_compare_dentry,
    };
    ```

---

### 4. Watch Out for Reasoning Loops & Repetitive Tool Calls

- Searching for `struct hfsplus_attr_key` in `fs/hfsplus` was called twice consecutively. Avoid re-querying `struct hfsplus_attr_key` as it is defined in `fs/hfsplus/hfsplus_raw.h` and is irrelevant to whether this patch warrants fuzzing.
- The analysis of reachability, configs, and focus symbols is complete. Next step is calling `set-results` with the final decision and formatting the final report.

Tokens:
							input: 65295
							output: 1930
							thoughts: 0
						

50/2 2026/09/21 03:57 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 46568
							output: 219
							thoughts: 865
						

Thoughts:
**Setting Up Fuzzing for the HFS+ Filesystem Patch**

Okay, let's break this down. First, we need to determine if this patch is even *worth* fuzzing. Given the changes, the answer is a resounding yes. We're touching HFS+ filesystem string parsing, decomposition, reordering, and legacy sequence lookups. This affects core directory entry lookup, comparison, and hashing algorithms – `hfsplus_hash_dentry`, `hfsplus_compare_dentry`, name conversion (`hfsplus_asc2uni`), and we've got new table searches and array manipulations (`hfsplus_fixup_legacy_sequences`, `hfsplus_combining_class`, `hfsplus_legacy_decompose`).  The beauty is that HFS+ is easily mounted within QEMU VMs using loopback devices, and syzkaller can readily exercise all this functionality through normal filesystem operations like creating, looking up, and getting file metadata.  So, `WorthFuzzing = true`. No question about it.

For the `Reasoning`, we need to be clear and concise. This patch messes with Unicode decomposition, canonical reordering, and legacy fixup logic within the HFS+ filesystem code, specifically in the `fs/hfsplus` directory.  These functions are crucial for the `d_hash`, `d_compare`, and catalog/extended attribute key generation via `hfsplus_asc2uni`. HFS+ is accessible in virtual environments, so we can use standard syscalls to drive the code changes.  The changes introduce new sorting loops, table lookups, and buffer modifications (using `memmove`/`memcpy` in `hfsplus_fixup_legacy_sequences`).  This makes it highly susceptible to boundary issues, infinite loops, memory corruption, and subtle semantic discrepancies, making fuzzing essential.

Next, the `EnableConfigs` are straightforward: `HFSPLUS_FS` and `BLOCK`. These are prerequisites for having HFS+ and block device support active, which is essential to reaching the code.

Now for the *crucial* part: `FocusSymbols`. We need to identify specific kernel functions that this fuzzing should focus on. We'll be using symbols that are not ubiquitous across the kernel, but are core to the new or modified logic.  This includes: `hfsplus_asc2uni`, `hfsplus_hash_dentry`, `hfsplus_compare_dentry`, `hfsplus_combining_class`, `hfsplus_legacy_decompose`, and `hfsplus_fixup_legacy_sequences`.

Alright, double-check on those symbols... all six are *non-static*, so they're visible and accessible. I checked. The patch directly modifies or introduces these specific functions, making them perfect targets.  I also looked at static functions like `hfsplus_canonical_reorder` or decomposition iterations, but since they're static and could be inlined, focusing on the non-static functions is the correct approach for targeted fuzzing. It follows the recommendation.

Okay, that's everything. Time to call `set-results`.



51/2 2026/09/21 03:57 tool set-results
0m Args:
{
  "EnableConfigs": [
    "HFSPLUS_FS",
    "BLOCK"
  ],
  "FocusSymbols": [
    "hfsplus_asc2uni",
    "hfsplus_hash_dentry",
    "hfsplus_compare_dentry",
    "hfsplus_combining_class",
    "hfsplus_legacy_decompose",
    "hfsplus_fixup_legacy_sequences"
  ],
  "Reasoning": "The patch modifies HFS+ Unicode name handling, introducing canonical combining class (CCC) reordering, legacy decomposition lookups, and in-place buffer fixups. These functions are directly executed during dentry hashing (d_hash), dentry comparison (d_compare), and catalog/xattr key encoding (hfsplus_asc2uni) when accessing an HFS+ filesystem mounted in standard virtual environments via loop/block devices. Fuzzing is warranted to test buffer manipulations, table searching, reordering loops, and string canonicalization consistency.",
  "WorthFuzzing": true
}

Results:
{
  "EnableConfigs": [
    "HFSPLUS_FS",
    "BLOCK"
  ],
  "FocusSymbols": [
    "hfsplus_asc2uni",
    "hfsplus_hash_dentry",
    "hfsplus_compare_dentry",
    "hfsplus_combining_class",
    "hfsplus_legacy_decompose",
    "hfsplus_fixup_legacy_sequences"
  ],
  "Reasoning": "The patch modifies HFS+ Unicode name handling, introducing canonical combining class (CCC) reordering, legacy decomposition lookups, and in-place buffer fixups. These functions are directly executed during dentry hashing (d_hash), dentry comparison (d_compare), and catalog/xattr key encoding (hfsplus_asc2uni) when accessing an HFS+ filesystem mounted in standard virtual environments via loop/block devices. Fuzzing is warranted to test buffer manipulations, table searching, reordering loops, and string canonicalization consistency.",
  "WorthFuzzing": true
}

52/1 2026/09/21 03:57 action If
1m Args:
{
  "WorthFuzzing": true
}

Results:
null

53/2 2026/09/21 03:57 agent kmsan-evaluator
1m Model:
core

Args:
null

Results:
{
  "KMSANReasoning": "The patch adds Unicode canonical combining class reordering and legacy sequence fixups to HFS+ filename processing (in hfsplus_asc2uni, hfsplus_hash_dentry, and hfsplus_compare_dentry). \n\nEvaluating KMSAN applicability:\n1. No structures are copied to user space (no copy_to_user, put_user, netlink, or ioctl info-leaks).\n2. Stack buffers introduced (e.g., `buf[HFSPLUS_MAX_STRLEN]` in `hfsplus_asc2uni` and `run[HFSPLUS_CCC_RUN_MAX]` in `struct hfsplus_decompose_iter`) have strictly bounded lengths tracked by `outlen` and `run_len`. In `hfsplus_decompose_str`, `hfsplus_canonical_reorder`, and `hfsplus_decompose_iter_refill`, only the exact elements that have been written are ever read or manipulated.\n3. The catalog key lengths (`ustr-\u003elength`) accurately represent the number of initialized code units written, preventing surrounding code from reading past initialized bytes.\n4. Any potential issues with array indexing, lookups, or `memmove` boundary conditions in sequence substitution are spatial memory safety bugs (out-of-bounds reads/writes), which are directly detected by standard KASAN.\n\nTherefore, the patch does not introduce or expose uninitialized memory risks, and a dedicated KMSAN fuzzing session is not warranted.",
  "NeedsKMSAN": false
}

Instruction:
You are an expert Linux kernel security engineer specializing in kernel memory
error detectors (KASAN and KMSAN). Your job is to review the provided patch series and
determine if the code changes justify spawning a dedicated KMSAN (KernelMemorySanitizer)
fuzzing session in addition to standard KASAN fuzzing.

CRITICAL DISTINCTION BETWEEN KASAN AND KMSAN:
- Standard KASAN kernel builds (upstream-apparmor-kasan.config) already enable
  a comprehensive suite of debugging tools and sanitizers, including KASAN
  (out-of-bounds accesses, use-after-free, double free, invalid free), LOCKDEP
  (locking bugs and deadlocks), UB-sanitizers, and memory corruption checks.
- KMSAN (KernelMemorySanitizer) detects reads of UNINITIALIZED memory (stack, heap,
  or page allocations) and kernel-to-user memory info-leaks.

Rule: THERE IS NO SENSE IN RUNNING A KMSAN SESSION IF A BUG CAN BE CAUGHT BY KASAN,
LOCKDEP, OR OTHER STANDARD BUG DETECTORS.
A dedicated KMSAN fuzzing session incurs significant resource costs. You must ONLY
set NeedsKMSAN=true if the code changes introduce or expose UNINITIALIZED MEMORY risks
that are detected ONLY by KMSAN.

Look holistically at the patch series and surrounding code. Even if no direct
uninitialized field accesses or new buffer allocations are added in the diff itself,
a patch may alter control flow, bounds checking, or data length calculations in ways
that change how the rest of the code operates on existing buffers (e.g. allowing
uninitialized stack/heap memory to be read, copied to user space, or used in control
flow). Do not hesitate to use your code access tools to inspect the surrounding code,
called functions, and callers.

Set NeedsKMSAN=true ONLY IF the patch introduces or modifies:
1. Kernel structures sent to user space (via copy_to_user, put_user, netlink skb
   attributes, ioctl output arguments, socket options, or BPF buffers) where fields
   or structure padding might not be fully initialized/zeroed.
2. Conditional logic or branching that depends on potentially uninitialized variables
   or struct fields.
3. Allocation or initialization of complex data structures where uninitialized fields
   could be read later in reachable code paths.
4. Bounds checks, lengths, or logic in a way that allows surrounding code to access
   uninitialized bytes of existing buffers.

Set NeedsKMSAN=false IF:
- The code changes primarily risk out-of-bounds access, array overflows, NULL pointer
  dereferences, locking deadlocks, or use-after-free bugs (these are already caught
  by KASAN, LOCKDEP, or standard bug detectors).
- All stack/heap structures touched or introduced by the patch are fully zeroed
  or initialized (e.g. using = {0}, memset, kzalloc) before being read or copied.
- The patch does not introduce any risk of uninitialized memory usage or info-leaks.

Use your code access tools to inspect the surrounding code if necessary, then provide
detailed KMSANReasoning contrasting KASAN vs KMSAN applicability for this patch.
Prefer calling several tools at the same time to save round-trips.


Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.

Prompt:
Target architecture: amd64

For your convenience, here is the diff of the changes:
commit 9b05d1884d74d63b2810e5bb43da4d00ab799a9c
Author: syz-cluster <triage@syzkaller.com>
Date:   Mon Sep 21 03:51:44 2026 +0000

    syz-cluster: applied patch under review

diff --git a/fs/hfsplus/hfsplus_fs.h b/fs/hfsplus/hfsplus_fs.h
index 1e5b58e6a13fc..916e6552e3f0b 100644
--- a/fs/hfsplus/hfsplus_fs.h
+++ b/fs/hfsplus/hfsplus_fs.h
@@ -17,6 +17,7 @@
 #include <linux/blkdev.h>
 #include <linux/fs_context.h>
 #include "hfsplus_raw.h"
+#include "unicode.h"
 
 /* Runtime config options */
 #define HFSPLUS_DEF_CR_TYPE    0x3F3F3F3F  /* '????' */
@@ -486,11 +487,6 @@ void hfsplus_mark_mdb_dirty(struct super_block *sb);
 void hfsplus_prepare_volume_header_for_commit(struct hfsplus_vh *vhdr);
 int hfsplus_commit_superblock(struct super_block *sb);
 
-/* tables.c */
-extern u16 hfsplus_case_fold_table[];
-extern u16 hfsplus_decompose_table[];
-extern u16 hfsplus_compose_table[];
-
 /* unicode.c */
 int hfsplus_strcasecmp(const struct hfsplus_unistr *s1,
 		       const struct hfsplus_unistr *s2);
diff --git a/fs/hfsplus/tables.c b/fs/hfsplus/tables.c
index a5fb8ee7d019d..2101201ab973f 100644
--- a/fs/hfsplus/tables.c
+++ b/fs/hfsplus/tables.c
@@ -3244,3 +3244,499 @@ u16 hfsplus_compose_table[] = {
 	/* 0x0342 0x0314 0x03c9 0x0345 */
 	0x1fa7, 0x0000,
 };
+
+/*
+ * Unicode canonical combining class (ccc) table, restricted to the Basic
+ * Multilingual Plane: HFS+ names are stored as UTF-16 and this kernel's
+ * wchar_t (see MAX_WCHAR_T in include/linux/nls.h) tops out at U+FFFF, so
+ * no HFS+ catalog name can contain a code point above the BMP anyway.
+ *
+ * Generated from the Unicode Character Database, version 12.1.0
+ * (https://www.unicode.org/Public/12.1.0/ucd/extracted/DerivedCombiningClass.txt),
+ * the same UCD version fs/unicode/README.utf8data documents. Class 0
+ * ("Not_Reordered") is the default for every code point not listed here
+ * and needs no entry.
+ *
+ * Used by hfsplus_canonical_reorder() to apply the Unicode Canonical
+ * Ordering Algorithm to a decomposed name, matching what macOS's own
+ * fsck_hfs (FixDecomps()) requires of a stored catalog name.
+ */
+struct hfsplus_ccc_range hfsplus_ccc_table[] = {
+	{ 0x0300, 0x0314, 230 },
+	{ 0x0315, 0x0315, 232 },
+	{ 0x0316, 0x0319, 220 },
+	{ 0x031a, 0x031a, 232 },
+	{ 0x031b, 0x031b, 216 },
+	{ 0x031c, 0x0320, 220 },
+	{ 0x0321, 0x0322, 202 },
+	{ 0x0323, 0x0326, 220 },
+	{ 0x0327, 0x0328, 202 },
+	{ 0x0329, 0x0333, 220 },
+	{ 0x0334, 0x0338,   1 },
+	{ 0x0339, 0x033c, 220 },
+	{ 0x033d, 0x0344, 230 },
+	{ 0x0345, 0x0345, 240 },
+	{ 0x0346, 0x0346, 230 },
+	{ 0x0347, 0x0349, 220 },
+	{ 0x034a, 0x034c, 230 },
+	{ 0x034d, 0x034e, 220 },
+	{ 0x0350, 0x0352, 230 },
+	{ 0x0353, 0x0356, 220 },
+	{ 0x0357, 0x0357, 230 },
+	{ 0x0358, 0x0358, 232 },
+	{ 0x0359, 0x035a, 220 },
+	{ 0x035b, 0x035b, 230 },
+	{ 0x035c, 0x035c, 233 },
+	{ 0x035d, 0x035e, 234 },
+	{ 0x035f, 0x035f, 233 },
+	{ 0x0360, 0x0361, 234 },
+	{ 0x0362, 0x0362, 233 },
+	{ 0x0363, 0x036f, 230 },
+	{ 0x0483, 0x0487, 230 },
+	{ 0x0591, 0x0591, 220 },
+	{ 0x0592, 0x0595, 230 },
+	{ 0x0596, 0x0596, 220 },
+	{ 0x0597, 0x0599, 230 },
+	{ 0x059a, 0x059a, 222 },
+	{ 0x059b, 0x059b, 220 },
+	{ 0x059c, 0x05a1, 230 },
+	{ 0x05a2, 0x05a7, 220 },
+	{ 0x05a8, 0x05a9, 230 },
+	{ 0x05aa, 0x05aa, 220 },
+	{ 0x05ab, 0x05ac, 230 },
+	{ 0x05ad, 0x05ad, 222 },
+	{ 0x05ae, 0x05ae, 228 },
+	{ 0x05af, 0x05af, 230 },
+	{ 0x05b0, 0x05b0,  10 },
+	{ 0x05b1, 0x05b1,  11 },
+	{ 0x05b2, 0x05b2,  12 },
+	{ 0x05b3, 0x05b3,  13 },
+	{ 0x05b4, 0x05b4,  14 },
+	{ 0x05b5, 0x05b5,  15 },
+	{ 0x05b6, 0x05b6,  16 },
+	{ 0x05b7, 0x05b7,  17 },
+	{ 0x05b8, 0x05b8,  18 },
+	{ 0x05b9, 0x05ba,  19 },
+	{ 0x05bb, 0x05bb,  20 },
+	{ 0x05bc, 0x05bc,  21 },
+	{ 0x05bd, 0x05bd,  22 },
+	{ 0x05bf, 0x05bf,  23 },
+	{ 0x05c1, 0x05c1,  24 },
+	{ 0x05c2, 0x05c2,  25 },
+	{ 0x05c4, 0x05c4, 230 },
+	{ 0x05c5, 0x05c5, 220 },
+	{ 0x05c7, 0x05c7,  18 },
+	{ 0x0610, 0x0617, 230 },
+	{ 0x0618, 0x0618,  30 },
+	{ 0x0619, 0x0619,  31 },
+	{ 0x061a, 0x061a,  32 },
+	{ 0x064b, 0x064b,  27 },
+	{ 0x064c, 0x064c,  28 },
+	{ 0x064d, 0x064d,  29 },
+	{ 0x064e, 0x064e,  30 },
+	{ 0x064f, 0x064f,  31 },
+	{ 0x0650, 0x0650,  32 },
+	{ 0x0651, 0x0651,  33 },
+	{ 0x0652, 0x0652,  34 },
+	{ 0x0653, 0x0654, 230 },
+	{ 0x0655, 0x0656, 220 },
+	{ 0x0657, 0x065b, 230 },
+	{ 0x065c, 0x065c, 220 },
+	{ 0x065d, 0x065e, 230 },
+	{ 0x065f, 0x065f, 220 },
+	{ 0x0670, 0x0670,  35 },
+	{ 0x06d6, 0x06dc, 230 },
+	{ 0x06df, 0x06e2, 230 },
+	{ 0x06e3, 0x06e3, 220 },
+	{ 0x06e4, 0x06e4, 230 },
+	{ 0x06e7, 0x06e8, 230 },
+	{ 0x06ea, 0x06ea, 220 },
+	{ 0x06eb, 0x06ec, 230 },
+	{ 0x06ed, 0x06ed, 220 },
+	{ 0x0711, 0x0711,  36 },
+	{ 0x0730, 0x0730, 230 },
+	{ 0x0731, 0x0731, 220 },
+	{ 0x0732, 0x0733, 230 },
+	{ 0x0734, 0x0734, 220 },
+	{ 0x0735, 0x0736, 230 },
+	{ 0x0737, 0x0739, 220 },
+	{ 0x073a, 0x073a, 230 },
+	{ 0x073b, 0x073c, 220 },
+	{ 0x073d, 0x073d, 230 },
+	{ 0x073e, 0x073e, 220 },
+	{ 0x073f, 0x0741, 230 },
+	{ 0x0742, 0x0742, 220 },
+	{ 0x0743, 0x0743, 230 },
+	{ 0x0744, 0x0744, 220 },
+	{ 0x0745, 0x0745, 230 },
+	{ 0x0746, 0x0746, 220 },
+	{ 0x0747, 0x0747, 230 },
+	{ 0x0748, 0x0748, 220 },
+	{ 0x0749, 0x074a, 230 },
+	{ 0x07eb, 0x07f1, 230 },
+	{ 0x07f2, 0x07f2, 220 },
+	{ 0x07f3, 0x07f3, 230 },
+	{ 0x07fd, 0x07fd, 220 },
+	{ 0x0816, 0x0819, 230 },
+	{ 0x081b, 0x0823, 230 },
+	{ 0x0825, 0x0827, 230 },
+	{ 0x0829, 0x082d, 230 },
+	{ 0x0859, 0x085b, 220 },
+	{ 0x08d3, 0x08d3, 220 },
+	{ 0x08d4, 0x08e1, 230 },
+	{ 0x08e3, 0x08e3, 220 },
+	{ 0x08e4, 0x08e5, 230 },
+	{ 0x08e6, 0x08e6, 220 },
+	{ 0x08e7, 0x08e8, 230 },
+	{ 0x08e9, 0x08e9, 220 },
+	{ 0x08ea, 0x08ec, 230 },
+	{ 0x08ed, 0x08ef, 220 },
+	{ 0x08f0, 0x08f0,  27 },
+	{ 0x08f1, 0x08f1,  28 },
+	{ 0x08f2, 0x08f2,  29 },
+	{ 0x08f3, 0x08f5, 230 },
+	{ 0x08f6, 0x08f6, 220 },
+	{ 0x08f7, 0x08f8, 230 },
+	{ 0x08f9, 0x08fa, 220 },
+	{ 0x08fb, 0x08ff, 230 },
+	{ 0x093c, 0x093c,   7 },
+	{ 0x094d, 0x094d,   9 },
+	{ 0x0951, 0x0951, 230 },
+	{ 0x0952, 0x0952, 220 },
+	{ 0x0953, 0x0954, 230 },
+	{ 0x09bc, 0x09bc,   7 },
+	{ 0x09cd, 0x09cd,   9 },
+	{ 0x09fe, 0x09fe, 230 },
+	{ 0x0a3c, 0x0a3c,   7 },
+	{ 0x0a4d, 0x0a4d,   9 },
+	{ 0x0abc, 0x0abc,   7 },
+	{ 0x0acd, 0x0acd,   9 },
+	{ 0x0b3c, 0x0b3c,   7 },
+	{ 0x0b4d, 0x0b4d,   9 },
+	{ 0x0bcd, 0x0bcd,   9 },
+	{ 0x0c4d, 0x0c4d,   9 },
+	{ 0x0c55, 0x0c55,  84 },
+	{ 0x0c56, 0x0c56,  91 },
+	{ 0x0cbc, 0x0cbc,   7 },
+	{ 0x0ccd, 0x0ccd,   9 },
+	{ 0x0d3b, 0x0d3c,   9 },
+	{ 0x0d4d, 0x0d4d,   9 },
+	{ 0x0dca, 0x0dca,   9 },
+	{ 0x0e38, 0x0e39, 103 },
+	{ 0x0e3a, 0x0e3a,   9 },
+	{ 0x0e48, 0x0e4b, 107 },
+	{ 0x0eb8, 0x0eb9, 118 },
+	{ 0x0eba, 0x0eba,   9 },
+	{ 0x0ec8, 0x0ecb, 122 },
+	{ 0x0f18, 0x0f19, 220 },
+	{ 0x0f35, 0x0f35, 220 },
+	{ 0x0f37, 0x0f37, 220 },
+	{ 0x0f39, 0x0f39, 216 },
+	{ 0x0f71, 0x0f71, 129 },
+	{ 0x0f72, 0x0f72, 130 },
+	{ 0x0f74, 0x0f74, 132 },
+	{ 0x0f7a, 0x0f7d, 130 },
+	{ 0x0f80, 0x0f80, 130 },
+	{ 0x0f82, 0x0f83, 230 },
+	{ 0x0f84, 0x0f84,   9 },
+	{ 0x0f86, 0x0f87, 230 },
+	{ 0x0fc6, 0x0fc6, 220 },
+	{ 0x1037, 0x1037,   7 },
+	{ 0x1039, 0x103a,   9 },
+	{ 0x108d, 0x108d, 220 },
+	{ 0x135d, 0x135f, 230 },
+	{ 0x1714, 0x1714,   9 },
+	{ 0x1734, 0x1734,   9 },
+	{ 0x17d2, 0x17d2,   9 },
+	{ 0x17dd, 0x17dd, 230 },
+	{ 0x18a9, 0x18a9, 228 },
+	{ 0x1939, 0x1939, 222 },
+	{ 0x193a, 0x193a, 230 },
+	{ 0x193b, 0x193b, 220 },
+	{ 0x1a17, 0x1a17, 230 },
+	{ 0x1a18, 0x1a18, 220 },
+	{ 0x1a60, 0x1a60,   9 },
+	{ 0x1a75, 0x1a7c, 230 },
+	{ 0x1a7f, 0x1a7f, 220 },
+	{ 0x1ab0, 0x1ab4, 230 },
+	{ 0x1ab5, 0x1aba, 220 },
+	{ 0x1abb, 0x1abc, 230 },
+	{ 0x1abd, 0x1abd, 220 },
+	{ 0x1b34, 0x1b34,   7 },
+	{ 0x1b44, 0x1b44,   9 },
+	{ 0x1b6b, 0x1b6b, 230 },
+	{ 0x1b6c, 0x1b6c, 220 },
+	{ 0x1b6d, 0x1b73, 230 },
+	{ 0x1baa, 0x1baa,   9 },
+	{ 0x1bab, 0x1bab,   9 },
+	{ 0x1be6, 0x1be6,   7 },
+	{ 0x1bf2, 0x1bf3,   9 },
+	{ 0x1c37, 0x1c37,   7 },
+	{ 0x1cd0, 0x1cd2, 230 },
+	{ 0x1cd4, 0x1cd4,   1 },
+	{ 0x1cd5, 0x1cd9, 220 },
+	{ 0x1cda, 0x1cdb, 230 },
+	{ 0x1cdc, 0x1cdf, 220 },
+	{ 0x1ce0, 0x1ce0, 230 },
+	{ 0x1ce2, 0x1ce8,   1 },
+	{ 0x1ced, 0x1ced, 220 },
+	{ 0x1cf4, 0x1cf4, 230 },
+	{ 0x1cf8, 0x1cf9, 230 },
+	{ 0x1dc0, 0x1dc1, 230 },
+	{ 0x1dc2, 0x1dc2, 220 },
+	{ 0x1dc3, 0x1dc9, 230 },
+	{ 0x1dca, 0x1dca, 220 },
+	{ 0x1dcb, 0x1dcc, 230 },
+	{ 0x1dcd, 0x1dcd, 234 },
+	{ 0x1dce, 0x1dce, 214 },
+	{ 0x1dcf, 0x1dcf, 220 },
+	{ 0x1dd0, 0x1dd0, 202 },
+	{ 0x1dd1, 0x1df5, 230 },
+	{ 0x1df6, 0x1df6, 232 },
+	{ 0x1df7, 0x1df8, 228 },
+	{ 0x1df9, 0x1df9, 220 },
+	{ 0x1dfb, 0x1dfb, 230 },
+	{ 0x1dfc, 0x1dfc, 233 },
+	{ 0x1dfd, 0x1dfd, 220 },
+	{ 0x1dfe, 0x1dfe, 230 },
+	{ 0x1dff, 0x1dff, 220 },
+	{ 0x20d0, 0x20d1, 230 },
+	{ 0x20d2, 0x20d3,   1 },
+	{ 0x20d4, 0x20d7, 230 },
+	{ 0x20d8, 0x20da,   1 },
+	{ 0x20db, 0x20dc, 230 },
+	{ 0x20e1, 0x20e1, 230 },
+	{ 0x20e5, 0x20e6,   1 },
+	{ 0x20e7, 0x20e7, 230 },
+	{ 0x20e8, 0x20e8, 220 },
+	{ 0x20e9, 0x20e9, 230 },
+	{ 0x20ea, 0x20eb,   1 },
+	{ 0x20ec, 0x20ef, 220 },
+	{ 0x20f0, 0x20f0, 230 },
+	{ 0x2cef, 0x2cf1, 230 },
+	{ 0x2d7f, 0x2d7f,   9 },
+	{ 0x2de0, 0x2dff, 230 },
+	{ 0x302a, 0x302a, 218 },
+	{ 0x302b, 0x302b, 228 },
+	{ 0x302c, 0x302c, 232 },
+	{ 0x302d, 0x302d, 222 },
+	{ 0x302e, 0x302f, 224 },
+	{ 0x3099, 0x309a,   8 },
+	{ 0xa66f, 0xa66f, 230 },
+	{ 0xa674, 0xa67d, 230 },
+	{ 0xa69e, 0xa69f, 230 },
+	{ 0xa6f0, 0xa6f1, 230 },
+	{ 0xa806, 0xa806,   9 },
+	{ 0xa8c4, 0xa8c4,   9 },
+	{ 0xa8e0, 0xa8f1, 230 },
+	{ 0xa92b, 0xa92d, 220 },
+	{ 0xa953, 0xa953,   9 },
+	{ 0xa9b3, 0xa9b3,   7 },
+	{ 0xa9c0, 0xa9c0,   9 },
+	{ 0xaab0, 0xaab0, 230 },
+	{ 0xaab2, 0xaab3, 230 },
+	{ 0xaab4, 0xaab4, 220 },
+	{ 0xaab7, 0xaab8, 230 },
+	{ 0xaabe, 0xaabf, 230 },
+	{ 0xaac1, 0xaac1, 230 },
+	{ 0xaaf6, 0xaaf6,   9 },
+	{ 0xabed, 0xabed,   9 },
+	{ 0xfb1e, 0xfb1e,  26 },
+	{ 0xfe20, 0xfe26, 230 },
+	{ 0xfe27, 0xfe2d, 220 },
+	{ 0xfe2e, 0xfe2f, 230 },
+};
+
+/*
+ * Some HFS Plus catalog names contain characters whose canonical
+ * decomposition either was not yet defined, or was later corrected, in
+ * the version of Unicode this file's tables above were generated from
+ * (Apple Technote #1150, itself derived from pre-Unicode-3.0/pre-"Jaguar"
+ * (Mac OS X 10.2) data). macOS's own fsck_hfs has carried a permanent
+ * "FixDecomps" fixup for exactly this since 2002 (see
+ * fsck_hfs.tproj/dfalib/CatalogCheck.c and DecompData.h in the hfsprogs /
+ * diskdev_cmds sources) and flags any catalog name it finds still using
+ * the old form as "Illegal name". The two tables and functions below are
+ * a port of that same fixup data, decoded from hfsprogs 540.1's
+ * DecompData.h, so this driver stores names the same way macOS has since
+ * 10.2 rather than the way the original HFS Plus format documentation
+ * described in 2001.
+ */
+
+/* Category A: single code point -> missing canonical decomposition */
+/* 44 entries */
+struct hfsplus_legacy_decomp hfsplus_legacy_decomp_table[] = {
+	{ 0x01f8, 2, { 0x004e, 0x0300 } },
+	{ 0x01f9, 2, { 0x006e, 0x0300 } },
+	{ 0x0218, 2, { 0x0053, 0x0326 } },
+	{ 0x0219, 2, { 0x0073, 0x0326 } },
+	{ 0x021a, 2, { 0x0054, 0x0326 } },
+	{ 0x021b, 2, { 0x0074, 0x0326 } },
+	{ 0x021e, 2, { 0x0048, 0x030c } },
+	{ 0x021f, 2, { 0x0068, 0x030c } },
+	{ 0x0226, 2, { 0x0041, 0x0307 } },
+	{ 0x0227, 2, { 0x0061, 0x0307 } },
+	{ 0x0228, 2, { 0x0045, 0x0327 } },
+	{ 0x0229, 2, { 0x0065, 0x0327 } },
+	{ 0x022a, 3, { 0x004f, 0x0308, 0x0304 } },
+	{ 0x022b, 3, { 0x006f, 0x0308, 0x0304 } },
+	{ 0x022c, 3, { 0x004f, 0x0303, 0x0304 } },
+	{ 0x022d, 3, { 0x006f, 0x0303, 0x0304 } },
+	{ 0x022e, 2, { 0x004f, 0x0307 } },
+	{ 0x022f, 2, { 0x006f, 0x0307 } },
+	{ 0x0230, 3, { 0x004f, 0x0307, 0x0304 } },
+	{ 0x0231, 3, { 0x006f, 0x0307, 0x0304 } },
+	{ 0x0232, 2, { 0x0059, 0x0304 } },
+	{ 0x0233, 2, { 0x0079, 0x0304 } },
+	{ 0x0400, 2, { 0x0415, 0x0300 } },
+	{ 0x040d, 2, { 0x0418, 0x0300 } },
+	{ 0x0450, 2, { 0x0435, 0x0300 } },
+	{ 0x045d, 2, { 0x0438, 0x0300 } },
+	{ 0x04ec, 2, { 0x042d, 0x0308 } },
+	{ 0x04ed, 2, { 0x044d, 0x0308 } },
+	{ 0x0622, 2, { 0x0627, 0x0653 } },
+	{ 0x0623, 2, { 0x0627, 0x0654 } },
+	{ 0x0624, 2, { 0x0648, 0x0654 } },
+	{ 0x0625, 2, { 0x0627, 0x0655 } },
+	{ 0x0626, 2, { 0x064a, 0x0654 } },
+	{ 0x06c0, 2, { 0x06d5, 0x0654 } },
+	{ 0x06c2, 2, { 0x06c1, 0x0654 } },
+	{ 0x06d3, 2, { 0x06d2, 0x0654 } },
+	{ 0x0a33, 2, { 0x0a32, 0x0a3c } },
+	{ 0x0a36, 2, { 0x0a38, 0x0a3c } },
+	{ 0x0dda, 2, { 0x0dd9, 0x0dca } },
+	{ 0x0ddc, 2, { 0x0dd9, 0x0dcf } },
+	{ 0x0ddd, 3, { 0x0dd9, 0x0dcf, 0x0dca } },
+	{ 0x0dde, 2, { 0x0dd9, 0x0ddf } },
+	{ 0x1026, 2, { 0x1025, 0x102e } },
+	{ 0xfb1d, 2, { 0x05d9, 0x05b4 } },
+};
+
+/* Category B: 2-3 code point sequence -> corrected replacement */
+/* 25 entries */
+struct hfsplus_legacy_seq_fixup hfsplus_legacy_seq_fixups[] = {
+	{ 2, { 0x00a8, 0x030d }, 2, { 0x00a8, 0x0301 } },
+	{ 2, { 0x0306, 0x0307 }, 1, { 0x0310 } },
+	{ 2, { 0x0308, 0x030d }, 2, { 0x0308, 0x0301 } },
+	{ 2, { 0x0391, 0x030d }, 2, { 0x0391, 0x0301 } },
+	{ 2, { 0x0395, 0x030d }, 2, { 0x0395, 0x0301 } },
+	{ 2, { 0x0397, 0x030d }, 2, { 0x0397, 0x0301 } },
+	{ 2, { 0x0399, 0x030d }, 2, { 0x0399, 0x0301 } },
+	{ 2, { 0x039f, 0x030d }, 2, { 0x039f, 0x0301 } },
+	{ 2, { 0x03a5, 0x030d }, 2, { 0x03a5, 0x0301 } },
+	{ 2, { 0x03a9, 0x030d }, 2, { 0x03a9, 0x0301 } },
+	{ 2, { 0x03b1, 0x030d }, 2, { 0x03b1, 0x0301 } },
+	{ 2, { 0x03b5, 0x030d }, 2, { 0x03b5, 0x0301 } },
+	{ 2, { 0x03b7, 0x030d }, 2, { 0x03b7, 0x0301 } },
+	{ 2, { 0x03b9, 0x030d }, 2, { 0x03b9, 0x0301 } },
+	{ 2, { 0x03bf, 0x030d }, 2, { 0x03bf, 0x0301 } },
+	{ 2, { 0x03c5, 0x030d }, 2, { 0x03c5, 0x0301 } },
+	{ 2, { 0x03c9, 0x030d }, 2, { 0x03c9, 0x0301 } },
+	{ 2, { 0x03d2, 0x030d }, 2, { 0x03d2, 0x0301 } },
+	{ 2, { 0x09ac, 0x09bc }, 1, { 0x09b0 } },
+	{ 2, { 0x0a21, 0x0a3c }, 1, { 0x0a5c } },
+	{ 2, { 0x0b2f, 0x0b3c }, 1, { 0x0b5f } },
+	{ 2, { 0x0e4d, 0x0e32 }, 1, { 0x0e33 } },
+	{ 2, { 0x0ecd, 0x0eb2 }, 1, { 0x0eb3 } },
+	{ 3, { 0x0fb2, 0x0f80, 0x0f71 }, 1, { 0x0f77 } },
+	{ 3, { 0x0fb3, 0x0f80, 0x0f71 }, 1, { 0x0f79 } },
+};
+
+/*
+ * Look up the Unicode canonical combining class of a BMP code point.
+ * Returns 0 ("Not_Reordered") for any code point not listed in the table,
+ * which includes every ordinary base character.
+ */
+u8 hfsplus_combining_class(u16 c)
+{
+	int lo = 0, hi = ARRAY_SIZE(hfsplus_ccc_table) - 1;
+
+	while (lo <= hi) {
+		int mid = (lo + hi) / 2;
+		const struct hfsplus_ccc_range *r = &hfsplus_ccc_table[mid];
+
+		if (c < r->first)
+			hi = mid - 1;
+		else if (c > r->last)
+			lo = mid + 1;
+		else
+			return r->combining_class;
+	}
+
+	return 0;
+}
+
+/*
+ * Look up the corrected canonical decomposition for a single BMP code
+ * point that Apple Technote #1150's own decomposition table (above)
+ * lacks. Returns NULL (and leaves *size alone) if @uc isn't one of these.
+ */
+const u16 *hfsplus_legacy_decompose(u16 uc, int *size)
+{
+	int lo = 0, hi = ARRAY_SIZE(hfsplus_legacy_decomp_table) - 1;
+
+	while (lo <= hi) {
+		int mid = (lo + hi) / 2;
+		const struct hfsplus_legacy_decomp *e =
+				&hfsplus_legacy_decomp_table[mid];
+
+		if (uc < e->uc)
+			hi = mid - 1;
+		else if (uc > e->uc)
+			lo = mid + 1;
+		else {
+			*size = e->len;
+			return e->repl;
+		}
+	}
+
+	return NULL;
+}
+
+/*
+ * Scan an already decomposed and canonically-reordered code unit buffer
+ * for any of the short legacy sequences above and replace them in place
+ * with their corrected form. @len is updated to the buffer's new length.
+ */
+void hfsplus_fixup_legacy_sequences(u16 *buf, int *len)
+{
+	int i = 0;
+
+	while (i < *len) {
+		unsigned int j;
+		bool matched = false;
+
+		for (j = 0; j < ARRAY_SIZE(hfsplus_legacy_seq_fixups); j++) {
+			struct hfsplus_legacy_seq_fixup *f =
+						&hfsplus_legacy_seq_fixups[j];
+			u16 *src, *dst;
+			size_t copy_len;
+			int k;
+
+			if (i + f->match_len > *len)
+				continue;
+			for (k = 0; k < f->match_len; k++)
+				if (buf[i + k] != f->match[k])
+					break;
+			if (k != f->match_len)
+				continue;
+
+			dst = &buf[i + f->repl_len];
+			src = &buf[i + f->match_len];
+			copy_len = (*len - i - f->match_len) * sizeof(*buf);
+			memmove(dst, src, copy_len);
+
+			dst = &buf[i];
+			src = f->repl;
+			copy_len = f->repl_len * sizeof(*buf);
+			memcpy(dst, src, copy_len);
+
+			*len += f->repl_len - f->match_len;
+			matched = true;
+			break;
+		}
+
+		if (!matched)
+			i++;
+	}
+}
diff --git a/fs/hfsplus/unicode.c b/fs/hfsplus/unicode.c
index 008fec186382b..59b8788a69a9e 100644
--- a/fs/hfsplus/unicode.c
+++ b/fs/hfsplus/unicode.c
@@ -16,6 +16,7 @@
 
 #include "hfsplus_fs.h"
 #include "hfsplus_raw.h"
+#include "unicode.h"
 
 /* Fold the case of a unicode char, given the 16 bit value */
 /* Returns folded char, or 0 if ignorable */
@@ -441,45 +442,264 @@ static u16 *decompose_unichar(wchar_t uc, int *size, u16 *hangul_buffer)
 	*size = hfsplus_try_decompose_hangul(uc, result);
 	if (*size == 0)
 		result = hfsplus_decompose_nonhangul(uc, size);
+	if (!result) {
+		/*
+		 * Not every character with a canonical decomposition is in
+		 * Apple Technote #1150's own table above; a small, fixed
+		 * set was only added to the decomposition standard (or had
+		 * its decomposition corrected) after that table was
+		 * generated. hfsplus_legacy_decompose() covers those.
+		 */
+		const u16 *legacy = hfsplus_legacy_decompose(uc, size);
+
+		if (legacy)
+			result = memcpy(hangul_buffer, legacy,
+					*size * sizeof(*legacy));
+	}
 	return result;
 }
 
-int hfsplus_asc2uni(struct super_block *sb,
-		    struct hfsplus_unistr *ustr, int max_unistr_len,
-		    const char *astr, int len, int name_type)
+/*
+ * Apply the Unicode Canonical Ordering Algorithm to a decomposed name held
+ * as plain host-order code units: within each maximal run of characters
+ * that have a nonzero combining class, stable-sort the run into ascending
+ * combining-class order. A character with combining class 0 always starts
+ * a new run and is never itself reordered.
+ *
+ * hfsplus_decompose_table decomposes each source character on its own; it
+ * says nothing about how the decompositions of two different source
+ * characters should be ordered relative to each other when both produce
+ * combining marks that end up adjacent. Without this pass, such a
+ * sequence can be stored in an order that macOS's own fsck_hfs
+ * (FixDecomps() in CatalogCheck.c) considers illegal, even though every
+ * individual character was decomposed correctly.
+ */
+static void hfsplus_canonical_reorder(u16 *ustr, int len)
 {
-	int size, dsize, decompose;
-	u16 *dstr, outlen = 0;
-	wchar_t c;
-	u16 dhangul[3];
+	int i;
+
+	for (i = 1; i < len; i++) {
+		u8 cls = hfsplus_combining_class(ustr[i]);
+		int j = i;
+
+		if (!cls)
+			continue;
+
+		while (j > 0) {
+			u8 prev_cls = hfsplus_combining_class(ustr[j - 1]);
+			u16 tmp;
+
+			if (!prev_cls || prev_cls <= cls)
+				break;
+
+			tmp = ustr[j];
+			ustr[j] = ustr[j - 1];
+			ustr[j - 1] = tmp;
+			j--;
+		}
+	}
+}
+
+#define HFSPLUS_HANGUL_MAX_JAMO		(3)       /* L + V + optional T */
+
+static_assert(HFSPLUS_HANGUL_MAX_JAMO >= HFSPLUS_LEGACY_DECOMP_MAX_LEN,
+		"hangul_buffer must fit the longest legacy decomposition too");
+
+/*
+ * Decompose and canonically reorder an entire Linux name, as plain
+ * host-order code units. hfsplus_asc2uni(), hfsplus_hash_dentry() and
+ * hfsplus_compare_dentry() all go through this so that storage, hashing
+ * and comparison always agree on what a given name canonicalizes to.
+ *
+ * @out must hold at least @max_len entries, which must not exceed
+ * HFSPLUS_MAX_STRLEN. Returns the number of code units written. If
+ * @consumed is non-NULL, it is set to the number of input bytes actually
+ * consumed, which is less than @len when @out fills up first.
+ */
+static int hfsplus_decompose_str(struct super_block *sb, const char *astr,
+				  int len, int max_len, int name_type,
+				  u16 *out, int *consumed)
+{
+	int decompose = !test_bit(HFSPLUS_SB_NODECOMPOSE, &HFSPLUS_SB(sb)->flags);
+	const char *start = astr;
+	int outlen = 0;
+
+	while (outlen < max_len && len > 0) {
+		u16 *dstr;
+		u16 dhangul[HFSPLUS_HANGUL_MAX_JAMO];
+		int dsize, size;
+		wchar_t c;
 
-	decompose = !test_bit(HFSPLUS_SB_NODECOMPOSE, &HFSPLUS_SB(sb)->flags);
-	while (outlen < max_unistr_len && len > 0) {
 		size = asc2unichar(sb, astr, len, &c, name_type);
 
-		if (decompose)
-			dstr = decompose_unichar(c, &dsize, dhangul);
-		else
-			dstr = NULL;
+		dstr = decompose ? decompose_unichar(c, &dsize, dhangul) : NULL;
 		if (dstr) {
-			if (outlen + dsize > max_unistr_len)
+			if (outlen + dsize > max_len)
 				break;
 			do {
-				ustr->unicode[outlen++] = cpu_to_be16(*dstr++);
+				out[outlen++] = *dstr++;
 			} while (--dsize > 0);
-		} else
-			ustr->unicode[outlen++] = cpu_to_be16(c);
+		} else {
+			out[outlen++] = c;
+		}
 
 		astr += size;
 		len -= size;
 	}
+
+	hfsplus_canonical_reorder(out, outlen);
+	hfsplus_fixup_legacy_sequences(out, &outlen);
+	if (consumed)
+		*consumed = astr - start;
+	return outlen;
+}
+
+int hfsplus_asc2uni(struct super_block *sb,
+		    struct hfsplus_unistr *ustr, int max_unistr_len,
+		    const char *astr, int len, int name_type)
+{
+	u16 buf[HFSPLUS_MAX_STRLEN];
+	int outlen, i, consumed;
+
+	if (max_unistr_len > HFSPLUS_MAX_STRLEN)
+		max_unistr_len = HFSPLUS_MAX_STRLEN;
+
+	outlen = hfsplus_decompose_str(sb, astr, len, max_unistr_len,
+				       name_type, buf, &consumed);
+	for (i = 0; i < outlen; i++)
+		ustr->unicode[i] = cpu_to_be16(buf[i]);
 	ustr->length = cpu_to_be16(outlen);
-	if (len > 0)
+
+	if (consumed < len)
 		return -ENAMETOOLONG;
 	return 0;
 }
 EXPORT_SYMBOL_IF_KUNIT(hfsplus_asc2uni);
 
+/*
+ * Maximum length of a single maximal run of nonzero-combining-class code
+ * units that hfsplus_decompose_iter_next() below will canonically
+ * reorder. Every code unit with combining class 0 starts a new run, so
+ * this only bounds how many *consecutive* combining marks between two
+ * base characters get sorted - real text, and even deliberately
+ * adversarial "Zalgo" text, essentially never approaches this. Keeping
+ * it small means hfsplus_hash_dentry() and hfsplus_compare_dentry() only
+ * ever need a tiny amount of lookahead state, rather than buffering an
+ * entire (up to 255-unit) name.
+ */
+#define HFSPLUS_CCC_RUN_MAX 32
+
+/*
+ * Iterator that produces the canonically-ordered, decomposed code units
+ * of a Linux name one at a time, without materializing the whole name.
+ * hfsplus_hash_dentry() and hfsplus_compare_dentry() use this so that
+ * hashing and comparison always agree with what hfsplus_asc2uni() would
+ * actually store, while still comparing lazily (stopping at the first
+ * difference) the way this code did before canonical reordering existed.
+ */
+struct hfsplus_decompose_iter {
+	struct super_block *sb;
+	const char *astr;
+	int len;
+	int name_type;
+	int decompose;
+
+	u16 run[HFSPLUS_CCC_RUN_MAX];
+	int run_len;
+	int run_pos;
+};
+
+static void hfsplus_decompose_iter_init(struct hfsplus_decompose_iter *it,
+					struct super_block *sb,
+					const char *astr, int len,
+					int name_type)
+{
+	it->sb = sb;
+	it->astr = astr;
+	it->len = len;
+	it->name_type = name_type;
+	it->decompose = !test_bit(HFSPLUS_SB_NODECOMPOSE, &HFSPLUS_SB(sb)->flags);
+	it->run_len = 0;
+	it->run_pos = 0;
+}
+
+/*
+ * Gather the next maximal run of nonzero-combining-class code units
+ * (starting with whatever character comes next, base or not) and
+ * canonically reorder just that run. A character is only included once
+ * we know the class of the first unit it produces, so decoding it is
+ * speculative until that's decided.
+ */
+static bool hfsplus_decompose_iter_refill(struct hfsplus_decompose_iter *it)
+{
+	it->run_pos = 0;
+	it->run_len = 0;
+
+	while (it->len > 0) {
+		u16 *dstr;
+		u16 dhangul[HFSPLUS_HANGUL_MAX_JAMO];
+		int dsize, size;
+		wchar_t c;
+
+		size = asc2unichar(it->sb, it->astr, it->len, &c,
+				   it->name_type);
+
+		dstr = it->decompose ?
+			decompose_unichar(c, &dsize, dhangul) : NULL;
+		if (!dstr) {
+			dhangul[0] = c;
+			dstr = dhangul;
+			dsize = 1;
+		}
+
+		if (it->run_len > 0 && !hfsplus_combining_class(dstr[0]))
+			break;
+
+		if (it->run_len + dsize > HFSPLUS_CCC_RUN_MAX)
+			break;
+
+		it->astr += size;
+		it->len -= size;
+
+		do {
+			it->run[it->run_len++] = *dstr++;
+		} while (--dsize > 0);
+	}
+
+	hfsplus_canonical_reorder(it->run, it->run_len);
+	hfsplus_fixup_legacy_sequences(it->run, &it->run_len);
+	return it->run_len > 0;
+}
+
+/* Returns the next code unit, or a negative value once @it is exhausted. */
+static int hfsplus_decompose_iter_next(struct hfsplus_decompose_iter *it)
+{
+	if (it->run_pos >= it->run_len && !hfsplus_decompose_iter_refill(it))
+		return -1;
+	return it->run[it->run_pos++];
+}
+
+/*
+ * Returns the next code unit that matters for comparison/hashing: folded
+ * if @casefold, with any character folding to 0 ("ignorable") skipped
+ * entirely. Returns a negative value once @it is exhausted.
+ */
+static int hfsplus_decompose_iter_next_folded(struct hfsplus_decompose_iter *it,
+					      int casefold)
+{
+	int c;
+
+	do {
+		c = hfsplus_decompose_iter_next(it);
+		if (c < 0)
+			return -1;
+		if (casefold)
+			c = case_fold(c);
+	} while (casefold && !c);
+
+	return c;
+}
+
 /*
  * Hash a string to an integer as appropriate for the HFS+ filesystem.
  * Composed unicode characters are decomposed and case-folding is performed
@@ -488,45 +708,17 @@ EXPORT_SYMBOL_IF_KUNIT(hfsplus_asc2uni);
 int hfsplus_hash_dentry(const struct dentry *dentry, struct qstr *str)
 {
 	struct super_block *sb = dentry->d_sb;
-	const char *astr;
-	const u16 *dstr;
-	int casefold, decompose, size, len;
+	int casefold = test_bit(HFSPLUS_SB_CASEFOLD, &HFSPLUS_SB(sb)->flags);
+	struct hfsplus_decompose_iter it;
 	unsigned long hash;
-	wchar_t c;
-	u16 c2;
-	u16 dhangul[3];
+	int c;
 
-	casefold = test_bit(HFSPLUS_SB_CASEFOLD, &HFSPLUS_SB(sb)->flags);
-	decompose = !test_bit(HFSPLUS_SB_NODECOMPOSE, &HFSPLUS_SB(sb)->flags);
-	hash = init_name_hash(dentry);
-	astr = str->name;
-	len = str->len;
-	while (len > 0) {
-		int dsize;
-		size = asc2unichar(sb, astr, len, &c, HFS_REGULAR_NAME);
-		astr += size;
-		len -= size;
+	hfsplus_decompose_iter_init(&it, sb, str->name, str->len,
+				    HFS_REGULAR_NAME);
 
-		if (decompose)
-			dstr = decompose_unichar(c, &dsize, dhangul);
-		else
-			dstr = NULL;
-		if (dstr) {
-			do {
-				c2 = *dstr++;
-				if (casefold)
-					c2 = case_fold(c2);
-				if (!casefold || c2)
-					hash = partial_name_hash(c2, hash);
-			} while (--dsize > 0);
-		} else {
-			c2 = c;
-			if (casefold)
-				c2 = case_fold(c2);
-			if (!casefold || c2)
-				hash = partial_name_hash(c2, hash);
-		}
-	}
+	hash = init_name_hash(dentry);
+	while ((c = hfsplus_decompose_iter_next_folded(&it, casefold)) >= 0)
+		hash = partial_name_hash(c, hash);
 	str->hash = end_name_hash(hash);
 
 	return 0;
@@ -542,87 +734,21 @@ int hfsplus_compare_dentry(const struct dentry *dentry,
 		unsigned int len, const char *str, const struct qstr *name)
 {
 	struct super_block *sb = dentry->d_sb;
-	int casefold, decompose, size;
-	int dsize1, dsize2, len1, len2;
-	const u16 *dstr1, *dstr2;
-	const char *astr1, *astr2;
-	u16 c1, c2;
-	wchar_t c;
-	u16 dhangul_1[3], dhangul_2[3];
-
-	casefold = test_bit(HFSPLUS_SB_CASEFOLD, &HFSPLUS_SB(sb)->flags);
-	decompose = !test_bit(HFSPLUS_SB_NODECOMPOSE, &HFSPLUS_SB(sb)->flags);
-	astr1 = str;
-	len1 = len;
-	astr2 = name->name;
-	len2 = name->len;
-	dsize1 = dsize2 = 0;
-	dstr1 = dstr2 = NULL;
-
-	while (len1 > 0 && len2 > 0) {
-		if (!dsize1) {
-			size = asc2unichar(sb, astr1, len1, &c,
-					   HFS_REGULAR_NAME);
-			astr1 += size;
-			len1 -= size;
-
-			if (decompose)
-				dstr1 = decompose_unichar(c, &dsize1,
-							  dhangul_1);
-			if (!decompose || !dstr1) {
-				c1 = c;
-				dstr1 = &c1;
-				dsize1 = 1;
-			}
-		}
+	int casefold = test_bit(HFSPLUS_SB_CASEFOLD, &HFSPLUS_SB(sb)->flags);
+	struct hfsplus_decompose_iter it1, it2;
 
-		if (!dsize2) {
-			size = asc2unichar(sb, astr2, len2, &c,
-					   HFS_REGULAR_NAME);
-			astr2 += size;
-			len2 -= size;
-
-			if (decompose)
-				dstr2 = decompose_unichar(c, &dsize2,
-							  dhangul_2);
-			if (!decompose || !dstr2) {
-				c2 = c;
-				dstr2 = &c2;
-				dsize2 = 1;
-			}
-		}
+	hfsplus_decompose_iter_init(&it1, sb, str, len, HFS_REGULAR_NAME);
+	hfsplus_decompose_iter_init(&it2, sb, name->name, name->len,
+				    HFS_REGULAR_NAME);
 
-		c1 = *dstr1;
-		c2 = *dstr2;
-		if (casefold) {
-			c1 = case_fold(c1);
-			if (!c1) {
-				dstr1++;
-				dsize1--;
-				continue;
-			}
-			c2 = case_fold(c2);
-			if (!c2) {
-				dstr2++;
-				dsize2--;
-				continue;
-			}
-		}
-		if (c1 < c2)
-			return -1;
-		else if (c1 > c2)
-			return 1;
+	while (1) {
+		int c1 = hfsplus_decompose_iter_next_folded(&it1, casefold);
+		int c2 = hfsplus_decompose_iter_next_folded(&it2, casefold);
 
-		dstr1++;
-		dsize1--;
-		dstr2++;
-		dsize2--;
+		if (c1 < 0 || c2 < 0)
+			return c1 == c2 ? 0 : (c1 < 0 ? -1 : 1);
+		if (c1 != c2)
+			return c1 < c2 ? -1 : 1;
 	}
-
-	if (len1 < len2)
-		return -1;
-	if (len1 > len2)
-		return 1;
-	return 0;
 }
 EXPORT_SYMBOL_IF_KUNIT(hfsplus_compare_dentry);
diff --git a/fs/hfsplus/unicode.h b/fs/hfsplus/unicode.h
new file mode 100644
index 0000000000000..31cc7691c9162
--- /dev/null
+++ b/fs/hfsplus/unicode.h
@@ -0,0 +1,63 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Unicode related declarations
+ */
+
+#ifndef _LINUX_HFSPLUS_UNICODE_H
+#define _LINUX_HFSPLUS_UNICODE_H
+
+/*
+ * struct hfsplus_ccc_range - one run of consecutive BMP code points that
+ *                            share the same Unicode canonical combining class
+ * @first: the first UTF-16 code point in the run
+ * @last: the last code point in the run (inclusive)
+ * @combining_class: canonical combining class (ccc) shared by @first..@last
+ */
+struct hfsplus_ccc_range {
+	u16 first;
+	u16 last;
+	u8 combining_class;
+};
+
+/*
+ * struct hfsplus_legacy_decomp - corrected canonical decomposition
+ * @uc: the code point (a UTF-16 code unit) to look up
+ * @len: number of valid code units in @repl
+ * @repl: corrected decomposition sequence (base letter + combining marks)
+ */
+struct hfsplus_legacy_decomp {
+	u16 uc;
+	u8 len;
+#define HFSPLUS_LEGACY_DECOMP_MAX_LEN	(3)
+	u16 repl[HFSPLUS_LEGACY_DECOMP_MAX_LEN];
+};
+
+/*
+ * struct hfsplus_legacy_seq_fixup - corrected replacement for a short
+ *                                   sequence of already-decomposed code units
+ * @match_len: number of valid code units in @match
+ * @match: decomposed sequence to look for in the buffer
+ * @repl_len: number of valid code units in @repl
+ * @repl: corrected sequence to substitute in place of @match
+ */
+struct hfsplus_legacy_seq_fixup {
+	u8 match_len;
+#define HFSPLUS_LEGACY_SEQ_MAX_MATCH	(3)
+	u16 match[HFSPLUS_LEGACY_SEQ_MAX_MATCH];
+	u8 repl_len;
+#define HFSPLUS_LEGACY_SEQ_MAX_REPL	(2)
+	u16 repl[HFSPLUS_LEGACY_SEQ_MAX_REPL];
+};
+
+extern u16 hfsplus_case_fold_table[];
+extern u16 hfsplus_decompose_table[];
+extern u16 hfsplus_compose_table[];
+extern struct hfsplus_ccc_range hfsplus_ccc_table[];
+extern struct hfsplus_legacy_decomp hfsplus_legacy_decomp_table[];
+extern struct hfsplus_legacy_seq_fixup hfsplus_legacy_seq_fixups[];
+
+u8 hfsplus_combining_class(u16 c);
+const u16 *hfsplus_legacy_decompose(u16 uc, int *size);
+void hfsplus_fixup_legacy_sequences(u16 *buf, int *len);
+
+#endif /* _LINUX_HFSPLUS_UNICODE_H */
diff --git a/fs/hfsplus/unicode_test.c b/fs/hfsplus/unicode_test.c
index 7f6b2a3c69d9a..a683c6d5fc221 100644
--- a/fs/hfsplus/unicode_test.c
+++ b/fs/hfsplus/unicode_test.c
@@ -10,6 +10,7 @@
 #include <linux/dcache.h>
 #include <linux/stringhash.h>
 #include "hfsplus_fs.h"
+#include "unicode.h"
 
 struct test_mock_string_env {
 	struct hfsplus_unistr str1;
@@ -947,6 +948,223 @@ static void hfsplus_asc2uni_decompose_test(struct kunit *test)
 	free_mock_sb(mock_sb);
 }
 
+/*
+ * Real UTF-8 <-> wchar_t conversion, mirroring what the "utf8" NLS table
+ * actually does (see char2uni()/uni2char() in fs/nls/nls_utf8.c). The
+ * test_char2uni()/test_uni2char() stand-ins above only handle one raw
+ * byte per character, which cannot represent the combining marks (e.g.
+ * U+0301, U+0323) the canonical-reordering tests below need.
+ */
+static int test_char2uni_utf8(const unsigned char *rawstring, int boundlen,
+			      wchar_t *uni)
+{
+	unicode_t u;
+	int n = utf8_to_utf32(rawstring, boundlen, &u);
+
+	if (n < 0 || u > MAX_WCHAR_T) {
+		*uni = 0x3f; /* ? */
+		return -EINVAL;
+	}
+	*uni = (wchar_t)u;
+	return n;
+}
+
+static int test_uni2char_utf8(wchar_t uni, unsigned char *out, int boundlen)
+{
+	int n = utf32_to_utf8(uni, out, boundlen);
+
+	if (n < 0) {
+		*out = '?';
+		return -EINVAL;
+	}
+	return n;
+}
+
+/*
+ * Test that hfsplus_asc2uni() brings combining marks contributed by
+ * different source characters into Unicode canonical (combining-class)
+ * order, instead of just storing them in whatever order they were typed.
+ *
+ * U+0301 (COMBINING ACUTE ACCENT) has combining class 230; U+0323
+ * (COMBINING DOT BELOW) has combining class 220. Since 220 < 230,
+ * canonical order requires the dot-below before the acute. A name
+ * created with them typed in the "wrong" order must still end up stored
+ * in canonical order - this is exactly what macOS's own fsck_hfs
+ * (FixDecomps() in CatalogCheck.c) requires and flags as "Illegal name"
+ * when it isn't true.
+ */
+static void hfsplus_asc2uni_combining_reorder_test(struct kunit *test)
+{
+	struct test_mock_sb *mock_sb;
+	struct hfsplus_unistr ustr;
+	/* "e" + COMBINING ACUTE ACCENT (U+0301) + COMBINING DOT BELOW (U+0323) */
+	static const char wrong_order[] = "e\xcc\x81\xcc\xa3";
+	/* "e" + COMBINING DOT BELOW (U+0323) + COMBINING ACUTE ACCENT (U+0301) */
+	static const char canonical_order[] = "e\xcc\xa3\xcc\x81";
+	/* Two class-230 marks: GRAVE (U+0300) then ACUTE (U+0301) */
+	static const char same_class[] = "e\xcc\x80\xcc\x81";
+	int result;
+
+	mock_sb = setup_mock_sb();
+	KUNIT_ASSERT_NOT_NULL(test, mock_sb);
+
+	mock_sb->nls.char2uni = test_char2uni_utf8;
+
+	/* Typed out of canonical order: must be reordered on storage. */
+	result = hfsplus_asc2uni(&mock_sb->sb, &ustr, HFSPLUS_MAX_STRLEN,
+				 wrong_order, strlen(wrong_order),
+				 HFS_REGULAR_NAME);
+
+	KUNIT_EXPECT_EQ(test, 0, result);
+	KUNIT_EXPECT_EQ(test, 3, be16_to_cpu(ustr.length));
+	KUNIT_EXPECT_EQ(test, 'e', be16_to_cpu(ustr.unicode[0]));
+	KUNIT_EXPECT_EQ(test, 0x0323, be16_to_cpu(ustr.unicode[1]));
+	KUNIT_EXPECT_EQ(test, 0x0301, be16_to_cpu(ustr.unicode[2]));
+
+	/* Already in canonical order: must come out unchanged. */
+	result = hfsplus_asc2uni(&mock_sb->sb, &ustr, HFSPLUS_MAX_STRLEN,
+				 canonical_order, strlen(canonical_order),
+				 HFS_REGULAR_NAME);
+
+	KUNIT_EXPECT_EQ(test, 0, result);
+	KUNIT_EXPECT_EQ(test, 3, be16_to_cpu(ustr.length));
+	KUNIT_EXPECT_EQ(test, 'e', be16_to_cpu(ustr.unicode[0]));
+	KUNIT_EXPECT_EQ(test, 0x0323, be16_to_cpu(ustr.unicode[1]));
+	KUNIT_EXPECT_EQ(test, 0x0301, be16_to_cpu(ustr.unicode[2]));
+
+	/* Two marks of equal combining class must keep their relative
+	 * (input) order - the sort must be stable, not just "sorted".
+	 */
+	result = hfsplus_asc2uni(&mock_sb->sb, &ustr, HFSPLUS_MAX_STRLEN,
+				 same_class, strlen(same_class),
+				 HFS_REGULAR_NAME);
+
+	KUNIT_EXPECT_EQ(test, 0, result);
+	KUNIT_EXPECT_EQ(test, 3, be16_to_cpu(ustr.length));
+	KUNIT_EXPECT_EQ(test, 'e', be16_to_cpu(ustr.unicode[0]));
+	KUNIT_EXPECT_EQ(test, 0x0300, be16_to_cpu(ustr.unicode[1]));
+	KUNIT_EXPECT_EQ(test, 0x0301, be16_to_cpu(ustr.unicode[2]));
+
+	free_mock_sb(mock_sb);
+}
+
+/*
+ * Test that a name written with combining marks in non-canonical order
+ * still reads back as valid, correct UTF-8 once reordered - i.e. that
+ * hfsplus_asc2uni() and hfsplus_uni2asc_str() stay consistent with each
+ * other across the reordering.
+ *
+ * NODECOMPOSE is set so hfsplus_uni2asc_str() doesn't also recompose
+ * "e" + COMBINING DOT BELOW back into the precomposed U+1EB9 ("e"): that
+ * composition behavior is real (and already covered elsewhere), but it
+ * would obscure what this test is actually checking.
+ */
+static void hfsplus_unicode_combining_reorder_roundtrip_test(struct kunit *test)
+{
+	struct test_mock_sb *mock_sb;
+	struct hfsplus_unistr ustr;
+	static const char wrong_order[] = "e\xcc\x81\xcc\xa3";
+	static const char expected[] = "e\xcc\xa3\xcc\x81"; /* canonical order */
+	char buf[32];
+	int len = sizeof(buf);
+	int result;
+
+	mock_sb = setup_mock_sb();
+	KUNIT_ASSERT_NOT_NULL(test, mock_sb);
+
+	set_bit(HFSPLUS_SB_NODECOMPOSE, &mock_sb->sb_info.flags);
+	mock_sb->nls.char2uni = test_char2uni_utf8;
+	mock_sb->nls.uni2char = test_uni2char_utf8;
+
+	result = hfsplus_asc2uni(&mock_sb->sb, &ustr, HFSPLUS_MAX_STRLEN,
+				 wrong_order, strlen(wrong_order),
+				 HFS_REGULAR_NAME);
+	KUNIT_EXPECT_EQ(test, 0, result);
+
+	result = hfsplus_uni2asc_str(&mock_sb->sb, &ustr, buf, &len);
+
+	KUNIT_EXPECT_EQ(test, 0, result);
+	KUNIT_EXPECT_EQ(test, (int)strlen(expected), len);
+	KUNIT_EXPECT_MEMEQ(test, expected, buf, len);
+
+	free_mock_sb(mock_sb);
+}
+
+/*
+ * Test that hfsplus_asc2uni() decomposes a character using the corrected
+ * (post-2002/"Jaguar") canonical decomposition even when Apple Technote
+ * #1150's own decomposition table doesn't have an entry for it.
+ *
+ * U+01F8 (LATIN CAPITAL LETTER N WITH GRAVE) is exactly one of the
+ * characters macOS's own fsck_hfs (FixDecomps() in CatalogCheck.c) has
+ * flagged "Illegal name" for since 2002 when found stored undecomposed.
+ */
+static void hfsplus_asc2uni_legacy_decomp_test(struct kunit *test)
+{
+	struct test_mock_sb *mock_sb;
+	struct hfsplus_unistr ustr;
+	static const char input[] = "\xc7\xb8"; /* U+01F8 */
+	int result;
+
+	mock_sb = setup_mock_sb();
+	KUNIT_ASSERT_NOT_NULL(test, mock_sb);
+
+	mock_sb->nls.char2uni = test_char2uni_utf8;
+
+	result = hfsplus_asc2uni(&mock_sb->sb, &ustr, HFSPLUS_MAX_STRLEN,
+				 input, strlen(input), HFS_REGULAR_NAME);
+
+	KUNIT_EXPECT_EQ(test, 0, result);
+	KUNIT_EXPECT_EQ(test, 2, be16_to_cpu(ustr.length));
+	KUNIT_EXPECT_EQ(test, 'N', be16_to_cpu(ustr.unicode[0]));
+	KUNIT_EXPECT_EQ(test, 0x0300, be16_to_cpu(ustr.unicode[1]));
+
+	free_mock_sb(mock_sb);
+}
+
+/*
+ * Test that hfsplus_asc2uni() corrects two more of fsck_hfs's known
+ * legacy decomposition sequences once combining marks from independently
+ * typed characters end up adjacent:
+ *
+ *  - GREEK SMALL LETTER ALPHA (U+03B1) + COMBINING VERTICAL LINE ABOVE
+ *    (U+030D) must become U+03B1 + COMBINING ACUTE ACCENT (U+0301).
+ *  - BENGALI LETTER BA (U+09AC) + BENGALI SIGN NUKTA (U+09BC) must become
+ *    the single character BENGALI LETTER RA WITH MIDDLE DIAGONAL (U+09B0).
+ */
+static void hfsplus_asc2uni_legacy_seq_fixup_test(struct kunit *test)
+{
+	struct test_mock_sb *mock_sb;
+	struct hfsplus_unistr ustr;
+	static const char greek_input[] = "\xce\xb1\xcc\x8d"; /* U+03B1 U+030D */
+	static const char bengali_input[] = "\xe0\xa6\xac\xe0\xa6\xbc"; /* U+09AC U+09BC */
+	int result;
+
+	mock_sb = setup_mock_sb();
+	KUNIT_ASSERT_NOT_NULL(test, mock_sb);
+
+	mock_sb->nls.char2uni = test_char2uni_utf8;
+
+	result = hfsplus_asc2uni(&mock_sb->sb, &ustr, HFSPLUS_MAX_STRLEN,
+				 greek_input, strlen(greek_input),
+				 HFS_REGULAR_NAME);
+
+	KUNIT_EXPECT_EQ(test, 0, result);
+	KUNIT_EXPECT_EQ(test, 2, be16_to_cpu(ustr.length));
+	KUNIT_EXPECT_EQ(test, 0x03b1, be16_to_cpu(ustr.unicode[0]));
+	KUNIT_EXPECT_EQ(test, 0x0301, be16_to_cpu(ustr.unicode[1]));
+
+	result = hfsplus_asc2uni(&mock_sb->sb, &ustr, HFSPLUS_MAX_STRLEN,
+				 bengali_input, strlen(bengali_input),
+				 HFS_REGULAR_NAME);
+
+	KUNIT_EXPECT_EQ(test, 0, result);
+	KUNIT_EXPECT_EQ(test, 1, be16_to_cpu(ustr.length));
+	KUNIT_EXPECT_EQ(test, 0x09b0, be16_to_cpu(ustr.unicode[0]));
+
+	free_mock_sb(mock_sb);
+}
+
 /* Mock dentry for testing hfsplus_hash_dentry */
 static struct dentry test_dentry;
 
@@ -1230,6 +1448,37 @@ static void hfsplus_hash_dentry_edge_cases_test(struct kunit *test)
 	free_mock_sb(mock_sb);
 }
 
+/*
+ * Test that hfsplus_hash_dentry() hashes two names identically when they
+ * differ only in the (non-canonical) typed order of the same combining
+ * marks - both must canonicalize to the same stored form, so they must
+ * hash the same or dcache lookups would spuriously miss.
+ */
+static void hfsplus_hash_dentry_combining_reorder_test(struct kunit *test)
+{
+	struct test_mock_sb *mock_sb;
+	struct qstr str1, str2;
+	int result;
+
+	mock_sb = setup_mock_sb();
+	KUNIT_ASSERT_NOT_NULL(test, mock_sb);
+
+	setup_mock_dentry(&mock_sb->sb);
+	mock_sb->nls.char2uni = test_char2uni_utf8;
+
+	create_qstr(&str1, "e\xcc\x81\xcc\xa3"); /* acute, then dot-below */
+	result = hfsplus_hash_dentry(&test_dentry, &str1);
+	KUNIT_EXPECT_EQ(test, 0, result);
+
+	create_qstr(&str2, "e\xcc\xa3\xcc\x81"); /* dot-below, then acute */
+	result = hfsplus_hash_dentry(&test_dentry, &str2);
+	KUNIT_EXPECT_EQ(test, 0, result);
+
+	KUNIT_EXPECT_EQ(test, str1.hash, str2.hash);
+
+	free_mock_sb(mock_sb);
+}
+
 /* Test hfsplus_compare_dentry basic functionality */
 static void hfsplus_compare_dentry_basic_test(struct kunit *test)
 {
@@ -1552,6 +1801,59 @@ static void hfsplus_compare_dentry_combined_flags_test(struct kunit *test)
 	free_mock_sb(mock_sb);
 }
 
+/*
+ * Test that hfsplus_compare_dentry() treats two names as equal when they
+ * differ only in the (non-canonical) typed order of the same combining
+ * marks, since both refer to the same canonically-ordered catalog entry.
+ */
+static void hfsplus_compare_dentry_combining_reorder_test(struct kunit *test)
+{
+	struct test_mock_sb *mock_sb;
+	struct qstr name;
+	int result;
+
+	mock_sb = setup_mock_sb();
+	KUNIT_ASSERT_NOT_NULL(test, mock_sb);
+
+	setup_mock_dentry(&mock_sb->sb);
+	mock_sb->nls.char2uni = test_char2uni_utf8;
+
+	create_qstr(&name, "e\xcc\xa3\xcc\x81"); /* dot-below, then acute */
+	result = hfsplus_compare_dentry(&test_dentry, 5, "e\xcc\x81\xcc\xa3",
+					&name); /* acute, then dot-below */
+	KUNIT_EXPECT_EQ(test, 0, result);
+
+	free_mock_sb(mock_sb);
+}
+
+/*
+ * Test that a precomposed character using one of fsck_hfs's known legacy
+ * decompositions compares equal to the already-decomposed form of the
+ * same character - i.e. that hfsplus_compare_dentry() applies the same
+ * legacy-decomposition correction as hfsplus_asc2uni() does on storage,
+ * so a lookup finds the entry regardless of which form was typed.
+ */
+static void hfsplus_compare_dentry_legacy_decomp_test(struct kunit *test)
+{
+	struct test_mock_sb *mock_sb;
+	struct qstr name;
+	int result;
+
+	mock_sb = setup_mock_sb();
+	KUNIT_ASSERT_NOT_NULL(test, mock_sb);
+
+	setup_mock_dentry(&mock_sb->sb);
+	mock_sb->nls.char2uni = test_char2uni_utf8;
+
+	/* "N" + COMBINING GRAVE ACCENT (U+0300), already decomposed */
+	create_qstr(&name, "N\xcc\x80");
+	/* U+01F8, precomposed */
+	result = hfsplus_compare_dentry(&test_dentry, 2, "\xc7\xb8", &name);
+	KUNIT_EXPECT_EQ(test, 0, result);
+
+	free_mock_sb(mock_sb);
+}
+
 static struct kunit_case hfsplus_unicode_test_cases[] = {
 	KUNIT_CASE(hfsplus_strcasecmp_test),
 	KUNIT_CASE(hfsplus_strcmp_test),
@@ -1567,12 +1869,17 @@ static struct kunit_case hfsplus_unicode_test_cases[] = {
 	KUNIT_CASE(hfsplus_asc2uni_buffer_limits_test),
 	KUNIT_CASE(hfsplus_asc2uni_edge_cases_test),
 	KUNIT_CASE(hfsplus_asc2uni_decompose_test),
+	KUNIT_CASE(hfsplus_asc2uni_combining_reorder_test),
+	KUNIT_CASE(hfsplus_unicode_combining_reorder_roundtrip_test),
+	KUNIT_CASE(hfsplus_asc2uni_legacy_decomp_test),
+	KUNIT_CASE(hfsplus_asc2uni_legacy_seq_fixup_test),
 	KUNIT_CASE(hfsplus_hash_dentry_basic_test),
 	KUNIT_CASE(hfsplus_hash_dentry_casefold_test),
 	KUNIT_CASE(hfsplus_hash_dentry_special_chars_test),
 	KUNIT_CASE(hfsplus_hash_dentry_decompose_test),
 	KUNIT_CASE(hfsplus_hash_dentry_consistency_test),
 	KUNIT_CASE(hfsplus_hash_dentry_edge_cases_test),
+	KUNIT_CASE(hfsplus_hash_dentry_combining_reorder_test),
 	KUNIT_CASE(hfsplus_compare_dentry_basic_test),
 	KUNIT_CASE(hfsplus_compare_dentry_casefold_test),
 	KUNIT_CASE(hfsplus_compare_dentry_special_chars_test),
@@ -1580,6 +1887,8 @@ static struct kunit_case hfsplus_unicode_test_cases[] = {
 	KUNIT_CASE(hfsplus_compare_dentry_decompose_test),
 	KUNIT_CASE(hfsplus_compare_dentry_edge_cases_test),
 	KUNIT_CASE(hfsplus_compare_dentry_combined_flags_test),
+	KUNIT_CASE(hfsplus_compare_dentry_combining_reorder_test),
+	KUNIT_CASE(hfsplus_compare_dentry_legacy_decomp_test),
 	{}
 };
 

54/3 2026/09/21 03:57 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 24861
							output: 19
							thoughts: 1310
						

Thoughts:
**Analyzing the HFS+ Unicode Patch for Potential KMSAN Needs**

Okay, so I'm looking at this patch for `fs/hfsplus/`. My primary concern right now is whether it introduces any uninitialized memory risks that would necessitate KMSAN. Since I know my stuff, I also know that KMSAN is a heavyweight tool, so I want to be *absolutely* sure we need it. KASAN and other standard bug detectors are the first line of defense; KMSAN is only for uninitialized memory reads that those tools miss.

First, I see the touched files: `hfsplus_fs.h`, `tables.c`, `unicode.c`, `unicode.h`, and `unicode_test.c`. Seems focused on unicode handling, as expected.

Now, let's zero in on what's changed in `tables.c`. Looks like new tables for character combining classes (`hfsplus_ccc_table`), legacy decomposition (`hfsplus_legacy_decomp_table`), and sequence fixups (`hfsplus_legacy_seq_fixups`) have been added. Also, some new functions: `hfsplus_combining_class()`, `hfsplus_legacy_decompose()`, and `hfsplus_fixup_legacy_sequences()`. The first two are pretty straightforward table lookups, but the last one, `hfsplus_fixup_legacy_sequences()`, has me a little concerned. This seems like the most likely place for a bug, so let's dig deeper there.

Right, let's see, the code looks like this:

```c
			dst = &buf[i + f->repl_len];
			src = &buf[i + f->match_len];
			copy_len = (*len - i - f->match_len) * sizeof(*buf);
			memmove(dst, src, copy_len);

			dst = &buf[i];
			src = f->repl;
			copy_len = f->repl_len * sizeof(*buf);
			memcpy(dst, src, copy_len);

			*len += f->repl_len - f->match_len;
			matched = true;
			break;
```

Okay, I see what they're doing. They're replacing character sequences. My initial thought is to make sure there are no buffer overflows in that code!  If `f->repl_len` (replacement length) is greater than `f->match_len` (matching length), it's *possible* `buf` could overflow, right? Let's check the table `hfsplus_legacy_seq_fixups`.

Alright, I've got the data structure from the table now. Okay, good. It looks like:
- `match_len: 2, repl_len: 2`
- `match_len: 2, repl_len: 1`
- `match_len: 3, repl_len: 1`
*Every* entry has `f->repl_len <= f->match_len`. So, the length of the buffer either stays the same or decreases. That eliminates the buffer overflow risk *for that case*. Even better, if it *were* an overflow, that would be an out-of-bounds write, which KASAN would catch. So, not a KMSAN issue there. Okay, good. One less thing to worry about.

Now, let's turn our attention to the call to `decompose_unichar()`. That is called within `hfsplus_decompose_str()`. This function looks like it's taking a character string and decomposing it, possibly using the legacy decomposition we examined above. I need to be sure the value passed to it is valid and initialized, though.

Hmm, what happens if `asc2unichar()` fails? Does it initialize that `c` variable it's passing? I'd better check the source for `asc2unichar()` to be certain. Gotta be thorough.



55/3 2026/09/21 03:57 tool grepper
0m Args:
{
  "Expression": "int asc2unichar"
}

Results:
{
  "Output": "fs/hfsplus/unicode.c=339=void hfsplus_linux2mac_compatibility_check(wchar_t *uc, int name_type)\n--\nfs/hfsplus/unicode.c-364- */\nfs/hfsplus/unicode.c:365:static inline int asc2unichar(struct super_block *sb, const char *astr, int len,\nfs/hfsplus/unicode.c-366-\t\t\t      wchar_t *uc, int name_type)\n"
}

56/3 2026/09/21 03:57 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 27192
							output: 37
							thoughts: 22
						

Thoughts:
Here's a summary of my thought process, as requested:

**Diving into `unicode.c`**

Okay, time to get my hands dirty. I'm going to navigate to `fs/hfsplus/unicode.c` in the kernel source. Specifically, I want to zero in around line 365. This likely means there's some interesting Unicode conversion or handling happening in that vicinity, and I'm curious to see how the HFS+ filesystem is dealing with it. I'm expecting to find some crucial code related to character set mapping, normalization, or perhaps some specific HFS+ nuances in its Unicode implementation. Let's see what gems are hidden there.



57/3 2026/09/21 03:58 tool read-file
0m Args:
{
  "File": "fs/hfsplus/unicode.c",
  "FirstLine": 360,
  "LineCount": 50
}

Results:
{
  "Contents": " 360:\t\n 361:\t/*\n 362:\t * Convert one or more ASCII characters into a single unicode character.\n 363:\t * Returns the number of ASCII characters corresponding to the unicode char.\n 364:\t */\n 365:\tstatic inline int asc2unichar(struct super_block *sb, const char *astr, int len,\n 366:\t\t\t\t      wchar_t *uc, int name_type)\n 367:\t{\n 368:\t\tint size = HFSPLUS_SB(sb)-\u003enls-\u003echar2uni(astr, len, uc);\n 369:\t\n 370:\t\tif (size \u003c= 0) {\n 371:\t\t\t*uc = '?';\n 372:\t\t\tsize = 1;\n 373:\t\t}\n 374:\t\n 375:\t\thfsplus_linux2mac_compatibility_check(uc, name_type);\n 376:\t\treturn size;\n 377:\t}\n 378:\t\n 379:\t/* Decomposes a non-Hangul unicode character. */\n 380:\tstatic u16 *hfsplus_decompose_nonhangul(wchar_t uc, int *size)\n 381:\t{\n 382:\t\tint off;\n 383:\t\n 384:\t\toff = hfsplus_decompose_table[(uc \u003e\u003e 12) \u0026 0xf];\n 385:\t\tif (off == 0 || off == 0xffff)\n 386:\t\t\treturn NULL;\n 387:\t\n 388:\t\toff = hfsplus_decompose_table[off + ((uc \u003e\u003e 8) \u0026 0xf)];\n 389:\t\tif (!off)\n 390:\t\t\treturn NULL;\n 391:\t\n 392:\t\toff = hfsplus_decompose_table[off + ((uc \u003e\u003e 4) \u0026 0xf)];\n 393:\t\tif (!off)\n 394:\t\t\treturn NULL;\n 395:\t\n 396:\t\toff = hfsplus_decompose_table[off + (uc \u0026 0xf)];\n 397:\t\t*size = off \u0026 3;\n 398:\t\tif (*size == 0)\n 399:\t\t\treturn NULL;\n 400:\t\treturn hfsplus_decompose_table + (off / 4);\n 401:\t}\n 402:\t\n 403:\t/*\n 404:\t * Try to decompose a unicode character as Hangul. Return 0 if @uc is not\n 405:\t * precomposed Hangul, otherwise return the length of the decomposition.\n 406:\t *\n 407:\t * This function was adapted from sample code from the Unicode Standard\n 408:\t * Annex #15: Unicode Normalization Forms, version 3.2.0.\n 409:\t *\n"
}

58/3 2026/09/21 03:58 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 28148
							output: 21
							thoughts: 1328
						

Thoughts:
**Analyzing the Unicode Conversion in HFS+ Filesystem**

Okay, let's break this down. First, I see that `asc2unichar` is a crucial function, as it always sets the `*uc` output, even if the input conversion fails, it defaults to a question mark. Now, I'm focusing on `hfsplus_asc2uni`. The code uses a local buffer `buf` of `u16`s, sized `HFSPLUS_MAX_STRLEN`. Hmm, that looks like an uninitialized stack buffer. But, is it read uninitialized?

The `hfsplus_decompose_str` function calculates `outlen`, which seems to be the critical size variable that determines how much of the local `buf` gets populated. Let's delve into `hfsplus_decompose_str`: it appears to iterate through the input string, performing some character decomposition and/or conversion logic. Critically, `outlen` starts at 0, and the code increments it for each valid character it processes, writing into the `out` buffer (which, in `hfsplus_asc2uni`, is the `buf` buffer). So, each element of `buf` from 0 to `outlen-1` gets assigned. Then, `hfsplus_canonical_reorder` and `hfsplus_fixup_legacy_sequences` operate on the buffer up to `outlen`, making changes in-place. So, the initialization is done by `hfsplus_decompose_str` so far.

Now back to `hfsplus_asc2uni`, this loop copies the data from the local `buf` into the `ustr->unicode` field: `ustr->unicode[i] = cpu_to_be16(buf[i]);`. The loop iterates from `0` to `outlen`. That makes it ok, since `buf` is populated only until `outlen`!

So, the concern about reading uninitialized memory in `buf` doesn't seem to be valid! 

Interestingly, before the patch, the code was different. It directly populated `ustr->unicode` in a similar fashion, but within a `while` loop, and the `outlen` variable (which was directly used to index into `ustr->unicode`) was similarly incremented. The resulting `ustr->length` was also set to the final `outlen`. The patched version is doing almost the same.

Therefore, the updated code appears safe concerning buffer overflow.

I need to see what the callers of `hfsplus_asc2uni` do, and what the `struct hfsplus_unistr` is all about.



59/3 2026/09/21 03:58 tool grepper
0m Args:
{
  "Expression": "struct hfsplus_unistr"
}

Results:
{
  "Output": "fs/hfsplus/attributes.c=35=int hfsplus_attr_bin_cmp_key(const hfsplus_btree_key *k1,\n--\nfs/hfsplus/attributes.c-45-\treturn hfsplus_strcmp(\nfs/hfsplus/attributes.c:46:\t\t\t(const struct hfsplus_unistr *)\u0026k1-\u003eattr.key_name,\nfs/hfsplus/attributes.c:47:\t\t\t(const struct hfsplus_unistr *)\u0026k2-\u003eattr.key_name);\nfs/hfsplus/attributes.c-48-}\n--\nfs/hfsplus/attributes.c=50=int hfsplus_attr_build_key(struct super_block *sb, hfsplus_btree_key *key,\n--\nfs/hfsplus/attributes.c-58-\t\tint res = hfsplus_asc2uni(sb,\nfs/hfsplus/attributes.c:59:\t\t\t\t(struct hfsplus_unistr *)\u0026key-\u003eattr.key_name,\nfs/hfsplus/attributes.c-60-\t\t\t\tHFSPLUS_ATTR_MAX_STRLEN, name, strlen(name),\n--\nfs/hfsplus/catalog.c=68=static void hfsplus_cat_build_key_uni(hfsplus_btree_key *key, u32 parent,\nfs/hfsplus/catalog.c:69:\t\t\t\t      struct hfsplus_unistr *name)\nfs/hfsplus/catalog.c-70-{\n--\nfs/hfsplus/hfsplus_fs.h=488=int hfsplus_commit_superblock(struct super_block *sb);\n--\nfs/hfsplus/hfsplus_fs.h-490-/* unicode.c */\nfs/hfsplus/hfsplus_fs.h:491:int hfsplus_strcasecmp(const struct hfsplus_unistr *s1,\nfs/hfsplus/hfsplus_fs.h:492:\t\t       const struct hfsplus_unistr *s2);\nfs/hfsplus/hfsplus_fs.h:493:int hfsplus_strcmp(const struct hfsplus_unistr *s1,\nfs/hfsplus/hfsplus_fs.h:494:\t\t   const struct hfsplus_unistr *s2);\nfs/hfsplus/hfsplus_fs.h-495-int hfsplus_uni2asc_str(struct super_block *sb,\nfs/hfsplus/hfsplus_fs.h:496:\t\t\tconst struct hfsplus_unistr *ustr, char *astr,\nfs/hfsplus/hfsplus_fs.h-497-\t\t\tint *len_p);\nfs/hfsplus/hfsplus_fs.h=498=int hfsplus_uni2asc_xattr_str(struct super_block *sb,\n--\nfs/hfsplus/hfsplus_fs.h-500-\t\t\t      char *astr, int *len_p);\nfs/hfsplus/hfsplus_fs.h:501:int hfsplus_asc2uni(struct super_block *sb, struct hfsplus_unistr *ustr,\nfs/hfsplus/hfsplus_fs.h-502-\t\t    int max_unistr_len, const char *astr, int len,\n--\nfs/hfsplus/hfsplus_fs.h=513=static inline u32 hfsplus_cat_thread_size(const struct hfsplus_cat_thread *thread)\n--\nfs/hfsplus/hfsplus_fs.h-515-\treturn offsetof(struct hfsplus_cat_thread, nodeName) +\nfs/hfsplus/hfsplus_fs.h:516:\t       offsetof(struct hfsplus_unistr, unicode) +\nfs/hfsplus/hfsplus_fs.h-517-\t       be16_to_cpu(thread-\u003enodeName.length) * sizeof(hfsplus_unichr);\n--\nfs/hfsplus/unicode.c=23=static inline u16 case_fold(u16 c)\n--\nfs/hfsplus/unicode.c-35-/* Compare unicode strings, return values like normal strcmp */\nfs/hfsplus/unicode.c:36:int hfsplus_strcasecmp(const struct hfsplus_unistr *s1,\nfs/hfsplus/unicode.c:37:\t\t       const struct hfsplus_unistr *s2)\nfs/hfsplus/unicode.c-38-{\n--\nfs/hfsplus/unicode.c=79=EXPORT_SYMBOL_IF_KUNIT(hfsplus_strcasecmp);\n--\nfs/hfsplus/unicode.c-81-/* Compare names as a sequence of 16-bit unsigned integers */\nfs/hfsplus/unicode.c:82:int hfsplus_strcmp(const struct hfsplus_unistr *s1,\nfs/hfsplus/unicode.c:83:\t\t   const struct hfsplus_unistr *s2)\nfs/hfsplus/unicode.c-84-{\n--\nfs/hfsplus/unicode.c=185=static int hfsplus_uni2asc(struct super_block *sb,\nfs/hfsplus/unicode.c:186:\t\t\t   const struct hfsplus_unistr *ustr,\nfs/hfsplus/unicode.c-187-\t\t\t   int max_len, char *astr, int *len_p,\n--\nfs/hfsplus/unicode.c=309=inline int hfsplus_uni2asc_str(struct super_block *sb,\nfs/hfsplus/unicode.c:310:\t\t\t       const struct hfsplus_unistr *ustr, char *astr,\nfs/hfsplus/unicode.c-311-\t\t\t       int *len_p)\n--\nfs/hfsplus/unicode.c=320=inline int hfsplus_uni2asc_xattr_str(struct super_block *sb,\n--\nfs/hfsplus/unicode.c-323-{\nfs/hfsplus/unicode.c:324:\treturn hfsplus_uni2asc(sb, (const struct hfsplus_unistr *)ustr,\nfs/hfsplus/unicode.c-325-\t\t\t\tHFSPLUS_ATTR_MAX_STRLEN, astr, len_p,\n--\nfs/hfsplus/unicode.c=557=int hfsplus_asc2uni(struct super_block *sb,\nfs/hfsplus/unicode.c:558:\t\t    struct hfsplus_unistr *ustr, int max_unistr_len,\nfs/hfsplus/unicode.c-559-\t\t    const char *astr, int len, int name_type)\n--\nfs/hfsplus/unicode_test.c=15=struct test_mock_string_env {\nfs/hfsplus/unicode_test.c:16:\tstruct hfsplus_unistr str1;\nfs/hfsplus/unicode_test.c:17:\tstruct hfsplus_unistr str2;\nfs/hfsplus/unicode_test.c-18-\tchar *buf;\n--\nfs/hfsplus/unicode_test.c=41=static void free_mock_str_env(struct test_mock_string_env *env)\n--\nfs/hfsplus/unicode_test.c-47-/* Helper function to create hfsplus_unistr */\nfs/hfsplus/unicode_test.c:48:static void create_unistr(struct hfsplus_unistr *ustr, const char *ascii_str)\nfs/hfsplus/unicode_test.c-49-{\n--\nfs/hfsplus/unicode_test.c-59-\nfs/hfsplus/unicode_test.c:60:static void corrupt_unistr(struct hfsplus_unistr *ustr)\nfs/hfsplus/unicode_test.c-61-{\n--\nfs/hfsplus/unicode_test.c=683=static void check_unistr_content(struct kunit *test,\nfs/hfsplus/unicode_test.c:684:\t\t\t\t struct hfsplus_unistr *ustr,\nfs/hfsplus/unicode_test.c-685-\t\t\t\t const char *expected_ascii)\n--\nfs/hfsplus/unicode_test.c=859=static void hfsplus_asc2uni_edge_cases_test(struct kunit *test)\n--\nfs/hfsplus/unicode_test.c-861-\tstruct test_mock_sb *mock_sb;\nfs/hfsplus/unicode_test.c:862:\tstruct hfsplus_unistr ustr;\nfs/hfsplus/unicode_test.c-863-\tchar test_str[] = {'a', '\\0', 'b'};\n--\nfs/hfsplus/unicode_test.c=996=static void hfsplus_asc2uni_combining_reorder_test(struct kunit *test)\n--\nfs/hfsplus/unicode_test.c-998-\tstruct test_mock_sb *mock_sb;\nfs/hfsplus/unicode_test.c:999:\tstruct hfsplus_unistr ustr;\nfs/hfsplus/unicode_test.c-1000-\t/* \"e\" + COMBINING ACUTE ACCENT (U+0301) + COMBINING DOT BELOW (U+0323) */\n--\nfs/hfsplus/unicode_test.c=1062=static void hfsplus_unicode_combining_reorder_roundtrip_test(struct kunit *test)\n--\nfs/hfsplus/unicode_test.c-1064-\tstruct test_mock_sb *mock_sb;\nfs/hfsplus/unicode_test.c:1065:\tstruct hfsplus_unistr ustr;\nfs/hfsplus/unicode_test.c-1066-\tstatic const char wrong_order[] = \"e\\xcc\\x81\\xcc\\xa3\";\n--\nfs/hfsplus/unicode_test.c=1102=static void hfsplus_asc2uni_legacy_decomp_test(struct kunit *test)\n--\nfs/hfsplus/unicode_test.c-1104-\tstruct test_mock_sb *mock_sb;\nfs/hfsplus/unicode_test.c:1105:\tstruct hfsplus_unistr ustr;\nfs/hfsplus/unicode_test.c-1106-\tstatic const char input[] = \"\\xc7\\xb8\"; /* U+01F8 */\n--\nfs/hfsplus/unicode_test.c=1135=static void hfsplus_asc2uni_legacy_seq_fixup_test(struct kunit *test)\n--\nfs/hfsplus/unicode_test.c-1137-\tstruct test_mock_sb *mock_sb;\nfs/hfsplus/unicode_test.c:1138:\tstruct hfsplus_unistr ustr;\nfs/hfsplus/unicode_test.c-1139-\tstatic const char greek_input[] = \"\\xce\\xb1\\xcc\\x8d\"; /* U+03B1 U+030D */\n--\ninclude/linux/hfs_common.h=149=struct hfs_name {\n--\ninclude/linux/hfs_common.h-154-/* A \"string\" as used in filenames, etc. */\ninclude/linux/hfs_common.h:155:struct hfsplus_unistr {\ninclude/linux/hfs_common.h-156-\t__be16 length;\n--\ninclude/linux/hfs_common.h=357=struct hfsplus_cat_key {\n--\ninclude/linux/hfs_common.h-359-\thfsplus_cnid parent;\ninclude/linux/hfs_common.h:360:\tstruct hfsplus_unistr name;\ninclude/linux/hfs_common.h-361-} __packed;\n--\ninclude/linux/hfs_common.h=588=struct hfsplus_cat_thread {\n--\ninclude/linux/hfs_common.h-591-\thfsplus_cnid parentID;\ninclude/linux/hfs_common.h:592:\tstruct hfsplus_unistr nodeName;\ninclude/linux/hfs_common.h-593-} __packed;\n"
}

60/3 2026/09/21 03:58 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 33198
							output: 25
							thoughts: 1233
						

Thoughts:
**Analyzing the `hfsplus_decompose_iter` Structure and its Operations**

Okay, let's break down how this `hfsplus_decompose_iter` works. First, the structure itself looks straightforward: a superblock pointer, the string to decompose, its length, a name type, a decompose flag, and then a buffer `run` of `u16` values to store decomposed characters. The initialisation `hfsplus_decompose_iter_init` sets up the basic parameters.  The important work is in `hfsplus_decompose_iter_refill` and `hfsplus_decompose_iter_next`.

`hfsplus_decompose_iter_refill` is where the decomposition happens. The iterator fills the `run` buffer. It fetches a Unicode character, decomposes it, and then adds the resulting components to `run`. The loop continues as long as there is input to process and space in `run`. The interesting part is how it uses `asc2unichar`, `decompose_unichar`, and the `dhangul` buffer.  If `decompose_unichar` fails, the original character is placed in `dhangul`. After decomposition, the code checks the combining class of the characters to prevent combining characters from being split. The code then reorders the characters in `run` and fixes up legacy sequences.

Now, let's scrutinize this `run` buffer management. The loop writes into the array `it->run` using the index `it->run_len`.  Crucially, `it->run_len` is incremented *after* each element is written. The following calls to `hfsplus_canonical_reorder` and `hfsplus_fixup_legacy_sequences` will operate on the elements *actually* written into `run`.

The `hfsplus_decompose_iter_next` function uses `it->run_pos` to track the current position in `run`, and, correctly, never reads past `it->run_len`. It correctly increments `it->run_pos` after each read. This seems safe.

But, back in `hfsplus_decompose_iter_refill`... if `decompose_unichar` fails, we set `dhangul[0]` to the original character, and then in the loop `it->run[it->run_len++] = *dstr++`. This reads one element. But, what happens if `decompose_unichar` succeeds? Let's check `decompose_unichar`.

`decompose_unichar` seems to handle Hangul decomposition. If `hfsplus_try_decompose_hangul(uc, result)` succeeds (returns a value > 0), then it's responsible for putting decomposed characters into `result`, in this case, the `hangul_buffer`. It seems important to check if it writes into the `hangul_buffer`. Let's check `hfsplus_try_decompose_hangul`.



61/3 2026/09/21 03:58 tool grepper
0m Args:
{
  "Expression": "int hfsplus_try_decompose_hangul"
}

Results:
{
  "Output": "fs/hfsplus/unicode.c=380=static u16 *hfsplus_decompose_nonhangul(wchar_t uc, int *size)\n--\nfs/hfsplus/unicode.c-412- */\nfs/hfsplus/unicode.c:413:static int hfsplus_try_decompose_hangul(wchar_t uc, u16 *result)\nfs/hfsplus/unicode.c-414-{\n"
}

62/3 2026/09/21 03:58 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 35213
							output: 37
							thoughts: 22
						

Thoughts:
Here's a summary of my thought process, as requested:

**Diving into `unicode.c`**

Okay, time to get my hands dirty. I need to take a look at the HFS+ Unicode handling, specifically around line 413 in `fs/hfsplus/unicode.c`. This suggests there's a specific section of the code I need to investigate, likely related to Unicode normalization, string conversion, or possibly some edge case handling. I'm hoping to quickly identify the relevant function or data structure being used there to understand the problem at hand, whatever it may be. I'll need to remember to keep my eyes open for any potential performance bottlenecks or subtle corner-case bugs that could be lurking in the code. Let's see what we can find.



63/3 2026/09/21 03:58 tool read-file
0m Args:
{
  "File": "fs/hfsplus/unicode.c",
  "FirstLine": 410,
  "LineCount": 40
}

Results:
{
  "Contents": " 410:\t * Copyright (C) 1991-2018 Unicode, Inc.  All rights reserved.  Distributed\n 411:\t * under the Terms of Use in http://www.unicode.org/copyright.html.\n 412:\t */\n 413:\tstatic int hfsplus_try_decompose_hangul(wchar_t uc, u16 *result)\n 414:\t{\n 415:\t\tint index;\n 416:\t\tint l, v, t;\n 417:\t\n 418:\t\tindex = uc - Hangul_SBase;\n 419:\t\tif (index \u003c 0 || index \u003e= Hangul_SCount)\n 420:\t\t\treturn 0;\n 421:\t\n 422:\t\tl = Hangul_LBase + index / Hangul_NCount;\n 423:\t\tv = Hangul_VBase + (index % Hangul_NCount) / Hangul_TCount;\n 424:\t\tt = Hangul_TBase + index % Hangul_TCount;\n 425:\t\n 426:\t\tresult[0] = l;\n 427:\t\tresult[1] = v;\n 428:\t\tif (t != Hangul_TBase) {\n 429:\t\t\tresult[2] = t;\n 430:\t\t\treturn 3;\n 431:\t\t}\n 432:\t\treturn 2;\n 433:\t}\n 434:\t\n 435:\t/* Decomposes a single unicode character. */\n 436:\tstatic u16 *decompose_unichar(wchar_t uc, int *size, u16 *hangul_buffer)\n 437:\t{\n 438:\t\tu16 *result;\n 439:\t\n 440:\t\t/* Hangul is handled separately */\n 441:\t\tresult = hangul_buffer;\n 442:\t\t*size = hfsplus_try_decompose_hangul(uc, result);\n 443:\t\tif (*size == 0)\n 444:\t\t\tresult = hfsplus_decompose_nonhangul(uc, size);\n 445:\t\tif (!result) {\n 446:\t\t\t/*\n 447:\t\t\t * Not every character with a canonical decomposition is in\n 448:\t\t\t * Apple Technote #1150's own table above; a small, fixed\n 449:\t\t\t * set was only added to the decomposition standard (or had\n"
}

64/3 2026/09/21 03:58 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 36087
							output: 21
							thoughts: 1313
						

Thoughts:
**Decomposition, Iteration, and String Handling: A Deep Dive**

Okay, so I'm focusing on the HFS+ decomposition logic. My initial thought was about how `hfsplus_try_decompose_hangul` initializes `result[0]`, `result[1]`, and potentially `result[2]` if it returns 3. But now I'm thinking about the related `hfsplus_legacy_decompose` function, which seems central to character decomposition.

Looking at `hfsplus_legacy_decompose`, it uses a binary search on `hfsplus_legacy_decomp_table`. Entries in this table specify a Unicode character (`uc`), a length (`len`), and a replacement sequence (`repl`).  The `len` is either 2 or 3, and the `repl` is initialized with that many elements. The `memcpy` call then copies the `*size` elements into `hangul_buffer`.  Good, the static assertion `static_assert(HFSPLUS_HANGUL_MAX_JAMO >= HFSPLUS_LEGACY_DECOMP_MAX_LEN, ...);` confirms that `hangul_buffer` can accommodate the decomposed characters, as `HFSPLUS_HANGUL_MAX_JAMO` and `HFSPLUS_LEGACY_DECOMP_MAX_LEN` are both 3.

But, a quick check of `asc2unichar`, will it ever return a `size` of 0? No, because when `size` is less than or equal to 0, it defaults to 1. That's good.

Next, I'm thinking about `hfsplus_decompose_iter_refill` when `it->len == 0`. It returns `it->run_len > 0`. If `len` is 0, the check returns `false`, which is what's expected. `hfsplus_decompose_iter_next` then returns -1. I see this is used in `hfsplus_hash_dentry` and `hfsplus_compare_dentry`, where the iterator is used to generate a hash or compare names. Both use a `while` loop that calls `hfsplus_decompose_iter_next_folded` until it returns -1.  This seems correct, iterating until the end of the decomposition.

Now, back to `hfsplus_asc2uni`. I'm concerned about how `hfsplus_decompose_str` and `hfsplus_asc2uni` work together.  `hfsplus_asc2uni` calls `hfsplus_decompose_str`, which returns the output length, and copies that to a buffer (`buf`). Then, the code loops through `buf`, converting each 16-bit value into a big-endian format and copying it to `ustr->unicode`. `ustr->length` is set to the output length.  Finally, it does a check on consumed characters vs the input character length, returning `ENAMETOOLONG` if the name is truncated.

The critical question now is, *where* is `hfsplus_asc2uni` used? Is this data copied to disk, or user space? That is the next step to figure out for a full understanding of the data flow and implications. I need to check all call sites to ensure data integrity and security.



65/3 2026/09/21 03:58 tool grepper
0m Args:
{
  "Expression": "hfsplus_asc2uni"
}

Results:
{
  "Output": "fs/hfsplus/attributes.c=50=int hfsplus_attr_build_key(struct super_block *sb, hfsplus_btree_key *key,\n--\nfs/hfsplus/attributes.c-57-\tif (name) {\nfs/hfsplus/attributes.c:58:\t\tint res = hfsplus_asc2uni(sb,\nfs/hfsplus/attributes.c-59-\t\t\t\t(struct hfsplus_unistr *)\u0026key-\u003eattr.key_name,\n--\nfs/hfsplus/catalog.c=43=int hfsplus_cat_build_key(struct super_block *sb,\n--\nfs/hfsplus/catalog.c-48-\tkey-\u003ecat.parent = cpu_to_be32(parent);\nfs/hfsplus/catalog.c:49:\terr = hfsplus_asc2uni(sb, \u0026key-\u003ecat.name, HFSPLUS_MAX_STRLEN,\nfs/hfsplus/catalog.c-50-\t\t\t      str-\u003ename, str-\u003elen, HFS_REGULAR_NAME);\n--\nfs/hfsplus/catalog.c=176=static int hfsplus_fill_cat_thread(struct super_block *sb,\n--\nfs/hfsplus/catalog.c-184-\tentry-\u003ethread.parentID = cpu_to_be32(parentid);\nfs/hfsplus/catalog.c:185:\terr = hfsplus_asc2uni(sb, \u0026entry-\u003ethread.nodeName, HFSPLUS_MAX_STRLEN,\nfs/hfsplus/catalog.c-186-\t\t\t\tstr-\u003ename, str-\u003elen, HFS_REGULAR_NAME);\n--\nfs/hfsplus/hfsplus_fs.h=498=int hfsplus_uni2asc_xattr_str(struct super_block *sb,\n--\nfs/hfsplus/hfsplus_fs.h-500-\t\t\t      char *astr, int *len_p);\nfs/hfsplus/hfsplus_fs.h:501:int hfsplus_asc2uni(struct super_block *sb, struct hfsplus_unistr *ustr,\nfs/hfsplus/hfsplus_fs.h-502-\t\t    int max_unistr_len, const char *astr, int len,\n--\nfs/hfsplus/unicode.c=505=static_assert(HFSPLUS_HANGUL_MAX_JAMO \u003e= HFSPLUS_LEGACY_DECOMP_MAX_LEN,\n--\nfs/hfsplus/unicode.c-509- * Decompose and canonically reorder an entire Linux name, as plain\nfs/hfsplus/unicode.c:510: * host-order code units. hfsplus_asc2uni(), hfsplus_hash_dentry() and\nfs/hfsplus/unicode.c-511- * hfsplus_compare_dentry() all go through this so that storage, hashing\n--\nfs/hfsplus/unicode.c=519=static int hfsplus_decompose_str(struct super_block *sb, const char *astr,\n--\nfs/hfsplus/unicode.c-556-\nfs/hfsplus/unicode.c:557:int hfsplus_asc2uni(struct super_block *sb,\nfs/hfsplus/unicode.c-558-\t\t    struct hfsplus_unistr *ustr, int max_unistr_len,\n--\nfs/hfsplus/unicode.c-576-}\nfs/hfsplus/unicode.c:577:EXPORT_SYMBOL_IF_KUNIT(hfsplus_asc2uni);\nfs/hfsplus/unicode.c-578-\n--\nfs/hfsplus/unicode.c-595- * hfsplus_hash_dentry() and hfsplus_compare_dentry() use this so that\nfs/hfsplus/unicode.c:596: * hashing and comparison always agree with what hfsplus_asc2uni() would\nfs/hfsplus/unicode.c-597- * actually store, while still comparing lazily (stopping at the first\n--\nfs/hfsplus/unicode_test.c=683=static void check_unistr_content(struct kunit *test,\n--\nfs/hfsplus/unicode_test.c-700-\nfs/hfsplus/unicode_test.c:701:/* Test hfsplus_asc2uni basic functionality */\nfs/hfsplus/unicode_test.c:702:static void hfsplus_asc2uni_basic_test(struct kunit *test)\nfs/hfsplus/unicode_test.c-703-{\n--\nfs/hfsplus/unicode_test.c-716-\t/* Test simple ASCII string conversion */\nfs/hfsplus/unicode_test.c:717:\tresult = hfsplus_asc2uni(\u0026mock_sb-\u003esb, \u0026mock_env-\u003estr1,\nfs/hfsplus/unicode_test.c-718-\t\t\t\t HFSPLUS_MAX_STRLEN, \"hello\", 5,\n--\nfs/hfsplus/unicode_test.c-724-\t/* Test empty string */\nfs/hfsplus/unicode_test.c:725:\tresult = hfsplus_asc2uni(\u0026mock_sb-\u003esb, \u0026mock_env-\u003estr1,\nfs/hfsplus/unicode_test.c-726-\t\t\t\t HFSPLUS_MAX_STRLEN, \"\", 0,\n--\nfs/hfsplus/unicode_test.c-732-\t/* Test single character */\nfs/hfsplus/unicode_test.c:733:\tresult = hfsplus_asc2uni(\u0026mock_sb-\u003esb, \u0026mock_env-\u003estr1,\nfs/hfsplus/unicode_test.c-734-\t\t\t\t HFSPLUS_MAX_STRLEN, \"A\", 1,\n--\nfs/hfsplus/unicode_test.c-740-\t/* Test null-terminated string with explicit length */\nfs/hfsplus/unicode_test.c:741:\tresult = hfsplus_asc2uni(\u0026mock_sb-\u003esb, \u0026mock_env-\u003estr1,\nfs/hfsplus/unicode_test.c-742-\t\t\t\t HFSPLUS_MAX_STRLEN, \"test\\0extra\", 4,\n--\nfs/hfsplus/unicode_test.c-752-/* Test special character handling in asc2uni */\nfs/hfsplus/unicode_test.c:753:static void hfsplus_asc2uni_special_chars_test(struct kunit *test)\nfs/hfsplus/unicode_test.c-754-{\n--\nfs/hfsplus/unicode_test.c-767-\t/* Test colon conversion (should become forward slash) */\nfs/hfsplus/unicode_test.c:768:\tresult = hfsplus_asc2uni(\u0026mock_sb-\u003esb, \u0026mock_env-\u003estr1,\nfs/hfsplus/unicode_test.c-769-\t\t\t\t HFSPLUS_MAX_STRLEN, \":\", 1,\n--\nfs/hfsplus/unicode_test.c-776-\t/* Test string with mixed special characters */\nfs/hfsplus/unicode_test.c:777:\tresult = hfsplus_asc2uni(\u0026mock_sb-\u003esb, \u0026mock_env-\u003estr1,\nfs/hfsplus/unicode_test.c-778-\t\t\t\t HFSPLUS_MAX_STRLEN, \"a:b\", 3,\n--\nfs/hfsplus/unicode_test.c-787-\t/* Test multiple special characters */\nfs/hfsplus/unicode_test.c:788:\tresult = hfsplus_asc2uni(\u0026mock_sb-\u003esb, \u0026mock_env-\u003estr1,\nfs/hfsplus/unicode_test.c-789-\t\t\t\t HFSPLUS_MAX_STRLEN, \":::\", 3,\n--\nfs/hfsplus/unicode_test.c-802-/* Test buffer length limits */\nfs/hfsplus/unicode_test.c:803:static void hfsplus_asc2uni_buffer_limits_test(struct kunit *test)\nfs/hfsplus/unicode_test.c-804-{\n--\nfs/hfsplus/unicode_test.c-818-\tmemset(mock_env-\u003ebuf, 'a', HFSPLUS_MAX_STRLEN);\nfs/hfsplus/unicode_test.c:819:\tresult = hfsplus_asc2uni(\u0026mock_sb-\u003esb,\nfs/hfsplus/unicode_test.c-820-\t\t\t\t \u0026mock_env-\u003estr1, HFSPLUS_MAX_STRLEN,\n--\nfs/hfsplus/unicode_test.c-829-\tmemset(mock_env-\u003ebuf, 'a', HFSPLUS_MAX_STRLEN + 5);\nfs/hfsplus/unicode_test.c:830:\tresult = hfsplus_asc2uni(\u0026mock_sb-\u003esb,\nfs/hfsplus/unicode_test.c-831-\t\t\t\t \u0026mock_env-\u003estr1, HFSPLUS_MAX_STRLEN,\n--\nfs/hfsplus/unicode_test.c-839-\t/* Test with smaller max_unistr_len */\nfs/hfsplus/unicode_test.c:840:\tresult = hfsplus_asc2uni(\u0026mock_sb-\u003esb,\nfs/hfsplus/unicode_test.c-841-\t\t\t\t \u0026mock_env-\u003estr1, 5, \"toolongstring\", 13,\n--\nfs/hfsplus/unicode_test.c-847-\t/* Test zero max length */\nfs/hfsplus/unicode_test.c:848:\tresult = hfsplus_asc2uni(\u0026mock_sb-\u003esb, \u0026mock_env-\u003estr1, 0, \"test\", 4,\nfs/hfsplus/unicode_test.c-849-\t\t\t\t HFS_REGULAR_NAME);\n--\nfs/hfsplus/unicode_test.c-858-/* Test error handling and edge cases */\nfs/hfsplus/unicode_test.c:859:static void hfsplus_asc2uni_edge_cases_test(struct kunit *test)\nfs/hfsplus/unicode_test.c-860-{\n--\nfs/hfsplus/unicode_test.c-871-\t/* Test zero length input */\nfs/hfsplus/unicode_test.c:872:\tresult = hfsplus_asc2uni(\u0026mock_sb-\u003esb,\nfs/hfsplus/unicode_test.c-873-\t\t\t\t \u0026ustr, HFSPLUS_MAX_STRLEN, \"test\", 0,\n--\nfs/hfsplus/unicode_test.c-879-\t/* Test input with length mismatch */\nfs/hfsplus/unicode_test.c:880:\tresult = hfsplus_asc2uni(\u0026mock_sb-\u003esb,\nfs/hfsplus/unicode_test.c-881-\t\t\t\t \u0026ustr, HFSPLUS_MAX_STRLEN, \"hello\", 3,\n--\nfs/hfsplus/unicode_test.c-887-\t/* Test with various printable ASCII characters */\nfs/hfsplus/unicode_test.c:888:\tresult = hfsplus_asc2uni(\u0026mock_sb-\u003esb,\nfs/hfsplus/unicode_test.c-889-\t\t\t\t \u0026ustr, HFSPLUS_MAX_STRLEN, \"ABC123!@#\", 9,\n--\nfs/hfsplus/unicode_test.c-895-\t/* Test null character in the middle */\nfs/hfsplus/unicode_test.c:896:\tresult = hfsplus_asc2uni(\u0026mock_sb-\u003esb,\nfs/hfsplus/unicode_test.c-897-\t\t\t\t \u0026ustr, HFSPLUS_MAX_STRLEN, test_str, 3,\n--\nfs/hfsplus/unicode_test.c-909-/* Test decomposition flag behavior */\nfs/hfsplus/unicode_test.c:910:static void hfsplus_asc2uni_decompose_test(struct kunit *test)\nfs/hfsplus/unicode_test.c-911-{\n--\nfs/hfsplus/unicode_test.c-925-\tclear_bit(HFSPLUS_SB_NODECOMPOSE, \u0026mock_sb-\u003esb_info.flags);\nfs/hfsplus/unicode_test.c:926:\tresult = hfsplus_asc2uni(\u0026mock_sb-\u003esb, \u0026mock_env-\u003estr1,\nfs/hfsplus/unicode_test.c-927-\t\t\t\t HFSPLUS_MAX_STRLEN, \"test\", 4,\n--\nfs/hfsplus/unicode_test.c-934-\tset_bit(HFSPLUS_SB_NODECOMPOSE, \u0026mock_sb-\u003esb_info.flags);\nfs/hfsplus/unicode_test.c:935:\tresult = hfsplus_asc2uni(\u0026mock_sb-\u003esb, \u0026mock_env-\u003estr2,\nfs/hfsplus/unicode_test.c-936-\t\t\t\t HFSPLUS_MAX_STRLEN, \"test\", 4,\n--\nfs/hfsplus/unicode_test.c=972=static int test_uni2char_utf8(wchar_t uni, unsigned char *out, int boundlen)\n--\nfs/hfsplus/unicode_test.c-983-/*\nfs/hfsplus/unicode_test.c:984: * Test that hfsplus_asc2uni() brings combining marks contributed by\nfs/hfsplus/unicode_test.c-985- * different source characters into Unicode canonical (combining-class)\n--\nfs/hfsplus/unicode_test.c-995- */\nfs/hfsplus/unicode_test.c:996:static void hfsplus_asc2uni_combining_reorder_test(struct kunit *test)\nfs/hfsplus/unicode_test.c-997-{\n--\nfs/hfsplus/unicode_test.c-1013-\t/* Typed out of canonical order: must be reordered on storage. */\nfs/hfsplus/unicode_test.c:1014:\tresult = hfsplus_asc2uni(\u0026mock_sb-\u003esb, \u0026ustr, HFSPLUS_MAX_STRLEN,\nfs/hfsplus/unicode_test.c-1015-\t\t\t\t wrong_order, strlen(wrong_order),\n--\nfs/hfsplus/unicode_test.c-1024-\t/* Already in canonical order: must come out unchanged. */\nfs/hfsplus/unicode_test.c:1025:\tresult = hfsplus_asc2uni(\u0026mock_sb-\u003esb, \u0026ustr, HFSPLUS_MAX_STRLEN,\nfs/hfsplus/unicode_test.c-1026-\t\t\t\t canonical_order, strlen(canonical_order),\n--\nfs/hfsplus/unicode_test.c-1037-\t */\nfs/hfsplus/unicode_test.c:1038:\tresult = hfsplus_asc2uni(\u0026mock_sb-\u003esb, \u0026ustr, HFSPLUS_MAX_STRLEN,\nfs/hfsplus/unicode_test.c-1039-\t\t\t\t same_class, strlen(same_class),\n--\nfs/hfsplus/unicode_test.c-1053- * still reads back as valid, correct UTF-8 once reordered - i.e. that\nfs/hfsplus/unicode_test.c:1054: * hfsplus_asc2uni() and hfsplus_uni2asc_str() stay consistent with each\nfs/hfsplus/unicode_test.c-1055- * other across the reordering.\n--\nfs/hfsplus/unicode_test.c=1062=static void hfsplus_unicode_combining_reorder_roundtrip_test(struct kunit *test)\n--\nfs/hfsplus/unicode_test.c-1078-\nfs/hfsplus/unicode_test.c:1079:\tresult = hfsplus_asc2uni(\u0026mock_sb-\u003esb, \u0026ustr, HFSPLUS_MAX_STRLEN,\nfs/hfsplus/unicode_test.c-1080-\t\t\t\t wrong_order, strlen(wrong_order),\n--\nfs/hfsplus/unicode_test.c-1093-/*\nfs/hfsplus/unicode_test.c:1094: * Test that hfsplus_asc2uni() decomposes a character using the corrected\nfs/hfsplus/unicode_test.c-1095- * (post-2002/\"Jaguar\") canonical decomposition even when Apple Technote\n--\nfs/hfsplus/unicode_test.c-1101- */\nfs/hfsplus/unicode_test.c:1102:static void hfsplus_asc2uni_legacy_decomp_test(struct kunit *test)\nfs/hfsplus/unicode_test.c-1103-{\n--\nfs/hfsplus/unicode_test.c-1113-\nfs/hfsplus/unicode_test.c:1114:\tresult = hfsplus_asc2uni(\u0026mock_sb-\u003esb, \u0026ustr, HFSPLUS_MAX_STRLEN,\nfs/hfsplus/unicode_test.c-1115-\t\t\t\t input, strlen(input), HFS_REGULAR_NAME);\n--\nfs/hfsplus/unicode_test.c-1125-/*\nfs/hfsplus/unicode_test.c:1126: * Test that hfsplus_asc2uni() corrects two more of fsck_hfs's known\nfs/hfsplus/unicode_test.c-1127- * legacy decomposition sequences once combining marks from independently\n--\nfs/hfsplus/unicode_test.c-1134- */\nfs/hfsplus/unicode_test.c:1135:static void hfsplus_asc2uni_legacy_seq_fixup_test(struct kunit *test)\nfs/hfsplus/unicode_test.c-1136-{\n--\nfs/hfsplus/unicode_test.c-1147-\nfs/hfsplus/unicode_test.c:1148:\tresult = hfsplus_asc2uni(\u0026mock_sb-\u003esb, \u0026ustr, HFSPLUS_MAX_STRLEN,\nfs/hfsplus/unicode_test.c-1149-\t\t\t\t greek_input, strlen(greek_input),\n--\nfs/hfsplus/unicode_test.c-1156-\nfs/hfsplus/unicode_test.c:1157:\tresult = hfsplus_asc2uni(\u0026mock_sb-\u003esb, \u0026ustr, HFSPLUS_MAX_STRLEN,\nfs/hfsplus/unicode_test.c-1158-\t\t\t\t bengali_input, strlen(bengali_input),\n--\nfs/hfsplus/unicode_test.c=1809=static void hfsplus_compare_dentry_combining_reorder_test(struct kunit *test)\n--\nfs/hfsplus/unicode_test.c-1832- * same character - i.e. that hfsplus_compare_dentry() applies the same\nfs/hfsplus/unicode_test.c:1833: * legacy-decomposition correction as hfsplus_asc2uni() does on storage,\nfs/hfsplus/unicode_test.c-1834- * so a lookup finds the entry regardless of which form was typed.\n--\nfs/hfsplus/unicode_test.c=1857=static struct kunit_case hfsplus_unicode_test_cases[] = {\n--\nfs/hfsplus/unicode_test.c-1866-\tKUNIT_CASE(hfsplus_uni2asc_edge_cases_test),\nfs/hfsplus/unicode_test.c:1867:\tKUNIT_CASE(hfsplus_asc2uni_basic_test),\nfs/hfsplus/unicode_test.c:1868:\tKUNIT_CASE(hfsplus_asc2uni_special_chars_test),\nfs/hfsplus/unicode_test.c:1869:\tKUNIT_CASE(hfsplus_asc2uni_buffer_limits_test),\nfs/hfsplus/unicode_test.c:1870:\tKUNIT_CASE(hfsplus_asc2uni_edge_cases_test),\nfs/hfsplus/unicode_test.c:1871:\tKUNIT_CASE(hfsplus_asc2uni_decompose_test),\nfs/hfsplus/unicode_test.c:1872:\tKUNIT_CASE(hfsplus_asc2uni_combining_reorder_test),\nfs/hfsplus/unicode_test.c-1873-\tKUNIT_CASE(hfsplus_unicode_combining_reorder_roundtrip_test),\nfs/hfsplus/unicode_test.c:1874:\tKUNIT_CASE(hfsplus_asc2uni_legacy_decomp_test),\nfs/hfsplus/unicode_test.c:1875:\tKUNIT_CASE(hfsplus_asc2uni_legacy_seq_fixup_test),\nfs/hfsplus/unicode_test.c-1876-\tKUNIT_CASE(hfsplus_hash_dentry_basic_test),\n"
}

66/3 2026/09/21 03:58 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 43474
							output: 36
							thoughts: 63
						

Thoughts:
Okay, here's my take on those code-level musings, from my own perspective as someone deeply familiar with this domain:

**My Deep Dive into HFS+ Key Construction and Unicode Conversion**

Alright, time to dig in. I need to understand how we're handling the translation between ASCII and Unicode, specifically within the HFS+ context. My primary interest is in the potential interactions between different key building methods and the `hfsplus_asc2uni` function. I'm focusing on those specific points because that's where I believe some subtle bugs could arise.

First, I need to trace the usage of `key->cat.name` or `key->attr.key_name` as arguments to the `hfsplus_asc2uni` function.  I'm betting this is a critical spot for ensuring proper character encoding and avoiding potential corruption, buffer overflows, or unexpected behavior due to differences in character representations. I'll need to see how the naming conventions for catalog entries and attributes are handled when `hfsplus_asc2uni` comes into play.

Then, I'll shift my attention to the key building functions themselves: `hfsplus_cat_build_key` and `hfsplus_attr_build_key`. The specific logic in them needs to be reevaluated in context, as well as their relation to the first point about character encoding. I need to understand exactly how the keys are constructed, what data they include, and most importantly, how those names or keys are getting to the point where they are sent to `hfsplus_asc2uni`. That connection is crucial for pinpointing where vulnerabilities may lay.



67/3 2026/09/21 03:58 tool read-file
0m Args:
{
  "File": "fs/hfsplus/catalog.c",
  "FirstLine": 40,
  "LineCount": 40
}

Results:
{
  "Contents": "  40:\t}\n  41:\t\n  42:\t/* Generates key for catalog file/folders record. */\n  43:\tint hfsplus_cat_build_key(struct super_block *sb,\n  44:\t\t\thfsplus_btree_key *key, u32 parent, const struct qstr *str)\n  45:\t{\n  46:\t\tint len, err;\n  47:\t\n  48:\t\tkey-\u003ecat.parent = cpu_to_be32(parent);\n  49:\t\terr = hfsplus_asc2uni(sb, \u0026key-\u003ecat.name, HFSPLUS_MAX_STRLEN,\n  50:\t\t\t\t      str-\u003ename, str-\u003elen, HFS_REGULAR_NAME);\n  51:\t\tif (unlikely(err \u003c 0))\n  52:\t\t\treturn err;\n  53:\t\n  54:\t\tlen = be16_to_cpu(key-\u003ecat.name.length);\n  55:\t\tkey-\u003ekey_len = cpu_to_be16(6 + 2 * len);\n  56:\t\treturn 0;\n  57:\t}\n  58:\t\n  59:\t/* Generates key for catalog thread record. */\n  60:\tvoid hfsplus_cat_build_key_with_cnid(struct super_block *sb,\n  61:\t\t\t\thfsplus_btree_key *key, u32 parent)\n  62:\t{\n  63:\t\tkey-\u003ecat.parent = cpu_to_be32(parent);\n  64:\t\tkey-\u003ecat.name.length = 0;\n  65:\t\tkey-\u003ekey_len = cpu_to_be16(6);\n  66:\t}\n  67:\t\n  68:\tstatic void hfsplus_cat_build_key_uni(hfsplus_btree_key *key, u32 parent,\n  69:\t\t\t\t\t      struct hfsplus_unistr *name)\n  70:\t{\n  71:\t\tint ustrlen;\n  72:\t\n  73:\t\tustrlen = be16_to_cpu(name-\u003elength);\n  74:\t\tkey-\u003ecat.parent = cpu_to_be32(parent);\n  75:\t\tkey-\u003ecat.name.length = cpu_to_be16(ustrlen);\n  76:\t\tustrlen *= 2;\n  77:\t\tmemcpy(key-\u003ecat.name.unicode, name-\u003eunicode, ustrlen);\n  78:\t\tkey-\u003ekey_len = cpu_to_be16(6 + ustrlen);\n  79:\t}\n"
}

68/3 2026/09/21 03:58 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 44584
							output: 30
							thoughts: 7240
						

Thoughts:
**Deep Dive into HFS+ String Conversion**

Okay, so I've been taking a close look at the HFS+ string conversion routines, specifically how ASCII strings are transformed into Unicode for use in the catalog and attributes. It's crucial to understand this because malformed strings can have security implications. Here’s what I've dissected:

First, let's start with `hfsplus_cat_build_key` and how it calculates the key length, `key->key_len`, based on the resulting Unicode string's length. The code reads the name length, calculates the Unicode length and sets the key length.

The core of the conversion happens in `hfsplus_asc2uni`. It calls `hfsplus_decompose_str` to do the heavy lifting of converting from ASCII to Unicode and handling decomposition (combining characters etc.). `hfsplus_asc2uni` then copies the results into the `hfsplus_unistr` struct. Specifically, `outlen` entries get written to `ustr->unicode`, and `ustr->length` is set to `outlen`.

Now, several things jumped out at me. First, what happens if the input string is empty (`len == 0`)? In this case, `hfsplus_decompose_str` returns 0, and the loop that copies characters does not execute. `ustr->length` becomes 0, and the code appears safe as `buf` is never read from.

Then, I focused on what might happen if the decomposed string has a non-zero length. My concern was about uninitialized reads. `hfsplus_decompose_str` populates `out`. So, I looked at functions that modify `out`: `hfsplus_canonical_reorder` and `hfsplus_fixup_legacy_sequences`. `hfsplus_canonical_reorder` is safe because it only reorders the initialized elements of the string.

`hfsplus_fixup_legacy_sequences` is a little more complex. I need to be sure the function is safe. In the code, `buf` contains initialized elements up to `*len - 1`. The function iterates through potential "legacy" sequences.
If a match is found, the routine performs an in-place replacement. I've confirmed that the replacement sequences in `hfsplus_legacy_seq_fixups` always result in a reduced or constant string length, so there's no way to create an out-of-bounds write or read. `dst` will always be less than or equal to `src`, and no uninitialized memory can be read! The algorithm is safe, and memory remains completely initialized.

Next, I turned my attention to the `hfsplus_decompose_iter` struct. This is used by `hfsplus_decompose_str`. It has an internal buffer `run`. Is there any scenario in which `run` could be read from before being written to? The struct is initialized with length 0 and position 0, so I needed to understand the refill logic. The `refill` function populates the `run` buffer with Unicode characters. Critically, it does *not* zero the `run` array. There are several steps in `refill`:

*   `asc2unichar`: The current character is initialized.
*   The code decides whether to decompose and stores it in `dstr`. `dstr` points to an initialized sequence.
*   If `run_len > 0` and the new character is a non-combining class, the process stops.
*   If the new decomposition exceeds the maximum buffer length, the process stops.
*   The code copies characters from `dstr` into `run`.

The `refill` function is safe: all copied bytes are initialized before being read. Then `hfsplus_canonical_reorder` and `hfsplus_fixup_legacy_sequences` will work on the initialized data!

I need to confirm all the scenarios for the `while` loop within `refill`:
1. If input is empty, while loop doesn't execute and `refill` returns, no read, ok.
2. The loop consumes one or more characters until a non-combining character is read, and `break` is called. The consumed bytes are always initialized, safe.

I made sure I understood how the `if (outlen + dsize > max_len) break;` inside `hfsplus_decompose_str` works. If this check triggers, the loop breaks *without* consuming the input character, and the code returns with `-ENAMETOOLONG`. The caller receives a truncated Unicode string but is also notified of the error and can handle the truncation.

Finally, I checked the callers of `hfsplus_


69/3 2026/09/21 03:59 tool grepper
0m Error:
no matches

Args:
{
  "Expression": "copy_to_user",
  "PathPrefix": "fs/hfsplus"
}

Results:
{
  "error": "no matches"
}

70/3 2026/09/21 03:59 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 52893
							output: 28
							thoughts: 23
						

Thoughts:
Here's my attempt at summarizing the thought process, tailored for an expert audience and written in the first person:

**Investigating HFS+ File System Interactions**

Okay, so I'm looking at something potentially related to file system operations in HFS+. I need to dive into the kernel code and see what's happening. My immediate instinct is to check out the functions that likely handle user-level file writes or directory entry manipulation, specifically within the `fs/hfsplus` directory. The primary candidates that come to mind are `put_user` – because this seems like the likely call to pass data from a user-space buffer to the kernel – and `dir_emit` – which must be the function that actually creates directory entries. I want to see how these calls interact with HFS+ structures and the on-disk format. Understanding their exact implementation should tell me what potential vulnerabilities may arise. Let's start with those.



71/3 2026/09/21 03:59 tool grepper
0m Args:
{
  "Expression": "dir_emit",
  "PathPrefix": "fs/hfsplus"
}

Results:
{
  "Output": "fs/hfsplus/dir.c=130=static int hfsplus_readdir(struct file *file, struct dir_context *ctx)\n--\nfs/hfsplus/dir.c-158-\t\t/* This is completely artificial... */\nfs/hfsplus/dir.c:159:\t\tif (!dir_emit_dot(file, ctx))\nfs/hfsplus/dir.c-160-\t\t\tgoto out;\n--\nfs/hfsplus/dir.c-180-\t\t}\nfs/hfsplus/dir.c:181:\t\tif (!dir_emit(ctx, \"..\", 2,\nfs/hfsplus/dir.c-182-\t\t\t    be32_to_cpu(entry.thread.parentID), DT_DIR))\n--\nfs/hfsplus/dir.c-228-\t\t\t\tgoto next;\nfs/hfsplus/dir.c:229:\t\t\tif (!dir_emit(ctx, strbuf, len,\nfs/hfsplus/dir.c-230-\t\t\t\t    be32_to_cpu(entry.folder.id), DT_DIR))\n--\nfs/hfsplus/dir.c-255-\nfs/hfsplus/dir.c:256:\t\t\tif (!dir_emit(ctx, strbuf, len,\nfs/hfsplus/dir.c-257-\t\t\t\t      be32_to_cpu(entry.file.id), type))\n"
}

72/3 2026/09/21 03:59 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 53507
							output: 344
							thoughts: 2914
						

Thoughts:
**Analysis of Uninitialized Memory Risks in HFS+ Unicode Handling**

Okay, so I've been reviewing this patch, and my initial assessment is that it looks good in terms of uninitialized memory risks. The primary focus of the patch is on enhancing Unicode handling within the HFS+ filesystem, specifically by introducing canonical reordering, decomposition, and legacy sequence fixups. This impacts the `hfsplus_asc2uni`, `hfsplus_hash_dentry`, and `hfsplus_compare_dentry` functions. The `readdir` function, however, remains untouched as it still utilizes `hfsplus_uni2asc` for character set conversion.

I've carefully examined the updated functions. The core of this work lies in how we iterate and process Unicode strings now. The patch introduces a new decomposition iterator (`hfsplus_decompose_iter`) and several helper functions like `hfsplus_decompose_iter_next_folded`, `case_fold`, `hfsplus_combining_class`, `hfsplus_legacy_decompose`, `hfsplus_fixup_legacy_sequences`, and `hfsplus_canonical_reorder`. My main concern is always around whether these introduce any vulnerabilities that could lead to uninitialized memory reads.

Looking at `hfsplus_hash_dentry` and `hfsplus_compare_dentry`, they both utilize this new iterator. I checked through `hfsplus_decompose_iter_next_folded` and `case_fold`, which seems to be safe and deterministic, relying on lookup tables, the main point for potential error. The Kunit tests in `fs/hfsplus/unicode_test.c` are a nice addition and exercise key functions. I looked at the new functions and can confirm that all local variables, array indexes, and loop variables appear to be initialized before use in every code path.

The patch doesn't introduce any new kernel structures sent to user space (nothing through `copy_to_user`, etc.), which is good. There's no dependency on uninitialized variables or struct fields in any conditional logic, a common source of bugs. I checked variables within the newly introduced functions and iterator logic to ensure that everything is properly initialized.

Regarding allocation, there are no dynamic memory allocations, so no heap issues. The code deals with local stack buffers. The key is to check lengths and bounds and I went through each path very carefully. All the functions use local stack buffers with clear lengths and boundaries. In `hfsplus_asc2uni`, the `buf` array, for example, is indexed strictly based on the `outlen` value, which represents the valid length. Similarly, the iterator logic tracks its `run_len` carefully.

The patch correctly calculates lengths, bounds, and string traversal in a way that avoids reading uninitialized bytes from surrounding buffers. In short, the patch carefully tracks the `unicode` length in `hfsplus_compare_dentry` and `hfsplus_hash_dentry`. These functions now ensure that string hashing and comparison are performed via the iterator, without overflowing buffers.

Given all of this, any potential bugs here would most likely be out-of-bounds access or, potentially, infinite loops, and are not specific to uninitialized memory, which is good. The patch does not introduce the need for KMSAN for uninitialized memory checks. KASAN should easily catch anything. My detailed analysis supports a `NeedsKMSAN=false` determination. I'm confident in setting the results accordingly.



73/3 2026/09/21 03:59 tool set-results
0m Args:
{
  "KMSANReasoning": "The patch adds Unicode canonical combining class reordering and legacy sequence fixups to HFS+ filename processing (in hfsplus_asc2uni, hfsplus_hash_dentry, and hfsplus_compare_dentry). \n\nEvaluating KMSAN applicability:\n1. No structures are copied to user space (no copy_to_user, put_user, netlink, or ioctl info-leaks).\n2. Stack buffers introduced (e.g., `buf[HFSPLUS_MAX_STRLEN]` in `hfsplus_asc2uni` and `run[HFSPLUS_CCC_RUN_MAX]` in `struct hfsplus_decompose_iter`) have strictly bounded lengths tracked by `outlen` and `run_len`. In `hfsplus_decompose_str`, `hfsplus_canonical_reorder`, and `hfsplus_decompose_iter_refill`, only the exact elements that have been written are ever read or manipulated.\n3. The catalog key lengths (`ustr-\u003elength`) accurately represent the number of initialized code units written, preventing surrounding code from reading past initialized bytes.\n4. Any potential issues with array indexing, lookups, or `memmove` boundary conditions in sequence substitution are spatial memory safety bugs (out-of-bounds reads/writes), which are directly detected by standard KASAN.\n\nTherefore, the patch does not introduce or expose uninitialized memory risks, and a dedicated KMSAN fuzzing session is not warranted.",
  "NeedsKMSAN": false
}

Results:
{
  "KMSANReasoning": "The patch adds Unicode canonical combining class reordering and legacy sequence fixups to HFS+ filename processing (in hfsplus_asc2uni, hfsplus_hash_dentry, and hfsplus_compare_dentry). \n\nEvaluating KMSAN applicability:\n1. No structures are copied to user space (no copy_to_user, put_user, netlink, or ioctl info-leaks).\n2. Stack buffers introduced (e.g., `buf[HFSPLUS_MAX_STRLEN]` in `hfsplus_asc2uni` and `run[HFSPLUS_CCC_RUN_MAX]` in `struct hfsplus_decompose_iter`) have strictly bounded lengths tracked by `outlen` and `run_len`. In `hfsplus_decompose_str`, `hfsplus_canonical_reorder`, and `hfsplus_decompose_iter_refill`, only the exact elements that have been written are ever read or manipulated.\n3. The catalog key lengths (`ustr-\u003elength`) accurately represent the number of initialized code units written, preventing surrounding code from reading past initialized bytes.\n4. Any potential issues with array indexing, lookups, or `memmove` boundary conditions in sequence substitution are spatial memory safety bugs (out-of-bounds reads/writes), which are directly detected by standard KASAN.\n\nTherefore, the patch does not introduce or expose uninitialized memory risks, and a dedicated KMSAN fuzzing session is not warranted.",
  "NeedsKMSAN": false
}

LLM Calls Summary:
Total Calls Total Tokens Avg Tokens Total Duration (Seconds) Avg Duration (Seconds)
Tool Calls Summary:
Total Calls Total Duration (Seconds) Avg Duration (Seconds)