]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore: avoid length overflow in extents returned by Stupid
authorIgor Fedotov <ifedotov@suse.com>
Tue, 9 Jul 2019 18:02:08 +0000 (21:02 +0300)
committerIgor Fedotov <ifedotov@suse.com>
Tue, 9 Jul 2019 18:02:08 +0000 (21:02 +0300)
Allocator.

Fixes: http://tracker.ceph.com/issues/40703
Signed-off-by: Igor Fedotov <ifedotov@suse.com>
src/os/bluestore/StupidAllocator.cc
src/test/objectstore/Allocator_test.cc

index 13f38d692e9fa9838d68c1d66e3b5d78c82a0a1b..db2e9e3634c2d84108f87d6dbf8fa68bcda98ad7 100644 (file)
@@ -206,10 +206,13 @@ int64_t StupidAllocator::allocate(
     bool can_append = true;
     if (!extents->empty()) {
       bluestore_pextent_t &last_extent  = extents->back();
-      if ((last_extent.end() == offset) &&
-         ((last_extent.length + length) <= max_alloc_size)) {
-       can_append = false;
-       last_extent.length += length;
+      if (last_extent.end() == offset) {
+        uint64_t l64 = last_extent.length;
+        l64 += length;
+        if (l64 < 0x100000000 && l64 <= max_alloc_size) {
+         can_append = false;
+         last_extent.length += length;
+        }
       }
     }
     if (can_append) {
index 2d72ec52e3e88fb03a2a8fa097780ab0ef7f64fb..afee6e19afc469dad942446e0cc89af9cc4a14ae 100644 (file)
@@ -326,6 +326,27 @@ TEST_P(AllocTest, test_alloc_bug_24598)
   EXPECT_EQ(0x200000u, tmp[0].length);
 }
 
+//Verifies issue from
+//http://tracker.ceph.com/issues/40703
+//
+TEST_P(AllocTest, test_alloc_big2)
+{
+  int64_t block_size = 4096;
+  int64_t blocks = 1048576 * 2;
+  int64_t mas = 1024*1024;
+  init_alloc(blocks*block_size, block_size);
+  alloc->init_add_free(0, blocks * block_size);
+  
+  PExtentVector extents;
+  uint64_t need = block_size * blocks / 4; // 2GB
+  EXPECT_EQ(need,
+      alloc->allocate(need, mas, 0, &extents));
+  need = block_size * blocks / 4; // 2GB
+  EXPECT_EQ(need,
+      alloc->allocate(need, mas, 0, &extents));
+  EXPECT_TRUE(extents[0].length > 0);
+}
+
 INSTANTIATE_TEST_SUITE_P(
   Allocator,
   AllocTest,