From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web12.14681.1641937079159543274 for ; Tue, 11 Jan 2022 13:37:59 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: sunny.wang@arm.com) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 764AA1FB; Tue, 11 Jan 2022 13:37:58 -0800 (PST) Received: from localhost.localdomain (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 246E33F774; Tue, 11 Jan 2022 13:37:56 -0800 (PST) From: "Sunny Wang" To: devel@edk2.groups.io Cc: Sunny Wang , Liming Gao , Heinrich Schuchardt , G Edhaya Chandran , Samer El-Haj-Mahmoud , Sunny Wang Subject: [PATCH] MdeModulePkg/Variable: Make only EFI_VARIABLE_NON_VOLATILE invalid Date: Tue, 11 Jan 2022 21:37:20 +0000 Message-Id: <20220111213720.1358-1-Sunny.Wang@arm.com> X-Mailer: git-send-email 2.32.0.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Only EFI_VARIABLE_NON_VOLATILE attribute is an invalid combination of attribute bits, so update the variable driver to return EFI_INVALID_PARAMETER so that we can prevent the invalid variable being created. This change also fixes the SCT failure below: - RT.QueryVariableInfo - With being an invalid combination -- FAILURE For details, please check the threads below: - https://edk2.groups.io/g/devel/topic/86486174 - https://edk2.groups.io/g/devel/message/82466 Cc: Liming Gao Cc: Heinrich Schuchardt Cc: G Edhaya Chandran Cc: Samer El-Haj-Mahmoud Signed-off-by: Sunny Wang --- .../Universal/Variable/RuntimeDxe/Variable.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c b/MdeM= odulePkg/Universal/Variable/RuntimeDxe/Variable.c index 9722a94420..6c1a3440ac 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c @@ -19,6 +19,7 @@ Copyright (c) 2006 - 2020, Intel Corporation. All rights reserved.
(C) Copyright 2015-2018 Hewlett Packard Enterprise Development LP
Copyright (c) Microsoft Corporation.
+Copyright (c) 2022, ARM Limited. All rights reserved.
=20 SPDX-License-Identifier: BSD-2-Clause-Patent =20 @@ -2660,14 +2661,22 @@ VariableServiceSetVariable ( } =20 // - // Make sure if runtime bit is set, boot service bit is set also. + // Check if the combination of attribute bits is valid. // if ((Attributes & (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERV= ICE_ACCESS)) =3D=3D EFI_VARIABLE_RUNTIME_ACCESS) { + // + // Make sure if runtime bit is set, boot service bit is set also. + // if ((Attributes & EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS) !=3D 0) { return EFI_UNSUPPORTED; } else { return EFI_INVALID_PARAMETER; } + } else if ((Attributes & EFI_VARIABLE_ATTRIBUTES_MASK) =3D=3D EFI_VARI= ABLE_NON_VOLATILE) { + // + // Only EFI_VARIABLE_NON_VOLATILE attribute is invalid + // + return EFI_INVALID_PARAMETER; } else if ((Attributes & VARIABLE_ATTRIBUTE_AT_AW) !=3D 0) { if (!mVariableModuleGlobal->VariableGlobal.AuthSupport) { // @@ -3142,6 +3151,11 @@ VariableServiceQueryVariableInfo ( // Make sure the Attributes combination is supported by the platform= . // return EFI_UNSUPPORTED; + } else if ((Attributes & EFI_VARIABLE_ATTRIBUTES_MASK) =3D=3D EFI_VARI= ABLE_NON_VOLATILE) { + // + // Only EFI_VARIABLE_NON_VOLATILE attribute is invalid + // + return EFI_INVALID_PARAMETER; } else if ((Attributes & (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_B= OOTSERVICE_ACCESS)) =3D=3D EFI_VARIABLE_RUNTIME_ACCESS) { // // Make sure if runtime bit is set, boot service bit is set also. --=20 2.33.0.windows.2