Эх сурвалжийг харах

Fixed #TASK_QT-9810 Go Tls

roger.wang 1 жил өмнө
parent
commit
0c617f5bc1

+ 1 - 1
ebpftracer/ebpf/ebpf.c

@@ -52,7 +52,7 @@
 #include "tcp/retransmit.c"
 //#include "l7/uprobe_base_bpf.c"
 #include "l7/l7.c"
-//#include "l7/gotls.c"
+#include "l7/gotls.c"
 //#include "l7/openssl.c"
 #include "utrace/go/net/server.probe.bpf.c"
 #include "utrace/go/net/client.probe.bpf.c"

+ 3 - 3
ebpftracer/ebpf/l7/gotls.c

@@ -1,8 +1,8 @@
 // Go internal ABI specification: https://go.dev/s/regabi
 #if defined(__TARGET_ARCH_x86)
-#define GO_PARAM1(x) ((x)->ax)
-#define GO_PARAM2(x) ((x)->bx)
-#define GO_PARAM3(x) ((x)->cx)
+#define GO_PARAM1(x) ((x)->rax)
+#define GO_PARAM2(x) ((x)->rbx)
+#define GO_PARAM3(x) ((x)->rcx)
 #define GOROUTINE(x) ((x)->r14)
 #define PT_GO_REGS_PARM1(x) ((x)->rax)
 #define PT_GO_REGS_PARM2(x) ((x)->rbx)

+ 12 - 5
ebpftracer/tls.go

@@ -7,6 +7,11 @@ import (
 	"debug/elf"
 	"errors"
 	"fmt"
+	"os"
+	"regexp"
+	"strconv"
+	"strings"
+
 	"github.com/cilium/ebpf/link"
 	"github.com/coroot/coroot-node-agent/ebpftracer/tracer"
 	"github.com/coroot/coroot-node-agent/proc"
@@ -15,10 +20,6 @@ import (
 	"golang.org/x/arch/arm64/arm64asm"
 	"golang.org/x/arch/x86/x86asm"
 	"golang.org/x/mod/semver"
-	"os"
-	"regexp"
-	"strconv"
-	"strings"
 )
 
 const (
@@ -99,15 +100,19 @@ func (t *Tracer) AttachOpenSslUprobes(pid uint32) ([]link.Link, error) {
 	for _, p := range progs {
 		if p.uprobe != "" {
 			l, err := exe.Uprobe(p.symbol, t.uprobes[p.uprobe], nil)
+			klog.Infoln("fucktls crypto/tls uprobes attached", p.symbol)
 			if err != nil {
 				//log("failed to attach uprobe", err)
+				klog.Infoln("fucktls crypto/tls uprobes attached error", p.symbol)
 				return nil, err
 			}
 			links = append(links, l)
 		}
 		if p.uretprobe != "" {
+			klog.Infoln("fucktls crypto/tls uprobes attached ret", p.symbol)
 			l, err := exe.Uretprobe(p.symbol, t.uprobes[p.uretprobe], nil)
 			if err != nil {
+				klog.Infoln("fucktls crypto/tls uprobes attached ret error", p.symbol)
 				//log("failed to attach uretprobe", err)
 				return nil, err
 			}
@@ -266,7 +271,7 @@ func (t *Tracer) AttachGoTlsUprobes(pid uint32, appInfo *AppInfo, codeType uint1
 			continue
 		}
 		switch s.Name {
-		//case goTlsWriteSymbol, goTlsReadSymbol:
+		case goTlsWriteSymbol, goTlsReadSymbol:
 		case goExecute, goNewproc1, goRunqget, goServeHTTP, goTransport:
 		default:
 			continue
@@ -413,6 +418,7 @@ func (t *Tracer) AttachGoTlsUprobes(pid uint32, appInfo *AppInfo, codeType uint1
 			}
 
 		case goTlsWriteSymbol:
+			klog.Infoln("fucktls goTlsWriteSymbol crypto/tls uprobes attached")
 			l, err := exe.Uprobe(s.Name, t.uprobes["go_crypto_tls_write_enter"], &link.UprobeOptions{Address: address})
 			if err != nil {
 				klog.WithError(err).Errorln("failed to attach write_enter uprobe")
@@ -420,6 +426,7 @@ func (t *Tracer) AttachGoTlsUprobes(pid uint32, appInfo *AppInfo, codeType uint1
 			}
 			links = append(links, l)
 		case goTlsReadSymbol:
+			klog.Infoln("fucktls goTlsReadSymbol crypto/tls uprobes attached")
 			l, err := exe.Uprobe(s.Name, t.uprobes["go_crypto_tls_read_enter"], &link.UprobeOptions{Address: address})
 			if err != nil {
 				klog.WithError(err).Errorln("failed to attach read_enter uprobe")