Skip to content

[CHERRY-PICK] MdeModulePkg: Improved error handling in RuntimeDxe Variable drivers [Rebase & FF] - #1899

Open
PaddyDeng-v wants to merge 1 commit into
microsoft:release/202511from
PaddyDeng-v:paddydeng-v-cp-edk2-harden-variable-smm-2511
Open

[CHERRY-PICK] MdeModulePkg: Improved error handling in RuntimeDxe Variable drivers [Rebase & FF]#1899
PaddyDeng-v wants to merge 1 commit into
microsoft:release/202511from
PaddyDeng-v:paddydeng-v-cp-edk2-harden-variable-smm-2511

Conversation

@PaddyDeng-v

Copy link
Copy Markdown
Contributor

Description

Cherry-pick of tianocore/edk2 PR #12670 (commit 8bf75267f9311a8a66a3864ee71426c70bb288bb).

This PR improves error handling in the Variable SMM/DXE RuntimeDxe drivers by replacing
ASSERT_EFI_ERROR calls with proper error-returning handling. This ensures platforms with
ASSERT_DEADLOOP_ENABLED disabled handle initialization errors gracefully instead of
silently continuing.

Changes

  • Replace ASSERT_EFI_ERROR with if (EFI_ERROR(...)) + DEBUG + goto ErrorExit pattern
  • Add comprehensive ErrorExit cleanup paths in VariableServiceInitialize() and MmVariableServiceInitialize()
  • Remove inline cleanup from VariableCommonInitialize() error paths (callers handle cleanup)
  • Move gEfiVariableArchProtocolGuid installation to end of VariableServiceInitialize()
  • Add VariableClearNotifySmmReady() function for SMM notification cleanup

Conflict Resolution

  • VariableDxe.c: Preserved mu_basecore's InitializeVariablePolicyLocking call (MU_CHANGE)
    while wrapping it with proper error handling instead of ASSERT_EFI_ERROR.

How This Was Tested

Cherry-picked and conflict-resolved from upstream edk2 where it passed CI.

Integration Checklist

  • Impacts functionality?
  • Impacts security? (improved error handling)
  • Breaking change?
  • Includes tests?
  • Includes documentation?

@PaddyDeng-v

Copy link
Copy Markdown
Contributor Author

/azp run

@mu-automation

mu-automation Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

⌛ QEMU Validation Pending

QEMU validation is pending on successful CI completion.

Note: Any previous results are available in this comment's edit history.

This comment was automatically generated by the Mu QEMU PR Validation workflow.

@azure-pipelines

Copy link
Copy Markdown
Commenter does not have sufficient privileges for PR 1899 in repo microsoft/mu_basecore

@codecov-commenter

Codecov Comments Bot (codecov-commenter) commented Aug 31, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 22 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (release/202511@f44f77a). Learn more about missing BASE report.

Files with missing lines Patch % Lines
...ModulePkg/Universal/Variable/RuntimeDxe/Variable.c 0.00% 18 Missing ⚠️
...versal/Variable/RuntimeDxe/VariableTraditionalMm.c 0.00% 4 Missing ⚠️
Additional details and impacted files
@@                Coverage Diff                @@
##             release/202511    #1899   +/-   ##
=================================================
  Coverage                  ?    1.65%           
=================================================
  Files                     ?      637           
  Lines                     ?   233220           
  Branches                  ?      519           
=================================================
  Hits                      ?     3865           
  Misses                    ?   229331           
  Partials                  ?       24           
Flag Coverage Δ
MdeModulePkg 1.65% <0.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@PaddyDeng-v
PaddyDeng-v marked this pull request as ready for review August 31, 2026 11:59
@apop5

Copy link
Copy Markdown
Collaborator

PaddyDeng-v

Please amend the commit to contain [Cherry-Pick] in the commit message title.

@makubacki Michael Kubacki (makubacki) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As Vineel Kovvuri[MSFT] (@vineelko) mentioned, you need to prepend the commit title with "[CHERRY-PICK]".

Cherry-pick commits are merged as-is (do not take the PR title), so it needs to be there.

Also, your original commit message in edk2 is:

MdeModulePkg: Improved error handling in RuntimeDxe Variable drivers
Some platforms may disable ASSERT_DEADLOOP_ENABLED in
PcdDebugPropertyMask. In this case ASSERT won't hang the machine.
Replaced those simple ASSERT with proper error returning handling.

Signed-off-by: Paddy Deng (AMI US Holdings Inc) v-dengpaddy@microsoft.com

Your current commit message here is:

MdeModulePkg: Improved error handling in RuntimeDxe Variable drivers
Replace ASSERT_EFI_ERROR with proper error handling that returns
failure status codes. This ensures platforms with
ASSERT_DEADLOOP_ENABLED disabled handle errors gracefully.

(cherry picked from commit 8bf75267f9311a8a66a3864ee71426c70bb288bb)

Co-authored-by: Copilot App 223556219+Copilot@users.noreply.github.com

You need to carry over you signed-off-by line. Your commit message here should be:

MdeModulePkg: Improved error handling in RuntimeDxe Variable drivers

Replace ASSERT_EFI_ERROR with proper error handling that returns
failure status codes. This ensures platforms with
ASSERT_DEADLOOP_ENABLED disabled handle errors gracefully.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Paddy Deng (AMI US Holdings Inc) <v-dengpaddy@microsoft.com>
(cherry picked from commit 8bf75267f9311a8a66a3864ee71426c70bb288bb)

…iable drivers

Replace ASSERT_EFI_ERROR with proper error handling that returns
failure status codes. This ensures platforms with
ASSERT_DEADLOOP_ENABLED disabled handle errors gracefully.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Paddy Deng (AMI US Holdings Inc) <v-dengpaddy@microsoft.com>
(cherry picked from commit 8bf75267f9311a8a66a3864ee71426c70bb288bb)
@PaddyDeng-v
PaddyDeng-v force-pushed the paddydeng-v-cp-edk2-harden-variable-smm-2511 branch from 4e91adf to 87e5a20 Compare September 3, 2026 05:57
@PaddyDeng-v

Copy link
Copy Markdown
Contributor Author

Hi Michael Kubacki (@makubacki) and Aaron (@apop5) ,

Thanks for pointing out. I have amended the commit message.
Please help to approve and merge the PR. Thank you.

@makubacki

Copy link
Copy Markdown
Member

PaddyDeng-v, is there a strong need for this change to go into 202511? I know this is intended to improve robustness overall and we've spent some time going through the individual changes, but release branches (especially 2511 at this point in its lifetime) are not really meant to absorb such impactful changes to error handling control flow logic that's been around for a long time unless there is a reason to risk regression.

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.

5 participants