]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/osd: inline log file stream setup to fix dangling pointer
authorKefu Chai <k.chai@proxmox.com>
Tue, 12 May 2026 09:55:06 +0000 (17:55 +0800)
committerKefu Chai <k.chai@proxmox.com>
Wed, 13 May 2026 05:23:15 +0000 (13:23 +0800)
maybe_set_logger() called logger().set_ostream() with a reference to a
local ofstream before returning it by value. Correctness relied on NRVO:
without it, _out would point to a moved-from object on a dead stack frame,
causing undefined behaviour that manifests as a heap-buffer-overflow under
ASan with GCC 14 (libasan.so.8).

Note that seastar::logger::_out is a static member shared by all logger
instances, so the dangling pointer affects every logger (seastore, network,
OSD), explaining why the crash appears across subsystems.

Inline the setup so log_file_stream and reset_logger share the same scope.
set_ostream() is now called with an unambiguously live object, with no
dependence on copy elision.

Fixes: 66c923d70354415cd1746c4f57cf31f3d55cc1bd
Signed-off-by: Kefu Chai <k.chai@proxmox.com>
src/crimson/osd/main.cc

index 174bdc2772a31aacb68206bd7b8fa988ce6e347c..c549277888de20d8fecd33da7f31060aab9b07d7 100644 (file)
@@ -74,20 +74,6 @@ seastar::future<> make_keyring()
   });
 }
 
-static std::ofstream maybe_set_logger()
-{
-  std::ofstream log_file_stream;
-  if (auto log_file = local_conf()->log_file; !log_file.empty()) {
-    log_file_stream.open(log_file, std::ios::app | std::ios::out);
-    try {
-      seastar::throw_system_error_on(log_file_stream.fail());
-    } catch (const std::system_error& e) {
-      ceph_abort_msg(fmt::format("unable to open log file: {}", e.what()));
-    }
-    logger().set_ostream(log_file_stream);
-  }
-  return log_file_stream;
-}
 
 int main(int argc, const char* argv[])
 {
@@ -171,7 +157,16 @@ int main(int argc, const char* argv[])
           local_conf().parse_argv(config_proxy_args).get();
 
           DEBUG("initializing logger output");
-          auto log_file_stream = maybe_set_logger();
+          std::ofstream log_file_stream;
+          if (auto log_file = local_conf()->log_file; !log_file.empty()) {
+            log_file_stream.open(log_file, std::ios::app | std::ios::out);
+            try {
+              seastar::throw_system_error_on(log_file_stream.fail());
+            } catch (const std::system_error& e) {
+              ceph_abort_msg(fmt::format("unable to open log file: {}", e.what()));
+            }
+            logger().set_ostream(log_file_stream);
+          }
           auto reset_logger = seastar::defer([] {
             logger().set_ostream(std::cerr);
           });