Skip to content

Go zero-code (G1) ​

Ready, nothing to approve

G1 needs no change to the service: the sensor attaches to Go binaries with symbols by itself. The hub's Runtime hooks page marks such containers zero-code.

For Go services you do not want to (or cannot) change: vulnboxd's sensor attaches to functions of the Go runtime, the standard library and the common server libraries inside the running binary — net/http (HTTP/1 and HTTP/2), golang.org/x/net/http2, grpc-go, fasthttp and fiber, goroutine creation, fork, dial and open — and links each request to the processes it starts, the connections it opens and the files it opens. Nothing changes: no source change, no compose change, no rebuild.

Services that G1 cannot trace (see Known gaps) get the same links through the G2 Go module, a source change.

Covers ​

Versions
Go1.17–1.26 (one offset table entry per release, generated from that release's DWARF)
Architecturesamd64 (tested); arm64 for Go 1.18+ (table generated, not tested: no arm64 VM available)
Binariesstatic and dynamic, cgo or not, PIE or not; stripped (-ldflags='-s -w') for net/http, unstripped for the third-party servers
net/httphttp.Server over HTTP/1.x and HTTP/2 (TLS, the bundled h2), plain or TLS — so every router on top of it: http.ServeMux, chi, gorilla/mux, echo, gin, ...
golang.org/x/net/http2http2.Server (h2c, or configured by hand) — any version, read from the binary's DWARF
gRPCgrpc-go Server (unary and streaming RPCs) — any version, read from the binary's DWARF
fasthttp, fiberfasthttp Server and fiber v2 on top of it — any version, read from the binary's DWARF
Kernelwhat the sensor needs (5.8+ with BTF); uprobes and the sched_process_fork tracepoint

Verified end to end in a QEMU VM: net/http (HTTP/1 and HTTP/2 over TLS) built by Go 1.17, 1.20, 1.21, 1.25 and 1.26, each plain and stripped; x/net h2c, grpc-go, fasthttp and fiber built by Go 1.21 and 1.26 (see Safety).

What the kernel already links without any hook: nothing, for Go. Goroutines move between OS threads and one thread runs many requests' goroutines in turn, so the sensor's "one client socket per thread" rule never applies to a Go server.

How it gets in ​

Zero-code. There is no diff. The hub shows "traced without any change" when it detects a Go service (go.mod, a golang: build stage, net/http), and the sensor checks the running binary itself:

  • it is an ELF Go binary for amd64 (arm64: Go 1.18+), built by a Go release in the table (from .go.buildinfo);
  • it does not carry the G2 module (then G2's probes report its requests and G1 stays off for them);
  • the functions G1 attaches to are in it (from the symbol table, or .gopclntab, which stripped Go binaries keep); for x/net/http2, grpc-go and fasthttp the binary's DWARF says their struct layout and argument registers, so those need an unstripped binary.

Otherwise the hub proposes G2.

To apply it by hand: nothing to do. Run the sensor; the service must be in a watched cgroup.

What it records ​

All probes are entry uprobes (return probes would corrupt Go's movable stacks). Every event is reported like the runtime hooks' USDT probes, with the hook package go-g1, so the hub links them the same way.

EventEmitted fromJoin key
request_begin (HTTP/1)net/http.serverHandler.ServeHTTP, on a connection whose net/http.(*conn).serve the sensor saw startthe accepted socket's peer address and port (from the connection's net.netFD), the request's index on the connection (counted from its start), the local port
request_begin (HTTP/2)(*http2serverConn).runHandler (net/http) or (*serverConn).runHandler (x/net)peer and local address from the connection, the index from the stream id ((id − 1) / 2; x/net's own h2c client starts at stream 3, so its first request is index 1), protocol http2
request_begin (gRPC)grpc.(*Server).handleStreampeer and local address from the transport's connection, the index from the stream id, protocol grpc
request_begin (fasthttp, fiber)(*Request).readLimitBody / readBodyStream on a connection whose (*Server).serveConn the sensor saw startpeer and local address, the request's index on the connection
request_end(*response).finishRequest; HTTP/2 handlerDone; gRPC (*http2Server).writeStatus (WriteStatus before grpc-go 1.69); fasthttp writeResponsethe request; the status from the response (gRPC: 200)
spawnedsyscall.forkAndExecInChild1 on a request's goroutine, then the kernel's sched_process_fork on that threadthe child's pid
connectednet.setNoDelay on a dialled (isConnected) TCP connectionthe connection's local port
openedos.OpenFile, then os.newFile with kind "opened by OpenFile" on the same goroutinepid + fd; flags as passed to open(2)

The request index is exact: an HTTP/1 or fasthttp connection is only counted from the start of its serve, so connections accepted before the sensor attached are not reported at all (G1 never guesses); HTTP/2 and gRPC streams carry their own position.

TLS connections are unwrapped (*tls.Conn, and wrappers that embed a net.Conn first, such as h2c's) — through the itabs when the binary has a symbol table, through checking the net.netFD behind them when it is stripped.

The sensor's TLS plaintext feature uses the same machinery for Go's crypto/tls ((*Conn).Write at entry, (*Conn).Read at each of its return instructions), in every Go binary, including ones that carry G2.

Context following ​

  • A request belongs to the goroutine its handler runs on (from the g register: r14 on amd64, x28 on arm64): net/http's connection goroutine for HTTP/1, the stream's goroutine for HTTP/2, the RPC's goroutine (or stream worker) for gRPC, fasthttp's worker goroutine — until the request ends.
  • Goroutines started by it — at any depth — belong to the same request: from Go 1.21 through the runtime's own parentGoid (checked when a goroutine first needs its request, and at every go statement in runtime.newproc1); before Go 1.21 by pairing runtime.newproc1 (which goroutine starts one) with the runtime.runqput that follows it on the same thread.
  • Nothing needs handoff: work handed to an existing worker goroutine (a pool fed through a channel) is not followed. Use G2's vbxtrace.Handoff for that.

Known gaps ​

  • Stripped binaries and third-party servers: x/net/http2, grpc-go and fasthttp/fiber need the binary's DWARF; -ldflags='-s -w' (or -w) removes it, and those servers are then not traced (the rest — net/http, goroutines, spawns, dials, opens — still is). Use G2 for them.
  • Connected UDP sockets and unix sockets are not reported as connected (only TCP dials).
  • Files opened without os.OpenFile (syscall.Open, os.Root paths in newer releases) are not reported.
  • Go releases not in the table (newer than 1.26, or devel builds) are left alone until the table is regenerated (crates/sensor-go/offsets/gen.sh); so are amd64 binaries older than Go 1.17 and arm64 binaries older than 1.18 (no register ABI).
  • Inlining that differs from the reference build: the table (and, for third-party servers, the binary's DWARF) records which functions are inlined. A binary built with profile-guided optimisation or unusual -gcflags may inline one of the standard library's functions somewhere; that call then goes unseen.
  • Hijacked connections (WebSocket upgrades): finishRequest never runs, so the request gets no request_end. h2c's upgrade pseudo-request (PRI * HTTP/2.0) is not reported as a request of its own.
  • gRPC served through net/http (grpc.Server as an http.Handler) is reported as HTTP/2 requests, not as gRPC.
  • Cost before Go 1.21: runtime.runqput runs on every goroutine wake-up, and each is a uprobe hit (from 1.21 it is not attached). Overhead has not been measured yet.
  • arm64 is not tested: the table has arm64 layouts, but no arm64 VM was available (qemu-system-aarch64 is not installed on the build host).

Safety ​

  • Strictly read-only: the eBPF programs only read the process's memory and registers; nothing is written to the process, and the service runs exactly the binary it always ran.
  • A process is traced only after the sensor wrote its layout (struct offsets, argument registers, itab addresses) for it, and only in watched cgroups. Every read is a checked bpf_probe_read_user: a wrong guess about memory yields no event, never a fault.
  • Every structure is checked before use: a connection must be a TCP net.netFD (family, socket type, and net = "tcp"), a request's response must belong to a connection seen starting.
  • Turning the sensor off detaches every probe.
  • Tested in a QEMU VM (crates/sensor-go/tests/vm/run.sh). For every build, every request of the driver — six HTTP/1 requests (two on one keep-alive connection) and five HTTP/2-over-TLS streams on one connection for net/http; six requests for fasthttp and fiber; six streams on one connection for x/net h2c; six RPCs on one connection for gRPC — gets a request_begin with the exact peer port and index, labelled go-g1, and a request_end; the child processes (from the handler and from a goroutine two levels down), the opened file and the dialled connection each carry their request's context. Stripped third-party builds are checked to report nothing. Overhead has not been measured yet.

Turning it off ​

Stop the sensor (or leave the service's cgroup unwatched). There is nothing in the service to revert. VBXTRACE=0 does not apply: G1 runs nothing inside the service.

Troubleshooting ​

  • Is the binary traceable? go version <binary> shows the release (it must be in the table); go tool nm <binary> | grep 'net/http.(\*conn).serve' (unstripped) shows the functions are there.
  • Did the sensor attach? Its log says G1: attached N probes to <binary> (go1.X.Y, symbols|stripped) for each Go binary, no HTTP/2 (x/net), gRPC or fasthttp support: no DWARF for a stripped one that links those, or why it left one alone (carries the vbxtrace module (G2), not in G1's offset table) at debug level (RUST_LOG=sensor_go=debug).
  • No request_begin for old connections. HTTP/1 and fasthttp connections accepted before the sensor attached are not reported (their index is unknown); new ones are.
  • Which links did a flow get? The hub shows each link's method; G1's hook events carry the package go-g1 (G2's: go-g2). The Trace tab labels those links "hook · Go (zero-code)" and "hook · Go (vbxtrace)".