]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore: fix segfault on out-of-bound offset provided to claim_free_to_right... 38637/head
authorIgor Fedotov <ifedotov@suse.com>
Mon, 5 Oct 2020 14:49:12 +0000 (17:49 +0300)
committerIgor Fedotov <ifedotov@suse.com>
Thu, 17 Dec 2020 12:58:13 +0000 (15:58 +0300)
Hybrid allocator might provide such an offset when final extent is marked as free by HybridAllocator::_add_to_tree().
Hence provides start+size point out to the end of the controled space.

Fixes: https://tracker.ceph.com/issues/47751
Signed-off-by: Igor Fedotov <ifedotov@suse.com>
(cherry picked from commit 0792382f4c51ec612d596efb13bf63fea92f3a2d)

src/os/bluestore/fastbmap_allocator_impl.cc
src/test/objectstore/fastbmap_allocator_test.cc

index 6155451738b4a0b2461e3f511b6815ca8fcafe03..c89096555841e47398ab07f2a56f8a2d935701a6 100755 (executable)
@@ -678,6 +678,9 @@ uint64_t AllocatorLevel01Loose::_claim_free_to_right_l0(int64_t l0_pos_start)
   int64_t pos = l0_pos_start;
   slot_t bits = (slot_t)1 << (pos % d0);
   size_t idx = pos / d0;
+  if (idx >= l0.size()) {
+    return pos;
+  }
   slot_t* val_s = l0.data() + idx;
 
   int64_t pos_e = p2roundup<int64_t>(pos + 1, d0);
index c3af73706569c8cd40f052ca8d81b2506134d391..c59531985050db1a03559df69ffd63e81db0a59b 100755 (executable)
@@ -1016,6 +1016,11 @@ TEST(TestAllocatorLevel01, test_claim_free_l2)
   ASSERT_EQ(0x1000, claimed);
   ASSERT_EQ(0x2000, al2.debug_get_free());
 
+  // claiming on the right boundary
+  claimed = al2.claim_free_to_right(capacity);
+  ASSERT_EQ(0x0, claimed);
+  ASSERT_EQ(0x2000, al2.debug_get_free());
+
   // extend allocator space up to 64M
   auto max_available2 = 64 * 1024 * 1024;
   al2.mark_free(max_available, max_available2 - max_available);