osd: Fix scrub object state pins: crash when the object becomes clean, leak in scrub_recalc_state #158

Open
koolkhel wants to merge 3 commits from koolkhel/vitastor:scrub-recalc-pin into master
Contributor

Description

Two follow-ups to 3bf0b45a ("Pin object state while reading"):

  • Crash when a pinned object becomes clean. Scrub now passes ref=true to mark_object(), which increments the ref count of the new state. add_object_to_set() returns NULL when the object becomes clean, so mark_object() dereferences NULL. One way to get there: a scrub of a misplaced object finds its extra copy outside the PG gone, the copy is dropped, and the object is clean. Reads and writes that mark objects corrupted with ref=true go the same way. Fix: skip the increment for a NULL state; all callers already handle NULL.
  • Unbalanced pin in scrub_recalc_state(). It still called mark_object() with ref=false. When it swapped states, the pin stayed on the old state, which then leaked with no objects. The final deref in continue_primary_scrub() then decremented the new, unpinned state, so its ref_count wrapped around, or a write to the same object lost its pin. Fix: ref=true, as in the other scrub path.

Tested: new osd_test cases.

  • test_scrub_drops_gone_misplaced_copy segfaults on master.
  • test_scrub_recalc_state_pin(degraded) fails its "no pin left" assertion on master.
  • test_scrub_recalc_state_pin(clean) segfaults with only the ref=true change.
  • The whole osd_test passes with the fix.

The second commit adds a check to test_read_enoent_without_racing_op_marks_corrupted that a failed primary read leaves no object state pinned, so the read-path pin from 3bf0b45a has a test too. It fails if the read never drops its pin.

capturing_bs_t::read_bitmap() in the test fixture can now report a version, so the recalculation can find an older local copy.

Contributor Name

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

CLA

### Description Two follow-ups to 3bf0b45a ("Pin object state while reading"): - **Crash when a pinned object becomes clean.** Scrub now passes `ref=true` to `mark_object()`, which increments the ref count of the new state. `add_object_to_set()` returns NULL when the object becomes clean, so `mark_object()` dereferences NULL. One way to get there: a scrub of a misplaced object finds its extra copy outside the PG gone, the copy is dropped, and the object is clean. Reads and writes that mark objects corrupted with `ref=true` go the same way. Fix: skip the increment for a NULL state; all callers already handle NULL. - **Unbalanced pin in `scrub_recalc_state()`.** It still called `mark_object()` with `ref=false`. When it swapped states, the pin stayed on the old state, which then leaked with no objects. The final deref in `continue_primary_scrub()` then decremented the new, unpinned state, so its `ref_count` wrapped around, or a write to the same object lost its pin. Fix: `ref=true`, as in the other scrub path. Tested: new `osd_test` cases. - `test_scrub_drops_gone_misplaced_copy` segfaults on master. - `test_scrub_recalc_state_pin(degraded)` fails its "no pin left" assertion on master. - `test_scrub_recalc_state_pin(clean)` segfaults with only the `ref=true` change. - The whole `osd_test` passes with the fix. The second commit adds a check to `test_read_enoent_without_racing_op_marks_corrupted` that a failed primary read leaves no object state pinned, so the read-path pin from 3bf0b45a has a test too. It fails if the read never drops its pin. `capturing_bs_t::read_bitmap()` in the test fixture can now report a version, so the recalculation can find an older local copy. ### 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-23 11:32:48 +03:00
3bf0b45a made scrub pin its object state and pass ref=true to
mark_object(). mark_object() then increments the ref count of the new
state, but add_object_to_set() returns NULL when the object becomes
clean, so a scrub that drops a vanished misplaced copy segfaults. Reads
and writes that mark objects corrupted with ref=true have the same path.

scrub_recalc_state() still called mark_object() with ref=false. When it
swapped states, the pin stayed on the old state, which then leaked with
no objects, and the final deref in continue_primary_scrub() decremented
the new, unpinned state: its ref_count wrapped around, or a write to the
same object lost its pin.
koolkhel added 1 commit 2026-11-23 21:48:04 +03:00
The read path pins the object state since 3bf0b45a, but no test checked
that the pin is released. Assert that no state in the PG is left pinned
after the read fails with EIO and the object is marked corrupted.
koolkhel added 1 commit 2026-11-23 23:59:00 +03:00
test_read_enoent_waits_behind_running_delete is the only test where a
read comes back to a replaced object state and drops its pin on the old
one. Assert that no state in the PG is left pinned there too.
This pull request has changes conflicting with the target branch.
  • src/test/osd_test_fixture.h
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u scrub-recalc-pin:koolkhel-scrub-recalc-pin
git checkout koolkhel-scrub-recalc-pin
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#158
No description provided.