]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd discard return -EINVAL if len > MAX_INT32 20287/head
authorHuan Zhang <zhanghuan@chinac.com>
Fri, 24 Jun 2016 03:27:53 +0000 (11:27 +0800)
committerNathan Cutler <ncutler@suse.com>
Sat, 3 Feb 2018 22:17:26 +0000 (23:17 +0100)
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 <zhanghuan@chinac.com>
(cherry picked from commit ec259dfde87ed9bc5e7247f311b629707c636895)

src/librbd/librbd.cc

index e9db0d4afe4a2f283040736e7df7bdd1087d5a44..a9bf7320319809b1437dbb1c725a18e0d01adbb0 100644 (file)
@@ -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<int32_t>::max()) {
+        tracepoint(librbd, discard_exit, -EINVAL);
+        return -EINVAL;
+    }
     int r = ictx->aio_work_queue->discard(ofs, len);
     tracepoint(librbd, discard_exit, r);
     return r;