Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

common/buffer: fix stack corruption in rebuild_aligned_size_and_memory() #42112

Merged
merged 1 commit into from Jul 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/common/buffer.cc
Expand Up @@ -1258,8 +1258,12 @@ static ceph::spinlock debug_lock;
buffer::create_aligned(unaligned._len, align_memory)));
had_to_rebuild = true;
}
_buffers.insert_after(p_prev, *ptr_node::create(unaligned._buffers.front()).release());
_num += 1;
if (unaligned.get_num_buffers()) {
_buffers.insert_after(p_prev, *ptr_node::create(unaligned._buffers.front()).release());
_num += 1;
} else {
// a bufferlist containing only 0-length bptrs is rebuilt as empty
}
++p_prev;
}
return had_to_rebuild;
Expand Down
17 changes: 17 additions & 0 deletions src/test/bufferlist.cc
Expand Up @@ -1848,6 +1848,23 @@ TEST(BufferList, rebuild_aligned_size_and_memory) {
EXPECT_TRUE(bl.is_aligned(SIMD_ALIGN));
EXPECT_TRUE(bl.is_n_align_sized(BUFFER_SIZE));
EXPECT_EQ(3U, bl.get_num_buffers());

{
/* bug replicator, to test rebuild_aligned_size_and_memory() in the
* scenario where the first bptr is both size and memory aligned and
* the second is 0-length */
bl.clear();
bufferptr ptr1(buffer::create_aligned(4096, 4096));
bl.append(ptr1);
bufferptr ptr(10);
/* bl.back().length() must be 0 */
bl.append(ptr, 0, 0);
EXPECT_EQ(bl.get_num_buffers(), 2);
EXPECT_EQ(bl.back().length(), 0);
/* rebuild_aligned() calls rebuild_aligned_size_and_memory() */
bl.rebuild_aligned(4096);
EXPECT_EQ(bl.get_num_buffers(), 1);
}
}

TEST(BufferList, is_zero) {
Expand Down