- 
                Notifications
    
You must be signed in to change notification settings  - Fork 162
 
Added explicit state validation in FindVariableEx() to skip variables with deleted state (0x3C) and only return valid variables #1551
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
Added explicit state validation in FindVariableEx() to skip variables with deleted state (0x3C) and only return valid variables #1551
Conversation
| 
           @microsoft-github-policy-service agree [company="Microsoft"]  | 
    
          Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@                Coverage Diff                @@
##             release/202502    #1551   +/-   ##
=================================================
  Coverage                  ?    1.55%           
=================================================
  Files                     ?      636           
  Lines                     ?   233982           
  Branches                  ?      370           
=================================================
  Hits                      ?     3649           
  Misses                    ?   230320           
  Partials                  ?       13           
 Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
  | 
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Marking PR as changes requested until the logic is clarified.
758a165    to
    a79453a      
    Compare
  
    When two identical variables exist in NVRAM with different states, FindVariableEx() incorrectly returns the deleted variable address instead of the valid variable address. This occurs when: One variable has deleted state (0x3C) One variable has valid state (0x3F) The function should prioritize and return the valid variable, but the original logic was returning the first match regardless of state validity. Root Cause: In the FindVariableEx() index table traversal, the function was not properly validating variable states before returning a match. When CompareWithValidVariable() found a matching variable name and GUID, it would return immediately without checking if the variable state was valid (0x3F) or deleted (0x3C). Solution: Added explicit state validation in FindVariableEx() to skip variables with deleted state (0x3C) and only return valid variables:
619982b    to
    27a2695      
    Compare
  
    
Description
Problem:
The Variable PEIM's index table optimization search path incorrectly returns deleted variables instead of valid variables when duplicate variables exist with different states. This occurs when:
One variable has deleted state (VAR_IN_DELETED_TRANSITION & VAR_ADDED, value 0x3C)
One variable has valid state (VAR_ADDED, value 0x3F)
Both variables have the same name and GUID
The function should prioritize and return the valid variable, but the index table search was returning the first match regardless of state validity.
Root Cause:
In the FindVariableEx() index table traversal, the function was not properly validating variable states before returning a match. When CompareWithValidVariable() found a matching variable name and GUID, it would return immediately without checking if the variable state was valid (0x3F) or deleted (0x3C).
This issue only affects the index table optimization search path and does not impact the linear traversal search path. The Variable PEIM has two main search mechanisms:
Linear traversal search - Walks through the entire variable store checking each header sequentially. This path has correct state validation logic and is unaffected by this issue.
Index table optimization search - Uses a gEfiVariableIndexTableGuid HOB to quickly jump to variable locations. This optimization is only active when the platform produces this HOB. This is the path affected by the bug.
Solution:
Added explicit state validation in FindVariableEx() to skip variables with deleted state (0x3C) and only return valid variables:
How This Was Tested
Create variable with delete and valid in NVRAM.
Call FindVariableEx() and check the variable address.
It only return valid variable address
Integration Instructions
N/A