OSD: Reject inverted ranges in primary LIST #176

Merged
vitalif merged 2 commits from koolkhel/vitastor:osd-primary-list-inverted-range into master 2026-11-25 20:52:19 +03:00
2 changed files with 70 additions and 0 deletions

View File

@@ -174,6 +174,7 @@ void osd_t::continue_primary_list(osd_op_t *cur_op)
!INODE_POOL(cur_op->req.sec_list.min_inode) ||
INODE_NO_POOL(cur_op->req.sec_list.min_inode) != INODE_NO_POOL(cur_op->req.sec_list.max_inode) ||
INODE_POOL(cur_op->req.sec_list.max_inode) != INODE_POOL(cur_op->req.sec_list.min_inode) ||
(cur_op->req.sec_list.max_stripe && cur_op->req.sec_list.min_stripe > cur_op->req.sec_list.max_stripe) ||
cur_op->req.sec_list.stable_limit ||
pool_cfg_it == st_cli->pool_config.end() ||
(cur_op->req.sec_list.pg_stripe_size != 0 && cur_op->req.sec_list.pg_stripe_size != pool_cfg_it->second.pg_stripe_size) ||

View File

@@ -5445,6 +5445,74 @@ void test_chained_read_through_incomplete_parent()
printf("test_chained_read_through_incomplete_parent passed\n");
}
// A primary LIST with min_stripe above max_stripe must be rejected,
// not walk the unclean object lists from lower_bound(min) past upper_bound(max)
void test_primary_list_inverted_range()
{
printf("test_primary_list_inverted_range\n");
osd_test_fixture_t f;
f.configure_replicated_pool(/*pool_id*/ 1, /*pg_size*/ 3, /*pg_minsize*/ 1, /*pg_count*/ 1,
{ { 1, 2, 3 } });
f.start(json11::Json::object {
{ "osd_num", 1 },
{ "etcd_address", "127.0.0.1:2379" },
{ "immediate_commit", "all" },
{ "block_size", 131072 },
{ "bitmap_granularity", 4096 },
{ "no_recovery", true },
});
f.connect_peer(2);
f.connect_peer(3);
inode_t inode = INODE_WITH_POOL(1, 1);
std::vector<obj_ver_id> objs;
for (uint64_t i = 1; i <= 3; i++)
objs.push_back({ .oid = { .inode = inode, .stripe = i*0x20000 }, .version = 1 });
// OSD 3 has no copies, so all three objects are degraded
f.reply_local_list(objs, objs.size());
f.reply_peer_list(2, objs, objs.size());
f.reply_peer_list(3, {}, 0);
f.pump();
assert(f.pg(1, 1).degraded_objects.size() == 3);
uint64_t client_id = f.connect_client();
uint64_t op_id = 0;
auto list = [&](uint64_t min_stripe, uint64_t max_stripe)
{
auto *op = new osd_op_t();
op->op_type = OSD_OP_IN;
op->client_id = client_id;
op->req.hdr.magic = SECONDARY_OSD_OP_MAGIC;
op->req.hdr.id = ++op_id;
op->req.hdr.opcode = OSD_OP_SEC_LIST;
op->req.sec_list.list_pg = 1;
op->req.sec_list.min_inode = inode;
op->req.sec_list.max_inode = inode;
op->req.sec_list.min_stripe = min_stripe;
op->req.sec_list.max_stripe = max_stripe;
op->req.sec_list.flags = OSD_LIST_PRIMARY;
f.exec(op);
auto *bs_list = f.bs->take(BS_OP_LIST, false);
if (bs_list)
{
// Empty local listing: only the unclean lists feed the reply
bs_list->retval = 0;
bs_list->version = 0;
bs_list->buf = NULL;
std::function<void(blockstore_op_t*)>(bs_list->callback)(bs_list);
}
assert(f.client(client_id)->sent_ops.count(op_id) == 1);
return f.client(client_id)->sent_ops.at(op_id)->reply.hdr.retval;
};
// lower_bound(min) is the 3rd object, upper_bound(max) is the 2nd one
assert(list(0x50000, 0x30000) == -EINVAL);
// max_stripe = 0 means no upper bound
assert(list(0x30000, 0) == 2);
printf("test_primary_list_inverted_range passed\n");
}
int main(int narg, char *args[])
{
test_load_global_config();
@@ -5495,6 +5563,7 @@ int main(int narg, char *args[])
test_chained_read_large_chain_info();
test_chained_read_eio_after_recovery_finishes();
test_chained_read_through_incomplete_parent();
test_primary_list_inverted_range();
test_peering_partial_unstable_ec_rolls_back();
test_peering_flush_primary_lost({ 2, 1, 2 }, 2);
test_peering_flush_primary_lost({ 2, 1, 2 }, 3);