Bug #80315
closedrgw: SIGSEGV in RGWOwnerStatsCache::init_refresh() after a realm reload — RGWRealmReloader::reload() stores the address of a stack-local DoutPrefix
0%
Description
Summary¶
RGWRealmReloader::reload() creates a stack-local DoutPrefix and passes its address into DriverManager::get_storage(). That pointer travels down to RGWOwnerStatsCache, which stores it as a member (const DoutPrefixProvider *dpp) for the lifetime of the driver.
When reload() returns, the pointer dangles. Any later asynchronous owner-quota refresh calls ldpp_dout(dpp, 20) inside RGWOwnerStatsCache::init_refresh(), which performs a virtual call through the dead stack object. Once that stack region has been reused, the vtable read yields garbage and the process jumps to address 0 -> SIGSEGV.
Every radosgw that has performed at least one realm reload is affected from that moment on. A freshly started radosgw is not affected, because there dpp is the DoutPrefix living in main()'s frame, which outlives the process's work.
Impact¶
radosgw crashes with SIGSEGV while serving a PutObject request. In our deployment (3 gateways behind a LoadBalancer VIP) each crash produced roughly 30 seconds of connection refusals from the affected gateway. Only writes are affected -- check_quota() is only reached on the write path -- and only for owners that have a quota configured.
Environment¶
| Item | Value |
|---|---|
| Ceph | 20.2.2 (06f6a7ab7187f570d9fc04b7ac9664f1fb6b84b0) tentacle |
| Packaging | Proxmox VE 9, radosgw 20.2.2-pve1, Debian 13 |
| Frontend | beast, two endpoints, otherwise default config |
| Deployment | 3 nodes, 3 RGW daemons, single realm/zonegroup/zone, no multisite |
| Trigger present | user-scoped quotas enabled on 4 users |
Backtrace¶
Identical in four separate core dumps across three hosts (no debug symbols available, hence the ?? frames):
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x00007bde48b6d95c in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#1 0x00007bde48b18cc2 in raise () from /lib/x86_64-linux-gnu/libc.so.6
#2 0x0000637b1dc93ee2 in ?? ()
#3 <signal handler called>
#4 0x0000000000000000 in ?? () <-- jumped to NULL
#5 0x0000637b1d065996 in RGWOwnerStatsCache::init_refresh(
std::variant<rgw_user, rgw_account_id> const&, rgw_bucket const&,
boost::intrusive_ptr<ceph::common::RefCountedWaitObject>) ()
#6 0x0000637b1d06d98a in RGWQuotaCache<std::variant<rgw_user, rgw_account_id> >::get_stats(...)
#7 0x0000637b1d06e25d in RGWQuotaHandlerImpl::check_quota(...)
#8 0x0000637b1d38a73d in rgw::sal::RadosBucket::check_quota(...)
#9 0x0000637b1d019ded in RGWPutObj::execute(optional_yield) ()
#10 0x0000637b1cde7adc in rgw_process_authenticated(...)
#11 0x0000637b1cdea341 in process_request(...)
Thread name is io_context_pool. The in-memory log ring ends with:
-1> ... 2 req <id> s3:put_obj executing
0> ... -1 *** Caught signal (Segmentation fault) **
Faulting instruction¶
RGWOwnerStatsCache::init_refresh+179:
mov 0x98(%rbp),%rdi ; rbp = this ; this+0x98 = member `dpp` test %rdi,%rdi je ... ; the null check passes -- dpp is NOT null mov (%rdi),%rax ; load vptr call *0x10(%rax) ; <-- FAULT: target is 0
This is the expansion of ldpp_dout(dpp, 20), which calls dpp->get_cct() and dpp->get_subsys() unconditionally, regardless of the configured log level.
Object inspection (one of the cores):
this = 0x637b2cad6288 vtable: RGWOwnerStatsCache (valid)
this+0x08 = 0x637b276f00c0 driver (valid)
this+0x10 = 0x637b1ec6a4b0 vtable: lru_map<...> (valid)
this+0x98 (dpp) = 0x00007bdcb23cf520 <-- STACK address
*(dpp) = 0x00007bdcb23d69c8 <-- "vptr" is also a stack
address = garbage
The dangling pointer is the realm reloader thread's stack¶
In all four cores the stored dpp falls inside the stack of the thread that logged the rgw realm reloader: messages -- matched by pthread id, at the same ...520 offset every time:
| Host | realm reloader thread (from log) | stored dpp (from core) | crash |
|---|---|---|---|
| host1 | 7f2e8f7d46c0 | 0x00007f2e8f7cd520 | 01:39:21 |
| host2 | 71ce5e8606c0 | 0x000071ce5e859520 | 05:29:55 |
| host3 | 7bdcb23d66c0 | 0x00007bdcb23cf520 | 05:29:54 |
| host3 (reproduced on demand) | 7bf012b4d6c0 | 0x00007bf012b46520 | 10:48:11 |
At crash time that thread is parked in CommonSafeTimer<std::mutex>::timer_thread() -> pthread_cond_wait(), i.e. reload()'s frame is long gone and the memory has been reused by the timer thread's own wait frames.
Root cause¶
src/rgw/rgw_realm_reloader.cc -- RGWRealmReloader::reload():
const DoutPrefix dp(cct, dout_subsys, "rgw realm reloader: "); // stack object
...
env.driver = DriverManager::get_storage(&dp, cct, cfg, io_context, ...);
&dp then propagates and is retained:
DriverManager::get_storage(dpp, ...)
-> RGWRados::init_complete(const DoutPrefixProvider *dpp, optional_yield y)
quota_handler = RGWQuotaHandler::generate_handler(dpp, this->driver, quota_threads);
-> RGWQuotaHandlerImpl(dpp, ...)
-> RGWOwnerStatsCache(dpp, ...)
src/rgw/rgw_quota.cc:
class RGWOwnerStatsCache : public RGWQuotaCache<rgw_owner> {
const DoutPrefixProvider *dpp; // retained for the lifetime of the driver
...
};
RGWOwnerStatsCache(const DoutPrefixProvider *dpp, rgw::sal::Driver* _driver,
bool quota_threads)
: RGWQuotaCache<rgw_owner>(_driver, _driver->ctx()->_conf->rgw_bucket_quota_cache_size),
dpp(dpp)
{ ... }
int RGWOwnerStatsCache::init_refresh(const rgw_owner& owner, const rgw_bucket& bucket,
boost::intrusive_ptr<RefCountedWaitObject> waiter)
{
boost::intrusive_ptr cb = new OwnerAsyncRefreshHandler(this, std::move(waiter), owner, bucket);
ldpp_dout(dpp, 20) << "initiating async quota refresh for owner=" << owner << dendl; // <-- crash
int r = driver->load_stats_async(dpp, owner, std::move(cb)); // <-- dangling dpp escapes further
...
}
Note that dpp is also handed to driver->load_stats_async(), so the dangling pointer escapes further into the async path.
On a normal startup the same member points at the DoutPrefix created in main(), which lives for the whole process -- that is why the bug only manifests after a realm reload.
Why this looks intermittent¶
Two independent conditions must coincide, which is why the crash appeared random and resisted stress testing:
- the realm reloader thread's stack region must have been overwritten, and
- an owner-quota cache entry must expire (
rgw_bucket_quota_ttl, default 600 s) and aPutObjectfor that owner must arrive, taking the async refresh path.
A hard cache miss takes the synchronous path and does not crash. Sustained write load keeps the cache warm: a 200,000-request stress run against a daemon that had not reloaded produced zero crashes, while the very same loop crashed on the second request after a reload.
Deterministic reproducer¶
# 1. a user with a quota, and a bucket
radosgw-admin user create --uid=crashtest --tenant=ops --display-name=repro
radosgw-admin quota set --quota-scope=user --uid=crashtest --tenant=ops --max-size=1G
radosgw-admin quota enable --quota-scope=user --uid=crashtest --tenant=ops
aws --endpoint-url http://<rgw>:7480 s3 mb s3://repro
# 2. shrink the quota cache TTL on that daemon only (runtime, no restart)
ceph --admin-daemon /var/run/ceph/ceph-client.rgw.<id>.asok \
config set rgw_bucket_quota_ttl 15
# 3. control run: PUT every 20 s, ten times -> no crash
# (raise debug_rgw to 20/20 to confirm "initiating async quota refresh" is executed)
# 4. arm the bug
radosgw-admin period update --commit --rgw-realm=<realm>
# 5. repeat the exact same loop -> the SECOND PUT crashes the daemon
radosgw-admin period update --commit --rgw-realm=<realm>
# 5. repeat the exact same loop -> the SECOND PUT crashes the daemon
Observed in step 5:
10:47:50 PUT ok <- hard cache miss, synchronous path 10:48:13 connection refused <- SIGSEGV at 10:48:11.168
The only difference between the control run and the failing run is the realm reload in step 4.
Affected versions¶
- v20.2.2 (tentacle) -- crashes observed in production and reproduced on demand.
- v19.2.3 (squid) -- same
RGWOwnerStatsCache::dppmember and the sameldpp_dout(dpp, 20)ininit_refresh(). - main (checked 2026-09-07) --
RGWRealmReloader::reload()still declaresconst DoutPrefix dp(...)as a local and still passes&dp. Not fixed.
Note for triage: this is not the same defect as PR #70262 ("rgw: Fix crashes on realm reload"). That change touches common/async/context_pool.h, rgw_rados.cc (init ordering), rgw_asio_frontend.cc, rgw_asio_frontend_connection.h and rgw_coroutine.cc; it modifies neither rgw_realm_reloader.cc nor rgw_quota.cc. We also verified the crash does not coincide with a reload -- it occurs minutes to hours afterwards.
Suggested fix¶
Give the DoutPrefixProvider handed to DriverManager::get_storage() a lifetime at least as long as the driver's. Options:
- make the
DoutPrefixa member ofRGWRealmReloaderinstead of a local ofreload()(smallest change), or - have
RGWOwnerStatsCacheown its prefix provider (e.g. construct one from theCephContextit already holds) instead of borrowing a caller-supplied pointer, or - more generally, audit the other consumers of the
dpppassed intoDriverManager::get_storage()for the same "retain a borrowed pointer" pattern.
Workaround¶
Restart radosgw after any operation that bumps the realm/period epoch (radosgw-admin period update --commit, realm set, zone/zonegroup edits). A process that never performs a realm reload is not affected.
Happy to provide further details on request. We have four core dumps retained, although the distribution packages ship without debug symbols, so symbolisation beyond the frames above was not possible on our side.
MH Updated by Matthew Heler 3 months ago · Edited
A fix for this looks to be in https://github.com/ceph/ceph/pull/70583
CB Updated by Casey Bodley 3 months ago
- Status changed from New to Fix Under Review
- Pull request ID set to 70583
JI Updated by J. Eric Ivancich 3 months ago
- Assignee set to caglar mersinli
@cmersinli Are you github user 317524211? I'm assuming you are and assigning this tracker to you. If that's a mistake please fix or let me know. Thanks!
CM Updated by caglar mersinli 3 months ago
J. Eric Ivancich wrote in #note-3:
@cmersinli Are you github user 317524211? I'm assuming you are and assigning this tracker to you. If that's a mistake please fix or let me know. Thanks!
No, I'm not — my GitHub account is cmersinli. I only reported the issue; PR #70583 was authored by @317524211 (dengjie). Feel free to reassign. I'd also be glad to see a tentacle backport, since we hit this on 20.2.2.
UB Updated by Upkeep Bot 3 months ago
- Status changed from Fix Under Review to Resolved
- Merge Commit set to 4ea70ceb1c97fe598e73b6913ad362b3263d7977
- Fixed In set to v21.3.0-3287-g4ea70ceb1c
- Upkeep Timestamp set to 2026-09-16T13:53:47+00:00