From ec259dfde87ed9bc5e7247f311b629707c636895 Mon Sep 17 00:00:00 2001 From: Huan Zhang Date: Fri, 24 Jun 2016 11:27:53 +0800 Subject: [PATCH] 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 --- src/librbd/librbd.cc | 4 ++++ 1 file changed, 4 insertions(+) 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; -- 2.47.3