Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[netebpfext] Add per-provider WFP handles to avoid improper use from parallel invocations #3866

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

matthewige
Copy link
Collaborator

@matthewige matthewige commented Sep 24, 2024

Description

Issue:
Our KM stress tests revealed an issue in our netebpfext code. There is a single global WFP handle, but multiple threads could use this at the same time (such as two programs attaching in parallel), leading to errors in the WFP APIs.

Fix:

  • Add per-provider handles
  • Make all WFP engine handles use static sessions (this allows a separate WFP handle to access the same objects, such as the sublayer/callouts)
  • Add proper cleanup logic to remove all WFP objects

Closes #3607

Testing

Existing tests validate this functionality.

Documentation

None.

Installation

None.

@matthewige matthewige changed the title [draft] [draft] [netebpfext] Add per-provider WFP handles to avoid improper use from parallel invocations Sep 26, 2024
@matthewige matthewige changed the title [draft] [netebpfext] Add per-provider WFP handles to avoid improper use from parallel invocations [netebpfext] Add per-provider WFP handles to avoid improper use from parallel invocations Sep 27, 2024
@matthewige matthewige marked this pull request as ready for review September 27, 2024 16:56
@@ -643,6 +662,26 @@ net_ebpf_ext_uninitialize_ndis_handles()
}
}

NTSTATUS
net_ebpf_extension_open_wfp_engine_handle(HANDLE* wfp_engine_handle)
Copy link
Collaborator

Choose a reason for hiding this comment

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

SAL _Out_

}

NTSTATUS
net_ebpf_extension_close_wfp_engine_handle(HANDLE wfp_engine_handle)
Copy link
Collaborator

@shankarseal shankarseal Sep 28, 2024

Choose a reason for hiding this comment

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

Add SAL _In_ because HANDLE is technically a pointer. There are many precedence of _In_ Handle elsewhere in the project.

@@ -222,6 +236,11 @@ net_ebpf_ext_bind_unregister_providers()
net_ebpf_extension_program_info_provider_unregister(_ebpf_bind_program_info_provider_context);
_ebpf_bind_program_info_provider_context = NULL;
}
if (_net_ebpf_extension_bind_wfp_engine_handle) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit != NULL

@@ -19,6 +19,8 @@ typedef struct _bind_context_header
// WFP filter related globals for bind hook.
//

static HANDLE _net_ebpf_extension_bind_wfp_engine_handle = NULL;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider storing the engine handle in net_ebpf_extension_wfp_filter_context_t and opening it inside net_ebpf_extension_wfp_filter_context_create.

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.

Workflow failed - km_mt_stress_tests
2 participants