From: "joeyli" <jlee@suse.com>
To: devel@edk2.groups.io, jiewen.yao@intel.com
Cc: "Lee, Chun-Yi" <joeyli.kernel@gmail.com>,
"Xu, Min M" <min.m.xu@intel.com>,
Gerd Hoffmann <kraxel@redhat.com>,
Tom Lendacky <thomas.lendacky@amd.com>,
James Bottomley <jejb@linux.ibm.com>,
"Aktas, Erdem" <erdemaktas@google.com>
Subject: Re: [edk2-devel] [PATCH] OvmfPkg/PlatformInitLib: Fix integrity checking failed of NvVarStore in some cases
Date: Wed, 14 Dec 2022 23:05:28 +0800 [thread overview]
Message-ID: <20221214150528.GA11807@linux-l9pv.suse> (raw)
In-Reply-To: <MW4PR11MB5872A40F62BCD454A19A29E58CE09@MW4PR11MB5872.namprd11.prod.outlook.com>
Hi Jiewen,
Thanks for your response!
On Wed, Dec 14, 2022 at 06:53:42AM +0000, Yao, Jiewen via groups.io wrote:
> Hey
> Good catch!
>
> I think we need handle below valid cases:
> 1. VAR_HEADER_VALID_ONLY (0x7F) <-- Header added (*)
> 2. VAR_ADDED (0x3F) <-- Header + data added
> 3. VAR_ADDED & VAR_IN_DELETED_TRANSITION (0x3E) <-- marked as deleted, but still valid, before new data is added. (*)
> 4. VAR_ADDED & VAR_IN_DELETED_TRANSITION & VAR_DELETED (0x3C) <-- deleted, after new data is added.
> 5. VAR_ADDED & VAR_DELETED (0x3D) <-- deleted directly, without new data.
> (*) means to support surprise shutdown.
>
>
> For the patch:
> > if (!((VariableHeader->State == VAR_IN_DELETED_TRANSITION) ||
> > (VariableHeader->State == VAR_DELETED) ||
> > (VariableHeader->State == VAR_HEADER_VALID_ONLY) ||
> > - (VariableHeader->State == VAR_ADDED)))
> > + (VariableHeader->State == VAR_ADDED) ||
> > + (VariableHeader->State == (VAR_ADDED & VAR_DELETED)) ||
> > + (VariableHeader->State == (VAR_ADDED & VAR_IN_DELETED_TRANSITION & VAR_DELETED))))
>
> I think:
> A. If we allow (VAR_HEADER_VALID_ONLY), then we support surprise shutdown, we need also allow (VAR_ADDED & VAR_IN_DELETED_TRANSITION). It should be added as well.
> B. The (VAR_IN_DELETED_TRANSITION) and (VAR_DELETED) are invalid state. They should be removed.
>
> Would you please double check?
>
I have followed your suggestion to change patch to add (VAR_ADDED & VAR_IN_DELETED_TRANSITION) and
removed (VAR_IN_DELETED_TRANSITION) and (VAR_DELETED). Like this:
Index: edk2/OvmfPkg/Library/PlatformInitLib/Platform.c
===================================================================
--- edk2.orig/OvmfPkg/Library/PlatformInitLib/Platform.c
+++ edk2/OvmfPkg/Library/PlatformInitLib/Platform.c
@@ -704,10 +704,11 @@ PlatformValidateNvVarStore (
VariableOffset = NvVarStoreHeader->Size - sizeof (VARIABLE_STORE_HEADER);
} else {
DEBUG ((DEBUG_ERROR, "VariableHeader->VendorGuid = %g, VariableHeader->State = 0x%x\n", VariableHeader->VendorGuid, VariableHeader->State));
- if (!((VariableHeader->State == VAR_IN_DELETED_TRANSITION) ||^M
- (VariableHeader->State == VAR_DELETED) ||^M
- (VariableHeader->State == VAR_HEADER_VALID_ONLY) ||^M
- (VariableHeader->State == VAR_ADDED)))^M
+ if (!((VariableHeader->State == VAR_HEADER_VALID_ONLY) ||^M
+ (VariableHeader->State == VAR_ADDED) ||^M
+ (VariableHeader->State == (VAR_ADDED & VAR_IN_DELETED_TRANSITION)) ||^M
+ (VariableHeader->State == (VAR_ADDED & VAR_DELETED)) ||^M
+ (VariableHeader->State == (VAR_ADDED & VAR_IN_DELETED_TRANSITION & VAR_DELETED))))^M
{
DEBUG ((DEBUG_ERROR, "NvVarStore Variable header State was invalid.\n"));
return FALSE;
The above change works to me no my OVMF.
Thanks a lot!
Joey Lee
>
>
>
> > -----Original Message-----
> > From: Lee, Chun-Yi <joeyli.kernel@gmail.com>
> > Sent: Tuesday, December 13, 2022 11:55 PM
> > To: devel@edk2.groups.io
> > Cc: Xu, Min M <min.m.xu@intel.com>; Gerd Hoffmann
> > <kraxel@redhat.com>; Yao, Jiewen <jiewen.yao@intel.com>; Tom Lendacky
> > <thomas.lendacky@amd.com>; James Bottomley <jejb@linux.ibm.com>;
> > Aktas, Erdem <erdemaktas@google.com>; Lee, Chun-Yi <jlee@suse.com>
> > Subject: [PATCH] OvmfPkg/PlatformInitLib: Fix integrity checking failed of
> > NvVarStore in some cases
> >
> > In the commit 4f173db8b4 "OvmfPkg/PlatformInitLib: Add functions for
> > EmuVariableNvStore"
> > , it introduced a PlatformValidateNvVarStore() function for checking the
> > integrity of NvVarStore.
> >
> > In some cases when the VariableHeader->StartId is VARIABLE_DATA, the
> > VariableHeader->State
> > is not just one of the four primary states: VAR_IN_DELETED_TRANSITION,
> > VAR_DELETED,
> > VAR_HEADER_VALID_ONLY, VAR_ADDED. The state may combined two or
> > three
> > states, e.g.
> > 0x3C = (VAR_IN_DELETED_TRANSITION & VAR_ADDED) & VAR_DELETED
> > or
> > 0x3D = VAR_ADDED & VAR_DELETED
> >
> > When the variable store has those variables, then system booting/rebooting
> > will
> > hangs in a ASSERT:
> >
> > NvVarStore Variable header State was invalid.
> > ASSERT
> > /mnt/working/source_code-
> > git/edk2/OvmfPkg/Library/PlatformInitLib/Platform.c(819):
> > ((BOOLEAN)(0==1))
> >
> > Adding more log to UpdateVariable() and PlatformValidateNvVarStore(), we
> > can see there have some variables have 0x3C or 0x3D state in store.
> > e.g.
> >
> > UpdateVariable(), VariableName=BootOrder
> > L1871, State=0000003F <-- VAR_ADDED
> > State &= VAR_DELETED=0000003D
> > FlushHobVariableToFlash(), VariableName=BootOrder
> > ...
> > UpdateVariable(), VariableName=InitialAttemptOrder
> > L1977, State=0000003F
> > State &= VAR_IN_DELETED_TRANSITION=0000003E
> > L2376, State=0000003E
> > State &= VAR_DELETED=0000003C
> > FlushHobVariableToFlash(), VariableName=InitialAttemptOrder
> > ...
> > UpdateVariable(), VariableName=ConIn
> > L1977, State=0000003F
> > State &= VAR_IN_DELETED_TRANSITION=0000003E
> > L2376, State=0000003E
> > State &= VAR_DELETED=0000003C
> > FlushHobVariableToFlash(), VariableName=ConIn
> > ...
> >
> > So, only allowing the four primary states is not enough. This patch adds
> > two more combined states to the valid states list:
> >
> > (VAR_IN_DELETED_TRANSITION & VAR_ADDED) & VAR_DELETED = 0x3c
> >
> > VAR_ADDED & VAR_DELETED = 0x3d
> >
> > Signed-off-by: "Lee, Chun-Yi" <jlee@suse.com>
> > ---
> > OvmfPkg/Library/PlatformInitLib/Platform.c | 4 +++-
> > 1 file changed, 3 insertions(+), 1 deletion(-)
> >
> > diff --git a/OvmfPkg/Library/PlatformInitLib/Platform.c
> > b/OvmfPkg/Library/PlatformInitLib/Platform.c
> > index 77f22de046..2af4cefd10 100644
> > --- a/OvmfPkg/Library/PlatformInitLib/Platform.c
> > +++ b/OvmfPkg/Library/PlatformInitLib/Platform.c
> > @@ -705,7 +705,9 @@ PlatformValidateNvVarStore (
> > if (!((VariableHeader->State == VAR_IN_DELETED_TRANSITION) ||
> > (VariableHeader->State == VAR_DELETED) ||
> > (VariableHeader->State == VAR_HEADER_VALID_ONLY) ||
> > - (VariableHeader->State == VAR_ADDED)))
> > + (VariableHeader->State == VAR_ADDED) ||
> > + (VariableHeader->State == (VAR_ADDED & VAR_DELETED)) ||
> > + (VariableHeader->State == (VAR_ADDED &
> > VAR_IN_DELETED_TRANSITION & VAR_DELETED))))
> > {
> > DEBUG ((DEBUG_ERROR, "NvVarStore Variable header State was
> > invalid.\n"));
> > return FALSE;
> > --
> > 2.35.3
>
>
>
>
>
prev parent reply other threads:[~2022-12-14 15:05 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-13 15:55 [PATCH] OvmfPkg/PlatformInitLib: Fix integrity checking failed of NvVarStore in some cases Lee, Chun-Yi
2022-12-14 6:15 ` Gerd Hoffmann
2022-12-14 13:46 ` [edk2-devel] " joeyli
2022-12-14 14:12 ` Gerd Hoffmann
2022-12-14 15:24 ` joeyli
2022-12-14 14:24 ` joeyli
2022-12-14 6:53 ` Yao, Jiewen
2022-12-14 15:05 ` joeyli [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221214150528.GA11807@linux-l9pv.suse \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox