btrfs: fix defrag 32-bit integer overflow
authorJustin Maggard <jmaggard10@gmail.com>
Tue, 21 Jan 2014 19:18:29 +0000 (11:18 -0800)
committerJiri Slaby <jslaby@suse.cz>
Fri, 20 Jun 2014 15:33:46 +0000 (17:33 +0200)
commit6e8451cbf0d2e90d8cabac10b47848e3aaf8aa4e
tree619d518d4c59d49b71f91c59527d03d2b4cf04cf
parent649066ce296368e2733ce1d4005f10dc673a9e8f
btrfs: fix defrag 32-bit integer overflow

commit c41570c9d29764f797fa35490d72b7395a0105c3 upstream.

When defragging a very large file, the cluster variable can wrap its 32-bit
signed int type and become negative, which eventually gets passed to
btrfs_force_ra() as a very large unsigned long value.  On 32-bit platforms,
this eventually results in an Oops from the SLAB allocator.

Change the cluster and max_cluster signed int variables to unsigned long to
match the readahead functions.  This also allows the min() comparison in
btrfs_defrag_file() to work as intended.

Signed-off-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: Chris Mason <clm@fb.com>
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
fs/btrfs/ioctl.c