public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH] MdeModulePkg VariablePei: Add Variable state check when find variable in IndexTable.
@ 2022-09-28  3:05 Jiading Zhang
  2022-09-30  2:46 ` 回复: [edk2-devel] " gaoliming
  2022-10-08  0:20 ` Jiading Zhang
  0 siblings, 2 replies; 10+ messages in thread
From: Jiading Zhang @ 2022-09-28  3:05 UTC (permalink / raw)
  To: devel


[-- Attachment #1.1: Type: text/plain, Size: 1780 bytes --]

When read a variable in PEI, it will find it first in the HOB, then find in variable store. When find in variable store, it will check the variable state, but find in HOB, it doesn't check the state, so if the variable was changed, it will find the obsolete variable in the HOB.

Signed-off-by: jdzhang <jdzhang@kunluntech.com.cn>
---
MdeModulePkg/Universal/Variable/Pei/Variable.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/MdeModulePkg/Universal/Variable/Pei/Variable.c b/MdeModulePkg/Universal/Variable/Pei/Variable.c
index 26a4c73b45..dffbd8cdb1 100644
--- a/MdeModulePkg/Universal/Variable/Pei/Variable.c
+++ b/MdeModulePkg/Universal/Variable/Pei/Variable.c
@@ -866,11 +866,13 @@ FindVariableEx (
Offset  += IndexTable->Index[Index];
MaxIndex = (VARIABLE_HEADER *)((UINT8 *)IndexTable->StartPtr + Offset);
GetVariableHeader (StoreInfo, MaxIndex, &VariableHeader);
-      if (CompareWithValidVariable (StoreInfo, MaxIndex, VariableHeader, VariableName, VendorGuid, PtrTrack) == EFI_SUCCESS) {
-        if (VariableHeader->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED)) {
-          InDeletedVariable = PtrTrack->CurrPtr;
-        } else {
-          return EFI_SUCCESS;
+      if ((VariableHeader->State == VAR_ADDED) || (VariableHeader->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED))) {
+        if (CompareWithValidVariable (StoreInfo, MaxIndex, VariableHeader, VariableName, VendorGuid, PtrTrack) == EFI_SUCCESS) {
+          if (VariableHeader->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED)) {
+            InDeletedVariable = PtrTrack->CurrPtr;
+          } else {
+            return EFI_SUCCESS;
+          }
}
}
}
--
2.20.1.windows.1

[-- Attachment #1.2: Type: text/html, Size: 2613 bytes --]

[-- Attachment #2: 0001-MdeModulePkg-VariablePei-Add-Variable-state-check-wh.patch --]
[-- Type: text/plain, Size: 2011 bytes --]

From d0a1e384ad04185cab915d2d577ac854169c3921 Mon Sep 17 00:00:00 2001
From: jdzhang <jdzhang@kunluntech.com.cn>
Date: Wed, 28 Sep 2022 10:57:47 +0800
Subject: [PATCH] MdeModulePkg VariablePei: Add Variable state check when find
 variable in IndexTable.

When read a variable in PEI, it will find it first in the HOB, then find in variable store. When find in variable store, it will check the variable state, but find in HOB, it doesn't check the state, so if the variable was changed, it will find the obsolete variable in the HOB.

Signed-off-by: jdzhang <jdzhang@kunluntech.com.cn>
---
 MdeModulePkg/Universal/Variable/Pei/Variable.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/MdeModulePkg/Universal/Variable/Pei/Variable.c b/MdeModulePkg/Universal/Variable/Pei/Variable.c
index 26a4c73b45..dffbd8cdb1 100644
--- a/MdeModulePkg/Universal/Variable/Pei/Variable.c
+++ b/MdeModulePkg/Universal/Variable/Pei/Variable.c
@@ -866,11 +866,13 @@ FindVariableEx (
       Offset  += IndexTable->Index[Index];
       MaxIndex = (VARIABLE_HEADER *)((UINT8 *)IndexTable->StartPtr + Offset);
       GetVariableHeader (StoreInfo, MaxIndex, &VariableHeader);
-      if (CompareWithValidVariable (StoreInfo, MaxIndex, VariableHeader, VariableName, VendorGuid, PtrTrack) == EFI_SUCCESS) {
-        if (VariableHeader->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED)) {
-          InDeletedVariable = PtrTrack->CurrPtr;
-        } else {
-          return EFI_SUCCESS;
+      if ((VariableHeader->State == VAR_ADDED) || (VariableHeader->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED))) {
+        if (CompareWithValidVariable (StoreInfo, MaxIndex, VariableHeader, VariableName, VendorGuid, PtrTrack) == EFI_SUCCESS) {
+          if (VariableHeader->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED)) {
+            InDeletedVariable = PtrTrack->CurrPtr;
+          } else {
+            return EFI_SUCCESS;
+          }
         }
       }
     }
-- 
2.20.1.windows.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2022-10-14  2:29 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-28  3:05 [PATCH] MdeModulePkg VariablePei: Add Variable state check when find variable in IndexTable Jiading Zhang
2022-09-30  2:46 ` 回复: [edk2-devel] " gaoliming
2022-10-10  0:35   ` [edk2-devel] " Jiading Zhang
2022-10-10  1:39     ` 回复: " gaoliming
2022-10-10  8:36       ` [edk2-devel] " Jiading Zhang
2022-10-14  1:57         ` 回复: " gaoliming
2022-10-14  2:29           ` [edk2-devel] " Jiading Zhang
2022-10-08  0:20 ` Jiading Zhang
2022-10-08  1:29   ` 回复: " gaoliming
2022-10-08 10:05     ` [edk2-devel] " Jiading Zhang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox