diff mbox

[1/2] uefi: uefirtvariable: report failure when setting variable with invalid attribute successfully (LP: #1310686)

Message ID 1398672406-3276-1-git-send-email-ivan.hu@canonical.com
State Accepted
Headers show

Commit Message

Ivan Hu April 28, 2014, 8:06 a.m. UTC
Some buggy firmwares allow to set variable with invalid attributes, and cannot
be got by the getvariable, that causes the test variable exists in the
firmware and cannot be set any more, setting variable by setvariable will
return EFI_INVALID_PARAMETER.
This patch adds to report fail and clean up the test variable.

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

Comments

Colin Ian King May 2, 2014, 9:39 a.m. UTC | #1
On 28/04/14 09:06, Ivan Hu wrote:
> Some buggy firmwares allow to set variable with invalid attributes, and cannot
> be got by the getvariable, that causes the test variable exists in the
> firmware and cannot be set any more, setting variable by setvariable will
> return EFI_INVALID_PARAMETER.
> This patch adds to report fail and clean up the test variable.
> 
> Signed-off-by: Ivan Hu <ivan.hu@canonical.com>
> ---
>  src/uefi/uefirtvariable/uefirtvariable.c |   11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/src/uefi/uefirtvariable/uefirtvariable.c b/src/uefi/uefirtvariable/uefirtvariable.c
> index 5d31ad8..6e40542 100644
> --- a/src/uefi/uefirtvariable/uefirtvariable.c
> +++ b/src/uefi/uefirtvariable/uefirtvariable.c
> @@ -1156,6 +1156,7 @@ static int setvariable_test5(fwts_framework *fw)
>  
>  static int setvariable_test6(fwts_framework *fw)
>  {
> +	int ret;
>  	uint64_t datasize = 10;
>  	uint8_t datadiff = 0;
>  	uint32_t attributesarray[] = {
> @@ -1166,7 +1167,15 @@ static int setvariable_test6(fwts_framework *fw)
>  	uint64_t index;
>  
>  	for (index = 0; index < (sizeof(attributesarray)/(sizeof attributesarray[0])); index++) {
> -		setvariable_invalidattr(fw, attributesarray[index], datasize, variablenametest, &gtestguid1, datadiff);
> +		ret = setvariable_invalidattr(fw, attributesarray[index], datasize, variablenametest, &gtestguid1, datadiff);
> +
> +		if (ret == FWTS_ERROR) {
> +			/* successfully set variable with invalid attributes, test fail */
> +			fwts_failed(fw, LOG_LEVEL_MEDIUM, "UEFIRuntimeSetVariable",
> +				"Successfully set variable with invalid attribute, expected fail.");
> +			setvariable_insertvariable(fw, 0, datasize, variablenametest, &gtestguid1, datadiff);
> +			return FWTS_ERROR;
> +		}
>  
>  		if (setvariable_checkvariable_notfound(fw, variablenametest,
>  			&gtestguid1) == FWTS_ERROR) {
> 
Acked-by: Colin Ian King <colin.king@canonical.com>
Alex Hung May 5, 2014, 8:26 a.m. UTC | #2
On 04/28/2014 04:06 PM, Ivan Hu wrote:
> Some buggy firmwares allow to set variable with invalid attributes, and cannot
> be got by the getvariable, that causes the test variable exists in the
> firmware and cannot be set any more, setting variable by setvariable will
> return EFI_INVALID_PARAMETER.
> This patch adds to report fail and clean up the test variable.
>
> Signed-off-by: Ivan Hu <ivan.hu@canonical.com>
> ---
>   src/uefi/uefirtvariable/uefirtvariable.c |   11 ++++++++++-
>   1 file changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/src/uefi/uefirtvariable/uefirtvariable.c b/src/uefi/uefirtvariable/uefirtvariable.c
> index 5d31ad8..6e40542 100644
> --- a/src/uefi/uefirtvariable/uefirtvariable.c
> +++ b/src/uefi/uefirtvariable/uefirtvariable.c
> @@ -1156,6 +1156,7 @@ static int setvariable_test5(fwts_framework *fw)
>
>   static int setvariable_test6(fwts_framework *fw)
>   {
> +	int ret;
>   	uint64_t datasize = 10;
>   	uint8_t datadiff = 0;
>   	uint32_t attributesarray[] = {
> @@ -1166,7 +1167,15 @@ static int setvariable_test6(fwts_framework *fw)
>   	uint64_t index;
>
>   	for (index = 0; index < (sizeof(attributesarray)/(sizeof attributesarray[0])); index++) {
> -		setvariable_invalidattr(fw, attributesarray[index], datasize, variablenametest, &gtestguid1, datadiff);
> +		ret = setvariable_invalidattr(fw, attributesarray[index], datasize, variablenametest, &gtestguid1, datadiff);
> +
> +		if (ret == FWTS_ERROR) {
> +			/* successfully set variable with invalid attributes, test fail */
> +			fwts_failed(fw, LOG_LEVEL_MEDIUM, "UEFIRuntimeSetVariable",
> +				"Successfully set variable with invalid attribute, expected fail.");
> +			setvariable_insertvariable(fw, 0, datasize, variablenametest, &gtestguid1, datadiff);
> +			return FWTS_ERROR;
> +		}
>
>   		if (setvariable_checkvariable_notfound(fw, variablenametest,
>   			&gtestguid1) == FWTS_ERROR) {
>

Acked-by: Alex Hung <alex.hung@canonical.com>
diff mbox

Patch

diff --git a/src/uefi/uefirtvariable/uefirtvariable.c b/src/uefi/uefirtvariable/uefirtvariable.c
index 5d31ad8..6e40542 100644
--- a/src/uefi/uefirtvariable/uefirtvariable.c
+++ b/src/uefi/uefirtvariable/uefirtvariable.c
@@ -1156,6 +1156,7 @@  static int setvariable_test5(fwts_framework *fw)
 
 static int setvariable_test6(fwts_framework *fw)
 {
+	int ret;
 	uint64_t datasize = 10;
 	uint8_t datadiff = 0;
 	uint32_t attributesarray[] = {
@@ -1166,7 +1167,15 @@  static int setvariable_test6(fwts_framework *fw)
 	uint64_t index;
 
 	for (index = 0; index < (sizeof(attributesarray)/(sizeof attributesarray[0])); index++) {
-		setvariable_invalidattr(fw, attributesarray[index], datasize, variablenametest, &gtestguid1, datadiff);
+		ret = setvariable_invalidattr(fw, attributesarray[index], datasize, variablenametest, &gtestguid1, datadiff);
+
+		if (ret == FWTS_ERROR) {
+			/* successfully set variable with invalid attributes, test fail */
+			fwts_failed(fw, LOG_LEVEL_MEDIUM, "UEFIRuntimeSetVariable",
+				"Successfully set variable with invalid attribute, expected fail.");
+			setvariable_insertvariable(fw, 0, datasize, variablenametest, &gtestguid1, datadiff);
+			return FWTS_ERROR;
+		}
 
 		if (setvariable_checkvariable_notfound(fw, variablenametest,
 			&gtestguid1) == FWTS_ERROR) {