]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ntfs: fix potential 32-bit truncation in ntfs_write_cb()
authorDan Carpenter <error27@gmail.com>
Fri, 10 Apr 2026 15:24:49 +0000 (00:24 +0900)
committerNamjae Jeon <linkinjeon@kernel.org>
Sat, 18 Apr 2026 02:33:21 +0000 (11:33 +0900)
Smatch warned that the bitwise negation in ntfs_write_cb() might lead to
unintended truncation. Casting the block size to loff_t before bitwise
negation prevents the upper 32 bits of pos from being incorrectly zeroed
out during the calculation of new_vcn.

Signed-off-by: Dan Carpenter <error27@gmail.com>
Reviewed-by: Hyunchul Lee <hyc.lee@gmail.com>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
fs/ntfs/compress.c

index 71a8d9c42674fcbb7aa70ada2081a7f81b130468..76bd806b41edd929819545002f34e597516f7e5c 100644 (file)
@@ -1374,7 +1374,8 @@ static int ntfs_write_cb(struct ntfs_inode *ni, loff_t pos, struct page **pages,
                bio_size = insz;
        }
 
-       new_vcn = ntfs_bytes_to_cluster(vol, pos & ~(ni->itype.compressed.block_size - 1));
+       new_vcn = ntfs_bytes_to_cluster(vol,
+                       pos & ~((loff_t)ni->itype.compressed.block_size - 1));
        new_length = ntfs_bytes_to_cluster(vol, round_up(bio_size, vol->cluster_size));
 
        err = ntfs_non_resident_attr_punch_hole(ni, new_vcn, ni->itype.compressed.block_clusters);