Repository navigation
journal/ObjectPlayer: don't acquire locks in destructor - #68613
Conversation
There was a problem hiding this comment.
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, callm_ioctx.aio_flush()to drain in-flight AIO/callback work before tearing down the rest of the fixture.
|
@idryomov hi Ilya, do you mind helping review this change at your convenience? |
ad38441 to
cd721d0
Compare
|
jenkins test make check arm64 |
cd721d0 to
cc19de6
Compare
|
jenkins test make check |
|
jenkins test make check arm64 |
cc19de6 to
e2d7a9b
Compare
|
changelog:
|
|
@idryomov could you take another look? |
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. |
e2d7a9b to
d0b3619
Compare
~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]>
d0b3619 to
a35a926
Compare
agreed. we might even need to backport it. |
|
changelog:
|
|
@idryomov thanks! could you please re-re-review this change? |
~ObjectPlayertook m_timer_lock only to assert two invariants. but thatlock is borrowed by reference from the caller's
SafeTimer, and anObjectPlayercan outlive it: aC_Fetch/C_WatchFetchcompletion on thelibrados finisher may hold the last reference and run
~ObjectPlayerafterthe timer and its lock are already gone. re-taking the freed lock is a
heap-use-after-free, whichunittest_journalhits on arm64 under ASan: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, andno 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
xbetween the brackets:[x]. Spaces and capitalization matter when checking off items this way.Checklist
Show available Jenkins commands
jenkins test classic perfJenkins Job | Jenkins Job Definitionjenkins test crimson perfJenkins Job | Jenkins Job Definitionjenkins test signedJenkins Job | Jenkins Job Definitionjenkins test make checkJenkins Job | Jenkins Job Definitionjenkins test make check arm64Jenkins Job | Jenkins Job Definitionjenkins test submodulesJenkins Job | Jenkins Job Definitionjenkins test dashboardJenkins Job | Jenkins Job Definitionjenkins test dashboard cephadmJenkins Job | Jenkins Job Definitionjenkins test apiJenkins Job | Jenkins Job Definitionjenkins test docsReadTheDocs | Github Workflow Definitionjenkins test ceph-volume allJenkins Jobs | Jenkins Jobs Definitionjenkins test windowsJenkins Job | Jenkins Job Definitionjenkins test rook e2eJenkins Job | Jenkins Job DefinitionYou must only issue one Jenkins command per-comment. Jenkins does not understand
comments with more than one command.