Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

jfs: Fix FITRIM argument handling

Currently when 'range->start' is beyond the end of file system
nothing is done and that fact is ignored, where in fact we should return
EINVAL. The same problem is when 'range.len' is smaller than file system
block.

Fix this by adding check for such conditions and return EINVAL
appropriately.

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
Acked-by: Tino Reichardt <milky-kernel@mcmilk.de>
Signed-off-by: Dave Kleikamp <dave.kleikamp@oracle.com>

authored by

Lukas Czerner and committed by
Dave Kleikamp
4e7a4b01 8d2b6b3a

+10 -6
+10 -6
fs/jfs/jfs_discard.c
··· 83 83 struct bmap *bmp = JFS_SBI(ip->i_sb)->bmap; 84 84 struct super_block *sb = ipbmap->i_sb; 85 85 int agno, agno_end; 86 - s64 start, end, minlen; 86 + u64 start, end, minlen; 87 87 u64 trimmed = 0; 88 88 89 89 /** ··· 93 93 * minlen: minimum extent length in Bytes 94 94 */ 95 95 start = range->start >> sb->s_blocksize_bits; 96 - if (start < 0) 97 - start = 0; 98 96 end = start + (range->len >> sb->s_blocksize_bits) - 1; 97 + minlen = range->minlen >> sb->s_blocksize_bits; 98 + if (minlen == 0) 99 + minlen = 1; 100 + 101 + if (minlen > bmp->db_agsize || 102 + start >= bmp->db_mapsize || 103 + range->len < sb->s_blocksize) 104 + return -EINVAL; 105 + 99 106 if (end >= bmp->db_mapsize) 100 107 end = bmp->db_mapsize - 1; 101 - minlen = range->minlen >> sb->s_blocksize_bits; 102 - if (minlen <= 0) 103 - minlen = 1; 104 108 105 109 /** 106 110 * we trim all ag's within the range