@@ -52,6 +52,11 @@ DEFINE_double(stirling_rescan_exp_backoff_factor, 2.0,
5252 " Exponential backoff factor used in decided how often to rescan binaries for "
5353 " dynamically loaded libraries" );
5454
55+ DEFINE_string (
56+ stirling_uprobe_opt_out, " " ,
57+ " Comma separated list of binary filenames that should be excluded from uprobe attachment."
58+ " For a binary at path /path/to/binary, the filename would be binary" );
59+
5560namespace px {
5661namespace stirling {
5762
@@ -64,6 +69,7 @@ using ::px::system::ProcPidRootPath;
6469
6570UProbeManager::UProbeManager (bpf_tools::BCCWrapper* bcc) : bcc_(bcc) {
6671 proc_parser_ = std::make_unique<system::ProcParser>();
72+ uprobe_opt_out_ = absl::StrSplit (FLAGS_stirling_uprobe_opt_out, " ," , absl::SkipWhitespace ());
6773}
6874
6975void UProbeManager::Init (bool disable_go_tls_tracing, bool enable_http2_tracing,
@@ -447,8 +453,8 @@ StatusOr<std::array<UProbeTmpl, 6>> UProbeManager::GetNodeOpensslUProbeTmpls(con
447453 return iter->second ;
448454}
449455
450- StatusOr<int > UProbeManager::AttachOpenSSLUProbesOnStaticBinary (const uint32_t pid) {
451- PX_ASSIGN_OR_RETURN ( const std::filesystem::path proc_exe, proc_parser_-> GetExePath (pid));
456+ StatusOr<int > UProbeManager::AttachOpenSSLUProbesOnStaticBinary (
457+ const uint32_t pid, const std::filesystem::path& proc_exe) {
452458 const auto host_proc_exe = ProcPidRootPath (pid, proc_exe);
453459
454460 PX_ASSIGN_OR_RETURN (auto elf_reader, ElfReader::Create (host_proc_exe));
@@ -467,13 +473,18 @@ StatusOr<int> UProbeManager::AttachOpenSSLUProbesOnStaticBinary(const uint32_t p
467473 return kOpenSSLUProbes .size ();
468474}
469475
470- StatusOr<int > UProbeManager::AttachNodeJsOpenSSLUprobes (const uint32_t pid) {
471- PX_ASSIGN_OR_RETURN (const std::filesystem::path proc_exe, proc_parser_->GetExePath (pid));
472-
476+ StatusOr<int > UProbeManager::AttachNodeJsOpenSSLUprobes (const uint32_t pid,
477+ const std::filesystem::path& proc_exe) {
473478 if (DetectApplication (proc_exe) != Application::kNode ) {
474479 return 0 ;
475480 }
476481
482+ const std::string exe_cmdline = proc_parser_->GetPIDCmdline (pid);
483+ const std::string node_application_filepath = GetNodeApplicationFilename (exe_cmdline);
484+ if (std::find (uprobe_opt_out_.begin (), uprobe_opt_out_.end (), node_application_filepath) !=
485+ uprobe_opt_out_.end ()) {
486+ return 0 ;
487+ }
477488 const auto host_proc_exe = ProcPidRootPath (pid, proc_exe);
478489
479490 const auto [_, inserted] = nodejs_binaries_.insert (host_proc_exe.string ());
@@ -551,7 +562,7 @@ namespace {
551562
552563// Convert PID list from list of UPIDs to a map with key=binary name, value=PIDs
553564std::map<std::string, std::vector<int32_t >> ConvertPIDsListToMap (
554- const absl::flat_hash_set<md::UPID>& upids) {
565+ const absl::flat_hash_set<md::UPID>& upids, const std::vector<std::string>& binary_filter ) {
555566 const system::ProcParser proc_parser;
556567
557568 // Convert to a map of binaries, with the upids that are instances of that binary.
@@ -565,6 +576,11 @@ std::map<std::string, std::vector<int32_t>> ConvertPIDsListToMap(
565576 if (!fs::Exists (host_exe_path)) {
566577 continue ;
567578 }
579+ // Add filter here if the executable should be omitted
580+ if (std::find (binary_filter.begin (), binary_filter.end (), host_exe_path.filename ()) !=
581+ binary_filter.end ()) {
582+ continue ;
583+ }
568584 pids[host_exe_path.string ()].push_back (upid.pid ());
569585 }
570586
@@ -608,6 +624,15 @@ int UProbeManager::DeployOpenSSLUProbes(const absl::flat_hash_set<md::UPID>& pid
608624 continue ;
609625 }
610626
627+ PX_ASSIGN_OR (const auto exe_path, proc_parser_->GetExePath (pid.pid ()), continue );
628+
629+ if (std::find (uprobe_opt_out_.begin (), uprobe_opt_out_.end (), exe_path.filename ()) !=
630+ uprobe_opt_out_.end ()) {
631+ VLOG (1 ) << absl::Substitute (
632+ " binary filename '$0' contained in uprobe opt out list, skipping." , exe_path.string ());
633+ continue ;
634+ }
635+
611636 auto count_or = AttachOpenSSLUProbesOnDynamicLib (pid.pid ());
612637 if (count_or.ok ()) {
613638 uprobe_count += count_or.ValueOrDie ();
@@ -622,7 +647,7 @@ int UProbeManager::DeployOpenSSLUProbes(const absl::flat_hash_set<md::UPID>& pid
622647 count_or.ToString ());
623648 }
624649
625- count_or = AttachNodeJsOpenSSLUprobes (pid.pid ());
650+ count_or = AttachNodeJsOpenSSLUprobes (pid.pid (), exe_path );
626651 if (count_or.ok ()) {
627652 uprobe_count += count_or.ValueOrDie ();
628653 VLOG (1 ) << absl::Substitute (
@@ -640,7 +665,7 @@ int UProbeManager::DeployOpenSSLUProbes(const absl::flat_hash_set<md::UPID>& pid
640665
641666 // Attach uprobes to statically linked applications only if no other probes have been attached.
642667 if (FLAGS_stirling_trace_static_tls_binaries && count_or.ok () && count_or.ValueOrDie () == 0 ) {
643- count_or = AttachOpenSSLUProbesOnStaticBinary (pid.pid ());
668+ count_or = AttachOpenSSLUProbesOnStaticBinary (pid.pid (), exe_path );
644669
645670 if (count_or.ok () && count_or.ValueOrDie () > 0 ) {
646671 uprobe_count += count_or.ValueOrDie ();
@@ -816,7 +841,7 @@ int UProbeManager::DeployGoUProbes(const absl::flat_hash_set<md::UPID>& pids) {
816841
817842 static int32_t kPID = getpid ();
818843
819- for (const auto & [binary, pid_vec] : ConvertPIDsListToMap (pids)) {
844+ for (const auto & [binary, pid_vec] : ConvertPIDsListToMap (pids, uprobe_opt_out_ )) {
820845 // Don't bother rescanning binaries that have been scanned before to avoid unnecessary work.
821846 if (!scanned_binaries_.insert (binary).second ) {
822847 continue ;
0 commit comments