Commit 660b9823 authored by Dan Carpenter's avatar Dan Carpenter Committed by Namjae Jeon
Browse files

ntfs: fix potential 32-bit truncation in ntfs_write_cb()



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: default avatarDan Carpenter <error27@gmail.com>
Reviewed-by: default avatarHyunchul Lee <hyc.lee@gmail.com>
Signed-off-by: default avatarNamjae Jeon <linkinjeon@kernel.org>
parent dacc1802
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -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);