Skip to content

Commit

Permalink
fix : incorret gotls event payload length.
Browse files Browse the repository at this point in the history
Signed-off-by: CFC4N <cfc4n.cs@gmail.com>
  • Loading branch information
cfc4n committed Mar 30, 2024
1 parent af499f2 commit 7ebb395
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
12 changes: 9 additions & 3 deletions kern/gotls_kern.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ static __always_inline int gotls_write(struct pt_regs *ctx,
len_ptr = (void *)go_get_argument(ctx, is_register_abi, 4);
bpf_probe_read_kernel(&len, sizeof(len), (void *)&len_ptr);

debug_bpf_printk("gotls_write record_type:%d\n", record_type);
if (len == 0) {
return 0;
}
debug_bpf_printk("gotls_write record_type:%d, len:%d\n", record_type, len);
if (record_type != recordTypeApplicationData) {
return 0;
}
Expand All @@ -115,7 +118,7 @@ static __always_inline int gotls_write(struct pt_regs *ctx,
if (!event) {
return 0;
}

len = len & 0xFFFF;
event->data_len = len;
int ret =
bpf_probe_read_user(&event->data, sizeof(event->data), (void *)str);
Expand Down Expand Up @@ -157,7 +160,10 @@ static __always_inline int gotls_read(struct pt_regs *ctx,
// Read函数的返回值第一个是int类型,存放在栈里的顺序是5
ret_len_ptr = (void *)go_get_argument_by_stack(ctx, 5);
bpf_probe_read_kernel(&ret_len, sizeof(ret_len), (void *)&ret_len_ptr);
if (len == 0) {
if (len <= 0) {
return 0;
}
if (ret_len <= 0 ) {
return 0;
}

Expand Down
1 change: 0 additions & 1 deletion user/config/config_gotls.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ func (gc *GoTLSConfig) Check() error {

gc.ReadTlsAddrs, err = gc.findRetOffsetsPie(GoTlsReadFunc)
if err != nil {
panic(err)
return err
}
} else {
Expand Down
14 changes: 14 additions & 0 deletions user/module/probe_gotls_text.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
manager "github.com/gojue/ebpfmanager"
"golang.org/x/sys/unix"
"math"
"strings"
)

func (g *GoTLSProbe) setupManagersText() error {
Expand All @@ -42,7 +43,20 @@ func (g *GoTLSProbe) setupManagersText() error {
readSec = "uprobe/gotls_read_stack"
readFn = "gotls_read_stack"
}
var gotlsConf = g.conf.(*config.GoTLSConfig)
var buildInfo = new(strings.Builder)
for _, setting := range gotlsConf.Buildinfo.Settings {
if setting.Value == "" {
continue
}
buildInfo.WriteString(" ")
buildInfo.WriteString(setting.Key)
buildInfo.WriteString("=")
buildInfo.WriteString(setting.Value)
}
g.logger.Printf("%s\teBPF Function Name:%s, isRegisterABI:%t\n", g.Name(), fn, g.isRegisterABI)
g.logger.Printf("%s\tGolang buildInfo version:%s, Params: %s\n", g.Name(), gotlsConf.Buildinfo.GoVersion, buildInfo.String())

if g.conf.(*config.GoTLSConfig).IsPieBuildMode {
// buildmode pie is enabled.
g.logger.Printf("%s\tGolang elf buildmode with pie\n", g.Name())
Expand Down

0 comments on commit 7ebb395

Please sign in to comment.