xfs: fix possible overflow in xfs_ioc_trim()
authorLukas Czerner <lczerner@redhat.com>
Wed, 21 Sep 2011 09:42:30 +0000 (09:42 +0000)
committerAlex Elder <aelder@sgi.com>
Wed, 12 Oct 2011 02:15:07 +0000 (21:15 -0500)
commitc029a50d51b8a9520105ec903639de03389915d0
treef0d3993b6429eea9f4843a3113eb9258613f30ef
parentd952e2f81244d6502aff126df5011fab10f92187
xfs: fix possible overflow in xfs_ioc_trim()

In xfs_ioc_trim it is possible that computing the last allocation group
to discard might overflow for big start & len values, because the result
might be bigger then xfs_agnumber_t which is 32 bit long. Fix this by not
allowing the start and end block of the range to be beyond the end of the
file system.

Note that if the start is beyond the end of the file system we have to
return -EINVAL, but in the "end" case we have to truncate it to the fs
size.

Also introduce "end" variable, rather than using start+len which which
might be more confusing to get right as this bug shows.

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Alex Elder <aelder@sgi.com>
fs/xfs/xfs_discard.c