diff mbox

[13/15] uefirtauthvar: test with both authenticated attributes are set

Message ID 1413970840-27212-6-git-send-email-ivan.hu@canonical.com
State Rejected
Headers show

Commit Message

Ivan Hu Oct. 22, 2014, 9:40 a.m. UTC
Set the authitecated variable with both EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS
and the EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS attributes, firmware
should return EFI_INVALID_PARAMETER.

Signed-off-by: Ivan Hu <ivan.hu@canonical.com>
---
 src/uefi/uefirtauthvar/uefirtauthvar.c |   50 ++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

Comments

Colin Ian King Oct. 22, 2014, 4:08 p.m. UTC | #1
On 22/10/14 10:40, Ivan Hu wrote:
> Set the authitecated variable with both EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS
> and the EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS attributes, firmware
> should return EFI_INVALID_PARAMETER.

authitecated --> authenticated
> 
> Signed-off-by: Ivan Hu <ivan.hu@canonical.com>
> ---
>  src/uefi/uefirtauthvar/uefirtauthvar.c |   50 ++++++++++++++++++++++++++++++++
>  1 file changed, 50 insertions(+)
> 
> diff --git a/src/uefi/uefirtauthvar/uefirtauthvar.c b/src/uefi/uefirtauthvar/uefirtauthvar.c
> index fc59487..387cd93 100644
> --- a/src/uefi/uefirtauthvar/uefirtauthvar.c
> +++ b/src/uefi/uefirtauthvar/uefirtauthvar.c
> @@ -665,6 +665,55 @@ static int uefirtauthvar_test11(fwts_framework *fw)
>  	return FWTS_ERROR;
>  }
>  
> +/*
> + * Set the authitecated variable with both EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS
> + * and the EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS attributes, firmware
> + * should return EFI_INVALID_PARAMETER.
> + */

authitecated --> authenticated

> +static int uefirtauthvar_test12(fwts_framework *fw)
> +{
> +	long ioret;
> +
> +	uint64_t status;
> +	uint32_t attr_both = attributes | FWTS_UEFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS;
> +
> +	ioret = setvar(&gtestguid, attr_both, sizeof(AuthVarCreate), AuthVarCreate, &status);
> +
> +	if (ioret == -1) {
> +		if (status == EFI_INVALID_PARAMETER) {
> +			fwts_passed(fw, "Test with both authenticated attributes are set passed.");
> +
> +			return FWTS_OK;
> +		}
> +		if (status == EFI_OUT_OF_RESOURCES) {
> +			fwts_uefi_print_status_info(fw, status);
> +			fwts_skipped(fw,
> +				"Run out of resources for SetVariable "
> +				"UEFI runtime interface: cannot test.");
> +			fwts_advice(fw,
> +				"Firmware may reclaim some resources "
> +				"after rebooting. Reboot and test "
> +				"again may be helpful to continue "
> +				"the test.");
> +			return FWTS_SKIP;
> +		}
> +		fwts_failed(fw, LOG_LEVEL_MEDIUM,
> +			"UEFIRuntimeSetVariable",
> +			"Failed to set variable with UEFI "
> +			"runtime service.");
> +
> +		fwts_uefi_print_status_info(fw, status);
> +		return FWTS_ERROR;
> +	}
> +
> +	fwts_failed(fw, LOG_LEVEL_HIGH,
> +		"UEFSetAuthVarWithBothAuthAttr",
> +		"Should not pass setting the autheticated variable "
> +		"with both autheticated attributes are set.");
> +	return FWTS_ERROR;
> +}
> +
> +
>  static fwts_framework_minor_test uefirtauthvar_tests[] = {
>  	{ uefirtauthvar_test1, "Create authenticated variable test." },
>  	{ uefirtauthvar_test2, "Authenticated variable test with the same authenticated variable." },
> @@ -677,6 +726,7 @@ static fwts_framework_minor_test uefirtauthvar_tests[] = {
>  	{ uefirtauthvar_test9, "Authenticated variable test with invalid modified timestamp." },
>  	{ uefirtauthvar_test10, "Authenticated variable test with different guid." },
>  	{ uefirtauthvar_test11, "Authenticated variable test with invalid attributes." },
> +	{ uefirtauthvar_test12, "Test with both authenticated attributes are set." },
>  	{ NULL, NULL }
>  };
>  
>
diff mbox

Patch

diff --git a/src/uefi/uefirtauthvar/uefirtauthvar.c b/src/uefi/uefirtauthvar/uefirtauthvar.c
index fc59487..387cd93 100644
--- a/src/uefi/uefirtauthvar/uefirtauthvar.c
+++ b/src/uefi/uefirtauthvar/uefirtauthvar.c
@@ -665,6 +665,55 @@  static int uefirtauthvar_test11(fwts_framework *fw)
 	return FWTS_ERROR;
 }
 
+/*
+ * Set the authitecated variable with both EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS
+ * and the EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS attributes, firmware
+ * should return EFI_INVALID_PARAMETER.
+ */
+static int uefirtauthvar_test12(fwts_framework *fw)
+{
+	long ioret;
+
+	uint64_t status;
+	uint32_t attr_both = attributes | FWTS_UEFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS;
+
+	ioret = setvar(&gtestguid, attr_both, sizeof(AuthVarCreate), AuthVarCreate, &status);
+
+	if (ioret == -1) {
+		if (status == EFI_INVALID_PARAMETER) {
+			fwts_passed(fw, "Test with both authenticated attributes are set passed.");
+
+			return FWTS_OK;
+		}
+		if (status == EFI_OUT_OF_RESOURCES) {
+			fwts_uefi_print_status_info(fw, status);
+			fwts_skipped(fw,
+				"Run out of resources for SetVariable "
+				"UEFI runtime interface: cannot test.");
+			fwts_advice(fw,
+				"Firmware may reclaim some resources "
+				"after rebooting. Reboot and test "
+				"again may be helpful to continue "
+				"the test.");
+			return FWTS_SKIP;
+		}
+		fwts_failed(fw, LOG_LEVEL_MEDIUM,
+			"UEFIRuntimeSetVariable",
+			"Failed to set variable with UEFI "
+			"runtime service.");
+
+		fwts_uefi_print_status_info(fw, status);
+		return FWTS_ERROR;
+	}
+
+	fwts_failed(fw, LOG_LEVEL_HIGH,
+		"UEFSetAuthVarWithBothAuthAttr",
+		"Should not pass setting the autheticated variable "
+		"with both autheticated attributes are set.");
+	return FWTS_ERROR;
+}
+
+
 static fwts_framework_minor_test uefirtauthvar_tests[] = {
 	{ uefirtauthvar_test1, "Create authenticated variable test." },
 	{ uefirtauthvar_test2, "Authenticated variable test with the same authenticated variable." },
@@ -677,6 +726,7 @@  static fwts_framework_minor_test uefirtauthvar_tests[] = {
 	{ uefirtauthvar_test9, "Authenticated variable test with invalid modified timestamp." },
 	{ uefirtauthvar_test10, "Authenticated variable test with different guid." },
 	{ uefirtauthvar_test11, "Authenticated variable test with invalid attributes." },
+	{ uefirtauthvar_test12, "Test with both authenticated attributes are set." },
 	{ NULL, NULL }
 };