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 13 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
netebpfext/net_ebpf_ext.c Outdated Show resolved Hide resolved
@@ -539,6 +581,9 @@ _net_ebpf_ext_register_wfp_callout(_Inout_ net_ebpf_ext_wfp_callout_state_t* cal
callout_register_state.flags = 0;

status = FwpsCalloutRegister(device_object, &callout_register_state, &callout_state->assigned_callout_id);
if (WFP_ERROR(status, ALREADY_EXISTS)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: in what case can it already exist?

Copy link
Collaborator

Choose a reason for hiding this comment

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

reboot without driver being unloaded - such as kernel crash or power failure.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Come to think of it, since FWPM_*_FLAG_PERSISTENT is not passed for any objects; none of these objects should remain after a reboot. You were likely hitting this during your intermediate testing. I think this check can be safely removed.

netebpfext/net_ebpf_ext.c Show resolved Hide resolved
shankarseal
shankarseal previously approved these changes Oct 2, 2024
…ks with asserts, remove unneded helper function
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
3 participants