Skip to content

librbd: fix use-after-free releasing object map locks in deep copy - #69620

Merged
idryomov merged 1 commit into
ceph:mainfrom
tchaikov:wip-rbd-fix-uaf
Jun 25, 2026
Merged

idryomov merged 1 commit into
ceph:mainfrom
tchaikov:wip-rbd-fix-uaf

Conversation

@tchaikov

@tchaikov tchaikov commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor

DeepCopyRequest::send_copy_object_map() holds the destination image's owner_lock and image_lock (shared), issues an asynchronous object_map->rollback(), and then releases the two locks through m_dst_image_ctx. The rollback callback drives the rest of the request to completion (handle_copy_object_map() ... finish() -> put()) on other threads. That path needs image_lock, so it only proceeds once this method releases it, and can then run to completion and free 'this' before the following owner_lock.unlock_shared() executes, dereferencing the freed DeepCopyRequest.

ASan reported this as a heap-use-after-free in
TestImageReplayer.StartReplayAndWrite: the object was freed on the finisher thread (handle_copy_metadata() -> finish()) while the io_context thread was still in send_copy_object_map().

The destination image ctx outlives the request, so operate through a local reference to it and release the locks through that reference rather than through 'this', as
operation/SnapshotRollbackRequest::send_rollback_object_map() already does.

Keep the explicit lock_shared()/unlock_shared() calls rather than scoped std::shared_lock guards: unlike
operation/SnapshotRollbackRequest::send_rollback_object_map(), send_copy_object_map() has four exit paths (send_copy_metadata(), send_refresh_object_map(), finish(), and the object map rollback), each of which must release the locks before running a different continuation, so RAII guards would push that continuation out of the locked scope and read less clearly than unlocking at each exit.

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

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.

DeepCopyRequest::send_copy_object_map() holds the destination image's
owner_lock and image_lock (shared), issues an asynchronous
object_map->rollback(), and then releases the two locks through
m_dst_image_ctx.  The rollback callback drives the rest of the request to
completion (handle_copy_object_map() ... finish() -> put()) on other
threads.  That path needs image_lock, so it only proceeds once this method
releases it, and can then run to completion and free 'this' before the
following owner_lock.unlock_shared() executes, dereferencing the freed
DeepCopyRequest.

ASan reported this as a heap-use-after-free in
TestImageReplayer.StartReplayAndWrite: the object was freed on the finisher
thread (handle_copy_metadata() -> finish()) while the io_context thread was
still in send_copy_object_map().

The destination image ctx outlives the request, so operate through a local
reference to it and release the locks through that reference rather than
through 'this', as
operation/SnapshotRollbackRequest::send_rollback_object_map() already does.

Keep the explicit lock_shared()/unlock_shared() calls rather than scoped
std::shared_lock guards: unlike
operation/SnapshotRollbackRequest::send_rollback_object_map(),
send_copy_object_map() has four exit paths (send_copy_metadata(),
send_refresh_object_map(), finish(), and the object map rollback), each of
which must release the locks before running a different continuation, so
RAII guards would push that continuation out of the locked scope and read
less clearly than unlocking at each exit.

Fixes: https://tracker.ceph.com/issues/77551
Signed-off-by: Kefu Chai <[email protected]>
@tchaikov
tchaikov requested a review from a team as a code owner June 22, 2026 00:27
@github-actions github-actions Bot added the rbd label Jun 22, 2026
@tchaikov

Copy link
Copy Markdown
Contributor Author

jenkins test make check arm64

@tchaikov

Copy link
Copy Markdown
Contributor Author

jenkins test windows

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.

2 participants