mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] hfsplus: reorder complete combining runs for dentry keys
@ 2026-11-26 16:07 shaos
  2026-11-27  3:52 ` kernel test robot
  0 siblings, 1 reply; 2+ messages in thread
From: shaos @ 2026-11-26 16:07 UTC (permalink / raw)
  To: slava, glaubitz, frank.li; +Cc: linux-fsdevel, linux-kernel

Hello,

HFS+ catalog names are decomposed and canonically reordered as a complete
string. The dentry iterator reorders a combining run in chunks of 32 code
units. With a 33-mark run, two spellings can produce the same catalog key
but different dentry hashes and comparisons. After creating one spelling,
lookup of the other returns ENOENT until remount.

Use the maximum decomposed HFS+ name length for the iterator buffer so a
representable combining run is reordered as a whole. Add a KUnit regression
test covering dentry hashes, dentry comparison, and the stored Unicode form
of two spellings with a 33-mark run.

The issue affects name lookup on a mounted HFS+ filesystem. The reproducer
shows a stale negative dentry, not a kernel crash or memory-safety violation.

Tested source:
HEAD commit:    8d7fe9885c62fc9a95bf55d9db244d9672a8aadc
git tree:       fe970b05333fb8e41da21e9e289f652abcc7cba7
source version: Linux 7.4.0-rc4
compiler:       gcc 11.4.0, GNU ld 2.38
QEMU:           6.2.0

Reproducer bundle (PoC, image builder, configurations, console output,
QEMU scripts, and KUnit results):
https://gist.github.com/shaos26/bf0227a0628804407940c14be25e4208
Reproduction guide:
https://gist.githubusercontent.com/shaos26/bf0227a0628804407940c14be25e4208/raw/9fdd6f6d081f7b772a03589367a0da955c811ee5/reproduce.md
Baseline console output:
https://gist.githubusercontent.com/shaos26/bf0227a0628804407940c14be25e4208/raw/95967671db4b687ea5305865f3c167e580ed4395/console-output.txt
Kernel configuration:
https://gist.githubusercontent.com/shaos26/bf0227a0628804407940c14be25e4208/raw/120b0b771aeca1f299a6cbc505b25c84c0725b78/kernel-config.txt
Userspace reproducer:
https://gist.githubusercontent.com/shaos26/bf0227a0628804407940c14be25e4208/raw/463437cdfc959b30109c7a2b5ce1871653a55509/poc.c

The unpatched kernel reproduced the lookup failure in two fresh QEMU boots;
the 31-mark control resolved immediately. With the patch, the alternate
spelling resolved immediately in two fresh boots. The hfsplus_unicode KUnit
suite passed all 35 tests. Restoring the old 32-unit limit made the new test
fail on hash equality and dentry comparison (34 passed, 1 failed). The
x86-64 bzImage build completed without warnings. checkpatch.pl with --strict,
git diff --check, and git apply --check all passed.

Fixes: bbe5ebcbc006 ("hfsplus: canonicalize decomposed catalog names like fsck_hfs expects")
Assisted-by: OpenAI Codex
Signed-off-by: shaos <shawnq1@163.com>
---
 fs/hfsplus/unicode.c      | 16 ++++-------
 fs/hfsplus/unicode_test.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 73 insertions(+), 11 deletions(-)

diff --git a/fs/hfsplus/unicode.c b/fs/hfsplus/unicode.c
index 59b8788a69a9e..585f3fd089aac 100644
--- a/fs/hfsplus/unicode.c
+++ b/fs/hfsplus/unicode.c
@@ -577,21 +577,15 @@ int hfsplus_asc2uni(struct super_block *sb,
 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.
+ * A maximal combining run can contain every code unit in an HFS+ catalog
+ * name. Keep the iterator limit aligned with the name limit so it can
+ * reorder the complete run like hfsplus_decompose_str().
  */
-#define HFSPLUS_CCC_RUN_MAX 32
+#define HFSPLUS_CCC_RUN_MAX HFSPLUS_MAX_STRLEN
 
 /*
  * Iterator that produces the canonically-ordered, decomposed code units
- * of a Linux name one at a time, without materializing the whole name.
+ * of a Linux name one combining run at a time.
  * 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
diff --git a/fs/hfsplus/unicode_test.c b/fs/hfsplus/unicode_test.c
index a683c6d5fc221..2e88697bc4e71 100644
--- a/fs/hfsplus/unicode_test.c
+++ b/fs/hfsplus/unicode_test.c
@@ -1479,6 +1479,73 @@ static void hfsplus_hash_dentry_combining_reorder_test(struct kunit *test)
 	free_mock_sb(mock_sb);
 }
 
+static void hfsplus_dentry_combining_reorder_long_test(struct kunit *test)
+{
+	static const char acute[] = "\xcc\x81";
+	static const char dot_below[] = "\xcc\x96";
+	enum { NR_ACUTE = 32, NAME_LEN = 1 + (NR_ACUTE + 1) * 2 + 1 };
+	char acute_first[NAME_LEN], dot_first[NAME_LEN];
+	struct hfsplus_unistr stored1, stored2;
+	struct test_mock_sb *mock_sb;
+	struct qstr str1, str2;
+	char *p;
+	int i, 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;
+
+	p = acute_first;
+	*p++ = 'e';
+	for (i = 0; i < NR_ACUTE; i++) {
+		memcpy(p, acute, sizeof(acute) - 1);
+		p += sizeof(acute) - 1;
+	}
+	memcpy(p, dot_below, sizeof(dot_below) - 1);
+	p += sizeof(dot_below) - 1;
+	*p = '\0';
+
+	p = dot_first;
+	*p++ = 'e';
+	memcpy(p, dot_below, sizeof(dot_below) - 1);
+	p += sizeof(dot_below) - 1;
+	for (i = 0; i < NR_ACUTE; i++) {
+		memcpy(p, acute, sizeof(acute) - 1);
+		p += sizeof(acute) - 1;
+	}
+	*p = '\0';
+
+	create_qstr(&str1, acute_first);
+	create_qstr(&str2, dot_first);
+	result = hfsplus_hash_dentry(&test_dentry, &str1);
+	KUNIT_ASSERT_EQ(test, 0, result);
+	result = hfsplus_hash_dentry(&test_dentry, &str2);
+	KUNIT_ASSERT_EQ(test, 0, result);
+	KUNIT_EXPECT_EQ(test, str1.hash, str2.hash);
+
+	KUNIT_EXPECT_EQ(test, 0,
+			hfsplus_compare_dentry(&test_dentry, str1.len,
+					       str1.name, &str2));
+
+	result = hfsplus_asc2uni(&mock_sb->sb, &stored1, HFSPLUS_MAX_STRLEN,
+				 str1.name, str1.len, HFS_REGULAR_NAME);
+	KUNIT_ASSERT_EQ(test, 0, result);
+	result = hfsplus_asc2uni(&mock_sb->sb, &stored2, HFSPLUS_MAX_STRLEN,
+				 str2.name, str2.len, HFS_REGULAR_NAME);
+	KUNIT_ASSERT_EQ(test, 0, result);
+	KUNIT_EXPECT_EQ(test, be16_to_cpu(stored1.length),
+			be16_to_cpu(stored2.length));
+	KUNIT_EXPECT_EQ(test, 34, be16_to_cpu(stored1.length));
+	KUNIT_EXPECT_EQ(test,
+			memcmp(stored1.unicode, stored2.unicode,
+			       be16_to_cpu(stored1.length) * sizeof(stored1.unicode[0])),
+			0);
+
+	free_mock_sb(mock_sb);
+}
+
 /* Test hfsplus_compare_dentry basic functionality */
 static void hfsplus_compare_dentry_basic_test(struct kunit *test)
 {
@@ -1880,6 +1947,7 @@ static struct kunit_case hfsplus_unicode_test_cases[] = {
 	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_dentry_combining_reorder_long_test),
 	KUNIT_CASE(hfsplus_compare_dentry_basic_test),
 	KUNIT_CASE(hfsplus_compare_dentry_casefold_test),
 	KUNIT_CASE(hfsplus_compare_dentry_special_chars_test),


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

* Re: [PATCH] hfsplus: reorder complete combining runs for dentry keys
  2026-11-26 16:07 [PATCH] hfsplus: reorder complete combining runs for dentry keys shaos
@ 2026-11-27  3:52 ` kernel test robot
  0 siblings, 0 replies; 2+ messages in thread
From: kernel test robot @ 2026-11-27  3:52 UTC (permalink / raw)
  To: shaos, slava, glaubitz, frank.li
  Cc: oe-kbuild-all, linux-fsdevel, linux-kernel

Hi shaos,

kernel test robot noticed the following build warnings:

[auto build test WARNING on brauner-vfs/vfs.all]
[also build test WARNING on linus/master v7.4-rc4 next-20261126]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/shaos/hfsplus-reorder-complete-combining-runs-for-dentry-keys/20261126-160720
base:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git vfs.all
patch link:    https://lore.kernel.org/r/20261126160720.3007837-1-shawnq1%40163.com
patch subject: [PATCH] hfsplus: reorder complete combining runs for dentry keys
config: arm-allyesconfig (https://download.01.org/0day-ci/archive/20261127/20261127114353.IlT3o2gb-lkp@intel.com/config)
compiler: arm-linux-gnueabi-gcc (GCC) 16.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261127/20261127114353.IlT3o2gb-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/20261127114353.IlT3o2gb-lkp@intel.com/

All warnings (new ones prefixed by >>):

   fs/hfsplus/unicode.c: In function 'hfsplus_compare_dentry':
>> fs/hfsplus/unicode.c:747:1: warning: the frame size of 1456 bytes is larger than 1280 bytes [-Wframe-larger-than=]
     747 | }
         | ^
--
   fs/hfsplus/unicode_test.c: In function 'hfsplus_dentry_combining_reorder_long_test':
>> fs/hfsplus/unicode_test.c:1547:1: warning: the frame size of 1680 bytes is larger than 1280 bytes [-Wframe-larger-than=]
    1547 | }
         | ^


vim +747 fs/hfsplus/unicode.c

d45bce8faf5551 Duane Griffin      2007-07-15  721  
d45bce8faf5551 Duane Griffin      2007-07-15  722  /*
d45bce8faf5551 Duane Griffin      2007-07-15  723   * Compare strings with HFS+ filename ordering.
d45bce8faf5551 Duane Griffin      2007-07-15  724   * Composed unicode characters are decomposed and case-folding is performed
d45bce8faf5551 Duane Griffin      2007-07-15  725   * if the appropriate bits are (un)set on the superblock.
d45bce8faf5551 Duane Griffin      2007-07-15  726   */
6fa67e70755930 Al Viro            2016-07-31  727  int hfsplus_compare_dentry(const struct dentry *dentry,
621e155a359196 Nicholas Piggin    2011-01-07  728  		unsigned int len, const char *str, const struct qstr *name)
d45bce8faf5551 Duane Griffin      2007-07-15  729  {
d3fe19852e96aa Al Viro            2016-07-29  730  	struct super_block *sb = dentry->d_sb;
bbe5ebcbc006ac Viacheslav Dubeyko 2026-09-18  731  	int casefold = test_bit(HFSPLUS_SB_CASEFOLD, &HFSPLUS_SB(sb)->flags);
bbe5ebcbc006ac Viacheslav Dubeyko 2026-09-18  732  	struct hfsplus_decompose_iter it1, it2;
d45bce8faf5551 Duane Griffin      2007-07-15  733  
bbe5ebcbc006ac Viacheslav Dubeyko 2026-09-18  734  	hfsplus_decompose_iter_init(&it1, sb, str, len, HFS_REGULAR_NAME);
bbe5ebcbc006ac Viacheslav Dubeyko 2026-09-18  735  	hfsplus_decompose_iter_init(&it2, sb, name->name, name->len,
897c2beb4a7799 Viacheslav Dubeyko 2026-03-23  736  				    HFS_REGULAR_NAME);
d45bce8faf5551 Duane Griffin      2007-07-15  737  
bbe5ebcbc006ac Viacheslav Dubeyko 2026-09-18  738  	while (1) {
bbe5ebcbc006ac Viacheslav Dubeyko 2026-09-18  739  		int c1 = hfsplus_decompose_iter_next_folded(&it1, casefold);
bbe5ebcbc006ac Viacheslav Dubeyko 2026-09-18  740  		int c2 = hfsplus_decompose_iter_next_folded(&it2, casefold);
d45bce8faf5551 Duane Griffin      2007-07-15  741  
bbe5ebcbc006ac Viacheslav Dubeyko 2026-09-18  742  		if (c1 < 0 || c2 < 0)
bbe5ebcbc006ac Viacheslav Dubeyko 2026-09-18  743  			return c1 == c2 ? 0 : (c1 < 0 ? -1 : 1);
bbe5ebcbc006ac Viacheslav Dubeyko 2026-09-18  744  		if (c1 != c2)
bbe5ebcbc006ac Viacheslav Dubeyko 2026-09-18  745  			return c1 < c2 ? -1 : 1;
bbe5ebcbc006ac Viacheslav Dubeyko 2026-09-18  746  	}
d45bce8faf5551 Duane Griffin      2007-07-15 @747  }

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

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

end of thread, other threads:[~2026-11-27  3:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-26 16:07 [PATCH] hfsplus: reorder complete combining runs for dentry keys shaos
2026-11-27  3:52 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®