]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commit
common/options: fix heap-use-after-free by using never-destroyed static 66895/head
authorKefu Chai <k.chai@proxmox.com>
Tue, 13 Jan 2026 01:19:17 +0000 (09:19 +0800)
committerKefu Chai <k.chai@proxmox.com>
Tue, 13 Jan 2026 01:27:54 +0000 (09:27 +0800)
commit1ab0a8cb726cb730954294423acec887b92fa5b0
treee3ddd904aeddd57a95201641fbd06b5b8dec1d41
parent3818189f554106ab05896280ba2d510e2cbf2f01
common/options: fix heap-use-after-free by using never-destroyed static

The config schema map was using string_view keys that pointed to the
name field of Option objects stored in the global ceph_options vector.
When the vector is destroyed during program exit, the Option objects
are freed, but background threads (like BlueStore::MempoolThread) may
still be accessing config options, causing use-after-free.

ASan reported:
  READ of size 19 at 0x503000047c80 thread T411
    #12 md_config_t::find_option(std::string_view) const config.cc:261
    #17 BlueStore::MempoolThread::entry() BlueStore.cc:5591

  0x503000047c80 is located 0 bytes inside of 20-byte region
  freed by thread T0 here:
    #7 Option::~Option() options.h:15
    #13 std::vector<Option>::~vector() stl_vector.h:730
    #14 __run_exit_handlers stdlib/exit.c:113

  previously allocated by thread T0 here:
    #7 Option::Option(Option const&) options.h:15
    #18 build_options() build_options.cc:44

Fix by converting ceph_options from a global variable to a function
get_ceph_options() that returns a reference to a static pointer that
is never destroyed. This ensures the Option objects remain valid for
the lifetime of the program, even during exit when background threads
may still be accessing them.

This preserves the memory efficiency of using string_view keys in the
schema map while fixing the lifetime issue.

Signed-off-by: Kefu Chai <k.chai@proxmox.com>
src/common/ceph_context.cc
src/common/config.cc
src/common/options.cc
src/common/options.h
src/crimson/admin/admin_socket.cc
src/mon/ConfigMonitor.cc