From nobody Tue May 7 11:56:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+97329+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+97329+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1670975567; cv=none; d=zohomail.com; s=zohoarc; b=U7ZaZr0YmGVWNXIje+/l0hdPEvdUEexrN1haq6Qu+JtUoO/C6nmlvCJrglf43ZLuPpWlGI6KbYIU34No0BK2vggJkORNZpYY57jeOh4uDzVRc7WhXI5Gu0xd7A0FASgTlEacKjixc5/+m99Ozh5dGVBZS1jtkGu7StzFWGyTRdE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1670975567; h=Cc:Date:From:List-Subscribe:List-Id:List-Help:List-Unsubscribe:Message-ID:Reply-To:Sender:Subject:To; bh=iWySRqQnAJbDjM2OOuvuzncPxsLv2xwgqpFgsHdBPW0=; b=NI+zLe9cr2ddnWeHTr1Ya/4zHACeekn1a5DD14T5r/h5vSG58DVLnspY7xKbDRRnSG0jer7Jzk9Ox1FP96Cc5Tbz9Ex3Zv1sI6RUAGIysRb0Nlx8VRKg6vHQY3rU2Wvhc2O3DFvFyPaBY0TJEOPO1vourpLyVLAWHEV1+SAKi1M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+97329+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1670975567796655.4587226870827; Tue, 13 Dec 2022 15:52:47 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id NwzCYY1788612x5vmg5jZr0b; Tue, 13 Dec 2022 15:52:47 -0800 X-Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by mx.groups.io with SMTP id smtpd.web11.77480.1670946913497442090 for ; Tue, 13 Dec 2022 07:55:13 -0800 X-Received: by mail-pl1-f179.google.com with SMTP id w23so162143ply.12 for ; Tue, 13 Dec 2022 07:55:13 -0800 (PST) X-Gm-Message-State: HKGfIuv8kJiTTzg3tmR3GXT1x1787277AA= X-Google-Smtp-Source: AA0mqf7rPLQ4BC+eAHMlIvXikGPSkocZoNBlzHsBfTUu3XnzjoiYd+JA5QNVSv/BjUJQir22G63+WA== X-Received: by 2002:a17:902:ed85:b0:185:441e:2d9f with SMTP id e5-20020a170902ed8500b00185441e2d9fmr18774758plj.54.1670946912551; Tue, 13 Dec 2022 07:55:12 -0800 (PST) X-Received: from linux-l9pv.suse ([124.11.22.254]) by smtp.gmail.com with ESMTPSA id x14-20020a170902ec8e00b001897d30143asm13442plg.289.2022.12.13.07.55.10 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Dec 2022 07:55:12 -0800 (PST) From: "Lee, Chun-Yi" X-Google-Original-From: "Lee, Chun-Yi" To: devel@edk2.groups.io Cc: Min M Xu , Gerd Hoffmann , Jiewen Yao , Tom Lendacky , James Bottomley , Erdem Aktas , "Lee, Chun-Yi" Subject: [edk2-devel] [PATCH] OvmfPkg/PlatformInitLib: Fix integrity checking failed of NvVarStore in some cases Date: Tue, 13 Dec 2022 23:55:02 +0800 Message-Id: <20221213155502.29548-1-jlee@suse.com> Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,joeyli.kernel@gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1670975567; bh=5T9hMmoB29iplBtr+aNq4+nXIf+7CRw6y9IYOZSpW0Y=; h=Cc:Date:From:Reply-To:Subject:To; b=nA4Y6eFtR+FWIrwY9NochuDmFh9IWGQFaRPJHk08G4MnmA1/hlDZbr5Zm02bGNmfVHo lvhXbxoctThffsgEr5BM0nnFsODPqwYyUvhjjElXtQaIq7rEHghsyMs6iv6VG+cqslHTy CS6pvh7c6GMBnx9onJQ1cJfzzVOWsizJ70Y= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1670975569492100015 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" In the commit 4f173db8b4 "OvmfPkg/PlatformInitLib: Add functions for EmuVar= iableNvStore" , it introduced a PlatformValidateNvVarStore() function for checking the integrity of NvVarStore. In some cases when the VariableHeader->StartId is VARIABLE_DATA, the Variab= leHeader->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 =3D (VAR_IN_DELETED_TRANSITION & VAR_ADDED) & VAR_DELETED or 0x3D =3D 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=3D=3D1)) 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=3DBootOrder L1871, State=3D0000003F <-- VAR_ADDED State &=3D VAR_DELETED=3D0000003D FlushHobVariableToFlash(), VariableName=3DBootOrder ... UpdateVariable(), VariableName=3DInitialAttemptOrder L1977, State=3D0000003F State &=3D VAR_IN_DELETED_TRANSITION=3D0000003E L2376, State=3D0000003E State &=3D VAR_DELETED=3D0000003C FlushHobVariableToFlash(), VariableName=3DInitialAttemptOrder ... UpdateVariable(), VariableName=3DConIn L1977, State=3D0000003F State &=3D VAR_IN_DELETED_TRANSITION=3D0000003E L2376, State=3D0000003E State &=3D VAR_DELETED=3D0000003C FlushHobVariableToFlash(), VariableName=3DConIn ... 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 =3D 0x3c VAR_ADDED & VAR_DELETED =3D 0x3d Signed-off-by: "Lee, Chun-Yi" --- OvmfPkg/Library/PlatformInitLib/Platform.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/Library/PlatformInitLib/Platform.c b/OvmfPkg/Library/P= latformInitLib/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 =3D=3D VAR_IN_DELETED_TRANSITION) || (VariableHeader->State =3D=3D VAR_DELETED) || (VariableHeader->State =3D=3D VAR_HEADER_VALID_ONLY) || - (VariableHeader->State =3D=3D VAR_ADDED))) + (VariableHeader->State =3D=3D VAR_ADDED) || + (VariableHeader->State =3D=3D (VAR_ADDED & VAR_DELETED)) || + (VariableHeader->State =3D=3D (VAR_ADDED & VAR_IN_DELETED_TRAN= SITION & VAR_DELETED)))) { DEBUG ((DEBUG_ERROR, "NvVarStore Variable header State was invalid= .\n")); return FALSE; --=20 2.35.3 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#97329): https://edk2.groups.io/g/devel/message/97329 Mute This Topic: https://groups.io/mt/95656983/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-