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
Contributor

Description

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 (degraded, misplaced, incomplete or inconsistent) object of the PG was between the two bounds, the loop never met its end iterator and walked past the end of the btree: an out-of-bounds read, and the result set filled with garbage until the OSD ran out of memory. The OSD stops answering meanwhile.

The request validation in continue_primary_list() already forces min_inode == max_inode, so the stripes alone decide the order. This rejects an inverted range there with -EINVAL, like the other malformed requests, which also skips the store LIST. It is the primary-LIST sibling of 6d7223d9 "OSD: Reject inverted ranges in DESCRIBE".

Such a request comes from a client, e.g. vitastor-cli rm-data --min-offset A --max-offset B with A > B while the PG is degraded, or any client with read access to the inode when use_perms is on.

Tested: new test_primary_list_inverted_range in osd_test: a replicated PG with three degraded objects, then a primary LIST with min_stripe=0x50000, max_stripe=0x30000 (must get -EINVAL), and one with min_stripe=0x30000 and no upper bound (must still list the two objects above it). Without the fix, ASan reports heap-buffer-overflow in add_primary_list(), and a build without ASan never returns while its memory grows. With the fix the request gets -EINVAL, and the whole osd_test passes.

Contributor Name

Yury Luneff (MIND Software LLC, https://mindsw.io)

CLA

### Description 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 (degraded, misplaced, incomplete or inconsistent) object of the PG was between the two bounds, the loop never met its end iterator and walked past the end of the btree: an out-of-bounds read, and the result set filled with garbage until the OSD ran out of memory. The OSD stops answering meanwhile. The request validation in `continue_primary_list()` already forces `min_inode == max_inode`, so the stripes alone decide the order. This rejects an inverted range there with `-EINVAL`, like the other malformed requests, which also skips the store LIST. It is the primary-LIST sibling of 6d7223d9 "OSD: Reject inverted ranges in DESCRIBE". Such a request comes from a client, e.g. `vitastor-cli rm-data --min-offset A --max-offset B` with A > B while the PG is degraded, or any client with read access to the inode when `use_perms` is on. Tested: new `test_primary_list_inverted_range` in `osd_test`: a replicated PG with three degraded objects, then a primary LIST with `min_stripe=0x50000`, `max_stripe=0x30000` (must get `-EINVAL`), and one with `min_stripe=0x30000` and no upper bound (must still list the two objects above it). Without the fix, ASan reports `heap-buffer-overflow` in `add_primary_list()`, and a build without ASan never returns while its memory grows. With the fix the request gets `-EINVAL`, and the whole `osd_test` passes. ### Contributor Name Yury Luneff (MIND Software LLC, https://mindsw.io) ### CLA - [x] I accept Vitastor CLA agreement: https://git.yourcmc.ru/vitalif/vitastor/src/branch/master/CLA-en.md
koolkhel added 1 commit 2026-11-24 14:28:48 +03:00
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.
koolkhel added 1 commit 2026-11-24 20:02:26 +03:00
max_stripe = 0 means no upper bound, so the inverted range check must
not reject a listing that only sets min_stripe.
vitalif merged commit 49e76ea850 into master 2026-11-25 20:52:19 +03:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: vitalif/vitastor#176
No description provided.