* [bug report] fs/ntfs3: mask truncates in ntfs_compress_write()
@ 2021-08-24 11:39 Dan Carpenter
0 siblings, 0 replies; only message in thread
From: Dan Carpenter @ 2021-08-24 11:39 UTC (permalink / raw)
To: almaz.alexandrovich; +Cc: ntfs3
Hello Konstantin Komarov,
The patch 4342306f0f0d: "fs/ntfs3: Add file operations and
implementation" from Aug 13, 2021, leads to the following
Smatch static checker warning:
fs/ntfs3/file.c:921 ntfs_compress_write()
warn: was expecting a 64 bit value instead of '~(frame_size - 1)'
fs/ntfs3/file.c
871 static ssize_t ntfs_compress_write(struct kiocb *iocb, struct iov_iter *from)
872 {
873 int err;
874 struct file *file = iocb->ki_filp;
875 size_t count = iov_iter_count(from);
876 loff_t pos = iocb->ki_pos;
877 struct inode *inode = file_inode(file);
878 loff_t i_size = inode->i_size;
879 struct address_space *mapping = inode->i_mapping;
880 struct ntfs_inode *ni = ntfs_i(inode);
881 u64 valid = ni->i_valid;
882 struct ntfs_sb_info *sbi = ni->mi.sbi;
883 struct page *page, **pages = NULL;
884 size_t written = 0;
885 u8 frame_bits = NTFS_LZNT_CUNIT + sbi->cluster_bits;
886 u32 frame_size = 1u << frame_bits;
887 u32 pages_per_frame = frame_size >> PAGE_SHIFT;
888 u32 ip, off;
889 CLST frame;
890 u64 frame_vbo;
891 pgoff_t index;
892 bool frame_uptodate;
893
894 if (frame_size < PAGE_SIZE) {
895 /*
896 * frame_size == 8K if cluster 512
897 * frame_size == 64K if cluster 4096
898 */
899 ntfs_inode_warn(inode, "page size is bigger than frame size");
900 return -EOPNOTSUPP;
901 }
902
903 pages = ntfs_malloc(pages_per_frame * sizeof(struct page *));
904 if (!pages)
905 return -ENOMEM;
906
907 current->backing_dev_info = inode_to_bdi(inode);
908 err = file_remove_privs(file);
909 if (err)
910 goto out;
911
912 err = file_update_time(file);
913 if (err)
914 goto out;
915
916 /* zero range [valid : pos) */
917 while (valid < pos) {
918 CLST lcn, clen;
919
920 frame = valid >> frame_bits;
--> 921 frame_vbo = valid & ~(frame_size - 1);
valid is u64 but the mask truncates to u32.
922 off = valid & (frame_size - 1);
923
924 err = attr_data_get_block(ni, frame << NTFS_LZNT_CUNIT, 0, &lcn,
925 &clen, NULL);
926 if (err)
regards,
dan carpenter
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-08-24 11:39 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-24 11:39 [bug report] fs/ntfs3: mask truncates in ntfs_compress_write() Dan Carpenter
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.