From: Dan Carpenter <dan.carpenter@oracle.com>
To: almaz.alexandrovich@paragon-software.com
Cc: ntfs3@lists.linux.dev
Subject: [bug report] fs/ntfs3: mask truncates in ntfs_compress_write()
Date: Tue, 24 Aug 2021 14:39:01 +0300 [thread overview]
Message-ID: <20210824113901.GB31143@kili> (raw)
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
reply other threads:[~2021-08-24 11:39 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210824113901.GB31143@kili \
--to=dan.carpenter@oracle.com \
--cc=almaz.alexandrovich@paragon-software.com \
--cc=ntfs3@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox