|
@@ -36,13 +36,13 @@ var (
|
|
|
opensslVersionRe = regexp.MustCompile(`OpenSSL\s(\d\.\d+\.\d+)`)
|
|
opensslVersionRe = regexp.MustCompile(`OpenSSL\s(\d\.\d+\.\d+)`)
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
-func (t *Tracer) AttachOpenSslUprobes(pid uint32) []link.Link {
|
|
|
|
|
|
|
+func (t *Tracer) AttachOpenSslUprobes(pid uint32) ([]link.Link, error) {
|
|
|
if t.DisableL7Tracing() {
|
|
if t.DisableL7Tracing() {
|
|
|
- return nil
|
|
|
|
|
|
|
+ return nil, nil
|
|
|
}
|
|
}
|
|
|
libPath, version := getSslLibPathAndVersion(pid)
|
|
libPath, version := getSslLibPathAndVersion(pid)
|
|
|
if libPath == "" || version == "" {
|
|
if libPath == "" || version == "" {
|
|
|
- return nil
|
|
|
|
|
|
|
+ return nil, nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
log := func(msg string, err error) {
|
|
log := func(msg string, err error) {
|
|
@@ -61,7 +61,7 @@ func (t *Tracer) AttachOpenSslUprobes(pid uint32) []link.Link {
|
|
|
exe, err := link.OpenExecutable(libPath)
|
|
exe, err := link.OpenExecutable(libPath)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
log("failed to open executable", err)
|
|
log("failed to open executable", err)
|
|
|
- return nil
|
|
|
|
|
|
|
+ return nil, err
|
|
|
}
|
|
}
|
|
|
var links []link.Link
|
|
var links []link.Link
|
|
|
writeEnter := "openssl_SSL_write_enter"
|
|
writeEnter := "openssl_SSL_write_enter"
|
|
@@ -97,7 +97,7 @@ func (t *Tracer) AttachOpenSslUprobes(pid uint32) []link.Link {
|
|
|
l, err := exe.Uprobe(p.symbol, t.uprobes[p.uprobe], nil)
|
|
l, err := exe.Uprobe(p.symbol, t.uprobes[p.uprobe], nil)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
//log("failed to attach uprobe", err)
|
|
//log("failed to attach uprobe", err)
|
|
|
- return nil
|
|
|
|
|
|
|
+ return nil, err
|
|
|
}
|
|
}
|
|
|
links = append(links, l)
|
|
links = append(links, l)
|
|
|
}
|
|
}
|
|
@@ -105,19 +105,19 @@ func (t *Tracer) AttachOpenSslUprobes(pid uint32) []link.Link {
|
|
|
l, err := exe.Uretprobe(p.symbol, t.uprobes[p.uretprobe], nil)
|
|
l, err := exe.Uretprobe(p.symbol, t.uprobes[p.uretprobe], nil)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
//log("failed to attach uretprobe", err)
|
|
//log("failed to attach uretprobe", err)
|
|
|
- return nil
|
|
|
|
|
|
|
+ return nil, err
|
|
|
}
|
|
}
|
|
|
links = append(links, l)
|
|
links = append(links, l)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//log("libssl uprobes attached", nil)
|
|
//log("libssl uprobes attached", nil)
|
|
|
- return links
|
|
|
|
|
|
|
+ return links, nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func (t *Tracer) AttachGoTlsUprobes(pid uint32, insID utils.ID, codeType uint16) []link.Link {
|
|
|
|
|
|
|
+func (t *Tracer) AttachGoTlsUprobes(pid uint32, insID utils.ID, codeType uint16) ([]link.Link, error) {
|
|
|
if t.DisableL7Tracing() {
|
|
if t.DisableL7Tracing() {
|
|
|
- return nil
|
|
|
|
|
|
|
+ return nil, nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
path := proc.Path(pid, "exe")
|
|
path := proc.Path(pid, "exe")
|
|
@@ -140,24 +140,24 @@ func (t *Tracer) AttachGoTlsUprobes(pid uint32, insID utils.ID, codeType uint16)
|
|
|
bi, err := buildinfo.ReadFile(path)
|
|
bi, err := buildinfo.ReadFile(path)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
log("failed to read build info", err)
|
|
log("failed to read build info", err)
|
|
|
- return nil
|
|
|
|
|
|
|
+ return nil, err
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
name, err = os.Readlink(path)
|
|
name, err = os.Readlink(path)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
log("failed to read name", err)
|
|
log("failed to read name", err)
|
|
|
- return nil
|
|
|
|
|
|
|
+ return nil, err
|
|
|
}
|
|
}
|
|
|
version = strings.Replace(bi.GoVersion, "go", "v", 1)
|
|
version = strings.Replace(bi.GoVersion, "go", "v", 1)
|
|
|
if semver.Compare(version, minSupportedGoVersion) < 0 {
|
|
if semver.Compare(version, minSupportedGoVersion) < 0 {
|
|
|
log(fmt.Sprintf("go_versions below %s are not supported", minSupportedGoVersion), nil)
|
|
log(fmt.Sprintf("go_versions below %s are not supported", minSupportedGoVersion), nil)
|
|
|
- return nil
|
|
|
|
|
|
|
+ return nil, err
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
ef, err := elf.Open(path)
|
|
ef, err := elf.Open(path)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
log("failed to open as elf binary", err)
|
|
log("failed to open as elf binary", err)
|
|
|
- return nil
|
|
|
|
|
|
|
+ return nil, err
|
|
|
}
|
|
}
|
|
|
defer ef.Close()
|
|
defer ef.Close()
|
|
|
|
|
|
|
@@ -165,28 +165,28 @@ func (t *Tracer) AttachGoTlsUprobes(pid uint32, insID utils.ID, codeType uint16)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
if errors.Is(err, elf.ErrNoSymbols) {
|
|
if errors.Is(err, elf.ErrNoSymbols) {
|
|
|
log("no symbol section", nil)
|
|
log("no symbol section", nil)
|
|
|
- return nil
|
|
|
|
|
|
|
+ return nil, err
|
|
|
}
|
|
}
|
|
|
log("failed to read symbols", err)
|
|
log("failed to read symbols", err)
|
|
|
- return nil
|
|
|
|
|
|
|
+ return nil, err
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
textSection := ef.Section(".text")
|
|
textSection := ef.Section(".text")
|
|
|
if textSection == nil {
|
|
if textSection == nil {
|
|
|
log("no text section", nil)
|
|
log("no text section", nil)
|
|
|
- return nil
|
|
|
|
|
|
|
+ return nil, err
|
|
|
}
|
|
}
|
|
|
textSectionData, err := textSection.Data()
|
|
textSectionData, err := textSection.Data()
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
log("failed to read text section", err)
|
|
log("failed to read text section", err)
|
|
|
- return nil
|
|
|
|
|
|
|
+ return nil, err
|
|
|
}
|
|
}
|
|
|
textSectionLen := uint64(len(textSectionData) - 1)
|
|
textSectionLen := uint64(len(textSectionData) - 1)
|
|
|
|
|
|
|
|
exe, err := link.OpenExecutable(path)
|
|
exe, err := link.OpenExecutable(path)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
log("failed to open executable", err)
|
|
log("failed to open executable", err)
|
|
|
- return nil
|
|
|
|
|
|
|
+ return nil, err
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
offset, ok := tracer.GetOffset(tracer.NewID("std", "runtime", "g", "goid"), path)
|
|
offset, ok := tracer.GetOffset(tracer.NewID("std", "runtime", "g", "goid"), path)
|
|
@@ -199,14 +199,17 @@ func (t *Tracer) AttachGoTlsUprobes(pid uint32, insID utils.ID, codeType uint16)
|
|
|
major, err = strconv.Atoi(parts[0])
|
|
major, err = strconv.Atoi(parts[0])
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
log("Error converting major version:", err)
|
|
log("Error converting major version:", err)
|
|
|
|
|
+ return nil, err
|
|
|
}
|
|
}
|
|
|
minor, err = strconv.Atoi(parts[1])
|
|
minor, err = strconv.Atoi(parts[1])
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
log("Error converting minor version:", err)
|
|
log("Error converting minor version:", err)
|
|
|
|
|
+ return nil, err
|
|
|
}
|
|
}
|
|
|
revision, err = strconv.Atoi(parts[2])
|
|
revision, err = strconv.Atoi(parts[2])
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
log("Error converting revision version:", err)
|
|
log("Error converting revision version:", err)
|
|
|
|
|
+ return nil, err
|
|
|
}
|
|
}
|
|
|
goVersion := ((major & 0xFF) << 16) + ((minor & 0xFF) << 8) + min(revision, 255)
|
|
goVersion := ((major & 0xFF) << 16) + ((minor & 0xFF) << 8) + min(revision, 255)
|
|
|
|
|
|
|
@@ -243,6 +246,7 @@ func (t *Tracer) AttachGoTlsUprobes(pid uint32, insID utils.ID, codeType uint16)
|
|
|
_, err = tracer.UpdateProcInfoToMap(t.collection, pid, info)
|
|
_, err = tracer.UpdateProcInfoToMap(t.collection, pid, info)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
klog.Error("failed to update program info", err)
|
|
klog.Error("failed to update program info", err)
|
|
|
|
|
+ return nil, err
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -277,7 +281,7 @@ func (t *Tracer) AttachGoTlsUprobes(pid uint32, insID utils.ID, codeType uint16)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
log("failed to attach write_enter uprobe", err)
|
|
log("failed to attach write_enter uprobe", err)
|
|
|
klog.Infoln("runtime.execute no")
|
|
klog.Infoln("runtime.execute no")
|
|
|
- return nil
|
|
|
|
|
|
|
+ return nil, err
|
|
|
} else {
|
|
} else {
|
|
|
klog.Infoln("runtime.execute ok")
|
|
klog.Infoln("runtime.execute ok")
|
|
|
}
|
|
}
|
|
@@ -287,7 +291,7 @@ func (t *Tracer) AttachGoTlsUprobes(pid uint32, insID utils.ID, codeType uint16)
|
|
|
l, err := exe.Uprobe(s.Name, t.uprobes["enter_runtime_newproc1"], &link.UprobeOptions{Address: address})
|
|
l, err := exe.Uprobe(s.Name, t.uprobes["enter_runtime_newproc1"], &link.UprobeOptions{Address: address})
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
log("failed to attach newproc1 uprobe", err)
|
|
log("failed to attach newproc1 uprobe", err)
|
|
|
- return nil
|
|
|
|
|
|
|
+ return nil, err
|
|
|
}
|
|
}
|
|
|
links = append(links, l)
|
|
links = append(links, l)
|
|
|
sStart := s.Value - textSection.Addr
|
|
sStart := s.Value - textSection.Addr
|
|
@@ -299,13 +303,13 @@ func (t *Tracer) AttachGoTlsUprobes(pid uint32, insID utils.ID, codeType uint16)
|
|
|
returnOffsets := getReturnOffsets(ef.Machine, sBytes)
|
|
returnOffsets := getReturnOffsets(ef.Machine, sBytes)
|
|
|
if len(returnOffsets) == 0 {
|
|
if len(returnOffsets) == 0 {
|
|
|
log("failed to attach enter_runtime_newproc1 uprobe", fmt.Errorf("no return offsets found"))
|
|
log("failed to attach enter_runtime_newproc1 uprobe", fmt.Errorf("no return offsets found"))
|
|
|
- return nil
|
|
|
|
|
|
|
+ return nil, err
|
|
|
}
|
|
}
|
|
|
for _, offset := range returnOffsets {
|
|
for _, offset := range returnOffsets {
|
|
|
l, err := exe.Uprobe(s.Name, t.uprobes["exit_runtime_newproc1"], &link.UprobeOptions{Address: address, Offset: uint64(offset)})
|
|
l, err := exe.Uprobe(s.Name, t.uprobes["exit_runtime_newproc1"], &link.UprobeOptions{Address: address, Offset: uint64(offset)})
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
log("failed to attach exit_runtime_newproc1 uprobe", err)
|
|
log("failed to attach exit_runtime_newproc1 uprobe", err)
|
|
|
- return nil
|
|
|
|
|
|
|
+ return nil, err
|
|
|
}
|
|
}
|
|
|
links = append(links, l)
|
|
links = append(links, l)
|
|
|
}
|
|
}
|
|
@@ -329,13 +333,13 @@ func (t *Tracer) AttachGoTlsUprobes(pid uint32, insID utils.ID, codeType uint16)
|
|
|
returnOffsets := getReturnOffsets(ef.Machine, sBytes)
|
|
returnOffsets := getReturnOffsets(ef.Machine, sBytes)
|
|
|
if len(returnOffsets) == 0 {
|
|
if len(returnOffsets) == 0 {
|
|
|
log("failed to attach uprobe_HandlerFunc_ServeHTTP uprobe", fmt.Errorf("no return offsets found"))
|
|
log("failed to attach uprobe_HandlerFunc_ServeHTTP uprobe", fmt.Errorf("no return offsets found"))
|
|
|
- return nil
|
|
|
|
|
|
|
+ return nil, err
|
|
|
}
|
|
}
|
|
|
for _, offset := range returnOffsets {
|
|
for _, offset := range returnOffsets {
|
|
|
l, err := exe.Uprobe(s.Name, t.uprobes["uprobe_HandlerFunc_ServeHTTP_Returns"], &link.UprobeOptions{Address: address, Offset: uint64(offset)})
|
|
l, err := exe.Uprobe(s.Name, t.uprobes["uprobe_HandlerFunc_ServeHTTP_Returns"], &link.UprobeOptions{Address: address, Offset: uint64(offset)})
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
log("failed to attach exit_runtime_newproc1 uprobe", err)
|
|
log("failed to attach exit_runtime_newproc1 uprobe", err)
|
|
|
- return nil
|
|
|
|
|
|
|
+ return nil, err
|
|
|
}
|
|
}
|
|
|
links = append(links, l)
|
|
links = append(links, l)
|
|
|
}
|
|
}
|
|
@@ -363,13 +367,13 @@ func (t *Tracer) AttachGoTlsUprobes(pid uint32, insID utils.ID, codeType uint16)
|
|
|
returnOffsets := getReturnOffsets(ef.Machine, sBytes)
|
|
returnOffsets := getReturnOffsets(ef.Machine, sBytes)
|
|
|
if len(returnOffsets) == 0 {
|
|
if len(returnOffsets) == 0 {
|
|
|
log("failed to attach uprobe_Transport_roundTrip uprobe", fmt.Errorf("no return offsets found"))
|
|
log("failed to attach uprobe_Transport_roundTrip uprobe", fmt.Errorf("no return offsets found"))
|
|
|
- return nil
|
|
|
|
|
|
|
+ return nil, err
|
|
|
}
|
|
}
|
|
|
for _, offset := range returnOffsets {
|
|
for _, offset := range returnOffsets {
|
|
|
l, err := exe.Uprobe(s.Name, t.uprobes["uprobe_Transport_roundTrip_Returns"], &link.UprobeOptions{Address: address, Offset: uint64(offset)})
|
|
l, err := exe.Uprobe(s.Name, t.uprobes["uprobe_Transport_roundTrip_Returns"], &link.UprobeOptions{Address: address, Offset: uint64(offset)})
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
log("failed to attach exit_runtime_newproc1 uprobe", err)
|
|
log("failed to attach exit_runtime_newproc1 uprobe", err)
|
|
|
- return nil
|
|
|
|
|
|
|
+ return nil, err
|
|
|
}
|
|
}
|
|
|
links = append(links, l)
|
|
links = append(links, l)
|
|
|
}
|
|
}
|
|
@@ -378,14 +382,14 @@ func (t *Tracer) AttachGoTlsUprobes(pid uint32, insID utils.ID, codeType uint16)
|
|
|
l, err := exe.Uprobe(s.Name, t.uprobes["go_crypto_tls_write_enter"], &link.UprobeOptions{Address: address})
|
|
l, err := exe.Uprobe(s.Name, t.uprobes["go_crypto_tls_write_enter"], &link.UprobeOptions{Address: address})
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
log("failed to attach write_enter uprobe", err)
|
|
log("failed to attach write_enter uprobe", err)
|
|
|
- return nil
|
|
|
|
|
|
|
+ return nil, err
|
|
|
}
|
|
}
|
|
|
links = append(links, l)
|
|
links = append(links, l)
|
|
|
case goTlsReadSymbol:
|
|
case goTlsReadSymbol:
|
|
|
l, err := exe.Uprobe(s.Name, t.uprobes["go_crypto_tls_read_enter"], &link.UprobeOptions{Address: address})
|
|
l, err := exe.Uprobe(s.Name, t.uprobes["go_crypto_tls_read_enter"], &link.UprobeOptions{Address: address})
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
log("failed to attach read_enter uprobe", err)
|
|
log("failed to attach read_enter uprobe", err)
|
|
|
- return nil
|
|
|
|
|
|
|
+ return nil, err
|
|
|
}
|
|
}
|
|
|
links = append(links, l)
|
|
links = append(links, l)
|
|
|
sStart := s.Value - textSection.Addr
|
|
sStart := s.Value - textSection.Addr
|
|
@@ -397,23 +401,23 @@ func (t *Tracer) AttachGoTlsUprobes(pid uint32, insID utils.ID, codeType uint16)
|
|
|
returnOffsets := getReturnOffsets(ef.Machine, sBytes)
|
|
returnOffsets := getReturnOffsets(ef.Machine, sBytes)
|
|
|
if len(returnOffsets) == 0 {
|
|
if len(returnOffsets) == 0 {
|
|
|
log("failed to attach read_exit uprobe", fmt.Errorf("no return offsets found"))
|
|
log("failed to attach read_exit uprobe", fmt.Errorf("no return offsets found"))
|
|
|
- return nil
|
|
|
|
|
|
|
+ return nil, err
|
|
|
}
|
|
}
|
|
|
for _, offset := range returnOffsets {
|
|
for _, offset := range returnOffsets {
|
|
|
l, err := exe.Uprobe(s.Name, t.uprobes["go_crypto_tls_read_exit"], &link.UprobeOptions{Address: address, Offset: uint64(offset)})
|
|
l, err := exe.Uprobe(s.Name, t.uprobes["go_crypto_tls_read_exit"], &link.UprobeOptions{Address: address, Offset: uint64(offset)})
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
log("failed to attach read_exit uprobe", err)
|
|
log("failed to attach read_exit uprobe", err)
|
|
|
- return nil
|
|
|
|
|
|
|
+ return nil, err
|
|
|
}
|
|
}
|
|
|
links = append(links, l)
|
|
links = append(links, l)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
if len(links) == 0 {
|
|
if len(links) == 0 {
|
|
|
- return nil
|
|
|
|
|
|
|
+ return nil, err
|
|
|
}
|
|
}
|
|
|
log("crypto/tls uprobes attached", nil)
|
|
log("crypto/tls uprobes attached", nil)
|
|
|
- return links
|
|
|
|
|
|
|
+ return links, nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func getSslLibPathAndVersion(pid uint32) (string, string) {
|
|
func getSslLibPathAndVersion(pid uint32) (string, string) {
|