Skip to content

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

Open
mikeagun wants to merge 1 commit into
microsoft:mainfrom
mikeagun:netebpfext-wfp-delete-mock
Open

Improve WFP filter-delete mock fidelity and add delete fault injection#317
mikeagun wants to merge 1 commit 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

1 participant