]> git.hungrycats.org Git - linux/commitdiff
f2fs: avoid returning uninitialized value to userspace from f2fs_trim_fs()
authorJan Kara <jack@suse.cz>
Tue, 21 Oct 2014 12:07:33 +0000 (14:07 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 8 Jan 2015 18:30:17 +0000 (10:30 -0800)
commit 9bd27ae4aafc9bfee6c8791f7d801ea16cc5622b upstream.

If user specifies too low end sector for trimming, f2fs_trim_fs() will
use uninitialized value as a number of trimmed blocks and returns it to
userspace. Initialize number of trimmed blocks early to avoid the
problem.

Coverity-id: 1248809
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/f2fs/segment.c

index 923cb76fdc46e1e9f26b3a5014690e5c58d59fd0..3c31221affe6c18b2caa82ad993e94f742715055 100644 (file)
@@ -1004,6 +1004,7 @@ int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range)
                                                range->len < sbi->blocksize)
                return -EINVAL;
 
+       cpc.trimmed = 0;
        if (end <= MAIN_BLKADDR(sbi))
                goto out;
 
@@ -1015,7 +1016,6 @@ int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range)
        cpc.trim_start = start_segno;
        cpc.trim_end = end_segno;
        cpc.trim_minlen = range->minlen >> sbi->log_blocksize;
-       cpc.trimmed = 0;
 
        /* do checkpoint to issue discard commands safely */
        write_checkpoint(sbi, &cpc);