OSDN Git Service

f2fs: fix potential overflow
authorChao Yu <yuchao0@huawei.com>
Wed, 25 Apr 2018 11:38:17 +0000 (19:38 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Thu, 31 May 2018 18:31:49 +0000 (11:31 -0700)
commita9af3fdcc4258af406879eca63d82e9d6baa892e
tree34a64f714cb55337dfdce76655d58a26e0f26534
parentb2532c694033fb6762478846c457382061f9f630
f2fs: fix potential overflow

In build_sit_entries(), if valid_blocks in SIT block is smaller than
valid_blocks in journal, for below calculation:

sbi->discard_blks += old_valid_blocks - se->valid_blocks;

There will be two times potential overflow:
- old_valid_blocks - se->valid_blocks will overflow, and be a very
large number.
- sbi->discard_blks += result will overflow again, comes out a correct
result accidently.

Anyway, it should be fixed.

Fixes: d600af236da5 ("f2fs: avoid unneeded loop in build_sit_entries")
Fixes: 1f43e2ad7bff ("f2fs: introduce CP_TRIMMED_FLAG to avoid unneeded discard")
Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/segment.c