Skip to content

Commit aceb942

Browse files
committed
Fix test compilation issues with from FLAGS_disable_dwarf_parsing. Add elf_reader_max_file_size flag to prevent huge allocations for large binaries
Signed-off-by: Dom Del Nano <ddelnano@gmail.com>
1 parent 9ad5dfa commit aceb942

File tree

7 files changed

+17
-5
lines changed

7 files changed

+17
-5
lines changed

src/stirling/obj_tools/dwarf_reader.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
#include "src/stirling/obj_tools/dwarf_utils.h"
3535
#include "src/stirling/obj_tools/init.h"
3636

37-
DECLARE_bool(disable_dwarf_parsing);
37+
DEFINE_bool(disable_dwarf_parsing, true,
38+
"Disable parsing of DWARF info for symbol offsets and uprobes");
3839

3940
namespace px {
4041
namespace stirling {

src/stirling/obj_tools/dwarf_reader.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
#include "src/stirling/obj_tools/abi_model.h"
3737
#include "src/stirling/obj_tools/utils.h"
3838

39+
DECLARE_bool(disable_dwarf_parsing);
40+
3941
namespace px {
4042
namespace stirling {
4143
namespace obj_tools {

src/stirling/obj_tools/elf_reader.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#include "src/common/fs/fs_wrapper.h"
3333
#include "src/stirling/obj_tools/init.h"
3434

35+
DEFINE_uint64(elf_reader_max_file_size, 30 << 20, "Maximum file size for ELF files. Value of 0 means no limit. Default is 30MB.");
36+
3537
namespace px {
3638
namespace stirling {
3739
namespace obj_tools {
@@ -167,6 +169,11 @@ StatusOr<std::unique_ptr<ElfReader>> ElfReader::Create(
167169

168170
elf_reader->binary_path_ = binary_path;
169171

172+
PX_ASSIGN_OR_RETURN(auto stat, fs::Stat(binary_path));
173+
uint64_t file_size = stat.st_size;
174+
if (file_size > FLAGS_elf_reader_max_file_size) {
175+
return error::Internal("File size $0 exceeds ElfReader's max file size $1. Refusing to process file", file_size, FLAGS_elf_reader_max_file_size);
176+
}
170177
if (!elf_reader->elf_reader_.load_header_and_sections(binary_path)) {
171178
return error::Internal("Can't find or process ELF file $0", binary_path);
172179
}

src/stirling/obj_tools/elf_reader.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333

3434
using ::px::utils::u8string;
3535

36+
DECLARE_uint64(elf_reader_max_file_size);
37+
3638
namespace px {
3739
namespace stirling {
3840
namespace obj_tools {

src/stirling/source_connectors/socket_tracer/socket_trace_bpf_tables.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ ConnInfoMapManager::ConnInfoMapManager(bpf_tools::BCCWrapper* bcc)
5353
std::filesystem::path self_path = GetSelfPath().ValueOrDie();
5454
auto elf_reader_or_s = obj_tools::ElfReader::Create(self_path.string());
5555
if (!elf_reader_or_s.ok()) {
56-
LOG(FATAL) << "Failed to create ElfReader for self probe";
56+
LOG(FATAL) << "Failed to create ElfReader for self probe: " << elf_reader_or_s.status();
5757
}
5858
auto elf_reader = elf_reader_or_s.ConsumeValueOrDie();
5959

src/stirling/source_connectors/socket_tracer/uprobe_manager.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,7 @@ StatusOr<int> UProbeManager::AttachOpenSSLUProbesOnStaticBinary(
650650
const uint32_t pid, const std::filesystem::path& proc_exe) {
651651
const auto host_proc_exe = ProcPidRootPath(pid, proc_exe);
652652

653+
VLOG(1) << absl::Substitute("Attaching OpenSSL probes on static binary: $0", host_proc_exe.string());
653654
PX_ASSIGN_OR_RETURN(auto elf_reader, ElfReader::Create(host_proc_exe));
654655
auto statusor = elf_reader->SearchTheOnlySymbol("SSL_write");
655656

@@ -663,6 +664,8 @@ StatusOr<int> UProbeManager::AttachOpenSSLUProbesOnStaticBinary(
663664
spec.probe_fn = absl::StrCat(spec.probe_fn, "_syscall_fd_access");
664665
PX_RETURN_IF_ERROR(LogAndAttachUProbe(spec));
665666
}
667+
VLOG(1) << absl::Substitute("Successfully attached OpenSSL probes on static binary: $0",
668+
host_proc_exe.string());
666669
return kOpenSSLUProbes.size();
667670
}
668671

src/stirling/source_connectors/socket_tracer/uprobe_symaddrs.cc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@ DEFINE_bool(openssl_raw_fptrs_enabled, false,
4747
"If true, allows the openssl tracing implementation to fall back to function pointers "
4848
"if dlopen/dlsym is unable to find symbols");
4949

50-
DEFINE_bool(disable_dwarf_parsing, true,
51-
"Disable parsing of DWARF info for symbol offsets and uprobes");
52-
5350
std::map<std::string, std::map<std::string, std::map<std::string, int32_t>>> g_structsOffsetMap;
5451

5552
std::map<std::string, std::map<std::string, std::map<std::string, std::unique_ptr<location_t>>>>

0 commit comments

Comments
 (0)