ext2: correct max file size computing
authorZhang Yi <yi.zhang@huawei.com>
Sat, 12 Feb 2022 05:05:32 +0000 (13:05 +0800)
committerJan Kara <jack@suse.cz>
Fri, 25 Feb 2022 12:57:14 +0000 (13:57 +0100)
commit50b3a818991074177a56c87124c7a7bdf5fa4f67
tree652be8cc316f75d774b70834eeb6c21073acf2e4
parent48b0e01109f5fb91eabb6f7c4a487b76942061cc
ext2: correct max file size computing

We need to calculate the max file size accurately if the total blocks
that can address by block tree exceed the upper_limit. But this check is
not correct now, it only compute the total data blocks but missing
metadata blocks are needed. So in the case of "data blocks < upper_limit
&& total blocks > upper_limit", we will get wrong result. Fortunately,
this case could not happen in reality, but it's confused and better to
correct the computing.

  bits   data blocks   metadatablocks   upper_limit
  10        16843020            66051    2147483647
  11       134480396           263171    1073741823
  12      1074791436          1050627     536870911 (*)
  13      8594130956          4198403     268435455 (*)
  14     68736258060         16785411     134217727 (*)
  15    549822930956         67125251      67108863 (*)
  16   4398314962956        268468227      33554431 (*)

  [*] Need to calculate in depth.

Fixes: 1c2d14212b15 ("ext2: Fix underflow in ext2_max_size()")
Link: https://lore.kernel.org/r/20220212050532.179055-1-yi.zhang@huawei.com
Signed-off-by: Zhang Yi <yi.zhang@huawei.com>
Signed-off-by: Jan Kara <jack@suse.cz>
fs/ext2/super.c