• Chao Yu's avatar
    f2fs: fix potential overflow · a9af3fdc
    Chao Yu authored
    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: d600af23 ("f2fs: avoid unneeded loop in build_sit_entries")
    Fixes: 1f43e2ad ("f2fs: introduce CP_TRIMMED_FLAG to avoid unneeded discard")
    Signed-off-by: default avatarChao Yu <yuchao0@huawei.com>
    Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
    a9af3fdc
segment.c 103 KB