From 2bb8967350fbac7ca8fcd6342c51d3054798daa4 Mon Sep 17 00:00:00 2001 From: Yury Luneff Date: Tue, 24 Nov 2026 14:28:33 +0300 Subject: [PATCH 1/2] OSD: Reject inverted ranges in primary LIST A primary LIST (OSD_OP_SEC_LIST with OSD_LIST_PRIMARY) with min_stripe above max_stripe made add_primary_list() start from lower_bound(min), which lies after upper_bound(max). If an unclean object of the PG was between the two bounds, the loop never met its end iterator and walked past the end of the btree, reading out of bounds and filling the result set with garbage until the OSD ran out of memory. Reject such a request with -EINVAL, like the other malformed ones. --- src/osd/osd_primary_describe.cpp | 1 + src/test/osd_test.cpp | 62 ++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/src/osd/osd_primary_describe.cpp b/src/osd/osd_primary_describe.cpp index 7b09a9c5..bcc35d9b 100644 --- a/src/osd/osd_primary_describe.cpp +++ b/src/osd/osd_primary_describe.cpp @@ -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) || diff --git a/src/test/osd_test.cpp b/src/test/osd_test.cpp index 74e1499e..54e3961b 100644 --- a/src/test/osd_test.cpp +++ b/src/test/osd_test.cpp @@ -5445,6 +5445,67 @@ 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 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(); + 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 = 1; + 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; + // lower_bound(min) is the 3rd object, upper_bound(max) is the 2nd one + op->req.sec_list.min_stripe = 0x50000; + op->req.sec_list.max_stripe = 0x30000; + 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(bs_list->callback)(bs_list); + } + assert(f.client(client_id)->sent_ops.count(1) == 1); + assert(f.client(client_id)->sent_ops.at(1)->reply.hdr.retval == -EINVAL); + + printf("test_primary_list_inverted_range passed\n"); +} + int main(int narg, char *args[]) { test_load_global_config(); @@ -5495,6 +5556,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); -- 2.47.3 From 4442a7906090c163d98f462a67078062da059fd1 Mon Sep 17 00:00:00 2001 From: Yury Luneff Date: Tue, 24 Nov 2026 20:02:22 +0300 Subject: [PATCH 2/2] OSD: Also test a primary LIST without an upper bound max_stripe = 0 means no upper bound, so the inverted range check must not reject a listing that only sets min_stripe. --- src/test/osd_test.cpp | 55 ++++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/src/test/osd_test.cpp b/src/test/osd_test.cpp index 54e3961b..1fc6ac44 100644 --- a/src/test/osd_test.cpp +++ b/src/test/osd_test.cpp @@ -5477,31 +5477,38 @@ void test_primary_list_inverted_range() assert(f.pg(1, 1).degraded_objects.size() == 3); uint64_t client_id = f.connect_client(); - 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 = 1; - 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; - // lower_bound(min) is the 3rd object, upper_bound(max) is the 2nd one - op->req.sec_list.min_stripe = 0x50000; - op->req.sec_list.max_stripe = 0x30000; - op->req.sec_list.flags = OSD_LIST_PRIMARY; - f.exec(op); - auto *bs_list = f.bs->take(BS_OP_LIST, false); - if (bs_list) + uint64_t op_id = 0; + auto list = [&](uint64_t min_stripe, uint64_t max_stripe) { - // Empty local listing: only the unclean lists feed the reply - bs_list->retval = 0; - bs_list->version = 0; - bs_list->buf = NULL; - std::function(bs_list->callback)(bs_list); - } - assert(f.client(client_id)->sent_ops.count(1) == 1); - assert(f.client(client_id)->sent_ops.at(1)->reply.hdr.retval == -EINVAL); + 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(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"); } -- 2.47.3