Skip to content

rgw: serialize send_partial_response in multi-object delete - #69193

Closed
mkogan1 wants to merge 1 commit into
ceph:mainfrom
mkogan1:wip-rgw-multi-delete-mtx
Closed

mkogan1 wants to merge 1 commit into
ceph:mainfrom
mkogan1:wip-rgw-multi-delete-mtx

Conversation

@mkogan1

@mkogan1 mkogan1 commented May 31, 2026 •

Copy link
Copy Markdown
Contributor

concurrent Multi Objects Delete request can run on different io_context pool threads, causing concurrent access to the shared formatter and ops_log_entries vector in send_partial_response().
this data race can lead to use-after-free during vector reallocation (detected by ASAN)

add a mutex to serialize the formatter writes and ops_log_entries push_back.

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

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.

concurrent Multi Objects Delete request can run on different io_context pool threads,
causing concurrent access to the shared formatter and ops_log_entries vector
in send_partial_response().
this data race can lead to use-after-free during vector reallocation
(detected by ASAN)

add a mutex to serialize the formatter writes and ops_log_entries
push_back.

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

Signed-off-by: Mark Kogan <[email protected]>
@smanjara

smanjara commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

LGTM. but I still don't understand why the strand fails to serialize.

@mkogan1
mkogan1 force-pushed the wip-rgw-multi-delete-mtx branch from 2d37be7 to 76737dd Compare June 2, 2026 07:14
@github-actions github-actions Bot added the common label Jun 2, 2026
Comment thread src/common/StackStringStream.h Outdated
Comment on lines +143 to +145
// Lock and double-check before accessing vector
std::lock_guard<std::mutex> lock(cache_ptr->mutex);
if (!cache_ptr->valid.load(std::memory_order_relaxed) || cache_ptr->c.empty()) {

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.

why is mutex/atomic necessary for a thread-local cache? do you see some access coming from a different thread?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@cbodley apologies, did not meant to push this commit - removed it

it is something that I need to cherry-pick occasionally on some machines to prevent crashes from RGW logger ...
(working on a better fix for it w/ Adam at #68705)

@mkogan1
mkogan1 force-pushed the wip-rgw-multi-delete-mtx branch from 76737dd to 2d37be7 Compare June 2, 2026 13:29
@mkogan1
mkogan1 marked this pull request as ready for review June 2, 2026 14:03
@mkogan1
mkogan1 requested a review from a team as a code owner June 2, 2026 14:03
@cbodley

cbodley commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

concurrent Multi Objects Delete request can run on different io_context pool threads, causing concurrent access to the shared formatter and ops_log_entries vector in send_partial_response().

like Shilpa, i still don't see anything unsafe about send_partial_response()

the initial coroutine from the beast frontend that calls RGWDeleteMultiObj::execute() does spawn additional coroutines for handle_individual_object(), but they're all scheduled on the same strand executor. this means that only one of them can be running at a time, while the rest are suspended - either waiting for their rados response, or waiting in the strand's queue (internally protected by a mutex) of handlers ready to resume

@mkogan1

mkogan1 commented Jun 2, 2026

Copy link
Copy Markdown
Contributor Author

@smanjara re:

LGTM. but I still don't understand why the strand fails to serialize.

The strand do serialize, only one fiber runs at a time, but the fibers resume on different threads (whichever pool thread picks up the completion)
The strand guarantees happens-before ordering, so in theory the access should be safe. However, ASAN flagged it as heap-use-after-free across threads (T448 freed, T460 read),
and there were also reproduced real crashes (SIGSEGV) with glibc malloc and tcmalloc under heavy OLH workload, in ops_log_entries.push_back() during vector reallocation.

❯ sudo cat asan.log.3180444
=================================================================
==3180444==ERROR: AddressSanitizer: heap-use-after-free on address 0x512000210040 at pc 0x5555573c515e bp 0x7fff77ca9e40 sp 0x7fff77ca9e38
READ of size 8 at 0x512000210040 thread T460
    #0 0x5555573c515d in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_data() const /usr/include/c++/14/bits/basic_string.h:228
    #1 0x5555573c515d in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_is_local() const /usr/include/c++/14/bits/basic_string.h:269
    #2 0x5555573c515d in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&) /usr/include/c++/14/bits/basic_string.h:685
    #3 0x5555573c515d in delete_multi_obj_entry::delete_multi_obj_entry(delete_multi_obj_entry&&) /mnt/raid/src-git/ceph--up--main/src/rgw/rgw_log.h:17
    #4 0x5555573c515d in decltype (::new ((void*)(0)) delete_multi_obj_entry((declval<delete_multi_obj_entry>)())) std::construct_at<delete_multi_obj_entry, delete_multi_obj_entry>(delete_multi_obj_entry*, delete_multi_obj_entry&&) /usr/include/c++/14/bits/stl_construct.h:97
    #5 0x5555573c515d in void std::allocator_traits<std::allocator<delete_multi_obj_entry> >::construct<delete_multi_obj_entry, delete_multi_obj_entry>(std::allocator<delete_multi_obj_entry>&, delete_multi_obj_entry*, delete_multi_obj_entry&&) /usr/include/c++/14/bits/alloc_traits.h:536
    #6 0x5555573c515d in void std::__relocate_object_a<delete_multi_obj_entry, delete_multi_obj_entry, std::allocator<delete_multi_obj_entry> >(delete_multi_obj_entry*, delete_multi_obj_entry*, std::allocator<delete_multi_obj_entry>&) /usr/include/c++/14/bits/stl_uninitialized.h:1075
    #7 0x5555573c515d in delete_multi_obj_entry* std::__relocate_a_1<delete_multi_obj_entry*, delete_multi_obj_entry*, std::allocator<delete_multi_obj_entry> >(delete_multi_obj_entry*, delete_multi_obj_entry*, delete_multi_obj_entry*, std::allocator<delete_multi_obj_entry>&) /usr/include/c++/14/bits/stl_uninitialized.h:1103
    #8 0x5555573c515d in delete_multi_obj_entry* std::__relocate_a<delete_multi_obj_entry*, delete_multi_obj_entry*, std::allocator<delete_multi_obj_entry> >(delete_multi_obj_entry*, delete_multi_obj_entry*, delete_multi_obj_entry*, std::allocator<delete_multi_obj_entry>&) /usr/include/c++/14/bits/stl_uninitialized.h:1145
    #9 0x5555573c515d in std::vector<delete_multi_obj_entry, std::allocator<delete_multi_obj_entry> >::_S_relocate(delete_multi_obj_entry*, delete_multi_obj_entry*, delete_multi_obj_entry*, std::allocator<delete_multi_obj_entry>&) /usr/include/c++/14/bits/stl_vector.h:509
    #10 0x5555573c515d in void std::vector<delete_multi_obj_entry, std::allocator<delete_multi_obj_entry> >::_M_realloc_append<delete_multi_obj_entry>(delete_multi_obj_entry&&) /usr/include/c++/14/bits/vector.tcc:647
    #11 0x555557302bcf in delete_multi_obj_entry& std::vector<delete_multi_obj_entry, std::allocator<delete_multi_obj_entry> >::emplace_back<delete_multi_obj_entry>(delete_multi_obj_entry&&) /usr/include/c++/14/bits/vector.tcc:123
    #12 0x555557302bcf in std::vector<delete_multi_obj_entry, std::allocator<delete_multi_obj_entry> >::push_back(delete_multi_obj_entry&&) /usr/include/c++/14/bits/stl_vector.h:1301
    #13 0x555557302bcf in RGWDeleteMultiObj_ObjStore_S3::send_partial_response(rgw_obj_key const&, bool, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int) /mnt/raid/src-git/ceph--up--main/src/rgw/rgw_rest_s3.cc:4996
    #14 0x555556f96bfd in RGWDeleteMultiObj::handle_individual_object(RGWMultiDelObject const&, optional_yield, bool) /mnt/raid/src-git/ceph--up--main/src/rgw/rgw_op.cc:8069
    #15 0x55555706f1cd in operator() /mnt/raid/src-git/ceph--up--main/src/rgw/rgw_op.cc:8091
    #16 0x55555706f1cd in call /mnt/raid/src-git/ceph--up--main/build/boost/include/boost/asio/impl/spawn.hpp:748
    #17 0x55555706f1cd in operator() /mnt/raid/src-git/ceph--up--main/build/boost/include/boost/asio/impl/spawn.hpp:737
    #18 0x55555706f1cd in operator() /mnt/raid/src-git/ceph--up--main/build/boost/include/boost/asio/impl/spawn.hpp:152
    #19 0x55555707035c in __invoke_impl<boost::context::fiber, boost::asio::detail::spawned_fiber_thread::entry_point<boost::asio::detail::spawn_entry_point<boost::asio::any_io_executor, RGWDeleteMultiObj::handle_versioned_objects(const std::vector<RGWMultiDelObject>&, uint32_t, boost::asio::yield_context)::<lambda(boost::asio::yield_context)>, ceph::async::detail::spawn_throttle_handler> >&, boost::context::fiber> /usr/include/c++/14/bits/invoke.h:61
    #20 0x55555707035c in __invoke<boost::asio::detail::spawned_fiber_thread::entry_point<boost::asio::detail::spawn_entry_point<boost::asio::any_io_executor, RGWDeleteMultiObj::handle_versioned_objects(const std::vector<RGWMultiDelObject>&, uint32_t, boost::asio::yield_context)::<lambda(boost::asio::yield_context)>, ceph::async::detail::spawn_throttle_handler> >&, boost::context::fiber> /usr/include/c++/14/bits/invoke.h:97
    #21 0x55555707035c in invoke<boost::asio::detail::spawned_fiber_thread::entry_point<boost::asio::detail::spawn_entry_point<boost::asio::any_io_executor, RGWDeleteMultiObj::handle_versioned_objects(const std::vector<RGWMultiDelObject>&, uint32_t, boost::asio::yield_context)::<lambda(boost::asio::yield_context)>, ceph::async::detail::spawn_throttle_handler> >&, boost::context::fiber> /usr/include/c++/14/functional:121
    #22 0x55555707035c in run /mnt/raid/src-git/ceph--up--main/build/boost/include/boost/context/fiber_fcontext.hpp:157
    #23 0x55555707035c in fiber_entry<boost::context::detail::fiber_record<boost::context::fiber, boost::context::basic_fixedsize_stack<boost::context::stack_traits>, boost::asio::detail::spawned_fiber_thread::entry_point<boost::asio::detail::spawn_entry_point<boost::asio::any_io_executor, RGWDeleteMultiObj::handle_versioned_objects(const std::vector<RGWMultiDelObject>&, uint32_t, boost::asio::yield_context)::<lambda(boost::asio::yield_context)>, ceph::async::detail::spawn_throttle_handler> > > > /mnt/raid/src-git/ceph--up--main/build/boost/include/boost/context/fiber_fcontext.hpp:97
    #24 0x55555a9b4dbe in make_fcontext (/mnt/osd--host/src-git/ceph--up--main/build/bin/radosgw+0x5460dbe) (BuildId: 6a2fc2f49d410632abc6ea1ab95881ef444cf7ed)

0x512000210040 is located 0 bytes inside of 272-byte region [0x512000210040,0x512000210150)
freed by thread T448 here:
    #0 0x7ffff78f93b8 in operator delete(void*, unsigned long) (/usr/lib64/libasan.so.8+0xf93b8) (BuildId: a4ad7eb954b390cf00f07fa10952988a41d9fc7a)

previously allocated by thread T458 here:
    #0 0x7ffff78f84b8 in operator new(unsigned long) (/usr/lib64/libasan.so.8+0xf84b8) (BuildId: a4ad7eb954b390cf00f07fa10952988a41d9fc7a)

Thread T460 created by T0 here:
    #0 0x7ffff78ef871 in pthread_create (/usr/lib64/libasan.so.8+0xef871) (BuildId: a4ad7eb954b390cf00f07fa10952988a41d9fc7a)
    #1 0x7ffff3ae7638 in std::thread::_M_start_thread(std::unique_ptr<std::thread::_State, std::default_delete<std::thread::_State> >, void (*)()) (/lib64/libstdc++.so.6+0xe7638) (BuildId: efdde18722aa72a0a779270371aeee5a9f6ddf87)
    #2 0x5555562751da in rgw::AppMain::init_storage() /mnt/raid/src-git/ceph--up--main/src/rgw/rgw_appmain.cc:239
    #3 0x55555621661d in main /mnt/raid/src-git/ceph--up--main/src/rgw/rgw_main.cc:143
    #4 0x7ffff3838087 in __libc_start_call_main (/lib64/libc.so.6+0x2a087) (BuildId: c8c3fa52aaee3f5d73b6fd862e39e9d4c010b6ba)
    #5 0x7ffff383814a in __libc_start_main_impl (/lib64/libc.so.6+0x2a14a) (BuildId: c8c3fa52aaee3f5d73b6fd862e39e9d4c010b6ba)
    #6 0x55555624df04 in _start (/mnt/osd--host/src-git/ceph--up--main/build/bin/radosgw+0xcf9f04) (BuildId: 6a2fc2f49d410632abc6ea1ab95881ef444cf7ed)

Thread T448 created by T0 here:
    #0 0x7ffff78ef871 in pthread_create (/usr/lib64/libasan.so.8+0xef871) (BuildId: a4ad7eb954b390cf00f07fa10952988a41d9fc7a)
    #1 0x7ffff3ae7638 in std::thread::_M_start_thread(std::unique_ptr<std::thread::_State, std::default_delete<std::thread::_State> >, void (*)()) (/lib64/libstdc++.so.6+0xe7638) (BuildId: efdde18722aa72a0a779270371aeee5a9f6ddf87)
    #2 0x5555562751da in rgw::AppMain::init_storage() /mnt/raid/src-git/ceph--up--main/src/rgw/rgw_appmain.cc:239
    #3 0x55555621661d in main /mnt/raid/src-git/ceph--up--main/src/rgw/rgw_main.cc:143
    #4 0x7ffff3838087 in __libc_start_call_main (/lib64/libc.so.6+0x2a087) (BuildId: c8c3fa52aaee3f5d73b6fd862e39e9d4c010b6ba)
    #5 0x7ffff383814a in __libc_start_main_impl (/lib64/libc.so.6+0x2a14a) (BuildId: c8c3fa52aaee3f5d73b6fd862e39e9d4c010b6ba)
    #6 0x55555624df04 in _start (/mnt/osd--host/src-git/ceph--up--main/build/bin/radosgw+0xcf9f04) (BuildId: 6a2fc2f49d410632abc6ea1ab95881ef444cf7ed)

Thread T458 created by T0 here:
    #0 0x7ffff78ef871 in pthread_create (/usr/lib64/libasan.so.8+0xef871) (BuildId: a4ad7eb954b390cf00f07fa10952988a41d9fc7a)
    #1 0x7ffff3ae7638 in std::thread::_M_start_thread(std::unique_ptr<std::thread::_State, std::default_delete<std::thread::_State> >, void (*)()) (/lib64/libstdc++.so.6+0xe7638) (BuildId: efdde18722aa72a0a779270371aeee5a9f6ddf87)
    #2 0x5555562751da in rgw::AppMain::init_storage() /mnt/raid/src-git/ceph--up--main/src/rgw/rgw_appmain.cc:239
    #3 0x55555621661d in main /mnt/raid/src-git/ceph--up--main/src/rgw/rgw_main.cc:143
    #4 0x7ffff3838087 in __libc_start_call_main (/lib64/libc.so.6+0x2a087) (BuildId: c8c3fa52aaee3f5d73b6fd862e39e9d4c010b6ba)
    #5 0x7ffff383814a in __libc_start_main_impl (/lib64/libc.so.6+0x2a14a) (BuildId: c8c3fa52aaee3f5d73b6fd862e39e9d4c010b6ba)
    #6 0x55555624df04 in _start (/mnt/osd--host/src-git/ceph--up--main/build/bin/radosgw+0xcf9f04) (BuildId: 6a2fc2f49d410632abc6ea1ab95881ef444cf7ed)

SUMMARY: AddressSanitizer: heap-use-after-free /usr/include/c++/14/bits/basic_string.h:228 in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_data() const
Shadow bytes around the buggy address:
  0x51200020fd80: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x51200020fe00: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x51200020fe80: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x51200020ff00: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x51200020ff80: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
=>0x512000210000: fa fa fa fa fa fa fa fa[fd]fd fd fd fd fd fd fd
  0x512000210080: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x512000210100: fd fd fd fd fd fd fd fd fd fd fa fa fa fa fa fa
  0x512000210180: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x512000210200: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x512000210280: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07 
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
==3180444==ABORTING

@BBoozmen

BBoozmen commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

I still don't understand why the strand fails to serialize.

The strand do serialize, only one fiber runs at a time, but the fibers resume on different threads (whichever pool
thread picks up the completion)

I believe this fix is bandaid to the original problem then, right? Otherwise, if the completion was indeed resuming on strand we shouldn't be seeing this race at all.

The source of the issue seems to be in Objecter.h::complete->boost::asio::defer

		     boost::asio::defer(e,
					boost::asio::append(std::move(arg), ec));

The arg is an any_completion_handler. it preserves the associated executor (the strand from the coroutine). But instead of dispatching through the handler's associated executor, it explicitly uses e which is service.get_executor(): the raw io_context executor. It should have been

boost::asio::defer(
    boost::asio::get_associated_executor(arg, e),  // Use handler's executor
    boost::asio::append(std::move(arg), ec));

In the same file, we have the correct usage pattern acutally: wait_for_osd_map

auto e = boost::asio::get_associated_executor(
	    handler, service.get_executor());

This affects all neorados async operations, not just multi-object delete. Any code relying on strand serialization with neorados is potentially a candiate to hit this race condition then.

The ASAN evidence is consistent with this theory. Two distinct pool threads were simultaneously inside the same vector storage. The trace shows T448 freed and T460 read — two different threads simultaneously inside vector::push_back(). If the strand were honored, only one thread at a time could be inside send_partial_response().

==3180444==ERROR: AddressSanitizer: heap-use-after-free on address 0x512000210040
READ of size 8 at 0x512000210040 thread T460

freed by thread T448 here:
    #0 0x7ffff78f93b8 in operator delete(void*, unsigned long)

Thread T460 is reading memory that thread T448 just freed. Two distinct pool threads are touching the same delete_multi_obj_entry storage.

@mkogan1 / @cbodley would it make sense to fix this at the Objecter layer instead of adding a per-op mutex here? The mutex addresses the symptom in this one path, but the underlying executor-bypass would still leak strand guarantees everywhere else.

@mkogan1

mkogan1 commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor Author

fix this at the Objecter layer

@BBoozmen - interesting, did not think of this option :-)
Will gladly keep the ASAN repro env up as long as needed and help check any WIP fix attempt PRs with ASAN on it

@cbodley

cbodley commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

It should have been

boost::asio::defer(
    boost::asio::get_associated_executor(arg, e),  // Use handler's executor
    boost::asio::append(std::move(arg), ec));

thanks @BBoozmen, that looks believable to me. cc @adamemerson

@mkogan1 can you confirm that this behavior only happens when configured for multisite? i don't think we'd interact with neorados unless the deletes were writing datalog entries

@mkogan1

mkogan1 commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor Author

@cbodley

only happens when configured for multisite?

confirm -- was NOT able to repro in SS despite considerable efforts - in the beginning we thought that its not MS related
it began reproducing only after switching to MS repro env which has 2 RGWs in each zone - the RGW that crashes is always the Client IO designated RGW in the Primary Zone (rgw_run_sync_thread=0) the other RGW is dedicated to Sync IO and does not crash as the RGWs on the Secondary zone which do not crash either

@anrao19

anrao19 commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

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

@cbodley cbodley 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.

it doesn't look like this will be needed after all, see #69253 and #69314

@mkogan1

mkogan1 commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

it doesn't look like this will be needed after all, see #69253 and #69314

ACK, closing ...

@mkogan1 mkogan1 closed this Jun 9, 2026
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.

5 participants