]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore: fix length overflow. 22610/head
authorJianpeng Ma <jianpeng.ma@intel.com>
Wed, 20 Jun 2018 12:22:38 +0000 (20:22 +0800)
committerJianpeng Ma <jianpeng.ma@intel.com>
Wed, 20 Jun 2018 12:22:38 +0000 (20:22 +0800)
In fact, length of 'struct interval_t' and 'struct bluestore_pextent_t'
is uint32_t. But len of AllocatorLevel02::_mark_allocated is uint64_t.
So it may cause data overflow which cause bug.

Signed-off-by: Jianpeng Ma <jianpeng.ma@intel.com>
src/os/bluestore/fastbmap_allocator_impl.h

index 179a22c80777f2a24c1a5204c4bd70be86ee34b6..762f2d37bf499bed454732eda9bc8f65e66303f5 100755 (executable)
@@ -390,10 +390,10 @@ protected:
     uint64_t* allocated,
     interval_vector_t* res);
 
-  uint64_t _mark_alloc_l1(const interval_t& r)
+  uint64_t _mark_alloc_l1(uint64_t offset, uint64_t length)
   {
-    uint64_t l0_pos_start = r.offset / l0_granularity;
-    uint64_t l0_pos_end = p2roundup(r.offset + r.length, l0_granularity) / l0_granularity;
+    uint64_t l0_pos_start = offset / l0_granularity;
+    uint64_t l0_pos_end = p2roundup(offset + length, l0_granularity) / l0_granularity;
     _mark_alloc_l1_l0(l0_pos_start, l0_pos_end);
     return l0_granularity * (l0_pos_end - l0_pos_start);
   }
@@ -710,7 +710,7 @@ protected:
     uint64_t l2_pos_end = p2roundup(int64_t(o + len), int64_t(l2_granularity)) / l2_granularity;
 
     std::lock_guard<std::mutex> l(lock);
-    auto allocated = l1._mark_alloc_l1(interval_t(o, len));
+    auto allocated = l1._mark_alloc_l1(o, len);
     assert(available >= allocated);
     available -= allocated;
     _mark_l2_on_l1(l2_pos, l2_pos_end);