Skip to content

Improve WFP filter-delete mock fidelity and add delete fault injection - #317

Merged
mikeagun merged 3 commits into
microsoft:mainfrom
mikeagun:netebpfext-wfp-delete-mock
Aug 3, 2026
Merged

Improve WFP filter-delete mock fidelity and add delete fault injection#317
mikeagun merged 3 commits into
microsoft:mainfrom
mikeagun:netebpfext-wfp-delete-mock

Conversation

@mikeagun

Copy link
Copy Markdown
Contributor

Description

The FWP user-mode mock diverged from real WFP filter-delete behavior in two ways that matter to callouts which track per-filter state:

  • The delete notification (FWPS_CALLOUT_NOTIFY_DELETE_FILTER) was raised with filterId = 0, so a callout that identifies the deleted filter by id could not match it.
  • remove_fwpm_filter asserted the callout was still registered and always raised the delete notification, whereas real WFP raises no delete notification once the callout function has been unregistered (e.g., during driver unload).

This change makes the mock faithful and adds a small test-only fault-injection surface so extensions can exercise their filter-delete-failure recovery paths.

Changes

  • Set fwps_filter.filterId on the add and delete notifications.
  • Raise the delete notification only when the callout is still registered.
  • Add test-only helpers: usersim_fwp_set_filter_delete_failure_count (fail the next N FwpmFilterDeleteById calls without removing the filter or notifying), usersim_fwp_get_fwpm_filter_count, and usersim_fwp_clear_fwpm_filters.

Testing

Consumed by the ebpf-for-windows netebpfext WFP filter-teardown regression tests. Existing usersim tests unaffected.

The FWP user-mode mock diverged from real WFP filter-delete behavior:
- The delete notification (FWPS_CALLOUT_NOTIFY_DELETE_FILTER) was raised with
  filterId = 0, so a callout that identifies the deleted filter by id could not
  match it.
- remove_fwpm_filter asserted the callout was still registered and always raised
  the delete notification, whereas real WFP raises no delete notification once the
  callout function has been unregistered.

Changes:
- Set fwps_filter.filterId on the add and delete notifications.
- Raise the delete notification only when the callout is still registered.
- Add test-only fault injection (usersim_fwp_set_filter_delete_failure_count) plus
  usersim_fwp_get_fwpm_filter_count and usersim_fwp_clear_fwpm_filters to simulate
  and inspect a filter whose delete fails without removing the filter or notifying.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: c5be9327-3fe0-4580-b5c1-17b6c052bbb2
Comment thread src/fwp_um.cpp
saxena-anurag and others added 2 commits August 1, 2026 11:12
Clarify the comments around usersim_fwp_set_filter_delete_failure_count
per review feedback: the public declaration in fwp_test.h now describes
what the hook does, how it differs from the generic cxplat
fault-injection harness (deterministic, opt-in, independent of
cxplat_fault_injection_is_enabled()), and how to use it. The injection
site in FwpmFilterDeleteById0 and the engine helper in fwp_um.h are
reduced to short notes that cross-reference it. Comments only; no
behavior change.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 1a991e01-4799-44d5-8290-68a48c363260
@mikeagun
mikeagun requested a review from saxena-anurag August 3, 2026 18:31
@mikeagun
mikeagun merged commit c95bf12 into microsoft:main Aug 3, 2026
9 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in eBPF for Windows Triage Aug 3, 2026
mikeagun pushed a commit to mikeagun/ebpf-for-windows that referenced this pull request Aug 3, 2026
microsoft/usersim#317 (the WFP filter-delete mock fidelity improvements
and deterministic delete fault-injection hooks used by the netebpfext
unit tests) has merged. Restore the external/usersim submodule URL to
microsoft/usersim and advance the gitlink to the merged commit, replacing
the temporary bump that pointed at the fork branch.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 1a991e01-4799-44d5-8290-68a48c363260
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants