Skip to content

ebpf_program: Fix rollback of program state on NmrClientAttachProvider failure#5287

Draft
Alan-Jowett wants to merge 1 commit into
microsoft:mainfrom
Alan-Jowett:fix/nmr-attach-failure-rollback
Draft

ebpf_program: Fix rollback of program state on NmrClientAttachProvider failure#5287
Alan-Jowett wants to merge 1 commit into
microsoft:mainfrom
Alan-Jowett:fix/nmr-attach-failure-rollback

Conversation

@Alan-Jowett
Copy link
Copy Markdown
Member

Summary

When \NmrClientAttachProvider\ fails in _ebpf_program_type_specific_program_information_attach_provider, the error path incorrectly cleared \general_helper_program_data\ (wrong field) instead of rolling back the state set before the call.

Issues Fixed

  1. Wrong field cleared — error path cleared \general_helper_program_data\ instead of \�xtension_program_data.
  2. Memory ownership — \�xtension_program_data\ was committed to the program (\program->extension_program_data = extension_program_data; extension_program_data = NULL;) but not reclaimed on failure, so the \Done:\ label's \�bpf_program_data_free(extension_program_data)\ was a no-op.
  3. Stale state — \�pf_prog_type\ and \program_type_specific_helper_function_count\ were not reset, leaving the program in an inconsistent state.

Note: The program destructor (_ebpf_program_free) already frees \�xtension_program_data, so the memory leak was bounded by program lifetime. The more significant issue was stale program state that could affect subsequent attach attempts.

Changes

  • **\libs/execution_context/ebpf_program.c**: Fixed the NmrClientAttachProvider failure path to reclaim \�xtension_program_data, clear \program->extension_program_data, and reset \program_type_specific_helper_function_count\ and \�pf_prog_type.

Testing

  • All 49 [execution_context]\ tests pass (39,105 assertions).
  • Existing fault injection tests cover this path via \cxplat_fault_injection_inject_fault()\ in usersim's \NmrClientAttachProvider.

@github-actions
Copy link
Copy Markdown
Contributor

This pull request isn't linked to any GitHub issue. Please reference an issue with a keyword such as Fixes #123, Closes #456, etc., so the work can be tracked.

…r failure

When NmrClientAttachProvider fails in the type-specific program
information attach callback, the error path incorrectly cleared
general_helper_program_data (wrong field) instead of rolling back
the state that was set before the NmrClientAttachProvider call.

Fix the error path to:
- Reclaim extension_program_data back to the local variable so it
  is freed at the Done label.
- Reset program->extension_program_data to NULL.
- Reset program_type_specific_helper_function_count and bpf_prog_type
  to their default values.
- Stop incorrectly clearing general_helper_program_data.

Note: the program destructor (_ebpf_program_free) already frees
extension_program_data, so the leak was bounded by program lifetime.
The more significant issue was the stale bpf_prog_type and helper
count that could affect subsequent attach attempts.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Alan-Jowett Alan-Jowett force-pushed the fix/nmr-attach-failure-rollback branch from ea5f27c to 5ab16a0 Compare May 19, 2026 22:36
@Alan-Jowett Alan-Jowett marked this pull request as draft May 19, 2026 22:37
@github-actions
Copy link
Copy Markdown
Contributor

This pull request isn't linked to any GitHub issue. Please reference an issue with a keyword such as Fixes #123, Closes #456, etc., so the work can be tracked.

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