From 7f120bbd6f1bf1e44b1afa8a28d071bd6ee06904 Mon Sep 17 00:00:00 2001 From: CFC4N Date: Wed, 23 Mar 2022 00:09:24 +0800 Subject: [PATCH] 1, fix tls module run codition,one of openssl/gnutls/(nspr|nss) file existed. Signed-off-by: CFC4N --- user/probe_gnutls.go | 14 ++++++++++++-- user/probe_openssl.go | 14 ++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/user/probe_gnutls.go b/user/probe_gnutls.go index 7a9d66a3c..06a71b066 100644 --- a/user/probe_gnutls.go +++ b/user/probe_gnutls.go @@ -10,6 +10,7 @@ import ( "golang.org/x/sys/unix" "log" "math" + "os" ) type MGnutlsProbe struct { @@ -46,7 +47,10 @@ func (this *MGnutlsProbe) start() error { } // setup the managers - this.setupManagers() + err = this.setupManagers() + if err != nil { + return errors.Wrap(err, "tls module couldn't find binPath.") + } // initialize the bootstrap manager if err := this.bpfManager.InitWithOptions(bytes.NewReader(byteBuf), this.bpfManagerOptions); err != nil { @@ -93,7 +97,7 @@ func (e *MGnutlsProbe) constantEditor() []manager.ConstantEditor { return editor } -func (this *MGnutlsProbe) setupManagers() { +func (this *MGnutlsProbe) setupManagers() error { var binaryPath string switch this.conf.(*GnutlsConfig).elfType { case ELF_TYPE_BIN: @@ -105,6 +109,11 @@ func (this *MGnutlsProbe) setupManagers() { binaryPath = "/lib/x86_64-linux-gnu/libgnutls.so.30" } + _, err := os.Stat(binaryPath) + if err != nil { + return err + } + this.logger.Printf("HOOK type:%d, binrayPath:%s\n", this.conf.(*GnutlsConfig).elfType, binaryPath) this.bpfManager = &manager.Manager{ @@ -158,6 +167,7 @@ func (this *MGnutlsProbe) setupManagers() { // 填充 RewriteContants 对应map ConstantEditors: this.constantEditor(), } + return nil } func (this *MGnutlsProbe) DecodeFun(em *ebpf.Map) (IEventStruct, bool) { diff --git a/user/probe_openssl.go b/user/probe_openssl.go index 6c87fc53f..065ad0032 100644 --- a/user/probe_openssl.go +++ b/user/probe_openssl.go @@ -10,6 +10,7 @@ import ( "golang.org/x/sys/unix" "log" "math" + "os" ) type MOpenSSLProbe struct { @@ -46,7 +47,10 @@ func (this *MOpenSSLProbe) start() error { } // setup the managers - this.setupManagers() + err = this.setupManagers() + if err != nil { + return errors.Wrap(err, "tls module couldn't find binPath.") + } // initialize the bootstrap manager if err := this.bpfManager.InitWithOptions(bytes.NewReader(byteBuf), this.bpfManagerOptions); err != nil { @@ -93,7 +97,7 @@ func (e *MOpenSSLProbe) constantEditor() []manager.ConstantEditor { return editor } -func (this *MOpenSSLProbe) setupManagers() { +func (this *MOpenSSLProbe) setupManagers() error { var binaryPath string switch this.conf.(*OpensslConfig).elfType { case ELF_TYPE_BIN: @@ -105,6 +109,11 @@ func (this *MOpenSSLProbe) setupManagers() { binaryPath = "/lib/x86_64-linux-gnu/libssl.so.1.1" } + _, err := os.Stat(binaryPath) + if err != nil { + return err + } + this.logger.Printf("HOOK type:%d, binrayPath:%s\n", this.conf.(*OpensslConfig).elfType, binaryPath) this.bpfManager = &manager.Manager{ @@ -184,6 +193,7 @@ func (this *MOpenSSLProbe) setupManagers() { // 填充 RewriteContants 对应map ConstantEditors: this.constantEditor(), } + return nil } func (this *MOpenSSLProbe) DecodeFun(em *ebpf.Map) (IEventStruct, bool) {