Add CONNECT_AUTHORIZATION readonly context test#5230
Conversation
9d79e79 to
bca9d04
Compare
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds a regression test for CONNECT_AUTHORIZATION read-only context enforcement by introducing a new sample eBPF program and wiring a socket test to exercise it across connection variants.
Changes:
- Added a new sample
cgroup_connect_authorization_readonly.cprogram that mutatesctx->user_portinconnect_authorization. - Added a new templated socket test case intended to validate that this context mutation is rejected for IPv4/IPv6 and TCP/UDP.
- Registered the new sample source in the sample project filters.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
tests/socket/socket_tests.cpp |
Adds the new socket regression test case that loads and attaches the readonly-context sample program. |
tests/sample/sample.vcxproj.filters |
Places the new sample source under the Visual Studio project’s source-file filter. |
tests/sample/cgroup_connect_authorization_readonly.c |
Adds the eBPF sample that mutates ctx->user_port from connect_authorization4/6. |
06f5f62 to
691a1a9
Compare
Add a socket test that covers the netebpfext path which rejects CONNECT_AUTHORIZATION programs that mutate read-only sock_addr context. Introduce a dedicated sample program that modifies the destination port while returning a soft permit, and add it to the sample project filters. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Make the readonly CONNECT_AUTHORIZATION regression test explicitly assert a blocked connection instead of relying on the default expected_result. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
691a1a9 to
7e797db
Compare
|
@Alan-Jowett this was discussed in Monday triage meeting that the extension should ignore modification of any read only fields in ctx (unless the modification is done to the ctx data). This behavior already exists for |
…TION Instead of overriding the verdict to REJECT when a CONNECT_AUTHORIZATION program modifies destination IP/port, restore the original context and proceed with the program's actual verdict. This matches Linux behavior where writes to read-only context fields are silently ignored. Update the readonly context test to expect the connection to succeed (allow) instead of being blocked. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Resolve conflict in net_ebpf_ext_sock_addr.c: keep the silent-ignore behavior for CONNECT_AUTHORIZATION read-only context mutations and adopt upstream's renamed logging macros (NET_EBPF_EXT_ -> EBPF_EXT_). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Requested changes have been made. |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
| @@ -1667,21 +1668,27 @@ _net_ebpf_extension_sock_addr_process_verdict(_Inout_ void* program_context, int | |||
| context->redirected = redirected; | |||
| context->address_changed = address_changed; | |||
There was a problem hiding this comment.
[non-blocking] I think there is an existing issue with cgroup\connect hook where the extension does not "restore" the read only fields before invoking next BPF program.
Filed #5271
Description
Add a socket-level regression test for CONNECT_AUTHORIZATION read-only context enforcement.
This introduces a dedicated sample program that mutates
ctx->user_portfrom aconnect_authorizationprogram while returningBPF_SOCK_ADDR_VERDICT_PROCEED_SOFT, plus a templated socket test that expects the connection to be blocked for IPv4/IPv6 and TCP/UDP.Fixes #5213.
Testing
Built:
msbuild /m /p:Configuration=Debug /p:Platform=x64 /p:SolutionDir=Q:\ebpf-for-windows\ tests\sample\sample.vcxprojmsbuild /m /p:Configuration=Debug /p:Platform=x64 /p:SolutionDir=Q:\ebpf-for-windows\ tests\socket\socket_tests.vcxprojAdded new socket coverage in
connection_test_connect_authorization_readonly_context.If new tests were added:
Local runtime note: in this environment,
socket_tests.exefails atbpf_object__load(obj)for both the new test and the existing baselineconnection_test_connect_authorizationcase, so the new runtime path could not be confirmed end-to-end here.Documentation
No documentation changes.
Installation
No installer impact.