f2fs: sanity check of crc_offset from raw checkpoint
authorKinglong Mee <kinglongmee@gmail.com>
Wed, 15 Mar 2017 13:12:50 +0000 (21:12 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Wed, 22 Mar 2017 02:34:34 +0000 (22:34 -0400)
The crc_offset towards or beyond the end of block is wrong,
sanity check it.

Signed-off-by: Kinglong Mee <kinglongmee@gmail.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/checkpoint.c

index 22348c7df67daa50843d94880126ebbbefd51143..7dd7dd5914c5e4488cfccb427fca37ecd6be229f 100644 (file)
@@ -678,7 +678,7 @@ static int get_checkpoint_version(struct f2fs_sb_info *sbi, block_t cp_addr,
        *cp_block = (struct f2fs_checkpoint *)page_address(*cp_page);
 
        crc_offset = le32_to_cpu((*cp_block)->checksum_offset);
-       if (crc_offset >= blk_size) {
+       if (crc_offset > (blk_size - sizeof(__le32))) {
                f2fs_msg(sbi->sb, KERN_WARNING,
                        "invalid crc_offset: %zu", crc_offset);
                return -EINVAL;