Skip to content

Add CONNECT_AUTHORIZATION readonly context test#5230

Merged
saxena-anurag merged 5 commits into
microsoft:mainfrom
Alan-Jowett:issue-5213-connect-auth-readonly-test
May 15, 2026
Merged

Add CONNECT_AUTHORIZATION readonly context test#5230
saxena-anurag merged 5 commits into
microsoft:mainfrom
Alan-Jowett:issue-5213-connect-auth-readonly-test

Conversation

@Alan-Jowett
Copy link
Copy Markdown
Member

Description

Add a socket-level regression test for CONNECT_AUTHORIZATION read-only context enforcement.

This introduces a dedicated sample program that mutates ctx->user_port from a connect_authorization program while returning BPF_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.vcxproj
  • msbuild /m /p:Configuration=Debug /p:Platform=x64 /p:SolutionDir=Q:\ebpf-for-windows\ tests\socket\socket_tests.vcxproj

Added new socket coverage in connection_test_connect_authorization_readonly_context.

If new tests were added:

  • Unit tests are added.
  • Driver tests are added.

Local runtime note: in this environment, socket_tests.exe fails at bpf_object__load(obj) for both the new test and the existing baseline connection_test_connect_authorization case, so the new runtime path could not be confirmed end-to-end here.

Documentation

No documentation changes.

Installation

No installer impact.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.c program that mutates ctx->user_port in connect_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.

Comment thread tests/socket/socket_tests.cpp
Comment thread tests/socket/socket_tests.cpp Outdated
Alan-Jowett and others added 2 commits May 13, 2026 11:40
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>
@Alan-Jowett Alan-Jowett force-pushed the issue-5213-connect-auth-readonly-test branch from 691a1a9 to 7e797db Compare May 13, 2026 18:40
mikeagun
mikeagun previously approved these changes May 13, 2026
@saxena-anurag
Copy link
Copy Markdown
Contributor

@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 cgroup/connect hook.

…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>
@Alan-Jowett
Copy link
Copy Markdown
Member Author

@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 cgroup/connect hook.

Requested changes have been made.

Comment thread .github/workflows/perf.yml Outdated
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;
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.

[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

@saxena-anurag saxena-anurag added this pull request to the merge queue May 15, 2026
Merged via the queue into microsoft:main with commit 464e55b May 15, 2026
213 of 215 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in eBPF for Windows Triage May 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

5 participants