Skip to content

Commit ed8948d

Browse files
committed
Fix Go 1.24 tls tracing issue caused by removal of http2bufferedWriter w (io.Writer) member
Signed-off-by: Dom Del Nano <ddelnano@gmail.com>
1 parent 269a354 commit ed8948d

4 files changed

Lines changed: 45 additions & 12 deletions

File tree

src/stirling/source_connectors/socket_tracer/bcc_bpf/go_http2_trace.c

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,19 @@ static __inline int32_t get_fd_from_http2_Framer(const void* framer_ptr,
141141
static __inline int32_t get_fd_from_http_http2Framer(const void* framer_ptr,
142142
const struct go_http2_symaddrs_t* symaddrs) {
143143
REQUIRE_SYMADDR(symaddrs->http2Framer_w_offset, kInvalidFD);
144-
REQUIRE_SYMADDR(symaddrs->http2bufferedWriter_w_offset, kInvalidFD);
144+
int32_t inner_intf_offset = symaddrs->http2bufferedWriter_w_offset;
145+
bool conn_intf = false;
146+
// Go 1.24 dropped the io.Writer w member from http2bufferedWriter,
147+
// in favor of a conn member (net.Conn interface).
148+
// Go 1.23 struct:
149+
// https://github.com/golang/go/blob/d375ae50633cdf1cd8536f2a199c382f9053b638/src/net/http/h2_bundle.go#L3552-L3556
150+
// Go 1.24 struct:
151+
// https://github.com/golang/go/blob/3901409b5d0fb7c85a3e6730a59943cc93b2835c/src/net/http/h2_bundle.go#L3733-L3739
152+
if (inner_intf_offset == -1) {
153+
inner_intf_offset = symaddrs->http2bufferedWriter_conn_offset;
154+
conn_intf = true;
155+
}
156+
REQUIRE_SYMADDR(inner_intf_offset, kInvalidFD);
145157

146158
struct go_interface io_writer_interface;
147159
BPF_PROBE_READ_VAR(io_writer_interface, framer_ptr + symaddrs->http2Framer_w_offset);
@@ -152,11 +164,13 @@ static __inline int32_t get_fd_from_http_http2Framer(const void* framer_ptr,
152164
return kInvalidFD;
153165
}
154166

155-
struct go_interface inner_io_writer_interface;
156-
BPF_PROBE_READ_VAR(inner_io_writer_interface,
157-
io_writer_interface.ptr + symaddrs->http2bufferedWriter_w_offset);
167+
struct go_interface inner_intf;
168+
BPF_PROBE_READ_VAR(inner_intf, io_writer_interface.ptr + inner_intf_offset);
158169

159-
return get_fd_from_io_writer_intf(inner_io_writer_interface.ptr);
170+
if (conn_intf) {
171+
return get_fd_from_conn_intf(inner_intf);
172+
}
173+
return get_fd_from_io_writer_intf(inner_intf.ptr);
160174
}
161175

162176
//-----------------------------------------------------------------------------
@@ -525,7 +539,7 @@ int probe_http2_server_operate_headers(struct pt_regs* ctx) {
525539
// Symbol:
526540
// net/http.(*http2serverConn).processHeaders
527541
//
528-
// Verified to be stable from go1.?? to t go.1.13.
542+
// Verified to be stable from go1.?? to go.1.24..
529543
int probe_http_http2serverConn_processHeaders(struct pt_regs* ctx) {
530544
uint32_t tgid = bpf_get_current_pid_tgid() >> 32;
531545
struct go_http2_symaddrs_t* symaddrs = http2_symaddrs_map.lookup(&tgid);
@@ -629,7 +643,7 @@ int probe_http_http2serverConn_processHeaders(struct pt_regs* ctx) {
629643
// Symbol:
630644
// golang.org/x/net/http2/hpack.(*Encoder).WriteField
631645
//
632-
// Verified to be stable from at least go1.6 to t go.1.13.
646+
// Verified to be stable from at least go1.6 to go.1.24.
633647
int probe_hpack_header_encoder(struct pt_regs* ctx) {
634648
uint32_t tgid = bpf_get_current_pid_tgid() >> 32;
635649
struct go_http2_symaddrs_t* symaddrs = http2_symaddrs_map.lookup(&tgid);
@@ -679,7 +693,7 @@ int probe_hpack_header_encoder(struct pt_regs* ctx) {
679693
// Symbol:
680694
// net/http.(*http2writeResHeaders).writeFrame
681695
//
682-
// Verified to be stable from go1.?? to t go.1.13.
696+
// Verified to be stable from go1.?? to go.1.24.
683697
int probe_http_http2writeResHeaders_write_frame(struct pt_regs* ctx) {
684698
uint32_t tgid = bpf_get_current_pid_tgid() >> 32;
685699
struct go_http2_symaddrs_t* symaddrs = http2_symaddrs_map.lookup(&tgid);
@@ -857,7 +871,7 @@ static __inline void go_http2_submit_data(struct pt_regs* ctx, enum http2_probe_
857871
// Symbol:
858872
// golang.org/x/net/http2.(*Framer).checkFrameOrder
859873
//
860-
// Verified to be stable from at least go1.6 to t go.1.13.
874+
// Verified to be stable from at least go1.6 to go.1.24.
861875
int probe_http2_framer_check_frame_order(struct pt_regs* ctx) {
862876
uint32_t tgid = bpf_get_current_pid_tgid() >> 32;
863877
struct go_http2_symaddrs_t* symaddrs = http2_symaddrs_map.lookup(&tgid);
@@ -962,7 +976,7 @@ int probe_http2_framer_check_frame_order(struct pt_regs* ctx) {
962976
// Symbol:
963977
// net/http.(*http2Framer).checkFrameOrder
964978
//
965-
// Verified to be stable from at least go1.?? to go.1.13.
979+
// Verified to be stable from at least go1.?? to go.1.24.
966980
int probe_http_http2framer_check_frame_order(struct pt_regs* ctx) {
967981
uint32_t tgid = bpf_get_current_pid_tgid() >> 32;
968982
struct go_http2_symaddrs_t* symaddrs = http2_symaddrs_map.lookup(&tgid);
@@ -1066,7 +1080,7 @@ int probe_http_http2framer_check_frame_order(struct pt_regs* ctx) {
10661080
// Symbol:
10671081
// golang.org/x/net/http2.(*Framer).WriteDataPadded
10681082
//
1069-
// Verified to be stable from go1.7 to t go.1.13.
1083+
// Verified to be stable from go1.7 to go.1.24.
10701084
int probe_http2_framer_write_data(struct pt_regs* ctx) {
10711085
uint32_t tgid = bpf_get_current_pid_tgid() >> 32;
10721086
struct go_http2_symaddrs_t* symaddrs = http2_symaddrs_map.lookup(&tgid);
@@ -1134,7 +1148,7 @@ int probe_http2_framer_write_data(struct pt_regs* ctx) {
11341148
// Symbol:
11351149
// net/http.(*http2Framer).WriteDataPadded
11361150
//
1137-
// Verified to be stable from go1.?? to t go.1.13.
1151+
// Verified to be stable from go1.?? to go.1.24.
11381152
int probe_http_http2framer_write_data(struct pt_regs* ctx) {
11391153
uint32_t tgid = bpf_get_current_pid_tgid() >> 32;
11401154
struct go_http2_symaddrs_t* symaddrs = http2_symaddrs_map.lookup(&tgid);

src/stirling/source_connectors/socket_tracer/bcc_bpf/go_trace_common.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,25 @@ static __inline int32_t get_fd_from_conn_intf_core(struct go_interface conn_intf
174174
REQUIRE_SYMADDR(symaddrs->FD_Sysfd_offset, kInvalidFD);
175175

176176
if (conn_intf.type == symaddrs->internal_syscallConn) {
177+
// TODO(ddelnano): The 4.14 verifier has stricter bounds checking limits when reading memory
178+
// offsets. Without this check, the verifier rejects the program. This can be removed when 4.14
179+
// kernel support is dropped.
180+
if (symaddrs->syscallConn_conn_offset < 0 || symaddrs->syscallConn_conn_offset > 1024) {
181+
return kInvalidFD;
182+
}
177183
REQUIRE_SYMADDR(symaddrs->syscallConn_conn_offset, kInvalidFD);
178184
const int kSyscallConnConnOffset = 0;
179185
bpf_probe_read(&conn_intf, sizeof(conn_intf),
180186
conn_intf.ptr + symaddrs->syscallConn_conn_offset);
181187
}
182188

183189
if (conn_intf.type == symaddrs->tls_Conn) {
190+
// TODO(ddelnano): The 4.14 verifier has stricter bounds checking limits when reading memory
191+
// offsets. Without this check, the verifier rejects the program. This can be removed when 4.14
192+
// kernel support is dropped.
193+
if (symaddrs->tlsConn_conn_offset < 0 || symaddrs->tlsConn_conn_offset > 1024) {
194+
return kInvalidFD;
195+
}
184196
REQUIRE_SYMADDR(symaddrs->tlsConn_conn_offset, kInvalidFD);
185197
bpf_probe_read(&conn_intf, sizeof(conn_intf), conn_intf.ptr + symaddrs->tlsConn_conn_offset);
186198
}

src/stirling/source_connectors/socket_tracer/bcc_bpf_intf/symaddrs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,8 @@ struct go_http2_symaddrs_t {
235235

236236
// Members of net/http.http2bufferedWriter
237237
int32_t http2bufferedWriter_w_offset; // 0
238+
// Go 1.24 switched from a w io.Writer member to a conn net.Conn one.
239+
int32_t http2bufferedWriter_conn_offset;
238240
};
239241

240242
struct go_tls_symaddrs_t {

src/stirling/source_connectors/socket_tracer/uprobe_symaddrs.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,11 @@ Status PopulateHTTP2DebugSymbols(DwarfReader* dwarf_reader, std::string_view ven
345345
dwarf_reader->GetStructMemberOffset(
346346
"net/http.http2bufferedWriter",
347347
"w"));
348+
349+
LOG_ASSIGN_STATUSOR(symaddrs->http2bufferedWriter_conn_offset,
350+
dwarf_reader->GetStructMemberOffset(
351+
"net/http.http2bufferedWriter",
352+
"conn"));
348353
// clang-format on
349354

350355
const std::map<std::string, obj_tools::ArgInfo> kEmptyMap;

0 commit comments

Comments
 (0)