Skip to content

Commit

Permalink
os/bluestore: avoid length overflow in extents returned by Stupid
Browse files Browse the repository at this point in the history
Allocator.

Fixes: http://tracker.ceph.com/issues/40703

Signed-off-by: Igor Fedotov <[email protected]>
  • Loading branch information
ifed01 committed Jul 9, 2019
1 parent 8189007 commit e1b4984
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/os/bluestore/StupidAllocator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
21 changes: 21 additions & 0 deletions src/test/objectstore/Allocator_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit e1b4984

Please sign in to comment.