]> git.baikalelectronics.ru Git - kernel.git/commit
rbd: check for overflow in rbd_get_num_segments()
authorAlex Elder <elder@inktank.com>
Thu, 9 Aug 2012 17:33:26 +0000 (10:33 -0700)
committerAlex Elder <elder@inktank.com>
Mon, 1 Oct 2012 19:30:50 +0000 (14:30 -0500)
commit65de6a26ca74121dea88918e59b148662f28b0ca
treede37a2197572af73ea74bdf1891b609719249a7f
parenta7f3c154d8208f147cb3cf3a5d2b9bb9057db55f
rbd: check for overflow in rbd_get_num_segments()

It is possible in rbd_get_num_segments() for an overflow to occur
when adding the offset and length.  This is easily avoided.

Since the function returns an int and the one caller is already
prepared to handle errors, have it return -ERANGE if overflow would
occur.

The overflow check would not work if a zero-length request was
being tested, so short-circuit that case, returning 0 for the
number of segments required.  (This condition might be avoided
elsewhere already, I don't know.)

Have the caller end the request if either an error or 0 is returned.
The returned value is passed to __blk_end_request_all(), meaning
a 0 length request is not treated an error.

Signed-off-by: Alex Elder <elder@inktank.com>
Reviewed-by: Yehuda Sadeh <yehuda@inktank.com>
drivers/block/rbd.c