Skip to content

journal/ObjectPlayer: don't acquire locks in destructor - #68613

Merged
idryomov merged 1 commit into
ceph:mainfrom
tchaikov:wip-test-journal-fix-use-after-free
Jun 19, 2026
Merged

idryomov merged 1 commit into
ceph:mainfrom
tchaikov:wip-test-journal-fix-use-after-free

Conversation

@tchaikov

@tchaikov tchaikov commented Apr 25, 2026 •

Copy link
Copy Markdown
Contributor

~ObjectPlayer took m_timer_lock only to assert two invariants. but that
lock is borrowed by reference from the caller's SafeTimer, and an
ObjectPlayer can outlive it: a C_Fetch/C_WatchFetch completion on the
librados finisher may hold the last reference and run ~ObjectPlayer after
the timer and its lock are already gone. re-taking the freed lock is a
heap-use-after-free, which unittest_journal hits on arm64 under ASan:

  ==ERROR: AddressSanitizer: heap-use-after-free
    journal::ObjectPlayer::~ObjectPlayer  ObjectPlayer.cc:63
    journal::ObjectPlayer::C_WatchFetch::~C_WatchFetch
    journal::ObjectPlayer::C_Fetch::finish

the lock isn't needed though: at refcount 0 the watch has been cancelled
(m_watch_ctx == nullptr, asserted below) so no timer task references us, and
no fetch is in flight since a pending fetch holds a reference. nothing else
can touch our state.

Fixes: https://tracker.ceph.com/issues/77496

Contribution Guidelines

  • To sign and title your commits, please refer to Submitting Patches to Ceph.

  • If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.

  • When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an x between the brackets: [x]. Spaces and capitalization matter when checking off items this way.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands

You must only issue one Jenkins command per-comment. Jenkins does not understand
comments with more than one command.

@tchaikov
tchaikov requested a review from a team as a code owner April 25, 2026 13:30
@tchaikov tchaikov mentioned this pull request Apr 25, 2026
4 of 14 tasks
@tchaikov
tchaikov requested review from Copilot and idryomov May 5, 2026 13:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a use-after-free race in unittest_journal teardown by ensuring any pending async RADOS callbacks that still hold ObjectPlayer references complete before the test fixture (and its m_timer_lock) is destroyed.

Changes:

  • After shutting down and deleting the SafeTimer, call m_ioctx.aio_flush() to drain in-flight AIO/callback work before tearing down the rest of the fixture.

@tchaikov

tchaikov commented May 5, 2026

Copy link
Copy Markdown
Contributor Author

@idryomov hi Ilya, do you mind helping review this change at your convenience?

@tchaikov
tchaikov force-pushed the wip-test-journal-fix-use-after-free branch 2 times, most recently from ad38441 to cd721d0 Compare May 30, 2026 10:46
@tchaikov

Copy link
Copy Markdown
Contributor Author

@idryomov hi Ilya, ping. do you mind helping review this change at your convenience? this is one of the last two commits allowing us to enable ASan in our CI. would be great if we can enable it sooner. see also #56537

@tchaikov

Copy link
Copy Markdown
Contributor Author

jenkins test make check arm64

@tchaikov
tchaikov force-pushed the wip-test-journal-fix-use-after-free branch from cd721d0 to cc19de6 Compare June 14, 2026 07:20
@tchaikov tchaikov changed the title test/journal: drain in-flight aio before destroying timer lock journal/ObjectPlayer: don't re-acquire the borrowed timer lock in the dtor Jun 14, 2026
@tchaikov

Copy link
Copy Markdown
Contributor Author

jenkins test make check

@tchaikov

Copy link
Copy Markdown
Contributor Author

jenkins test make check arm64

Comment thread src/journal/ObjectPlayer.cc Resolved
@tchaikov
tchaikov force-pushed the wip-test-journal-fix-use-after-free branch from cc19de6 to e2d7a9b Compare June 18, 2026 11:14
@tchaikov

Copy link
Copy Markdown
Contributor Author

changelog:

  • incorporated reviewer's comments: do not acquire m_lock when checking m_fetch_in_progress and m_watch_ctx

@tchaikov
tchaikov requested a review from idryomov June 18, 2026 11:16
@tchaikov

Copy link
Copy Markdown
Contributor Author

@idryomov could you take another look?

@idryomov

idryomov commented Jun 18, 2026 •

Copy link
Copy Markdown
Contributor
  • Code cleanup (no ticket needed)

Since this is technically a use-after-free and we ended up changing production rather than test code to fix it, I'd suggest filing a tracker ticket and treating this as a bug fix.

@idryomov idryomov added bug-fix and removed tests labels Jun 18, 2026
@tchaikov
tchaikov force-pushed the wip-test-journal-fix-use-after-free branch from e2d7a9b to d0b3619 Compare June 18, 2026 11:42
~ObjectPlayer took m_timer_lock only to assert two invariants. but that
lock is borrowed by reference from the caller's SafeTimer, and an
ObjectPlayer can outlive it: a C_Fetch/C_WatchFetch completion on the
librados finisher may hold the last reference and run ~ObjectPlayer after
the timer and its lock are already gone. re-taking the freed lock is a
heap-use-after-free, which unittest_journal hits on arm64 under ASan:

  ==ERROR: AddressSanitizer: heap-use-after-free
    journal::ObjectPlayer::~ObjectPlayer  ObjectPlayer.cc:63
    journal::ObjectPlayer::C_WatchFetch::~C_WatchFetch
    journal::ObjectPlayer::C_Fetch::finish

the lock isn't needed though: at refcount 0 the watch has been cancelled
(m_watch_ctx == nullptr, asserted below) so no timer task references us, and
no fetch is in flight since a pending fetch holds a reference. nothing else
can touch our state. Furthermore, we can also skip acquiring `m_lock` as
well, because, in the destructor, it shouldn't really matter -- if one
of these asserts fails because the execution of the destructor races
with some `ObjectPlayer` mthod, we would get what the `assert()` was
added for. They are here to catch bugs and such a race just being
possible is a bug in itself.

Fixes: https://tracker.ceph.com/issues/77496
Signed-off-by: Kefu Chai <[email protected]>
@tchaikov
tchaikov force-pushed the wip-test-journal-fix-use-after-free branch from d0b3619 to a35a926 Compare June 18, 2026 11:43
@tchaikov tchaikov changed the title journal/ObjectPlayer: don't re-acquire the borrowed timer lock in the dtor journal/ObjectPlayer: don't acquire locks in destructor Jun 18, 2026
@tchaikov

Copy link
Copy Markdown
Contributor Author
  • Code cleanup (no ticket needed)

Since this is technically a use-after-free and we ended up changing production rather than test code to fix it, I'd suggest filing a tracker ticket and treating this as a bug fix.

agreed. we might even need to backport it.

@tchaikov

Copy link
Copy Markdown
Contributor Author

changelog:

  • add Fixes tag to link the tracker issue addressed by it.
  • update the title of pull request to reflect the change

@tchaikov

Copy link
Copy Markdown
Contributor Author

@idryomov thanks! could you please re-re-review this change?

@idryomov
idryomov merged commit 1ba7d25 into ceph:main Jun 19, 2026
21 checks passed
@tchaikov
tchaikov deleted the wip-test-journal-fix-use-after-free branch June 19, 2026 11:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants