From 6338e415095e0e747ee881f6eaa75c61504d3643 Mon Sep 17 00:00:00 2001 From: Daniel Rosenberg Date: Fri, 1 Dec 2023 17:05:40 -0800 Subject: [PATCH] BACKPORT: f2fs: Restrict max filesize for 16K f2fs Blocks are tracked by u32, so the max permitted filesize is (U32_MAX + 1) * BLOCK_SIZE. Additionally, in order to support crypto data unit sizes of 4K with a 16K block with IV_INO_LBLK_{32,64}, we must further restrict max filesize to (U32_MAX + 1) * 4096. This does not affect 4K blocksize f2fs as the natural limit for files are well below that. Fixes: cf46c5872022 ("BACKPORT: Support Block Size == Page Size") Signed-off-by: Daniel Rosenberg Signed-off-by: Jaegeuk Kim Change-Id: I8697e37841e1882a3f613e9aab1857ad7e4c3f2f Bug: 248132568 (cherry picked from commit a6a010f5def544af3efcfe21683905a712b60536) --- fs/f2fs/super.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index ab79c9ccfeda..48dfcac6463a 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -3266,6 +3266,14 @@ loff_t max_file_blocks(struct inode *inode) leaf_count *= NIDS_PER_BLOCK; result += leaf_count; + /* + * For compatibility with FSCRYPT_POLICY_FLAG_IV_INO_LBLK_{64,32} with + * a 4K crypto data unit, we must restrict the max filesize to what can + * fit within U32_MAX + 1 data units. + */ + + result = min(result, (((loff_t)U32_MAX + 1) * 4096) >> F2FS_BLKSIZE_BITS); + return result; }