aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/block
diff options
context:
space:
mode:
authorAlex Elder <elder@inktank.com>2013-01-10 13:56:58 -0500
committerAlex Elder <elder@inktank.com>2013-01-25 18:33:14 -0500
commit38901e0f240b634467fb31743365af80a006be33 (patch)
treed69c8ed51d926b9bc79b2e7a6c078be3d79cb55f /drivers/block
parent98571b5aa776d4a69eadd7d4e5c9d4e69365ab9a (diff)
rbd: check for overflow in rbd_get_num_segments()
The return type of rbd_get_num_segments() is int, but the values it operates on are u64. Although it's not likely, there's no guarantee the result won't exceed what can be respresented in an int. The function is already designed to return -ERANGE on error, so just add this possible overflow as another reason to return that. Signed-off-by: Alex Elder <elder@inktank.com> Reviewed-by: Dan Mick <dan.mick@inktank.com> Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
Diffstat (limited to 'drivers/block')
-rw-r--r--drivers/block/rbd.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index 4ed074138f8d..58d01e3a0fce 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -820,6 +820,7 @@ static int rbd_get_num_segments(struct rbd_image_header *header,
820{ 820{
821 u64 start_seg; 821 u64 start_seg;
822 u64 end_seg; 822 u64 end_seg;
823 u64 result;
823 824
824 if (!len) 825 if (!len)
825 return 0; 826 return 0;
@@ -829,7 +830,11 @@ static int rbd_get_num_segments(struct rbd_image_header *header,
829 start_seg = ofs >> header->obj_order; 830 start_seg = ofs >> header->obj_order;
830 end_seg = (ofs + len - 1) >> header->obj_order; 831 end_seg = (ofs + len - 1) >> header->obj_order;
831 832
832 return end_seg - start_seg + 1; 833 result = end_seg - start_seg + 1;
834 if (result > (u64) INT_MAX)
835 return -ERANGE;
836
837 return (int) result;
833} 838}
834 839
835/* 840/*