diff options
author | Akinobu Mita <akinobu.mita@gmail.com> | 2014-05-25 08:43:34 -0400 |
---|---|---|
committer | Jens Axboe <axboe@fb.com> | 2014-07-01 12:43:09 -0400 |
commit | 9b4231bf995996d6459c57959ead5a1829ff2c57 (patch) | |
tree | f9c44bc06c67b67448950624da3ea80b5d4b3bd2 | |
parent | 63f264965947ac6299452711f614f086955b2515 (diff) |
block: fix SG_[GS]ET_RESERVED_SIZE ioctl when max_sectors is huge
SG_GET_RESERVED_SIZE and SG_SET_RESERVED_SIZE ioctls access a reserved
buffer in bytes as int type. The value needs to be capped at the request
queue's max_sectors. But integer overflow is not correctly handled in
the calculation when converting max_sectors from sectors to bytes.
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/scsi_ioctl.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c index 14695c6221c8..bda1497add4c 100644 --- a/block/scsi_ioctl.c +++ b/block/scsi_ioctl.c | |||
@@ -82,9 +82,18 @@ static int sg_set_timeout(struct request_queue *q, int __user *p) | |||
82 | return err; | 82 | return err; |
83 | } | 83 | } |
84 | 84 | ||
85 | static int max_sectors_bytes(struct request_queue *q) | ||
86 | { | ||
87 | unsigned int max_sectors = queue_max_sectors(q); | ||
88 | |||
89 | max_sectors = min_t(unsigned int, max_sectors, INT_MAX >> 9); | ||
90 | |||
91 | return max_sectors << 9; | ||
92 | } | ||
93 | |||
85 | static int sg_get_reserved_size(struct request_queue *q, int __user *p) | 94 | static int sg_get_reserved_size(struct request_queue *q, int __user *p) |
86 | { | 95 | { |
87 | unsigned val = min(q->sg_reserved_size, queue_max_sectors(q) << 9); | 96 | int val = min_t(int, q->sg_reserved_size, max_sectors_bytes(q)); |
88 | 97 | ||
89 | return put_user(val, p); | 98 | return put_user(val, p); |
90 | } | 99 | } |
@@ -98,10 +107,8 @@ static int sg_set_reserved_size(struct request_queue *q, int __user *p) | |||
98 | 107 | ||
99 | if (size < 0) | 108 | if (size < 0) |
100 | return -EINVAL; | 109 | return -EINVAL; |
101 | if (size > (queue_max_sectors(q) << 9)) | ||
102 | size = queue_max_sectors(q) << 9; | ||
103 | 110 | ||
104 | q->sg_reserved_size = size; | 111 | q->sg_reserved_size = min(size, max_sectors_bytes(q)); |
105 | return 0; | 112 | return 0; |
106 | } | 113 | } |
107 | 114 | ||