Skip to content

rgw: fix use-after-free on cancellation in shard_io::async_reads() - #70918

Merged
anrao19 merged 1 commit into
ceph:mainfrom
cbodley:wip-79095
Aug 18, 2026
Merged

anrao19 merged 1 commit into
ceph:mainfrom
cbodley:wip-79095

Conversation

@cbodley

@cbodley cbodley commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

when ReadHandler encounters an error and cancels other outstanding requests, its calls to emit() likely execute those cancellation handlers inline. these can cause async_reads() to wake up and co_return prematurely while the initial ReadHandler is still looping over the 'outstanding' list on its stack

prevent this early return by leaving this initial shard in the 'outstanding' list during the cancellation loop

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

Show available Jenkins commands

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

@cbodley
cbodley requested a review from a team as a code owner August 7, 2026 15:32
@github-actions github-actions Bot added the rgw label Aug 7, 2026
@cbodley
cbodley force-pushed the wip-79095 branch 2 times, most recently from e16ca4c to ba3b42f Compare August 7, 2026 15:35
@cbodley
cbodley requested review from adamemerson and smanjara August 7, 2026 16:15
@smanjara

smanjara commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

looks good! there is a similar pattern in WaitCancellation::operator(). I don't know what would trigger it but probably worth applying the same fix there as well?

@cbodley

cbodley commented Aug 10, 2026

Copy link
Copy Markdown
Contributor Author

looks good! there is a similar pattern in WaitCancellation::operator(). I don't know what would trigger it but probably worth applying the same fix there as well?

WaitCancellation handles cancellation signals from outside of the coroutine, so there isn't a natural entry in 'outstanding' to preserve until the end. rather than using while (i != outstanding.end()) as the loop condition there (which accesses outstanding after its potential destruction), i store a local variable bool done = (i == outstanding.end()); before the emit() that we can safely check afterwards

when ReadHandler encounters an error and cancels other outstanding
requests, its calls to emit() likely execute those cancellation handlers
inline. these can cause async_reads() to wake up and co_return
prematurely while the initial ReadHandler is still looping over the
'outstanding' list on its stack

prevent this early return by leaving this initial shard in the
'outstanding' list during the cancellation loop

adjust WaitCancellation to use a local variable for the loop condition.
this way if the final cancellation wakes the calling coroutine and
causes it to return, we don't try to access its stack memory again with
'i != outstanding.end()'

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

Signed-off-by: Casey Bodley <[email protected]>
Co-authored-by: Shilpa Jagannath <[email protected]>
@cbodley

cbodley commented Aug 10, 2026

Copy link
Copy Markdown
Contributor Author

i added some printfs to verify that these test cases are in fact exercising the race between ReadHandlers and co_return:

[ RUN      ] Reader.throttle_errors
> ReadHandler 0 Success
< ReadHandler 0
> ReadHandler 1 No such file or directory
  ReadHandler 1 cancelling 2
> ReadHandler 2 Operation canceled
co_return
< ReadHandler 2
< ReadHandler 1
[       OK ] Reader.throttle_errors (0 ms)
[ RUN      ] Reader.drain_errors
> ReadHandler 0 Success
< ReadHandler 0
> ReadHandler 1 No such file or directory
  ReadHandler 1 cancelling 2
> ReadHandler 2 Operation canceled
< ReadHandler 2
  ReadHandler 1 cancelling 3
> ReadHandler 3 Operation canceled
co_return
< ReadHandler 3
< ReadHandler 1
[       OK ] Reader.drain_errors (0 ms)

@anrao19

anrao19 commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

pr testing completed and approved by @ivancich , more details in : https://tracker.ceph.com/issues/79449
@cbodley , if there no further testing is needed then this pr can be merged

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