Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make gRPC frame pos deterministic for eBPF verifier #574

Merged
merged 2 commits into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions internal/include/arguments.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
// Injected in init
volatile const bool is_registers_abi;

void *get_argument_by_reg(struct pt_regs *ctx, int index)
void __always_inline *get_argument_by_reg(struct pt_regs *ctx, int index)
{
switch (index)
{
Expand All @@ -50,7 +50,7 @@ void *get_argument_by_reg(struct pt_regs *ctx, int index)
}
}

void *get_argument_by_stack(struct pt_regs *ctx, int index)
void __always_inline *get_argument_by_stack(struct pt_regs *ctx, int index)
{
void *ptr = 0;
bpf_probe_read(&ptr, sizeof(ptr), (void *)(PT_REGS_SP(ctx) + (index * 8)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ volatile const u64 frame_fields_pos;
volatile const u64 frame_stream_id_pod;
volatile const u64 stream_id_pos;
volatile const u64 stream_ctx_pos;
volatile const u64 frame_pos;
volatile const bool is_new_frame_pos;

// This instrumentation attaches uprobe to the following function:
// func (s *Server) handleStream(t transport.ServerTransport, stream *transport.Stream, trInfo *traceInfo)
Expand Down Expand Up @@ -124,9 +124,15 @@ int uprobe_server_handleStream(struct pt_regs *ctx)
UPROBE_RETURN(server_handleStream, struct grpc_request_t, grpc_events, events, 4, stream_ctx_pos, false)

// func (d *http2Server) operateHeader(frame *http2.MetaHeadersFrame) error
// for version 1.60 and above:
// func (t *http2Server) operateHeaders(ctx context.Context, frame *http2.MetaHeadersFrame, handle func(*Stream)) error
SEC("uprobe/http2Server_operateHeader")
int uprobe_http2Server_operateHeader(struct pt_regs *ctx)
{
u64 frame_pos = 2;
if (is_new_frame_pos) {
frame_pos = 4;
}
void *frame_ptr = get_argument(ctx, frame_pos);
struct go_slice header_fields = {};
bpf_probe_read(&header_fields, sizeof(header_fields), (void *)(frame_ptr + frame_fields_pos));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,7 @@ func (c framePosConst) InjectOption(td *process.TargetDetails) (inject.Option, e
return nil, fmt.Errorf("unknown module version: %s", pkg)
}

var pos uint64 = 2
if ver.GreaterThanOrEqual(paramChangeVer) {
pos = 4
}
return inject.WithKeyValue("frame_pos", pos), nil
return inject.WithKeyValue("is_new_frame_pos", ver.GreaterThanOrEqual(paramChangeVer)), nil
}

func uprobeHandleStream(name string, exec *link.Executable, target *process.TargetDetails, obj *bpfObjects) ([]link.Link, error) {
Expand Down
Loading