]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
ntfs: only alias volume $UpCase to default on exact match
authorDaeMyung Kang <charsyam@gmail.com>
Thu, 21 May 2026 10:17:51 +0000 (19:17 +0900)
committerNamjae Jeon <linkinjeon@kernel.org>
Fri, 5 Jun 2026 15:19:44 +0000 (00:19 +0900)
load_and_init_upcase() currently aliases vol->upcase to the global
default upcase whenever the shared prefix matches, and then truncates
vol->upcase_len to that shorter prefix.  The result is correct only by
accident: upcase[] accesses in name collation are gated by upcase_len,
so the prefix-equality alias produces the same fold output as keeping
the volume's own shorter table.

Still, prefix equality is not equality: the volume table is logically
distinct from the default and should not be replaced by it unless they
are byte-for-byte identical.  Use memcmp() to compare the complete table
in one expression and drop the now-redundant upcase_len rewrite.

No user-visible change is expected for compliant volumes whose $UpCase
has exactly default_upcase_len entries; shorter volume tables are no
longer aliased to the default.

Cc: stable@vger.kernel.org # v7.1
Signed-off-by: DaeMyung Kang <charsyam@gmail.com>
Reviewed-by: Hyunchul Lee <hyc.lee@gmail.com>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
fs/ntfs/super.c

index 7e3561265b47e159341e26ff96ed683c1c5aa66b..e51573be2182b1ff2eb81f2d0cef94fd80746591 100644 (file)
@@ -1323,7 +1323,6 @@ static bool load_and_init_upcase(struct ntfs_volume *vol)
        u8 *addr;
        pgoff_t index, max_index;
        unsigned int size;
-       int i, max;
 
        ntfs_debug("Entering.");
        /* Read upcase table and setup vol->upcase and vol->upcase_len. */
@@ -1374,16 +1373,11 @@ read_partial_upcase_page:
                mutex_unlock(&ntfs_lock);
                return true;
        }
-       max = default_upcase_len;
-       if (max > vol->upcase_len)
-               max = vol->upcase_len;
-       for (i = 0; i < max; i++)
-               if (vol->upcase[i] != default_upcase[i])
-                       break;
-       if (i == max) {
+       if (default_upcase_len == vol->upcase_len &&
+           !memcmp(vol->upcase, default_upcase,
+                   default_upcase_len * sizeof(*default_upcase))) {
                kvfree(vol->upcase);
                vol->upcase = default_upcase;
-               vol->upcase_len = max;
                ntfs_nr_upcase_users++;
                mutex_unlock(&ntfs_lock);
                ntfs_debug("Volume specified $UpCase matches default. Using default.");