Skip to content

rgw: avoid dangling DoutPrefixProvider in RGWOwnerStatsCache - #70583

Merged
cbodley merged 1 commit into
ceph:mainfrom
317524211:wip-rgw-owner-stats-dangling-dpp
Sep 16, 2026
Merged

cbodley merged 1 commit into
ceph:mainfrom
317524211:wip-rgw-owner-stats-dangling-dpp

Conversation

@317524211

@317524211 317524211 commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Problem

RGWOwnerStatsCache stores the DoutPrefixProvider* passed to its constructor as a member, then dereferences it later in init_refresh() via ldpp_dout() / driver->load_stats_async().

When the store is recreated by RGWRealmReloader::reload(), that pointer is &dp — a stack-local DoutPrefix in reload()'s frame (src/rgw/rgw_realm_reloader.cc). Once reload() returns, the member dangles, and the next async owner-quota refresh dereferences it (use-after-free).

Normal startup is unaffected because its dp lives in a frame that never returns (rgw_appmain.cc), so this only manifests after a realm period reload.

Call chain that carries the stack pointer into the heap member:

RGWRealmReloader::reload()            // const DoutPrefix dp on stack
  -> DriverManager::get_storage(&dp)
  -> RGWRados::init_complete(dpp=&dp)                 // driver/rados/rgw_rados.cc
  -> RGWQuotaHandler::generate_handler(dpp)           // rgw_quota.cc
  -> new RGWQuotaHandlerImpl(dpp)
  -> RGWOwnerStatsCache(dpp)                          // stores dpp = &dp as a member
... reload() returns, dp destroyed, member dangles ...
  -> RGWOwnerStatsCache::init_refresh()               // ldpp_dout(dpp, ...) / load_stats_async(dpp, ...)

Fix

The sibling RGWBucketStatsCache already avoids this by not storing dpp and constructing a local DoutPrefix in init_refresh(). Mirror that for RGWOwnerStatsCache, and drop the now-unused dpp parameter from RGWQuotaHandler::generate_handler() and its two callers.

Changes:

  • src/rgw/rgw_quota.cc — RGWOwnerStatsCache: remove the dpp member; remove dpp from the constructor; init_refresh() builds a local const DoutPrefix dp(driver->ctx(), dout_subsys, ...); propagate the removal through RGWQuotaHandlerImpl and generate_handler().
  • src/rgw/rgw_quota.h — drop dpp from the generate_handler() declaration.
  • src/rgw/driver/rados/rgw_rados.cc, src/rgw/driver/posix/rgw_sal_posix.cc — update the two call sites.

No new allocations, threads, or lifetime changes — purely replacing the dangling pointer with an always-valid local object (the cache outlives any single request, and driver->ctx() is valid for the cache's whole lifetime).

Reproducer (optional, not included): build radosgw with -fsanitize=address, configure a realm, radosgw-admin period commit to force a reload, then enable owner/bucket quota and generate stats activity to trigger an async refresh; ASAN reports heap-use-after-free in RGWOwnerStatsCache::init_refresh().

Signed-off-by: dengjie [email protected]


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)

@317524211
317524211 requested a review from a team as a code owner July 27, 2026 15:19
@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

16 similar comments
@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@github-actions

Copy link
Copy Markdown

This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved

@317524211
317524211 force-pushed the wip-rgw-owner-stats-dangling-dpp branch from 0fc7595 to 5251862 Compare July 27, 2026 15:26
@317524211
317524211 force-pushed the wip-rgw-owner-stats-dangling-dpp branch from 5251862 to b879270 Compare July 28, 2026 03:46
@mheler

mheler commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

ok-to-test

1 similar comment
@mheler

mheler commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

ok-to-test

@cbodley

cbodley commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

compilation failure from https://jenkins.ceph.com/job/ceph-pr-pipeline/826/stages/?selected-node=50

[2026-09-08T13:57:01.327Z] FAILED: src/test/rgw/CMakeFiles/unittest_rgw_posix_driver.dir/test_rgw_posix_driver.cc.o 
[2026-09-08T13:57:01.329Z] /usr/local/bin/sccache /usr/bin/clang++-19 -DBOOST_ASIO_DISABLE_THREAD_KEYWORD_EXTENSION -DBOOST_ASIO_NO_TS_EXECUTORS -DHAVE_CONFIG_H -DLMDB_SAFE_NO_CPP_UTILITIES -DXXH_NO_INLINE_HINTS=1 -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -D_REENTRANT -D_THREAD_SAFE -D__CEPH__ -D__STDC_FORMAT_MACROS -D__linux__ -I/ceph/src/dmclock/support/src -I/ceph/src/rgw/driver/rados -I/ceph/src/rgw/services -I/usr/include/lua5.3 -I/ceph/src/BLAKE3/c -isystem /ceph/build/boost/src/Boost -isystem /ceph/build/src/include -isystem /ceph/src -isystem /ceph/build/include -isystem /ceph/src/jaegertracing/opentelemetry-cpp/api/include -isystem /ceph/src/jaegertracing/opentelemetry-cpp/exporters/jaeger/include -isystem /ceph/src/jaegertracing/opentelemetry-cpp/ext/include -isystem /ceph/src/jaegertracing/opentelemetry-cpp/sdk/include -isystem /ceph/src/xxHash -isystem /ceph/src/fmt/include -isystem /ceph/src/rgw -isystem /ceph/src/test/rgw/SYSTEM -isystem /ceph/src/rgw/driver/posix -isystem /ceph/src/googletest/googlemock/include -isystem /ceph/src/googletest/googlemock -isystem /ceph/src/googletest/googletest/include -isystem /ceph/src/googletest/googletest -isystem /ceph/src/s3select/rapidjson/include -g -Werror -fPIE -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free -Wall -fno-strict-aliasing -fsigned-char -Wtype-limits -Wignored-qualifiers -Wpointer-arith -Werror=format-security -Winit-self -Wno-unknown-pragmas -Wnon-virtual-dtor -Wno-ignored-qualifiers -Wsign-compare -ftemplate-depth-1024 -DBOOST_ALLOW_DEPRECATED_HEADERS -Wpessimizing-move -Wredundant-move -Wno-inconsistent-missing-override -Wno-mismatched-tags -Wno-unused-private-field -Wno-address-of-packed-member -Wno-unknown-warning-option -Wno-unused-function -Wno-unused-local-typedef -Wno-varargs -Wno-gnu-designator -Wno-missing-braces -Wno-parentheses -Wno-deprecated-register -Wno-vla-cxx-extension -DCEPH_DEBUG_MUTEX -D_GLIBCXX_ASSERTIONS -fdiagnostics-color=auto -DWITH_RADOSGW_STANDALONE -DWITH_RADOSGW_DBSTORE -UWITH_RADOSGW_D4N -UWITH_RADOSGW_RADOS -UWITH_RADOSGW_MOTR -UWITH_RADOSGW_DAOS -UWITH_RADOSGW_AMQP_ENDPOINT -std=c++2b -MD -MT src/test/rgw/CMakeFiles/unittest_rgw_posix_driver.dir/test_rgw_posix_driver.cc.o -MF src/test/rgw/CMakeFiles/unittest_rgw_posix_driver.dir/test_rgw_posix_driver.cc.o.d -o src/test/rgw/CMakeFiles/unittest_rgw_posix_driver.dir/test_rgw_posix_driver.cc.o -c /ceph/src/test/rgw/test_rgw_posix_driver.cc
[2026-09-08T13:57:01.330Z] /ceph/src/test/rgw/test_rgw_posix_driver.cc:1102:71: error: too many arguments to function call, expected 2, have 3
[2026-09-08T13:57:01.330Z]  1102 |     quota_handler = RGWQuotaHandler::generate_handler(env->dpp, this, false);
[2026-09-08T13:57:01.330Z]       |                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                 ^~~~~
[2026-09-08T13:57:01.330Z] /ceph/src/rgw/rgw_quota.h:40:27: note: 'generate_handler' declared here
[2026-09-08T13:57:01.330Z]    40 |   static RGWQuotaHandler *generate_handler(rgw::sal::Driver* driver, bool quota_threads);
[2026-09-08T13:57:01.330Z]       |                           ^                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[2026-09-08T13:57:01.330Z] 1 error generated.

RGWOwnerStatsCache stores the DoutPrefixProvider* passed to its
constructor as a member and dereferences it later in init_refresh().
When the store is recreated by RGWRealmReloader::reload(), that
pointer is &dp, a stack-local DoutPrefix in reload()'s frame; once
reload() returns the member dangles and the next async owner-quota
refresh dereferences it (use-after-free). Normal startup is unaffected
because its dp lives in a frame that never returns.

The sibling RGWBucketStatsCache already avoids this by not storing dpp
and constructing a local DoutPrefix in init_refresh(). Mirror that for
RGWOwnerStatsCache and drop the now-unused dpp parameter from
generate_handler() and its callers.

Signed-off-by: dengjie <[email protected]>
@317524211

Copy link
Copy Markdown
Contributor Author

Fixed the compilation failure in 4c8a515. The affected RGW targets also compile locally with -Werror. Could a Ceph developer please re-approve CI? Thanks!

@anrao19

anrao19 commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

This PR has been added to main integration testing by anuchaithra started 2026-09-10-10:12.

@anrao19

anrao19 commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

This PR has been added to main integration testing by anuchaithra started 2026-09-10-10:12.

Pr testing completed and approved by @ivancich, more details : https://tracker.ceph.com/issues/80444.
@317524211 , if no further testing is needed then pr can be merged

@cbodley
cbodley merged commit 4ea70ce into ceph:main Sep 16, 2026
16 checks passed
@github-actions

Copy link
Copy Markdown

This is an automated message by src/script/redmine-upkeep.py.

I have resolved the following tracker ticket due to the merge of this PR:

No backports are pending for the ticket. If this is incorrect, please update the tracker
ticket and reset to Pending Backport state.

Update Log: https://github.com/ceph/ceph/actions/runs/35104660507

aainscow pushed a commit to aainscow/ceph that referenced this pull request Sep 18, 2026
…ling-dpp

rgw: avoid dangling DoutPrefixProvider in RGWOwnerStatsCache

Reviewed-by: Casey Bodley <[email protected]>
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