Skip to content

Fix Linux local mode process name matching - #340

Open
sainimal1ba-hue wants to merge 1 commit into
mitmproxy:mainfrom
sainimal1ba-hue:fix-local-mode-process-name-matching
Open

sainimal1ba-hue wants to merge 1 commit into
mitmproxy:mainfrom
sainimal1ba-hue:fix-local-mode-process-name-matching

Conversation

@sainimal1ba-hue

Copy link
Copy Markdown

Fixes #7931

Name patterns in Linux local mode were matched against the comm of the thread that creates a socket. That only works when the socket-opening thread happens to be named like the process, so multithreaded applications were impossible to filter, and patterns got cut off at 15 characters because comm is.

The eBPF program can't match process names itself: the kernel only exposes the creating thread's comm there, and bpf-linker doesn't support the CO-RE relocations we'd need to read the thread group leader's name. So name patterns now become marker actions in the intercept conf and userspace resolves them to tgid sets by scanning /proc every 250 ms, using the executable name from /proc//exe like the other platforms do (substring matching, so "fire" still matches "firefox"). The eBPF program then matches the creating task's tgid against those sets, in the same include/exclude order as the spec, so mixed specs behave like they do on the other platforms.

Pids keep their exact matching from before. New processes are picked up within one scan interval, so a process that starts and connects immediately can miss its first connections.

Tests: pattern parsing, tgid resolution against a fake process list and /proc scanning of the test process itself. cargo test --workspace --exclude mitmproxy-linux-ebpf passes, fmt and clippy are clean. The root test loads the new maps through the verifier, it needs sudo so it only runs in CI.

Process name patterns were matched against the name of the thread that
creates a socket, so multithreaded applications could not be filtered
unless you knew the name of the thread that opens their connections.
Patterns were also truncated to 15 characters, kernel comm style.

The eBPF program cannot match process names itself: the kernel only
exposes the comm of the creating thread there, and bpf-linker does not
support the CO-RE relocations that reading the thread group leader's
comm would need. So name patterns now become marker actions in the
intercept conf, and userspace resolves them to tgid sets by scanning
/proc every 250 ms. The eBPF program then matches the creating task's
tgid against those sets, which keeps the include and exclude ordering
semantics of the other platforms.

Issue: mitmproxy/mitmproxy#7931
Signed-off-by: sainimal1ba-hue <230497022+sainimal1ba-hue@users.noreply.github.com>

This branch has not been deployed

No deployments
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.

1 participant