From 2003e6da3e2500a12d3dbd018cc7b8deba92d36b 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 (cherry picked from commit ec259dfde87ed9bc5e7247f311b629707c636895) --- src/librbd/librbd.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/librbd/librbd.cc b/src/librbd/librbd.cc index e9db0d4afe4a2..a9bf732031980 100644 --- a/src/librbd/librbd.cc +++ b/src/librbd/librbd.cc @@ -1167,6 +1167,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.39.5