Skip to content

Lesson 6 of 13 · 12m

USDT and Uprobes: Reading a Binary You Didn't Write

Compiled-in NOP probes versus breakpoint uprobes, per-hit overhead math, and the plaintext your TLS uprobes see.

Two different mechanisms get lumped together as "dynamic tracing," and the cost model splits cleanly on the difference. A uprobe is a breakpoint: the kernel patches a trap instruction (int3 on x86) over the target address in your userspace binary, and every time execution reaches it, the trap fires, the probe runs, and the original instruction is stepped out of line. A USDT probe is a NOP the developer compiled in ahead of time — it costs nothing until you attach to it. Same attach syntax in bpftrace, completely different physics.

USDT: probes the author left for you

USDT — userland statically defined tracing — comes from DTrace and SystemTap's sys/sdt.h. The compiler emits a NOP at the probe site plus an ELF note (.note.stapsdt, NT_STAPSDT) recording the provider, probe name, address, and argument layout. You can inventory them without running anything:

readelf -n /usr/bin/python3.12 | grep -A4 stapsdt
tplist -l /usr/bin/python3.12        # BCC's USDT listing tool
bpftrace -l 'usdt:/usr/bin/python3.12:*'

Binaries that carry them: PostgreSQL built --enable-dtrace (transaction start/commit, query start), the JVM (-XX:+DTraceMethodProbes, -XX:+ExtendedDTraceProbes), Node built --with-dtrace, CPython built --with-dtrace (GC and function-entry probes), Ruby, and the BEAM VM. Attach with bpftrace -e 'usdt:/path/bin:probe_name { @[arg0] = count() }'. Some probes pair with an in-process "semaphore" counter the app increments while enabled, so expensive argument computation only runs when someone is actually listening. Arguments decode by position — arg0, arg1, typed per the note — so bpftrace -e 'usdt:/usr/bin/psql:transaction__start { @[comm] = count() }' works without touching source. The honest tradeoff: zero-cost until enabled, per-hit cost after — and a hot USDT site is still a hot site.

Uprobes: breakpoints on whatever you point at

Uprobes need no cooperation from the binary. Point one at PyEval_EvalFrameDefault in libpython and you get per-function tracing of a runtime that never shipped a probe. This is how some Python profilers and TLS-tracing tools work, and it's also where the cost model bites: a uprobe hit costs the trap plus dispatch, roughly microseconds versus a tracepoint's hundreds of nanoseconds. On a function called thousands of times a second, that's fine. On malloc, it's a self-inflicted DDoS — allocator hit rates run into the millions per second and you'll measure the slowdown before you finish Ctrl-C.

The same mechanism is a security boundary. sslsniff (BCC) and ecapture attach uprobes to SSL_read/SSL_write in libssl and read plaintext before encryption. As a debugging tool on your own host, that's how you inspect traffic without terminating TLS. As a posture statement, it means your observability tooling can bypass your transport security — treat probe privileges like the data access they are, and don't let a debug attach window become a standing capability.

Why you'd choose each

USDT first: stable ABI, author-intended semantics, arguments decoded in the note. Uprobes when nothing else exists, on cold-enough functions to afford the trap. For anything on a hot path, run funccount first — funccount -i 1 'c:malloc' counts hits per second — and look at the number before deciding the probe is free. In managed runtimes the uprobe target is the VM's interpreter frame (PyEval_EvalFrameDefault, the BEAM scheduler), which is how several Python and Erlang profilers trace code the language runtime never instrumented.

Practice

  • Inventory with tplist or readelf -n before writing a uprobe by hand.
  • Bound attach windows; count hits with funccount before adding payload.
  • Prefer tracepoints and USDT over kprobes/uprobes for the stable ABI.
  • Remember SSL_read/SSL_write uprobes see plaintext — grant CAP_BPF like it decrypts, because it does.

The runtime you didn't write is still legible. The kernel doesn't care whose symbol it patched.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.