Skip to content

fix(sslsniff): make --extra-lib work instead of being rejected - #238

Merged
yunwei37 merged 2 commits into
mainfrom
fix/sslsniff-extra-lib
Nov 24, 2026
Merged

yunwei37 merged 2 commits into
mainfrom
fix/sslsniff-extra-lib

Conversation

@yunwei37

Copy link
Copy Markdown
Member

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:PATH in opts and handle EXTRA_LIB_KEY in parse_arg (the #define was 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 own libnspr4.so inside an application directory, which is exactly the reproduction in [BUG] 30-sslsniff unable to capture latest firefox(NSS) packet #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.

Copilot AI balanced review requested due to automatic review settings November 13, 2026 08:42

@yunwei37 yunwei37 left a comment •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:PATH in opts and handle EXTRA_LIB_KEY in parse_arg (the #define was 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 own libnspr4.so inside 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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
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:PATH in argp options and stores the value in env.extra_lib.
  • Adds parse-time validation for PROVIDER:PATH with 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

Comment thread src/30-sslsniff/sslsniff.c Resolved
Comment thread src/30-sslsniff/sslsniff.c Resolved
Comment thread src/30-sslsniff/sslsniff.c Resolved
Comment thread src/30-sslsniff/sslsniff.c Resolved
Comment thread src/30-sslsniff/sslsniff.c Resolved

@yunwei37 yunwei37 left a comment •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:PATH in opts and handle EXTRA_LIB_KEY in parse_arg (the #define was 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 own libnspr4.so inside 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 yunwei37 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-latest moved past LLVM 14. #236 pins that job to ubuntu-22.04.
  • build (Test bpftrace examples, job 132331868283): the job greps for Attaching 1 probe, while this bpftrace prints Attached 1 probe and does trace (traced present 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 yunwei37 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 yunwei37 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@yunwei37

yunwei37 commented Nov 19, 2026 •

Copy link
Copy Markdown
Member Author

Verdict: ready to merge once CI is green

The bug is exactly as described and the fix is right: --extra-lib was in the help text and in env.extra_lib but never in argp_option opts[], so argp rejected it before any code that used the field could run. Adding it to the table and parsing it in one place (parse_extra_lib, with the "*why describes -EINVAL" contract) is the shape that keeps the option table and the attach path from disagreeing again.

Checked at 235551ab (3 files, 110 additions, src/30-sslsniff/ only):

  • parse_extra_lib splits on the first :, rejects an empty provider or path, and returns a specific why — so --extra-lib b reported "expected PROVIDER:PATH" rather than a generic argp error. Good.
  • The ssl_provider table (openssl, gnutls, nss) maps a name to an attach function, so the parse cannot accept a provider the attach path does not implement.
  • Both READMEs get the example, in English and Chinese, which is the tutorial's contract.

The red check on the head is not this change. build (job 132331868283) fails at Error: bpftrace failed to attach or trace the hello function — a bpftrace attach in the Rust/38-btf-uprobe part of the workflow, which this PR does not touch (its three files are all under src/30-sslsniff). Recent runs of the same workflow on other branches (bpftrace-attach-wording-fix, fix/pin-eunomia-examples-runner-2204) are green, so it is a runner/bpftrace-attach condition rather than the branch; a re-run should clear it.

CodeFactor is a style score, not a check on the change.

One request: since --extra-lib is now accepted, the #122 half about --extra-lib can be answered with the exact form that works (--extra-lib openssl:/tmp/x.so), which makes the issue closable.

AI patrol review

@yunwei37 yunwei37 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 at Error: bpftrace failed to attach or trace the hello function — the same assertion that fails on main's own run 43657301192, because the workflow greps for the literal Attaching 1 probe while bpftrace 0.20+ prints Attaching 1 probe.... This branch does not touch that workflow or the 38-btf-uprobe example 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, because runs-on: ubuntu-latest is now the 24.04/26.04 image and that package name is not in its archive. Also not this branch, which touches only src/30-sslsniff/.
  • CodeFactor reports one minor style issue in the new code, which is a review nit rather than a gate; it does not appear on main only because main has 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

@yunwei37 yunwei37 added AI review: ready to merge patrol review verdict AI review: merge after CI patrol review verdict and removed AI review: merge after CI patrol review verdict AI review: ready to merge patrol review verdict labels Nov 19, 2026
`--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.
@yunwei37
yunwei37 force-pushed the fix/sslsniff-extra-lib branch from 235551a to 85b6b05 Compare November 20, 2026 09:52

@yunwei37 yunwei37 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 yunwei37 added AI review: ready to merge patrol review verdict and removed AI review: merge after CI patrol review verdict labels Nov 20, 2026

@yunwei37 yunwei37 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, trigger and GitGuardian — pass.
  • CodeFactor — fail. It is not a required context here: GET /branches/main/protection reports required_status_checks.contexts: [], so nothing about the CodeFactor grade gates this pull request. For the record it reviews src/30-sslsniff/sslsniff.c added 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

@yunwei37
yunwei37 merged commit 0404358 into main Nov 24, 2026
6 of 7 checks passed
@yunwei37
yunwei37 deleted the fix/sslsniff-extra-lib branch November 24, 2026 01:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants