diff options
author | Akinobu Mita <akinobu.mita@gmail.com> | 2014-05-25 08:43:33 -0400 |
---|---|---|
committer | Jens Axboe <axboe@fb.com> | 2014-07-01 12:43:07 -0400 |
commit | 63f264965947ac6299452711f614f086955b2515 (patch) | |
tree | 20050c8d77eb14fbb1439eb9af85916bf87f7dd2 | |
parent | 16e1556526241b893d40b01d1c1b14a4e83ee499 (diff) |
block: fix BLKSECTGET ioctl when max_sectors is greater than USHRT_MAX
BLKSECTGET ioctl loads the request queue's max_sectors as unsigned
short value to the argument pointer. So if the max_sector is greater
than USHRT_MAX, the upper 16 bits of that is just discarded.
In such case, USHRT_MAX is more preferable than the lower 16 bits of
max_sectors.
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: "James E.J. Bottomley" <JBottomley@parallels.com>
Cc: Douglas Gilbert <dgilbert@interlog.com>
Cc: linux-scsi@vger.kernel.org
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@fb.com>
-rw-r--r-- | block/compat_ioctl.c | 6 | ||||
-rw-r--r-- | block/ioctl.c | 5 |
2 files changed, 8 insertions, 3 deletions
diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c index fbd5a67cb773..e0393cd2ea7f 100644 --- a/block/compat_ioctl.c +++ b/block/compat_ioctl.c | |||
@@ -663,6 +663,7 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg) | |||
663 | fmode_t mode = file->f_mode; | 663 | fmode_t mode = file->f_mode; |
664 | struct backing_dev_info *bdi; | 664 | struct backing_dev_info *bdi; |
665 | loff_t size; | 665 | loff_t size; |
666 | unsigned int max_sectors; | ||
666 | 667 | ||
667 | /* | 668 | /* |
668 | * O_NDELAY can be altered using fcntl(.., F_SETFL, ..), so we have | 669 | * O_NDELAY can be altered using fcntl(.., F_SETFL, ..), so we have |
@@ -718,8 +719,9 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg) | |||
718 | case BLKSSZGET: /* get block device hardware sector size */ | 719 | case BLKSSZGET: /* get block device hardware sector size */ |
719 | return compat_put_int(arg, bdev_logical_block_size(bdev)); | 720 | return compat_put_int(arg, bdev_logical_block_size(bdev)); |
720 | case BLKSECTGET: | 721 | case BLKSECTGET: |
721 | return compat_put_ushort(arg, | 722 | max_sectors = min_t(unsigned int, USHRT_MAX, |
722 | queue_max_sectors(bdev_get_queue(bdev))); | 723 | queue_max_sectors(bdev_get_queue(bdev))); |
724 | return compat_put_ushort(arg, max_sectors); | ||
723 | case BLKROTATIONAL: | 725 | case BLKROTATIONAL: |
724 | return compat_put_ushort(arg, | 726 | return compat_put_ushort(arg, |
725 | !blk_queue_nonrot(bdev_get_queue(bdev))); | 727 | !blk_queue_nonrot(bdev_get_queue(bdev))); |
diff --git a/block/ioctl.c b/block/ioctl.c index 7d5c3b20af45..d6cda8147c91 100644 --- a/block/ioctl.c +++ b/block/ioctl.c | |||
@@ -278,6 +278,7 @@ int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd, | |||
278 | struct backing_dev_info *bdi; | 278 | struct backing_dev_info *bdi; |
279 | loff_t size; | 279 | loff_t size; |
280 | int ret, n; | 280 | int ret, n; |
281 | unsigned int max_sectors; | ||
281 | 282 | ||
282 | switch(cmd) { | 283 | switch(cmd) { |
283 | case BLKFLSBUF: | 284 | case BLKFLSBUF: |
@@ -375,7 +376,9 @@ int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd, | |||
375 | case BLKDISCARDZEROES: | 376 | case BLKDISCARDZEROES: |
376 | return put_uint(arg, bdev_discard_zeroes_data(bdev)); | 377 | return put_uint(arg, bdev_discard_zeroes_data(bdev)); |
377 | case BLKSECTGET: | 378 | case BLKSECTGET: |
378 | return put_ushort(arg, queue_max_sectors(bdev_get_queue(bdev))); | 379 | max_sectors = min_t(unsigned int, USHRT_MAX, |
380 | queue_max_sectors(bdev_get_queue(bdev))); | ||
381 | return put_ushort(arg, max_sectors); | ||
379 | case BLKROTATIONAL: | 382 | case BLKROTATIONAL: |
380 | return put_ushort(arg, !blk_queue_nonrot(bdev_get_queue(bdev))); | 383 | return put_ushort(arg, !blk_queue_nonrot(bdev_get_queue(bdev))); |
381 | case BLKRASET: | 384 | case BLKRASET: |