Skip to content

feat: Support stapsdt#48

Draft
wkpark wants to merge 4 commits intoavilum:masterfrom
wkpark:support-stapsdt
Draft

feat: Support stapsdt#48
wkpark wants to merge 4 commits intoavilum:masterfrom
wkpark:support-stapsdt

Conversation

@wkpark
Copy link
Copy Markdown

@wkpark wkpark commented Mar 6, 2026

Dynamic USDT Support via stapsdt and Security Hardening

Enhanced secimport with dynamic USDT support for standard Python and hardened security against optimized mode bypasses.

Key Technical Changes

  • Dynamic USDT Support: Integrated stapsdt to support standard Python binaries without DTrace, using a singleton pattern
    for the provider to prevent resource leaks.
  • CLI Enhancements: Added detection for WITH_DTRACE and provided detailed installation guides for libstapsdt and stapsdt.

changes

  • Implement dynamic USDT probe firing in secure_import using stapsdt to support standard Python binaries without DTrace.
  • Replace assert with explicit RuntimeError in sandbox_helper.py
  • Update CLI to detect WITH_DTRACE and provide installation guides for libstapsdt and stapsdt.
  • Add tests/test_stapsdt_support.py (excluded)
  • support uv / add PEP 621 [project] to pyproject.toml (excluded)

References

Note

I used the Gemini CLI to help with the specific implementation details and drafting this PR description.

See also: linux-usdt/libstapsdt#34

as expected, normal trace.bt will not work.

$ sudo secimport/profiles/trace.bt -c .venv/bin/python3 -o trace0.log .venv/bin/python3
ERROR: couldn't get argument 0 for .venv/bin/python3::function__entry

so I just added some more commits to address this issue.

remain issues

  • need to add missing_probes config to work with libstapsdt
diff --git a/secimport/profiles/trace.bt b/secimport/profiles/trace.bt
index 9609ce9..0535b82 100755
--- a/secimport/profiles/trace.bt
+++ b/secimport/profiles/trace.bt
@@ -1,5 +1,9 @@
 #!/usr/bin/env bpftrace

+config = {
+  missing_probes = "ignore";
+}
+
 // A profiling script that logs all the syscalls, per python module.
 // It can be attached to a running process using -p or can be used to trace a python shell interactively.
 //
  • the bpftrace works just fine but older version emits some error under arm64. so I prepend bpftrace command like as ./bpftrace to use local bpftrace version. (we might needs some os.getenv("BPFTRACE_BIN", "bpftrace") or somthing.

@wkpark wkpark force-pushed the support-stapsdt branch from f0a22dc to bc7d6e2 Compare March 6, 2026 06:33
@avilum
Copy link
Copy Markdown
Owner

avilum commented Mar 7, 2026

@wkpark Hey - thanks for the additions! I love this approach.

If I understand it correctly, we better wait for the linux-usdt repo PR to merge the ARM support PR you opened, am I right?

Also, did you test it with the secimport docker container?

Thank you!

@wkpark wkpark force-pushed the support-stapsdt branch from 8590574 to 4b09761 Compare March 8, 2026 13:12
@wkpark
Copy link
Copy Markdown
Author

wkpark commented Mar 8, 2026

@wkpark Hey - thanks for the additions! I love this approach.

If I understand it correctly, we better wait for the linux-usdt repo PR to merge the ARM support PR you opened, am I right?

I would like to see that PR merged, but the upstream (libstapsdt) hasn't been active for a long time. I don't think it will happen soon, so I think we shouldn't wait for it. Maybe merging this PR first will encourage them.

Also, did you test it with the secimport docker container?

Regarding Docker, it is not fully tested yet. But since the secimport + stapsdt combination worked so well, I wanted to share the code quickly. I will test Docker further very soon.

Thank you!

Thank you for your great project!!

wkpark added 2 commits March 22, 2026 05:57
- Implement dynamic USDT probe firing in `secure_import` using `stapsdt` to support standard Python binaries without DTrace.
- Replace `assert` with explicit `RuntimeError` in `sandbox_helper.py` to prevent security bypass in optimized mode (-O).
- Update CLI to detect `WITH_DTRACE` and provide installation guides for `libstapsdt` and `stapsdt`.
- Add `tests/test_stapsdt_support.py`
@wkpark
Copy link
Copy Markdown
Author

wkpark commented Mar 22, 2026

rebased.
(only minimal changes are applied)

@wkpark wkpark closed this Mar 22, 2026
@wkpark wkpark reopened this Mar 23, 2026
@wkpark wkpark marked this pull request as draft March 23, 2026 12:06
wkpark added 2 commits March 23, 2026 12:33
- Refactor `secimport/cli.py` to handle `stapsdt` injection without shell quoting issues.
- Enable wildcard USDT probe matching in bpftrace for non-DTrace environments.

fix

fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants