linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christophe Vu-Brugier <cvubrugier@fastmail.fm>
To: linux-fsdevel@vger.kernel.org
Cc: Namjae Jeon <linkinjeon@kernel.org>,
	Sungjong Seo <sj1557.seo@samsung.com>,
	Christophe Vu-Brugier <christophe.vu-brugier@seagate.com>
Subject: [PATCH 1/1] exfat: fix i_blocks for files truncated over 4 GiB
Date: Thu, 18 Nov 2021 22:28:28 +0100	[thread overview]
Message-ID: <20211118212828.4360-2-cvubrugier@fastmail.fm> (raw)
In-Reply-To: <20211118212828.4360-1-cvubrugier@fastmail.fm>

From: Christophe Vu-Brugier <christophe.vu-brugier@seagate.com>

In exfat_truncate(), the computation of inode->i_blocks is wrong if
the file is larger than 4 GiB because a 32-bit variable is used as a
mask. This is fixed by casting the variable to loff_t which is 64-bit.

Also fix the same computation in exfat_read_root().

This commit is similar to Sungjong Seo's fix in exfat_fill_inode()
last month:

  commit 0c336d6e33f4 ("exfat: fix incorrect loading of i_blocks for
                        large files")

Signed-off-by: Christophe Vu-Brugier <christophe.vu-brugier@seagate.com>
---
 fs/exfat/file.c  | 2 +-
 fs/exfat/super.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/exfat/file.c b/fs/exfat/file.c
index 6af0191b648f..109ade79da33 100644
--- a/fs/exfat/file.c
+++ b/fs/exfat/file.c
@@ -252,7 +252,7 @@ void exfat_truncate(struct inode *inode, loff_t size)
 		mark_inode_dirty(inode);
 
 	inode->i_blocks = ((i_size_read(inode) + (sbi->cluster_size - 1)) &
-			~(sbi->cluster_size - 1)) >> inode->i_blkbits;
+		~((loff_t)sbi->cluster_size - 1)) >> inode->i_blkbits;
 write_size:
 	aligned_size = i_size_read(inode);
 	if (aligned_size & (blocksize - 1)) {
diff --git a/fs/exfat/super.c b/fs/exfat/super.c
index 5539ffc20d16..ea16769380c6 100644
--- a/fs/exfat/super.c
+++ b/fs/exfat/super.c
@@ -364,8 +364,8 @@ static int exfat_read_root(struct inode *inode)
 	inode->i_op = &exfat_dir_inode_operations;
 	inode->i_fop = &exfat_dir_operations;
 
-	inode->i_blocks = ((i_size_read(inode) + (sbi->cluster_size - 1))
-			& ~(sbi->cluster_size - 1)) >> inode->i_blkbits;
+	inode->i_blocks = ((i_size_read(inode) + (sbi->cluster_size - 1)) &
+		~((loff_t)sbi->cluster_size - 1)) >> inode->i_blkbits;
 	EXFAT_I(inode)->i_pos = ((loff_t)sbi->root_dir << 32) | 0xffffffff;
 	EXFAT_I(inode)->i_size_aligned = i_size_read(inode);
 	EXFAT_I(inode)->i_size_ondisk = i_size_read(inode);
-- 
2.33.0


  reply	other threads:[~2021-11-18 21:28 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-18 21:28 [PATCH 0/1] exfat: fix i_blocks for files truncated over 4 GiB Christophe Vu-Brugier
2021-11-18 21:28 ` Christophe Vu-Brugier [this message]
2021-11-18 21:50   ` [PATCH 1/1] " Matthew Wilcox
2021-11-18 22:43     ` Christophe Vu-Brugier
2021-11-19 17:37     ` [PATCH v2] " Christophe Vu-Brugier
2021-11-22  2:10       ` Sungjong Seo
2021-11-22  2:33         ` Namjae Jeon

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=20211118212828.4360-2-cvubrugier@fastmail.fm \
    --to=cvubrugier@fastmail.fm \
    --cc=christophe.vu-brugier@seagate.com \
    --cc=linkinjeon@kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=sj1557.seo@samsung.com \
    /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;
as well as URLs for NNTP newsgroup(s).