From: Huan Zhang Date: Fri, 24 Jun 2016 03:27:53 +0000 (+0800) Subject: rbd discard return -EINVAL if len > MAX_INT32 X-Git-Tag: v11.0.0~16^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F9856%2Fhead;p=ceph.git rbd discard return -EINVAL if len > MAX_INT32 rbd discard use 'int' to return discarded length, but the 'len' user passed is 'uint64', in some case, the ret value will be truncated and return a negative value which means discard failed. ret -EINVAL if len > MAX_INT32 to indicate support len <= MAX_INT32 only. Fixes: http://tracker.ceph.com/issues/16465 Signed-off-by: Huan Zhang --- diff --git a/src/librbd/librbd.cc b/src/librbd/librbd.cc index 41ae32c06b6a..edef49a78c6f 100644 --- a/src/librbd/librbd.cc +++ b/src/librbd/librbd.cc @@ -1160,6 +1160,10 @@ namespace librbd { { ImageCtx *ictx = (ImageCtx *)ctx; tracepoint(librbd, discard_enter, ictx, ictx->name.c_str(), ictx->snap_name.c_str(), ictx->read_only, ofs, len); + if (len > std::numeric_limits::max()) { + tracepoint(librbd, discard_exit, -EINVAL); + return -EINVAL; + } int r = ictx->aio_work_queue->discard(ofs, len); tracepoint(librbd, discard_exit, r); return r;