Skip to content
This repository has been archived by the owner on Jun 23, 2022. It is now read-only.

fix(asan): fix heap-use-after-free in perf_counters #773

Merged
merged 8 commits into from
Mar 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/perf_counter/perf_counters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ namespace dsn {

perf_counters::perf_counters()
{
// make shared_io_service destructed after perf_counters,
// because shared_io_service will destruct the timer created by perf_counters
// It will produce heap-use-after-free error if shared_io_service destructed in front of
// perf_counters
tools::shared_io_service::instance();

_perf_counters_cmd = command_manager::instance().register_command(
{"perf-counters"},
"perf-counters - query perf counters, filtered by OR of POSIX basic regular expressions",
Expand Down
19 changes: 12 additions & 7 deletions src/runtime/service_api_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,18 @@ bool run(const char *config_file,
bool is_server,
std::string &app_list)
{
// We put the loading of configuration at the beginning of this func.
// Because in dsn_global_init(), it calls perf_counters::instance(), which calls
// shared_io_service::instance(). And in the cstor of shared_io_service, it calls
// dsn_config_get_value_uint64() to load the corresponding configs. That will make
// dsn_config_get_value_uint64() get wrong value if we put dsn_config_load at behind of
// dsn_global_init()
if (!dsn_config_load(config_file, config_arguments)) {
printf("Fail to load config file %s\n", config_file);
return false;
}
dsn::flags_initialize();

dsn_global_init();
dsn_core_init();
::dsn::task::set_tls_dsn_context(nullptr, nullptr);
Expand All @@ -358,13 +370,6 @@ bool run(const char *config_file,
dsn_all.engine = &::dsn::service_engine::instance();
dsn_all.magic = 0xdeadbeef;

if (!dsn_config_load(config_file, config_arguments)) {
printf("Fail to load config file %s\n", config_file);
return false;
}

dsn::flags_initialize();

// pause when necessary
if (dsn_config_get_value_bool("core",
"pause_on_start",
Expand Down