fsck: detect case-insensitive duplicate filenames
Subsystems (2)
PATCH 1/1 fsck: detect case-insensitive duplicate filenames
exFAT file names are case-insensitive, but filter_lookup_file() compares them with memcmp(). This makes fsck miss duplicate names that differ only in case.
Keep memcmp() as the fast path and fall back to the volume upcase table. Add a regression image for case-insensitive duplicate names.
--- lib/exfat_dir.c | 24 ++++++++++++++++-- .../duplicated_name_casefold/exfat.img.tar.xz | Bin 0 -> 3808 bytes 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 tests/duplicated_name_casefold/exfat.img.tar.xz
lib/exfat_dir.c +22 -2
@@ -551,6 +551,7 @@ static int filter_lookup_file(struct exfat_de_iter *de_iter,for (i =2 ; i <= file_de->dentry.file.num_ext && name_len >0 ; i++) {int len; +int j; retval =exfat_de_iter_get (de_iter, i, &name_de);if (retval || name_de->type !=EXFAT_NAME )
@@ -558,8 +559,27 @@ static int filter_lookup_file(struct exfat_de_iter *de_iter, len =MIN (name_len +1 ,ENTRY_NAME_MAX );if (memcmp (name_de->dentry.name.unicode_0_14, - name, len *2 ) !=0 ) -return 1 ; + name, len *sizeof (*name)) !=0 ) { +__le16 dentry_name[ENTRY_NAME_MAX ]; + +memcpy (dentry_name, name_de->dentry.name.unicode_0_14, +sizeof (dentry_name)); +/* +* exFAT file names are case-insensitive according to the +* volume upcase table. Keep the exact comparison as the fast +* path, then compare the canonical characters when the on-disk +* spelling differs. +*/ +for (j =0 ; j < len; j++) { +__u16 dentry_ch = de_iter->exfat->upcase_table[ +le16_to_cpu (dentry_name[j])]; +__u16 name_ch = de_iter->exfat->upcase_table[ +le16_to_cpu (name[j])]; + +if (dentry_ch != name_ch) +return 1 ; + } + } name += len; name_len -= len;
tests/duplicated_name_casefold/exfat.img.tar.xz new file binary +0 -0
Signature · 1 line
2.34.1
Namjae Jeon
maintainerQuoted 37 lines · Yang Wen
exFAT file names are case-insensitive, but
filter_lookup_file()compares them withmemcmp(). This makes fsck miss duplicate names that differ only in case.Keep
memcmp()as the fast path and fall back to the volume upcase table. Add a regression image for case-insensitive duplicate names.Signed-off-by Yang Wen <[email protected]>--- lib/exfat_dir.c | 24 ++++++++++++++++-- .../duplicated_name_casefold/exfat.img.tar.xz | Bin 0 -> 3808 bytes 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 tests/duplicated_name_casefold/exfat.img.tar.xzlib/exfat_dir.c +5
-2@@ -551,6 +551,7 @@ static int filter_lookup_file(struct exfat_de_iter *de_iter,for (i =2 ; i <= file_de->dentry.file.num_ext && name_len >0 ; i++) {int len; +int j; retval =exfat_de_iter_get (de_iter, i, &name_de);if (retval || name_de->type !=EXFAT_NAME )@@ -558,8 +559,27 @@ static int filter_lookup_file(struct exfat_de_iter *de_iter, len =MIN (name_len +1 ,ENTRY_NAME_MAX );if (memcmp (name_de->dentry.name.unicode_0_14, - name, len *2 ) !=0 ) -return 1 ; + name, len *sizeof (*name)) !=0 ) { +__le16 dentry_name[ENTRY_NAME_MAX ]; + + memcpy(dentry_name, name_de->dentry.name.unicode_0_14,
lib/exfat_dir.c static int filter_lookup_file(struct exfat_de_iter *de_iter, · line 575
Quoted 10 lines
lib/exfat_dir.c +10
-0+ sizeof(dentry_name)); +/* +* exFAT file names are case-insensitive according to the +* volume upcase table. Keep the exact comparison as the fast +* path, then compare the canonical characters when the on-disk +* spelling differs. +*/ +for (j =0 ; j < len; j++) { +__u16 dentry_ch = de_iter->exfat->upcase_table[ +le16_to_cpu (dentry_name[j])];
dump.exfat calls exfat_lookup_file_by_utf16name() with upcase_table still NULL. If an earlier directory entry has a different name of the same length, memcmp() reports a mismatch and the lookup dereferences NULL here. I reproduced the crash with dump.exfat -d while looking up an existing file on a clean image. Please return 1 on a memcmp() mismatch when upcase_table is NULL.
$ sudo mount -t exfat /dev/sdc1 /mnt/test $ sudo touch /mnt/test/AAAA $ sudo touch /mnt/test/BBBB $ sudo umount /mnt/test $ sudo dump.exfat -d /BBBB /dev/sdc1 exfatprogs version : 1.4.5 (2026-11-18) Segmentation fault
Quoted 94 lines
lib/exfat_dir.c +7
-0+__u16 name_ch = de_iter->exfat->upcase_table[ +le16_to_cpu (name[j])]; + +if (dentry_ch != name_ch) +return 1 ; + } + } name += len; name_len -= len;tests/duplicated_name_casefold/exfat.img.tar.xz new file binary +0
-1--2.34.1
Quoted 7 lines · On Thu, 26 Nov 2026 09:32:13 Namjae Jeon <[email protected]> wrote:
dump.exfat calls
exfat_lookup_file_by_utf16name()withupcase_tablestill NULL. If an earlier directory entry has a different name of the same length,memcmp()reports a mismatch and the lookup dereferences NULL here. I reproduced the crash with dump.exfat -d while looking up an existing file on a clean image. Please return 1 on amemcmp()mismatch whenupcase_tableis NULL.
Quoted 7 lines
$ sudo mount -t exfat /dev/sdc1 /mnt/test $ sudo touch /mnt/test/AAAA $ sudo touch /mnt/test/BBBB $ sudo umount /mnt/test $ sudo dump.exfat -d /BBBB /dev/sdc1 exfatprogs version : 1.4.5 (2026-11-18) Segmentation fault
Thanks for catching this.
I will send v2 patch.
Thanks.