@@ -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,20 @@ 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+ VLOG (1 ) << absl::Substitute (
487+ " binary filename '$0' contained in uprobe opt out list, skipping." , node_application_filepath);
488+ return 0 ;
489+ }
477490 const auto host_proc_exe = ProcPidRootPath (pid, proc_exe);
478491
479492 const auto [_, inserted] = nodejs_binaries_.insert (host_proc_exe.string ());
@@ -551,7 +564,7 @@ namespace {
551564
552565// Convert PID list from list of UPIDs to a map with key=binary name, value=PIDs
553566std::map<std::string, std::vector<int32_t >> ConvertPIDsListToMap (
554- const absl::flat_hash_set<md::UPID>& upids) {
567+ const absl::flat_hash_set<md::UPID>& upids, const std::vector<std::string>& binary_filter ) {
555568 const system::ProcParser proc_parser;
556569
557570 // Convert to a map of binaries, with the upids that are instances of that binary.
@@ -565,6 +578,13 @@ std::map<std::string, std::vector<int32_t>> ConvertPIDsListToMap(
565578 if (!fs::Exists (host_exe_path)) {
566579 continue ;
567580 }
581+ // Add filter here if the executable should be omitted
582+ if (std::find (binary_filter.begin (), binary_filter.end (), host_exe_path.filename ()) !=
583+ binary_filter.end ()) {
584+ VLOG (1 ) << absl::Substitute (
585+ " binary filename '$0' contained in uprobe opt out list, skipping." , host_exe_path.string ());
586+ continue ;
587+ }
568588 pids[host_exe_path.string ()].push_back (upid.pid ());
569589 }
570590
@@ -608,6 +628,15 @@ int UProbeManager::DeployOpenSSLUProbes(const absl::flat_hash_set<md::UPID>& pid
608628 continue ;
609629 }
610630
631+ PX_ASSIGN_OR (const auto exe_path, proc_parser_->GetExePath (pid.pid ()), continue );
632+
633+ if (std::find (uprobe_opt_out_.begin (), uprobe_opt_out_.end (), exe_path.filename ()) !=
634+ uprobe_opt_out_.end ()) {
635+ VLOG (1 ) << absl::Substitute (
636+ " binary filename '$0' contained in uprobe opt out list, skipping." , exe_path.string ());
637+ continue ;
638+ }
639+
611640 auto count_or = AttachOpenSSLUProbesOnDynamicLib (pid.pid ());
612641 if (count_or.ok ()) {
613642 uprobe_count += count_or.ValueOrDie ();
@@ -622,7 +651,7 @@ int UProbeManager::DeployOpenSSLUProbes(const absl::flat_hash_set<md::UPID>& pid
622651 count_or.ToString ());
623652 }
624653
625- count_or = AttachNodeJsOpenSSLUprobes (pid.pid ());
654+ count_or = AttachNodeJsOpenSSLUprobes (pid.pid (), exe_path );
626655 if (count_or.ok ()) {
627656 uprobe_count += count_or.ValueOrDie ();
628657 VLOG (1 ) << absl::Substitute (
@@ -640,7 +669,7 @@ int UProbeManager::DeployOpenSSLUProbes(const absl::flat_hash_set<md::UPID>& pid
640669
641670 // Attach uprobes to statically linked applications only if no other probes have been attached.
642671 if (FLAGS_stirling_trace_static_tls_binaries && count_or.ok () && count_or.ValueOrDie () == 0 ) {
643- count_or = AttachOpenSSLUProbesOnStaticBinary (pid.pid ());
672+ count_or = AttachOpenSSLUProbesOnStaticBinary (pid.pid (), exe_path );
644673
645674 if (count_or.ok () && count_or.ValueOrDie () > 0 ) {
646675 uprobe_count += count_or.ValueOrDie ();
@@ -816,7 +845,7 @@ int UProbeManager::DeployGoUProbes(const absl::flat_hash_set<md::UPID>& pids) {
816845
817846 static int32_t kPID = getpid ();
818847
819- for (const auto & [binary, pid_vec] : ConvertPIDsListToMap (pids)) {
848+ for (const auto & [binary, pid_vec] : ConvertPIDsListToMap (pids, uprobe_opt_out_ )) {
820849 // Don't bother rescanning binaries that have been scanned before to avoid unnecessary work.
821850 if (!scanned_binaries_.insert (binary).second ) {
822851 continue ;
0 commit comments