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

luminous: osd: additional protection for out-of-bounds EC reads #18413

Merged
merged 1 commit into from Oct 26, 2017
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
19 changes: 17 additions & 2 deletions src/osd/PrimaryLogPG.cc
Expand Up @@ -4716,13 +4716,28 @@ int PrimaryLogPG::do_extent_cmp(OpContext *ctx, OSDOp& osd_op)
dout(20) << __func__ << dendl;
ceph_osd_op& op = osd_op.op;

if (!ctx->obs->exists || ctx->obs->oi.is_whiteout()) {
auto& oi = ctx->new_obs.oi;
uint64_t size = oi.size;
if ((oi.truncate_seq < op.extent.truncate_seq) &&
(op.extent.offset + op.extent.length > op.extent.truncate_size)) {
size = op.extent.truncate_size;
}

if (op.extent.offset >= size) {
op.extent.length = 0;
} else if (op.extent.offset + op.extent.length > size) {
op.extent.length = size - op.extent.offset;
}

if (op.extent.length == 0) {
dout(20) << __func__ << " zero length extent" << dendl;
return finish_extent_cmp(osd_op, bufferlist{});
} else if (!ctx->obs->exists || ctx->obs->oi.is_whiteout()) {
dout(20) << __func__ << " object DNE" << dendl;
return finish_extent_cmp(osd_op, {});
} else if (pool.info.require_rollback()) {
// If there is a data digest and it is possible we are reading
// entire object, pass the digest.
auto& oi = ctx->new_obs.oi;
boost::optional<uint32_t> maybe_crc;
if (oi.is_data_digest() && op.checksum.offset == 0 &&
op.checksum.length >= oi.size) {
Expand Down
22 changes: 22 additions & 0 deletions src/test/librados/misc.cc
Expand Up @@ -28,6 +28,7 @@ using std::string;

typedef RadosTest LibRadosMisc;
typedef RadosTestPP LibRadosMiscPP;
typedef RadosTestECPP LibRadosMiscECPP;

TEST(LibRadosMiscVersion, Version) {
int major, minor, extra;
Expand Down Expand Up @@ -1356,3 +1357,24 @@ TEST_F(LibRadosMiscPP, Applications) {
ASSERT_EQ(0, ioctx.application_metadata_list("app1", &meta));
ASSERT_EQ(expected_meta, meta);
}

TEST_F(LibRadosMiscECPP, CompareExtentRange) {
bufferlist bl1;
bl1.append("ceph");
ObjectWriteOperation write;
write.write(0, bl1);
ASSERT_EQ(0, ioctx.operate("foo", &write));

bufferlist bl2;
bl2.append("ph");
bl2.append(std::string(2, '\0'));
ObjectReadOperation read1;
read1.cmpext(2, bl2, nullptr);
ASSERT_EQ(0, ioctx.operate("foo", &read1, nullptr));

bufferlist bl3;
bl3.append(std::string(4, '\0'));
ObjectReadOperation read2;
read2.cmpext(2097152, bl3, nullptr);
ASSERT_EQ(0, ioctx.operate("foo", &read2, nullptr));
}