Repository navigation
Conversation
✅ Deploy Preview for tetragon ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
FedeDP
force-pushed
the
fededp/new/sopath-ldso-resolve-libc
branch
from
November 5, 2026 14:08
673fd0a to
5e7d99c
Compare
Contributor
Author
|
Example output on an alpine container (with a convenient libcFile ld-musl-x86_64.so.1
level=info msg="Loaded generic uprobe program: bpf/objs/bpf_generic_uprobe_v61.o -> /home/main [foo]"
level=info msg="Loaded sensor successfully" sensor=generic_uprobe
level=info msg="Added TracingPolicy with success" TracingPolicy=override-so.yaml metadata.namespace="" metadata.name=uprobe-dyn-test
level=info msg="Perf ring buffer size (bytes)" percpu=68K total=1M
level=info msg="Events queue size (events)" size=63K
level=info msg="Listening for events..."
/work # /home/main
22
bar 22
bar 22
creating secondary thread
bar 22
end
/work # fg
./tetragon --bpf-lib bpf/objs/ --tracing-policy override-so.yaml
^Clevel=info msg="Received signal interrupt, shutting down..."
level=info msg="Listening for events completed." error="context canceled"
level=info msg="Unloading sensor generic_uprobe"
level=info msg="Sensor unloaded" sensor=generic_uprobe maps-error=[]
level=info msg="Unloading sensor __base__"
level=info msg="Sensor unloaded" sensor=__base__ maps-error=[]
level=info msg="BPF events statistics: 121 received, 0% events loss"
level=info msg="Observer events statistics" received=121 lost=0 errors=0 filterPass=0 filterDrop=0
/work # /home/main
22
foo 22
foo 22
creating secondary thread
foo 22
end |
Member
|
could |
Contributor
Author
|
@immanuwell totally makes sense, thanks for the hint! I'll fix it asap 🚀 |
FedeDP
force-pushed
the
fededp/new/sopath-ldso-resolve-libc
branch
from
November 6, 2026 09:30
5e7d99c to
b878b46
Compare
Contributor
Author
|
can you re-test @immanuwell ? Thanks! |
FedeDP
force-pushed
the
fededp/new/sopath-ldso-resolve-libc
branch
2 times, most recently
from
November 6, 2026 11:45
fb323e6 to
d12f33b
Compare
Member
FedeDP
force-pushed
the
fededp/new/sopath-ldso-resolve-libc
branch
from
November 6, 2026 15:43
d12f33b to
e75fa36
Compare
This work will enable the support for musl, that will be introduced in subsequent commits. In bpf code, the uprobe `sopath` override looks for the libc base address in the process VMA by comparing their filename against hardcoded "libc.so.6". Let userspace provide the library name instead,through a new `libc_name` field of `struct uprobe_regs`, sized `SONAME_MAX`, following what we already did for `soname`, since it is compared by find_library_base() the same way. Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
It abstracts the filesystem in which a binary and its shared library dependencies are resolved. Paths passed to a `Root` method are absolute paths as seen from inside it, so that the same resolution logic can later be applied to container root filesystems, by providing an implementation that confines lookups (including symlinks) to them. For now, only `HostRoot()` is provided. Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
Add a parser for glibc `/etc/ld.so.cache`, that maps sonames to library paths. It supports only the "new" format, written by default by ldconfig since glibc 2.32. The old and compat formats are intentionally left out: uprobe `sopath` override feature requires glibc >= 2.34 anyway. Such caches will be reported as malformed, so that the resolver can fall back to the default library directories. The cache may come from an untrusted root, so its size is capped and every offset is bounds checked. Tests cover truncated and malformed caches, and compare the result of parsing the host cache against `ldconfig -p`. AIL: 3 (https://danielmiessler.com/blog/ai-influence-level-ail) Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
Add `ResolveNeeded()`, which looks up a direct dependency of a dynamically linked binary by parsing its ELF headers and following the glibc dynamic loader search order: DT_RPATH (if no DT_RUNPATH), DT_RUNPATH, /etc/ld.so.cache and the default directories, the latter two being skipped for binaries linked with `-z nodefaultlib`. $ORIGIN, $LIB and $PLATFORM are expanded in DT_RUNPATH/DT_RPATH. Default directories cover both multiarch (Debian/Ubuntu) and lib64 (Fedora/RHEL) layouts. Candidates whose ELF class, data encoding or machine don't match the binary are skipped, like ld.so does. LD_LIBRARY_PATH is not taken into account, as it depends on each process environment. Static binaries, musl binaries and binaries not directly depending on the requested library are reported with dedicated errors. Unlike ldd, nothing is executed, and all lookups go through a `Root`, so that binaries from other root filesystems can be supported. Tests run against synthetic root filesystems, built from minimal generated ELF files, and check we agree with ldd on host binaries. AIL: 3 (https://danielmiessler.com/blog/ai-influence-level-ail) Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
Add `ResolveInterpreter()`, returning the program interpreter (PT_INTERP) of a binary, opened through the `Root` and checked to be compatible with the binary like any other resolved library. This is meant for musl binaries, where libc and the dynamic loader are the same object: e.g. on Alpine, binaries depend on libc.musl-x86_64.so.1, a symlink to their interpreter /lib/ld-musl-x86_64.so.1. Looking it up through the interpreter avoids dealing with arch and distro specific musl sonames, and with musl's own library search order. `ErrMusl` documentation is updated to point to it. AIL: 3 (https://danielmiessler.com/blog/ai-influence-level-ail) Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
FedeDP
force-pushed
the
fededp/new/sopath-ldso-resolve-libc
branch
from
November 23, 2026 11:48
e75fa36 to
d28b294
Compare
Contributor
Author
|
Dropped first commit that is now part of #6132 |
It's going to be used to detect the CPU features glibc relies on to pick glibc-hwcaps subdirectories. golang.org/x/sys is already a dependency, so this only vendors one more of its packages. Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
glibc >= 2.33 looks up libraries in the glibc-hwcaps subdirectories of each search directory first (e.g. /usr/lib64/glibc-hwcaps/x86-64-v3/), for each subdirectory supported by the CPU, in priority order. Add `hostHwcaps()`, returning the glibc-hwcaps subdirectories supported on the host for binaries of a given ELF machine and class, in priority order. On x86-64, they are computed from the CPU features glibc checks for each ISA level, read through CPUID like glibc does. On arm64, none is returned, as glibc defines no glibc-hwcaps subdirectories for it. The CPU is shared by all processes on the machine, containers included. Per process overrides (ld.so --glibc-hwcaps-* options, glibc.cpu.hwcaps tunable) are not taken into account. Tests check the result against the host ld.so `--help` output. AIL: 3 (https://danielmiessler.com/blog/ai-influence-level-ail) Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
Distros use glibc-hwcaps subdirectories to ship library builds optimized for newer CPUs, whose symbol offsets differ from the baseline build: resolving the baseline one while ld.so loads an optimized one leads to wrong offsets. Like ld.so, in `ResolveNeeded()`: - for each search directory, try its glibc-hwcaps subdirectories supported by the host first, in priority order; - parse the glibc-hwcaps cache extension of ld.so.cache, and prefer entries of supported subdirectories, by priority, over regular ones, skipping entries of unsupported subdirectories. A missing or malformed extension only drops the glibc-hwcaps entries. Entries flagged with legacy hwcaps, removed in glibc 2.37, are ignored. Tests also check the cache parser against `ldconfig -p` on a cache with glibc-hwcaps entries generated by ldconfig itself. Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
Add `ldso.ResolveLibc()`, which resolves the libc of a binary: the libc.so.6 (`GlibcSoname`) dependency for glibc binaries, resolved with `ResolveNeeded()`, or the program interpreter for musl binaries, where libc is also the dynamic loader, resolved with `ResolveInterpreter()`. Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
Replace the ldd-based `resolveDep()` with `ldso.ResolveLibc()` to find the libc of the uprobed binary. ldd does not work for binaries from another root filesystem, e.g. a container's, and it may execute the binary it inspects. As a bonus, musl binaries are now supported too: musl libc exports both mmap and dlopen, and the libc file name passed to the bpf side is the musl dynamic loader one. The resolved libc is parsed from the file returned by the resolver rather than reopened by path, and its real path is computed through the resolver `Root`. Also, report a clear error when libc does not export dlopen, which was moved from libdl into libc with glibc 2.34. Drop `TestDynamicSOResolveDep`, now covered by pkg/elf/ldso tests. Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
Add mention of new musl support and properly explain how is libc.so.6 looked up in glibc executables. Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
FedeDP
force-pushed
the
fededp/new/sopath-ldso-resolve-libc
branch
from
November 23, 2026 11:51
d28b294 to
7c486b1
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
In #5563 , we used
lddto determine fullpath to libc for the binary that was going to be traced withoverride.sopathaction.As noted here: #5825, ldd would not work for uprobes in container (once #5190 is in) and it has also some security concerns: #5563 (comment)
This PR implements an
ld.so.cacheparser and ELF headers parsing direct dependencies looking for libc, thus avoidingldd.Also, a
Rootinterface is introduced that will allow an easy introduction for container support once needed.Finally, musl support is introduced; since bpf code was hardcoded to look for
libc.so.6in process VMA, we now pass an additionallibc_nameinregs_mapthat is used by bpf code as libc to look for.AIL: 3 (https://danielmiessler.com/blog/ai-influence-level-ail)
Changelog