From: Igor Fedotov Date: Tue, 9 Jul 2019 18:02:08 +0000 (+0300) Subject: os/bluestore: avoid length overflow in extents returned by Stupid X-Git-Tag: v15.1.0~2221^2~1 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=e1b4984a63e79ab2e2aec7aa17bd80a77e79ec8c;p=ceph-ci.git os/bluestore: avoid length overflow in extents returned by Stupid Allocator. Fixes: http://tracker.ceph.com/issues/40703 Signed-off-by: Igor Fedotov --- diff --git a/src/os/bluestore/StupidAllocator.cc b/src/os/bluestore/StupidAllocator.cc index 13f38d692e9..db2e9e3634c 100644 --- a/src/os/bluestore/StupidAllocator.cc +++ b/src/os/bluestore/StupidAllocator.cc @@ -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) { diff --git a/src/test/objectstore/Allocator_test.cc b/src/test/objectstore/Allocator_test.cc index 2d72ec52e3e..afee6e19afc 100644 --- a/src/test/objectstore/Allocator_test.cc +++ b/src/test/objectstore/Allocator_test.cc @@ -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,