f2fs: Restrict max filesize for 16K f2fs
PATCH v2 1/1 f2fs: Restrict max filesize for 16K f2fs
Blocks are tracked by u32, so the max permitted filesize is U32_MAX * BLOCK_SIZE. Additionally, in order to support crypto data unit sizes of 4K with a 16K block size with IV_INO_LBLK_{32,63}, we must further restrict max filesize to U32_MAX * 4096. This does not affect 4K blocksize f2fs as the natural limit for files are well below that.
--- fs/f2fs/super.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
fs/f2fs/super.c +12 -0
@@ -3364,6 +3364,18 @@ loff_t max_file_blocks(struct inode *inode) leaf_count *=NIDS_PER_BLOCK ; result += leaf_count; +/* +* For compatibility with FSCRYPT_POLICY_IV_INO_LBLK_{64,32} with a +* 4K crypto data unit, we must restrict the max filesize to what can +* fit within U32_MAX data units. +* +* Since the blocksize must currently be equal to the page size, +* we can use a constant for that. Note if this is not the case +* in the future that inode is NULL while setting up the superblock. +*/ + + result =min (result, ((loff_t )U32_MAX *4096 ) >>F2FS_BLKSIZE_BITS ); +return result; }
base-commit: d346fa09abff46988de9267b67b6900d9913d5a2
Signature · 8 lines
2.43.0.rc2.451.g8631bc7472-goog _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Quoted 3 lines · On Mon, Dec 04, 2023 at 03:46:15PM -0800, Daniel Rosenberg via…
Blocks are tracked by u32, so the max permitted filesize is
U32_MAX*BLOCK_SIZE. Additionally, in order to support crypto data unit sizes of 4K with a 16K block size with IV_INO_LBLK_{32,63}, we must
{32,63} should be {32,64}
fs/f2fs/super.c loff_t max_file_blocks(struct inode *inode) · line 3370
Quoted 4 lines
fs/f2fs/super.c +4
-0+/* +* For compatibility with FSCRYPT_POLICY_IV_INO_LBLK_{64,32} with a +* 4K crypto data unit, we must restrict the max filesize to what can +* fit within U32_MAX data units.
FSCRYPT_POLICY_IV_INO_LBLK_{64,32} should be
FSCRYPT_POLICY_FLAG_IV_INO_LBLK_{64,32}
fs/f2fs/super.c loff_t max_file_blocks(struct inode *inode) · line 3374
Quoted 4 lines
fs/f2fs/super.c +4
-0+* +* Since the blocksize must currently be equal to the page size, +* we can use a constant for that. Note if this is not the case +* in the future that inode is NULL while setting up the superblock.
I'm not sure what the last sentence is trying to say.
fs/f2fs/super.c loff_t max_file_blocks(struct inode *inode) · line 3377
Quoted 3 lines
fs/f2fs/super.c +3
-0+*/ + + result =min (result, ((loff_t )U32_MAX *4096 ) >>F2FS_BLKSIZE_BITS );
Is it intentional that this is off by 1? If indices can be up to U32_MAX, then the maximum size is U32_MAX + 1. It's not a bad idea to go with the lower size, so that max_index + 1 does not overflow. But that's not what the explanation says, so this seems to be accidental.
- Eric