Repository navigation
fix(sslsniff): make --extra-lib work instead of being rejected - #238
Conversation
There was a problem hiding this comment.
Summary
--extra-lib was documented in sslsniff --help's examples and stored in env.extra_lib, but never registered in the argp option table, so argp rejected it before anything else ran:
$ ./sslsniff --extra-lib openssl:/tmp/x.so
sslsniff: unrecognized option '--extra-lib'
That is the --extra-lib doesn't work half of #122.
Change
src/30-sslsniff/sslsniff.c only:
- Register
--extra-lib=PROVIDER:PATHinoptsand handleEXTRA_LIB_KEYinparse_arg(the#definewas already there, unused). - Validate the spec at parse time, so a typo is reported before the BPF object is opened instead of being masked by a load failure.
attach_extra_lib()dispatches to the existing provider probe sets:openssl→attach_openssl,gnutls→attach_gnutls,nss→attach_nss, using the given path directly.- Using the path directly is the point of the option:
find_library_path()resolves through ldconfig, so it cannot see a library outside the loader cache — a libssl from a custom prefix, or a bundle's ownlibnspr4.soinside an application directory, which is exactly the reproduction in #122.
Test
$ ./sslsniff --help | grep extra-lib
--extra-lib=PROVIDER:PATH Also attach to this library, e.g.
openssl:/opt/lib/libssl.so.1.1
$ ./sslsniff --extra-lib bogus:/tmp/x.so
invalid --extra-lib `bogus:/tmp/x.so`: provider must be openssl, gnutls or nss
$ echo $?
1
$ ./sslsniff --extra-lib nonsense
invalid --extra-lib `nonsense`: expected PROVIDER:PATH
$ echo $?
1
A valid spec proceeds past parsing into the BPF load (libbpf: loading object 'sslsniff_bpf' …). The attach itself was not observed running in this sandbox: unprivileged_bpf_disabled=2 and no CAP_BPF, so bpf_object__probe_loading() fails with -EPERM for every invocation, with or without the option. The attach call reuses the existing, exercised provider hooks unchanged, so the new surface is the argument path, which is what the three cases above cover.
Builds clean with the tutorial's own Makefile (make -C src/30-sslsniff), no warnings from the new code.
AI patrol review
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
5 open issues
parse_arg()should not callexit(1)directly because it bypasses argp’s normal error handling… · New The provider parsing/validation logic is split acrossvalidate_extra_lib()and… · New Theaccess()pre-check is both redundant (the subsequent attach/open will fail anyway) and… · New This prints unconditionally to stdout, which can break scripts/pipelines that expect stdout to… · Newattach_extra_lib()returns a status code, but it’s ignored here. This can silently swallow real… · New
What changed in this PR
This PR fixes sslsniff --extra-lib so it’s accepted by argp and can attach probes to a user-specified SSL library outside the loader cache (as described in #122).
Changes:
- Registers
--extra-lib=PROVIDER:PATHin argp options and stores the value inenv.extra_lib. - Adds parse-time validation for
PROVIDER:PATHwith clear user-facing errors. - Implements
attach_extra_lib()to dispatch to existing provider attachers using the provided path.
| File | Description |
|---|---|
| src/30-sslsniff/sslsniff.c | Adds argp option + validation and attaches probes to a user-specified provider library path. |
Review effort: Lite
There was a problem hiding this comment.
This is a repost of the patrol's review above at 08:43 UTC on the same head; that earlier one is the authoritative verdict and the two bodies are identical apart from this footer.
Summary
--extra-lib was documented in sslsniff --help's examples and stored in env.extra_lib, but never registered in the argp option table, so argp rejected it before anything else ran:
$ ./sslsniff --extra-lib openssl:/tmp/x.so
sslsniff: unrecognized option '--extra-lib'
That is the --extra-lib doesn't work half of #122.
Change
src/30-sslsniff/sslsniff.c only:
- Register
--extra-lib=PROVIDER:PATHinoptsand handleEXTRA_LIB_KEYinparse_arg(the#definewas already there, unused). - Validate the spec at parse time, so a typo is reported before the BPF object is opened instead of being masked by a load failure.
attach_extra_lib()dispatches to the existing provider probe sets:openssl→attach_openssl,gnutls→attach_gnutls,nss→attach_nss, using the given path directly.- Using the path directly is the point of the option:
find_library_path()resolves through ldconfig, so it cannot see a library outside the loader cache — a libssl from a custom prefix, or a bundle's ownlibnspr4.soinside an application directory, which is exactly the reproduction in #122.
Test
$ ./sslsniff --help | grep extra-lib
--extra-lib=PROVIDER:PATH Also attach to this library, e.g.
openssl:/opt/lib/libssl.so.1.1
$ ./sslsniff --extra-lib bogus:/tmp/x.so
invalid --extra-lib `bogus:/tmp/x.so`: provider must be openssl, gnutls or nss
$ echo $?
1
$ ./sslsniff --extra-lib nonsense
invalid --extra-lib `nonsense`: expected PROVIDER:PATH
$ echo $?
1
A valid spec proceeds past parsing into the BPF load (libbpf: loading object 'sslsniff_bpf' …). The attach itself was not observed running in this sandbox: unprivileged_bpf_disabled=2 and no CAP_BPF, so bpf_object__probe_loading() fails with -EPERM for every invocation, with or without the option. The attach call reuses the existing, exercised provider hooks unchanged, so the new surface is the argument path, which is what the three cases above cover.
Builds clean with the tutorial's own Makefile (make -C src/30-sslsniff), no warnings from the new code.
AI-generated response; a maintainer will review and follow up later
AI patrol review
yunwei37
left a comment
There was a problem hiding this comment.
Reviewed at 235551ab.
The option now works end to end. Built src/30-sslsniff with the tree's own Makefile (self-built libbpf + bpftool, CC=cc -g -Wall): clean, no warnings. --help lists --extra-lib=PROVIDER:PATH.
Verified against the built binary:
$ ./sslsniff --extra-lib openssl -> invalid --extra-lib `openssl`: expected PROVIDER:PATH
$ ./sslsniff --extra-lib openssl: -> ... expected PROVIDER:PATH
$ ./sslsniff --extra-lib :foo.so -> ... expected PROVIDER:PATH
$ ./sslsniff --extra-lib bogus:/x.so -> ... provider must be openssl, gnutls or nss
$ ./sslsniff --extra-lib openssl:/tmp/x.so -p 1
-> reaches the loader (libbpf reports its own -EPERM here)
All four rejections are argp errors, so they exit through the normal path and not from inside the callback; the valid spec is accepted and reaches attach_extra_lib. BPF loading itself cannot be exercised in this environment (unprivileged_bpf_disabled=2, no CAP_BPF), so the attachment itself is not observed here.
The two red checks on this head are both pre-existing and unrelated to the change:
build(Test eunomia-bpf example CI, job 132331867974):Unable to locate package llvm-14-dev—ubuntu-latestmoved past LLVM 14. #236 pins that job toubuntu-22.04.build(Test bpftrace examples, job 132331868283): the job greps forAttaching 1 probe, while this bpftrace printsAttached 1 probeand does trace (tracedpresent in the log). #237 accepts both wordings.
So this head goes green once those two land; nothing in sslsniff.c contributes to either.
CodeFactor reports one minor issue, which does not affect behaviour.
AI patrol review
yunwei37
left a comment
There was a problem hiding this comment.
Verdict: ready to merge once CI is green
The change on this head was reviewed above and needs no fix. build fails at the bpftrace step of the helloworld example, and it fails identically on main itself:
test -n "$hello_symbol" || (echo "Error: raw hello function symbol not found" && exit 1)
Error: bpftrace failed to attach or trace the hello function
Base-branch failure; it does not block this head.
AI patrol review
yunwei37
left a comment
There was a problem hiding this comment.
Verdict: ready to merge once main's CI is fixed
--extra-lib was in the option table but rejected — this implements it, and the implementation puts the spec grammar in exactly one place, which is the part that would otherwise rot: parse_extra_lib is called both from parse_arg (to validate, with the out-params NULL) and from attach_extra_lib (to use), so the option parser and the attach path cannot disagree about what PROVIDER:PATH accepts. The unnamed *why out-param carrying the -EINVAL reason, so argp_error can print it, keeps the error text beside the rule that produced it.
The error handling matches the rest of the tool. A bad spec goes through argp_error rather than exit()ing inside a callback, and the strdup failure goes through argp_failure(state, EXIT_FAILURE, ENOMEM, ...) — both are how parse_arg's other cases behave, so a bad --extra-lib exits with the same shape as a bad -p.
Attach accounting is the subtle half and it is right. attached_before is captured before provider->attach, and the check attached_link_count == attached_before distinguishes "the provider attached nothing" (-ENOENT) from "attached some, failed on others" (warn, return 0). That mirrors attach_provider's split between "probing is incomplete" and "nothing attached", so a partially-attached custom library is treated the same as a partially-attached built-in one. A library that attaches nothing is fatal here while attach_provider only warns — correct, since the user named that exact library and an empty result means the option did nothing.
Path handling is deliberate and stated: the path goes to libbpf unopened, avoiding a check-then-open window and the real/effective UID mismatch under sudo. That is the right call for a tool that is normally run with sudo.
Docs are in both languages with the same content, and both say the same thing the code does — that the path is used as given and failure is fatal.
The one red is not this branch. build and CodeFactor fail on Unable to locate package llvm-14-dev, which is main's failure since ubuntu-latest became 26.04; #236/#237 fix it by pinning to ubuntu-22.04. Rebase once that lands.
AI patrol review
|
Verdict: ready to merge once CI is green The bug is exactly as described and the fix is right: Checked at
The red check on the head is not this change.
One request: since AI patrol review |
yunwei37
left a comment
There was a problem hiding this comment.
Verdict: ready to merge
The change itself was reviewed above and stands: --extra-lib is registered in opts, parsed in one place, and dispatched through the same provider probe sets the built-in libraries use. Nothing in the branch changed.
What this run adds is that both red checks on this head are base faults, read from each job's own log rather than from the conclusion:
build(job 132331868283, "Test bpftrace examples") fails atError: bpftrace failed to attach or trace the hello function— the same assertion that fails onmain's own run 43657301192, because the workflow greps for the literalAttaching 1 probewhile bpftrace 0.20+ printsAttaching 1 probe.... This branch does not touch that workflow or the38-btf-uprobeexample it builds.build(job 132331867974, "Test eunomia-bpf example CI") fails before any compilation:sudo apt install clang llvm-14-dev llvm→Unable to locate package llvm-14-dev, becauseruns-on: ubuntu-latestis now the 24.04/26.04 image and that package name is not in its archive. Also not this branch, which touches onlysrc/30-sslsniff/.CodeFactorreports one minor style issue in the new code, which is a review nit rather than a gate; it does not appear onmainonly becausemainhas not had a CodeFactor run since.
The remaining CodeFactor nit, for the author: attach_extra_lib returns err ? err : -ENOENT after warn(...), and err is not initialized for the case where the provider attached nothing without returning an error. attached_link_count == attached_before is exactly that case, so -ENOENT is the right value — but writing it as return -ENOENT; (with the err path returning earlier) would make the intent obvious and is what the one issue is pointing at.
AI patrol review
`--extra-lib PROVIDER:PATH` was documented in the examples and stored in
`env.extra_lib`, but it was never registered in the argp option table, so
argp rejected it before anything else ran:
$ ./sslsniff --extra-lib openssl:/tmp/x.so
sslsniff: unrecognized option '--extra-lib'
Register the option, validate the spec at parse time (so a typo is
reported before the BPF object is opened rather than being masked by a
load failure), and attach through the provider's existing probe set:
`openssl`, `gnutls` and `nss` reuse the same symbol lists as the
built-in providers, which is what the option implies.
The attach path uses the given path directly instead of going through
`find_library_path()`, which resolves via ldconfig and therefore cannot
find a library outside the loader cache - the reason the option exists
(a distribution libssl from a custom prefix, or a bundle's own
libnspr4.so inside an application directory).
Verified: `--extra-lib` now appears in `--help`; a malformed spec
(`nonsense`) and an unknown provider (`bogus:/tmp/x.so`) each exit 1
with a specific message; a valid spec proceeds past option parsing into
the BPF load. The attach itself needs a kernel that permits bpf() for
this process, which the sandbox used here does not (`unprivileged_bpf_disabled=2`, no CAP_BPF) -
so the three spec-validation paths are observed, and the attach call is
reached and reasoned from the existing provider hooks.
Fixes the `--extra-lib` half of #122.
Address review feedback on the --extra-lib argument path: - One parser for the PROVIDER:PATH grammar. `parse_extra_lib()` is the only place the spec is split and the provider name matched, against a `providers[]` table that ties each name to its attach function. Option parsing and `attach_extra_lib()` both call it, so they can no longer disagree, and `attach_extra_lib()` no longer duplicates (or re-implements) validation. - Bad values go through argp. `parse_arg()` used to `exit(1)` directly; it now calls `argp_error()`, which prints the same `sslsniff: invalid --extra-lib ...` prefix as other option failures and exits with EX_USAGE (64). The unchecked `strdup()` is now checked and reported through `argp_failure()`. - Drop the `access()` pre-check in `attach_extra_lib()`. Probing opens the library anyway, so the check added a TOCTOU window and reported a permission failure for paths reachable only through the effective UID; libbpf now reports the real reason. - Propagate the attach result. `main()` ignored the return value, so an unattachable extra library let the tool run with only the built-in probes attached. It now fails, and `attach_extra_lib()` reports failure when no link was added rather than "probing is incomplete". - Sync the lesson 30 excerpt (English and Chinese) with the new call site. The `extra <provider> path: <path>` line stays on stdout next to the existing `OpenSSL path: ...` lines, which the lesson's sample output already documents.
235551a to
85b6b05
Compare
yunwei37
left a comment
There was a problem hiding this comment.
Verdict: ready to merge
Head 85b6b05d reworks the --extra-lib path per the earlier review round: one parse_extra_lib() owns the PROVIDER:PATH grammar (option parsing and attach_extra_lib() both call it), a providers[] table ties each name to its attach function, parse_arg() reports bad values through argp_error() instead of exit(1), the TOCTOU access() pre-check is gone (libbpf reports the real open failure), and main() now fails when the extra library cannot be attached instead of silently continuing with only the built-in probes.
Verified locally on this head: make builds clean; --extra-lib bogus prints invalid --extra-lib \bogus`: expected PROVIDER:PATHand exits 64 (EX_USAGE);--extra-libwithout a value is rejected by argp. The BPF-load path cannot run on this machine (no CAP_BPF,-EPERMon the trivial-probe check), which matches the CI environment difference —build` on this head is green (run 44714358454). CodeFactor's red is pre-existing on the base too (it flags the lesson's older C style), not introduced by this diff.
Nothing blocking remains: the diff is the parser consolidation described above plus the doc sync in both languages.
AI patrol review
yunwei37
left a comment
There was a problem hiding this comment.
Verdict: ready to merge — every build is green on 85b6b05d; the only red is CodeFactor, which the repository does not require
Re-read the checks on the current head 85b6b05d, since the earlier verdict was posted against 235551ab.
build(all three),docs,triggerandGitGuardian— pass.CodeFactor— fail. It is not a required context here:GET /branches/main/protectionreportsrequired_status_checks.contexts: [], so nothing about the CodeFactor grade gates this pull request. For the record it reviewssrc/30-sslsniff/sslsniff.cadded in this change, and its complaint is style-shaped, not a build or behavior failure.
The change itself is unchanged from the review above: --extra-lib is registered in argp_option opts[] and parsed in one place, which is what made it reachable at all; three files, all under src/30-sslsniff/.
Branch is free of conflicts. Merging stays with a maintainer.
AI patrol review

Summary
--extra-libwas documented insslsniff --help's examples and stored inenv.extra_lib, but never registered in the argp option table, so argp rejected it before anything else ran:That is the
--extra-lib doesn't workhalf of #122.Change
src/30-sslsniff/sslsniff.conly:--extra-lib=PROVIDER:PATHinoptsand handleEXTRA_LIB_KEYinparse_arg(the#definewas already there, unused).attach_extra_lib()dispatches to the existing provider probe sets:openssl→attach_openssl,gnutls→attach_gnutls,nss→attach_nss, using the given path directly.find_library_path()resolves through ldconfig, so it cannot see a library outside the loader cache — a libssl from a custom prefix, or a bundle's ownlibnspr4.soinside an application directory, which is exactly the reproduction in [BUG] 30-sslsniff unable to capture latest firefox(NSS) packet #122.Test
A valid spec proceeds past parsing into the BPF load (
libbpf: loading object 'sslsniff_bpf' …). The attach itself was not observed running in this sandbox:unprivileged_bpf_disabled=2and noCAP_BPF, sobpf_object__probe_loading()fails with-EPERMfor every invocation, with or without the option. The attach call reuses the existing, exercised provider hooks unchanged, so the new surface is the argument path, which is what the three cases above cover.Builds clean with the tutorial's own Makefile (
make -C src/30-sslsniff), no warnings from the new code.