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; }