Skip to content

Commit

Permalink
Fix harcoded offset bug in grpc-go (#763)
Browse files Browse the repository at this point in the history
  • Loading branch information
grcevski authored Apr 19, 2024
1 parent 6bf78e9 commit e36cd60
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 10 deletions.
4 changes: 2 additions & 2 deletions bpf/go_grpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ int uprobe_grpcFramerWriteHeaders(struct pt_regs *ctx) {
void *framer = GO_PARAM1(ctx);
u64 stream_id = (u64)GO_PARAM2(ctx);

bpf_printk("framer=%llx, stream_id=%lld", framer, ((u64)stream_id));
bpf_printk("framer=%llx, stream_id=%lld, framer_w_pos %llx", framer, ((u64)stream_id), framer_w_pos);

u32 stream_lookup = (u32)stream_id;

Expand Down Expand Up @@ -549,7 +549,7 @@ int uprobe_grpcFramerWriteHeaders_returns(struct pt_regs *ctx) {
bpf_probe_write_user(buf_arr + (n & 0x0ffff), tp_str, sizeof(tp_str));
n += TP_MAX_VAL_LENGTH;
// Update the value of n in w to reflect the new size
bpf_probe_write_user((void *)(w_ptr + 32), &n, sizeof(n));
bpf_probe_write_user((void *)(w_ptr + grpc_transport_buf_writer_offset_pos), &n, sizeof(n));

// http2 encodes the length of the headers in the first 3 bytes of buf, we need to update those
u8 size_1 = 0;
Expand Down
Binary file modified pkg/internal/ebpf/grpc/bpf_tp_bpfel_arm64.o
Binary file not shown.
Binary file modified pkg/internal/ebpf/grpc/bpf_tp_bpfel_x86.o
Binary file not shown.
Binary file modified pkg/internal/ebpf/grpc/bpf_tp_debug_bpfel_arm64.o
Binary file not shown.
Binary file modified pkg/internal/ebpf/grpc/bpf_tp_debug_bpfel_x86.o
Binary file not shown.
9 changes: 1 addition & 8 deletions pkg/internal/ebpf/grpc/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,7 @@ func (p *Tracer) Constants(_ *exec.FileInfo, offsets *goexec.Offsets) map[string
"fd_laddr_pos",
"fd_raddr_pos",
} {
// Since gRPC 1.60 remoteaddr and localaddr were replaced by peer.
// We don't fail the store of unknown fields, we make them -1 so we detect
// what to read from the Go structures.
if off, ok := offsets.Field[s]; ok {
constants[s] = off
} else {
constants[s] = uint64(0xffffffffffffffff)
}
constants[s] = offsets.Field[s]
}
return constants
}
Expand Down

0 comments on commit e36cd60

Please sign in to comment.