From mboxrd@z Thu Jan 1 00:00:00 1970 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 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Y/xgRD2D; spf=pass (domain: gmail.com, ip: 209.85.214.179, mailfrom: joeyli.kernel@gmail.com) Received: by mail-pl1-f179.google.com with SMTP id w23so162143ply.12 for ; Tue, 13 Dec 2022 07:55:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Dv2/FshZByhSYz8R8VnUIrzw+6Ejge3eEP8y/zP4QVY=; b=Y/xgRD2DO5kK3j2S22vAZgZQuxETGTXeVuWW1UM6W2t8TImiSPBKTV66spodGgFVnH eLAnTmoWhEIo+pbyR0k2cfTRZGICyKsOKlvob8GQYzluC4AFCWN7EO1D6ScAjuUD91Hp i3bpMyqOUtJAWsXXDmYG9fTmBaCZmtQCkdnkTIx+zdvmBf8iai8VJ52hFVHusIze/nkK GA4ZEq7tfnlBYDaIshszreWn1cnAuoGwm5fzGMyzhk/ih5ES83w660aMkzO4vbTpGD/r Js+J1mKxNGbcscBvj+eYLm/0LUItUCX6Xjnd4SuqhkEISH5NwJkouVGqI9pAQ7USyR1P LAtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Dv2/FshZByhSYz8R8VnUIrzw+6Ejge3eEP8y/zP4QVY=; b=tTHs60mOPUt8cgSNwvF8Cs4ieo2ui+iawTAJdwtUqIMbSFjourwdUUpT/oioE+DU0e joZbj7NKb8Me9Ip2SElKD81fWTOhNcFSb/aAXick6bCzUGwRAOV+735LpIBB8LWVX7mS fP+MS6XYTk9IcsYJSv8O9aNRPU3KudZMrZH7lUuOLa2EAW9BlGTrdNo2zAl8uArPgI8k YD02SxnbPIM9rdfCFNHbMddCE6V8dsPppPbvh3W8+96kBPpy33YOZcer1mmlTHAqI8Ic /rHbYLRCu7JTcoteR8volt80HmRp2+kURhgOHrsiDSdTj4DOK5cCN2yJGvHkVgZlxy7F vl6g== X-Gm-Message-State: ANoB5plwzOSp6aYcDQwt0SvaWhdyEqEgJvb7tW2dJ3u4xdHB0Otrg2OY RuNm72FC4EePH0tYJ56Ji+zgEZk1BY4= 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) Return-Path: 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: [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> X-Mailer: git-send-email 2.12.3 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" --- 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