diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 033af907c3b1d..5dfbc6b4c0ac8 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -3364,6 +3364,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; }