fix: cgroup filtering for TC hook and GoTLS uprobe#979
Merged
Conversation
Agent-Logs-Url: https://github.com/gojue/ecapture/sessions/5753b1a2-b1f4-432d-8bf4-20f7cd71dd08 Co-authored-by: cfc4n <709947+cfc4n@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
cfc4n
April 8, 2026 13:28
View session
✅ E2E Test Results: PASSEDTest Run: #24137964017 Tests Executed:
✅ All e2e tests passed successfully! The TLS capture functionality is working correctly. Automated e2e test results for commit ac01c29 |
Member
|
@skylar2826 试试这个PR的产物 解决了 #977 |
There was a problem hiding this comment.
Pull request overview
Fixes cgroup-based filtering (--cgroup_path) regressions across TC packet capture and GoTLS uprobes by separating “safe in any context” PID/UID filtering from “process-context-only” cgroup filtering, and ensuring GoTLS probes apply the standard filter guard.
Changes:
- Split filter logic into
filter_rejects_base(pid, uid)andfilter_rejects(pid, uid)(adds cgroup check viabpf_get_current_cgroup_id()only where context is reliable). - Correct TC cgroup filtering by recording
cgroup_idin thetcp_sendmsg/udp_sendmsgkprobe context and comparing it in the TC classifier. - Add missing
passes_filter(ctx)guards to GoTLS probe entrypoints (gotls_write,gotls_read,gotls_mastersecret).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
kern/ecapture.h |
Introduces filter_rejects_base and redefines filter_rejects to keep cgroup checks out of TC-safe paths. |
kern/tc.h |
Stores per-flow cgroup_id at sendmsg time and uses it for TC filtering instead of bpf_get_current_cgroup_id() in softirq/TC context. |
kern/gotls_kern.c |
Ensures GoTLS probes respect PID/UID/cgroup filters by adding passes_filter(ctx) guards. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Two independent bugs prevented cgroup filtering (
--cgroup_path) from working correctly: GoTLS uprobe ignored all filters entirely, and TC's cgroup check usedbpf_get_current_cgroup_id()in softirq context — which returns the cgroup of whatever process happens to be scheduled on that CPU, not the packet sender's cgroup.kern/ecapture.h — split
filter_rejectsinto two layersfilter_rejects_base(pid, uid)— PID/UID only; safe to call from any BPF program typefilter_rejects(pid, uid)— calls base then addsbpf_get_current_cgroup_id(); valid only in uprobe/kprobe context where execution context == traced processkern/tc.h — correct cgroup filtering in TC path
u64 cgroup_idtonet_ctx_tbpf_get_current_cgroup_id()intrace_sendmsg()kprobe (semantically correct context) alongside PID/UIDcapture_packets(), replacefilter_rejects(net_ctx->pid, net_ctx->uid)withfilter_rejects_base+ directnet_ctx->cgroup_idcomparison:kern/gotls_kern.c — add missing filter guards to GoTLS uprobe
gotls_write,gotls_read, andgotls_mastersecretwere the only probe entry points not callingpasses_filter(ctx), causing them to capture all processes regardless of--pid/--uid/--cgroup_path. Added the standard guard at the top of each.