From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.173 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796171882; b=wUnmePvLpHeUwefjXZIUDdHxmsN/NOPhb5ILKC0r+0l992WCN3pEixiHQmwt4D+PhByL 0YEUAJK7PzNKpgIlxtNJrS3mDhDf3rJZ+h9PZUuSh7OnnaFtDX3ntlGBfgt7syWBEXelM bp6UsufG/guqX3SO3lE3j8zAg2IH9YTldlTx60Qc6OVuwZWa3DPppvwX9Zo55tRBNoSsB 70uosQ1toerLB9uRc9qSROaaKtARv6Z1N9jl+vTvon4pxT+j/1GHJsHv781rtwJLyFQIm i2X8iGP3pIvgnVVZEynWhvOs4NlzvmMVK84B/fMjPYQA5UiRElBHwUBeoOqvNK+dmmw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796171882; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References:Autocrypt: Content-Type:Content-Transfer-Encoding:User-Agent:MIME-Version; bh=vPb4gTPoBIBjnrXcd1tX+v8Fx9vD9KB5g44sWXnfp2Y=; b=5G3sGT74gla7S8bywmHtZsRKfzmKAAL3D4FfHQBYc4kCmffwhDZ2m+Kc09OZisqUKjwg iGJBpP5BtIC3LrwSR4kZHTI29dDn6O/B6ShSbCiy2pRWNQNrDPtzyLn3j1/2XXXzmsd8L MPZD/3eJD4hCmVwzxUI/h60wNMH9qm9nk/VREA7BY63PV5fdmplA9AAWDRSoKk4R7uG7g szxTixPrZYImbl8Q7LU4lpULjvEcqXM9RleTRlnF2fP0uDf3XOrVAyE/1n9r3go87JTn1 zj0msn7Srt5lyikIuRNhTzrUzMxBeLRdkShMRJOujgGEP0TeY5xRUmnLnvt/7J1HWAw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=dubeyko.com; spf=pass smtp.mailfrom=dubeyko.com; dkim=pass header.d=dubeyko-com.20260707.gappssmtp.com header.i=@dubeyko-com.20260707.gappssmtp.com header.a=rsa-sha256 header.s=20260707 header.b="JDfz6/Ly"; arc=none smtp.remote-ip=209.85.128.173 Received: from mail-yw1-f173.google.com (mail-yw1-f173.google.com [209.85.128.173]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A6783606A31A for ; Wed, 2 Dec 2026 00:38:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A6783606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=dubeyko.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=dubeyko.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=dubeyko-com.20260707.gappssmtp.com header.i=@dubeyko-com.20260707.gappssmtp.com header.a=rsa-sha256 header.s=20260707 header.b=JDfz6/Ly Received: by mail-yw1-f173.google.com with SMTP id 00721157ae682-8b10d24345dso113587647b3.3 for ; Tue, 01 Dec 2026 16:38:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dubeyko-com.20260707.gappssmtp.com; s=20260707; t=1796171879; x=1796776679; darn=vger.kernel.org; h=mime-version:user-agent:content-transfer-encoding:content-type :autocrypt:references:in-reply-to:date:cc:to:from:subject:message-id :from:to:cc:subject:date:message-id:reply-to:content-type; bh=vPb4gTPoBIBjnrXcd1tX+v8Fx9vD9KB5g44sWXnfp2Y=; b=JDfz6/LyYqsuRCoH/R2fZmZkZDv8Z7xNFK0Fdh1aCNJUyuxYFBC99HKcg7lgwTyR0P T8qB+V/zzCSKXCNmUXbME7ghdXmCAOFCZHke6jlQpKBP2kGUyA7DaeWsLUduCQvpzp3j LV3/jQEg9FT0nLT83cnPHcd3E7TZlKxoY5TxJUj3MlXkohKgyQIYlD5FA1dbYUJSpy+D riUBMZF+PfPMg/ezjtGR/tdjbJoOdwW0J4Bd5U5OyukMttX7zgymCtOiW58LeyuNby7c dZZTDEuvebAuGDka2WETGYyxwK2wsNSHccDxeArEOVEk4qwdZ/qi3ioSSCJ6PpZ9UE3M mffA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796171879; x=1796776679; h=mime-version:user-agent:content-transfer-encoding:content-type :autocrypt:references:in-reply-to:date:cc:to:from:subject:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=vPb4gTPoBIBjnrXcd1tX+v8Fx9vD9KB5g44sWXnfp2Y=; b=KsYCmTzW6Elg4J5hv08e25Vjrf+K3uPw6qz46s028HiDwXi/AlcENM4bnlBrnEp3mT kRZYWeZSnAWYdbPOYjqBKhLAA+29cZlAXEqkYb7l0RoitleEyWZZ3xuu3wVJtkZ85AIl gdkEcZY68L8d8nN1C5Q5F+hUN5Zvziv+VOep4+N1qQj8hbfqzxze63i4JW1TwbZxvG5G iCdv9eD8+FJwkGqYMlTEXgAHx9FXKnu0KQuOhHMYHtPtjcLsikO6yfVDKBGijgKqaeKq uAgu06Cft0UAAsq9zFrtflWM2CMfYOvQ0mXm2npUfJ8MpeOEv5tsGp4nkdz+mEdJXu+K hReQ== X-Forwarded-Encrypted: i=1; AL+hErETzWruUQLqIexNyGHxoKfpWkHEMSsAQEBQtKXNz9vDa6PLAUe6+WjjRVJn5wa/kfVrIFUgyrViilne3tI=@vger.kernel.org X-Gm-Message-State: APuU4Z+5bccixGF0IBKOjVPp/Gy1tNmmZhA5/Kjk30Vf9wxSnqjLg0w+ nKzrq/yJYUawpqVI2VveI2E9Smbu2XssctcjS6HxQC6S7XPvB/66+WYES6qFqsEkqJ0= X-Gm-Gg: AZFdTZdR1MUxTWgbENX3NtKriPIBz+MAJfjrooc7DzAHbQDdMSkkH5Po2Km+bA44j4V /RsnUl4etl0srfQIvGQfnIGBsNSe1Twt7jpqZrjx4MT9SeVMdGjxwOcdQd+hc7sBJn4obIKFA4p lNVL+fQABZG4ocQXQRLNWN0rL/eYL0YzNE1O/X0JpblH1XhbaEwj+VwbBO5xrVNktGYHcR4BG94 QtOTZYXzqycu5DUsROmOXf0VXY9dg768YKI9nShtdiDoY5KiXHrkn09cEt7TbNsjBetq3y7p21O XmEHAmvEFRcyUcJIunYWvw4UfyHQftAy2IkkNOpk8ODgXMRmSQc9SgAoL4KUueyvcbQK7E4Zrk8 0jZh+654XaxIcD6/Nzcdka0wlVxO2BF8Q6vAtAo91Gr1mcTCdv51lvmSP+3LK35Pe0kmdgVNlFD U6yhf2Je2KA7LFPo5+UyaNS+CaQQKOWXDPZfRQq3fD87OV4Y+QtWy21jrRmcawDRv13+x6ccPof 6ZBo1fMhqnAH3QA1v7ZFvg2amgc5yU9FvJx3G1LQ7zrW4fG8q+QmXkuR81HR348gh2we6HNQUfl sxe2KS4TFgfd2Gfs44z4/yOSB2n7FB2q7raQPLg/rkwxqQV9C6d+838RFSrJ7N7/4BSdkXtuNyA OgrEY3HGcmzjQ/waMlSOGM6D/MtqGz3LPsfg4OwL4vL4YyNCvINow7OPgY1pHhNMncJPQsw== X-Received: by 2002:a05:690c:74c4:b0:8b4:cc58:78da with SMTP id 00721157ae682-8b52046bffamr161374457b3.24.1796171879398; Tue, 01 Dec 2026 16:37:59 -0800 (PST) Received: from system76-laptop.attlocal.net ([2600:1700:6476:1430:f726:86c4:c7ef:c27]) by smtp.gmail.com with ESMTPSA id 00721157ae682-8b5203325adsm151749407b3.37.2026.12.01.16.37.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 16:37:58 -0800 (PST) Message-ID: <4d40982a598dff9bc50fccbaee34a313fb896fb0.camel@dubeyko.com> Subject: Re: [PATCH v3] hfsplus: reorder complete combining runs for dentry keys From: Viacheslav Dubeyko To: Shawn Shao Cc: John Paul Adrian Glaubitz , Yangtao Li , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Date: Tue, 01 Dec 2026 16:37:57 -0800 In-Reply-To: <179613469562.187341.17619275012718061046.1796134695.7-1-shawnq1@163.com> References: <20261126160720.3007837-1-shawnq1@163.com> <20261130074816.2537284-1-shawnq1@163.com> <16d041e4b01dc83a82168696742c731710f4db69.camel@dubeyko.com> <179613469562.187341.17619275012718061046.1796134695.7-1-shawnq1@163.com> Autocrypt: addr=slava@dubeyko.com; prefer-encrypt=mutual; keydata=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 NFdvziOa4FgUBC4X71upsZIoZJeii2V/Jtc3B4g== Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.56.2-9 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 On Tue, 2026-12-01 at 14:18 +0000, Shawn Shao wrote: > Hello, >=20 > Thanks for asking for a clearer explanation. HFSPLUS_MAX_STRLEN is Please, send it as formal patch. > the > maximum number of UTF-16 code units in an HFS+ catalog name. The > catalog > conversion decomposes and canonically reorders names within this > bound. > Dentry hashing and comparison must use the same ordering for every > name > that the catalog conversion accepts. >=20 > The iterator's 32-unit limit splits a longer combining run. If a > later > mark has a lower combining class than marks in the earlier chunk, it > cannot be moved before those marks. Two spellings that convert to the > same catalog key can then get different dentry hashes or compare > unequal. > Using HFSPLUS_MAX_STRLEN lets the iterator reorder any run within the > accepted catalog-name limit; it does not increase that limit. OK. I think that bug takes place. But I cannot accept the fix. The run[] grows from 64 to 510 bytes per iterator. hfsplus_compare_dentry() keeps two iterators (it1, it2) on its stack, so it needs about 1.1 KB. It runs as ->d_compare in RCU path walk, often deep in the call stack. Canonical reordering is a stable sort by combining class. A long run can be produced in order without buffering it: remember where the run starts in the input, then for each class present, in ascending order, rescan the run and emit the marks of that class. That uses constant memory and only costs anything for these pathological runs. A simpler alternative: keep the 32-unit fast path and, when a run overflows, decompose the whole name in a slow path. It has to work without sleeping in RCU walk; on failure it can return -ECHILD from a non-RCU context, or the reorder can be bounded some other way. Please, rework the patch. Thanks, Slava. >=20 > The KUnit test uses two spellings that differ only in the order of a > 33-mark combining run. `hfsplus_asc2uni()` stores both as the same > canonical key, so hashing and dentry comparison must also treat them > as > equal. With the old 32-unit limit, the iterator sorts the run in two > pieces and the test catches the resulting hash/comparison mismatch. > This exercises the exact boundary that caused the bug without needing > a > mounted image. > The QEMU reproducer also checks the lookup behavior before and after > the > change. >=20 > Tested source: > HEAD commit:=C2=A0=C2=A0=C2=A0 d536283b12c4597f8fc8cc65a034edb8753a9880 > Git tree:=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 7399834a6b1da5c9c4c420886536a105b= 63eff89 > Source:=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 HFS for-next, Linux 7.4= .0-rc1 > Compiler:=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 gcc 11.4.0, GNU ld 2.38 > QEMU:=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 6.2.0, x86-64= TCG >=20 > Reproducer and test results: > https://gist.github.com/shaos26/73b61181ce48283492d2a10f69bb11eb >=20 > console output: > https://gist.githubusercontent.com/shaos26/73b61181ce48283492d2a10f69bb11= eb/raw/e7d209d77bd88674ea5306b437539d8f1c02693b/console-output.txt > kernel configuration: > https://gist.githubusercontent.com/shaos26/73b61181ce48283492d2a10f69bb11= eb/raw/e7d209d77bd88674ea5306b437539d8f1c02693b/kernel-config.txt > userspace reproducer: > https://gist.githubusercontent.com/shaos26/73b61181ce48283492d2a10f69bb11= eb/raw/e7d209d77bd88674ea5306b437539d8f1c02693b/poc.c > HFS+ image builder: > https://gist.githubusercontent.com/shaos26/73b61181ce48283492d2a10f69bb11= eb/raw/e7d209d77bd88674ea5306b437539d8f1c02693b/make_hfsplus.c > initramfs init: > https://gist.githubusercontent.com/shaos26/73b61181ce48283492d2a10f69bb11= eb/raw/e7d209d77bd88674ea5306b437539d8f1c02693b/init > initramfs builder: > https://gist.githubusercontent.com/shaos26/73b61181ce48283492d2a10f69bb11= eb/raw/e7d209d77bd88674ea5306b437539d8f1c02693b/build-initramfs.sh > QEMU runner: > https://gist.githubusercontent.com/shaos26/73b61181ce48283492d2a10f69bb11= eb/raw/e7d209d77bd88674ea5306b437539d8f1c02693b/run-qemu.sh > KUnit configuration: > https://gist.githubusercontent.com/shaos26/73b61181ce48283492d2a10f69bb11= eb/raw/e7d209d77bd88674ea5306b437539d8f1c02693b/kunit-config.txt > KUnit results: > https://gist.githubusercontent.com/shaos26/73b61181ce48283492d2a10f69bb11= eb/raw/e7d209d77bd88674ea5306b437539d8f1c02693b/kunit-results.txt >=20 > Build the HFS for-next tree at the tested revision and run the > baseline: >=20 > =C2=A0=C2=A0=C2=A0 git clone \ > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 > https://git.kernel.org/pub/scm/linux/kernel/git/vdubeyko/hfs.git=C2=A0lin= u > x > =C2=A0=C2=A0=C2=A0 cd linux > =C2=A0=C2=A0=C2=A0 git checkout d536283b12c4597f8fc8cc65a034edb8753a9880 > =C2=A0=C2=A0=C2=A0 mkdir build > =C2=A0=C2=A0=C2=A0 cp ../kernel-config.txt build/.config > =C2=A0=C2=A0=C2=A0 make O=3Dbuild olddefconfig > =C2=A0=C2=A0=C2=A0 make O=3Dbuild -j"$(nproc)" bzImage > =C2=A0=C2=A0=C2=A0 cd .. > =C2=A0=C2=A0=C2=A0 gcc -O2 -Wall -Wextra -Werror -o make_hfsplus make_hfs= plus.c > =C2=A0=C2=A0=C2=A0 ./make_hfsplus hfsplus.img > =C2=A0=C2=A0=C2=A0 sh ./build-initramfs.sh initramfs.cpio.gz > =C2=A0=C2=A0=C2=A0 sh ./run-qemu.sh linux/build/arch/x86/boot/bzImage \ > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 initramfs.cpio.gz hfsplus.img = baseline.log vulnerable >=20 > The baseline reports POS_BAD_AFTER_CREATE=3D0 and > POS_BAD_AFTER_REMOUNT=3D1; the 31-mark control resolves immediately. > After applying the patch below and rebuilding, run: >=20 > =C2=A0=C2=A0=C2=A0 sh ./run-qemu.sh linux/build/arch/x86/boot/bzImage \ > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 initramfs.cpio.gz hfsplus.img = fixed.log fixed >=20 > The fixed run reports POS_BAD_AFTER_CREATE=3D1 and the fixed oracle > passes. > The x86-64 build also completed with CONFIG_FRAME_WARN=3D1280 and > KCFLAGS=3D-Wframe-larger-than=3D1280 without frame-size warnings. Run the > KUnit regression suite with: >=20 > =C2=A0=C2=A0=C2=A0 cd linux > =C2=A0=C2=A0=C2=A0 python3 tools/testing/kunit/kunit.py run \ > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 --build_dir=3Dbuild-kunit --ku= nitconfig=3D../kunit-config.txt \ > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 --jobs=3D"$(nproc)" hfsplus_un= icode --summary >=20 > The hfsplus_unicode suite passed all 36 tests. >=20 > Changes in v3: > - Explain why the iterator limit follows HFSPLUS_MAX_STRLEN. > - Base the patch on the HFS for-next tree and use its renamed KUnit > file. > - Make the reproducer report separate vulnerable and fixed oracles. >=20 > Fixes: bbe5ebcbc006 ("hfsplus: canonicalize decomposed catalog names > like fsck_hfs expects") > Thanks, > Shawn Shao >=20 > Signed-off-by: Shawn Shao > --- > =C2=A0fs/hfsplus/hfsplus_unicode_test.c | 73 > +++++++++++++++++++++++++++++++++++++++ > =C2=A0fs/hfsplus/unicode.c=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | 19 +++++------ > =C2=A02 files changed, 80 insertions(+), 12 deletions(-) >=20 > diff --git a/fs/hfsplus/hfsplus_unicode_test.c > b/fs/hfsplus/hfsplus_unicode_test.c > index cb237a40c..80ba1d499 100644 > --- a/fs/hfsplus/hfsplus_unicode_test.c > +++ b/fs/hfsplus/hfsplus_unicode_test.c > @@ -1533,6 +1533,78 @@ static void > hfsplus_hash_dentry_combining_reorder_test(struct kunit *test) > =C2=A0 free_mock_sb(mock_sb); > =C2=A0} > =C2=A0 > +static void hfsplus_dentry_combining_reorder_long_test(struct kunit > *test) > +{ > + static const char acute[] =3D "\xcc\x81"; > + static const char dot_below[] =3D "\xcc\x96"; > + enum { NR_ACUTE =3D 32, NAME_LEN =3D 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 =3D setup_mock_sb(); > + KUNIT_ASSERT_NOT_NULL(test, mock_sb); > + > + stored1 =3D kunit_kzalloc(test, sizeof(*stored1), GFP_KERNEL); > + KUNIT_ASSERT_NOT_NULL(test, stored1); > + stored2 =3D kunit_kzalloc(test, sizeof(*stored2), GFP_KERNEL); > + KUNIT_ASSERT_NOT_NULL(test, stored2); > + > + setup_mock_dentry(&mock_sb->sb); > + mock_sb->nls.char2uni =3D test_char2uni_utf8; > + > + p =3D acute_first; > + *p++ =3D 'e'; > + for (i =3D 0; i < NR_ACUTE; i++) { > + memcpy(p, acute, sizeof(acute) - 1); > + p +=3D sizeof(acute) - 1; > + } > + memcpy(p, dot_below, sizeof(dot_below) - 1); > + p +=3D sizeof(dot_below) - 1; > + *p =3D '\0'; > + > + p =3D dot_first; > + *p++ =3D 'e'; > + memcpy(p, dot_below, sizeof(dot_below) - 1); > + p +=3D sizeof(dot_below) - 1; > + for (i =3D 0; i < NR_ACUTE; i++) { > + memcpy(p, acute, sizeof(acute) - 1); > + p +=3D sizeof(acute) - 1; > + } > + *p =3D '\0'; > + > + create_qstr(&str1, acute_first); > + create_qstr(&str2, dot_first); > + result =3D hfsplus_hash_dentry(&test_dentry, &str1); > + KUNIT_ASSERT_EQ(test, 0, result); > + result =3D 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, > + =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 str1.name, &str2)); > + > + result =3D hfsplus_asc2uni(&mock_sb->sb, stored1, > HFSPLUS_MAX_STRLEN, > + str1.name, str1.len, > HFS_REGULAR_NAME); > + KUNIT_ASSERT_EQ(test, 0, result); > + result =3D 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, > + =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 be16_to_cpu(stored1->length) * > sizeof(stored1->unicode[0])), > + 0); > + > + free_mock_sb(mock_sb); > +} > + > =C2=A0/* Test hfsplus_compare_dentry basic functionality */ > =C2=A0static void hfsplus_compare_dentry_basic_test(struct kunit *test) > =C2=A0{ > @@ -1935,6 +2007,7 @@ static struct kunit_case > hfsplus_unicode_test_cases[] =3D { > =C2=A0 KUNIT_CASE(hfsplus_hash_dentry_consistency_test), > =C2=A0 KUNIT_CASE(hfsplus_hash_dentry_edge_cases_test), > =C2=A0 KUNIT_CASE(hfsplus_hash_dentry_combining_reorder_test), > + KUNIT_CASE(hfsplus_dentry_combining_reorder_long_test), > =C2=A0 KUNIT_CASE(hfsplus_compare_dentry_basic_test), > =C2=A0 KUNIT_CASE(hfsplus_compare_dentry_casefold_test), > =C2=A0 KUNIT_CASE(hfsplus_compare_dentry_special_chars_test), > diff --git a/fs/hfsplus/unicode.c b/fs/hfsplus/unicode.c > index 59b8788a6..840a11560 100644 > --- a/fs/hfsplus/unicode.c > +++ b/fs/hfsplus/unicode.c > @@ -577,21 +577,15 @@ int hfsplus_asc2uni(struct super_block *sb, > =C2=A0EXPORT_SYMBOL_IF_KUNIT(hfsplus_asc2uni); > =C2=A0 > =C2=A0/* > - * 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(). > =C2=A0 */ > -#define HFSPLUS_CCC_RUN_MAX 32 > +#define HFSPLUS_CCC_RUN_MAX HFSPLUS_MAX_STRLEN > =C2=A0 > =C2=A0/* > =C2=A0 * 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. > =C2=A0 * hfsplus_hash_dentry() and hfsplus_compare_dentry() use this so > that > =C2=A0 * hashing and comparison always agree with what hfsplus_asc2uni() > would > =C2=A0 * actually store, while still comparing lazily (stopping at the > first > @@ -630,7 +624,8 @@ static void hfsplus_decompose_iter_init(struct > hfsplus_decompose_iter *it, > =C2=A0 * we know the class of the first unit it produces, so decoding it > is > =C2=A0 * speculative until that's decided. > =C2=A0 */ > -static bool hfsplus_decompose_iter_refill(struct > hfsplus_decompose_iter *it) > +static noinline_for_stack bool > +hfsplus_decompose_iter_refill(struct hfsplus_decompose_iter *it) > =C2=A0{ > =C2=A0 it->run_pos =3D 0; > =C2=A0 it->run_len =3D 0;