efi_loader: variable: attributes may not be changed if a variable exists
v2 cover efi_loader: variable: attributes may not be changed if a variable exists
Changes in v2
* add patch#1 and patch#2 to avoid sefltest failure
* doesn't free a buffer returned by env_get() (patch#3)
AKASHI Takahiro (3):
efi: selftest: APPEND_WRITE is not supported
efi_loader: variable: return error for APPEND_WRITE
efi_loader: variable: attributes may not be changed if a variable
exists
lib/efi_loader/efi_variable.c | 16 ++++++++++--- lib/efi_selftest/efi_selftest_variables.c | 28 +++++++++++------------ 2 files changed, 27 insertions(+), 17 deletions(-)
Signature · 1 line
2.21.0
PATCH v2 1/3 efi: selftest: APPEND_WRITE is not supported
The error here should be marked *todo*.
--- lib/efi_selftest/efi_selftest_variables.c | 28 +++++++++++------------ 1 file changed, 14 insertions(+), 14 deletions(-)
lib/efi_selftest/efi_selftest_variables.c +14 -14
@@ -116,21 +116,21 @@ static int execute(void)EFI_VARIABLE_APPEND_WRITE , 7, v + 8);if (ret !=EFI_SUCCESS ) { -efi_st_error ("SetVariable failed\n" ); -return EFI_ST_FAILURE ; - } - len =EFI_ST_MAX_DATA_SIZE ; - ret = runtime->get_variable (L"efi_st_var1" , &guid_vendor1, - &attr, &len, data); -if (ret !=EFI_SUCCESS ) { -efi_st_error ("GetVariable failed\n" ); -return EFI_ST_FAILURE ; +efi_st_todo ("SetVariable(APPEND_WRITE) failed\n" ); + }else { + len =EFI_ST_MAX_DATA_SIZE ; + ret = runtime->get_variable (L"efi_st_var1" , &guid_vendor1, + &attr, &len, data); +if (ret !=EFI_SUCCESS ) { +efi_st_error ("GetVariable failed\n" ); +return EFI_ST_FAILURE ; + } +if (len !=15 ) +efi_st_todo ("GetVariable returned wrong length %u\n" , + (unsigned int )len); +if (memcmp (data, v, len)) +efi_st_todo ("GetVariable returned wrong value\n" ); } -if (len !=15 ) -efi_st_todo ("GetVariable returned wrong length %u\n" , - (unsigned int )len); -if (memcmp (data, v, len)) -efi_st_todo ("GetVariable returned wrong value\n" );/* Enumerate variables */ boottime->set_mem (&guid,16 ,0 ); *varname =0 ;
Signature · 1 line
2.21.0
PATCH v2 1/3 efi: selftest: APPEND_WRITE is not supported
Quoted 3 lines · AKASHI Takahiro
The error here should be marked *todo*.
Signed-off-by AKASHI Takahiro <[email protected]>
PATCH v2 2/3 efi_loader: variable: return error for APPEND_WRITE
In reply to AKASHI TakahiroThe current efi_et_variable() doesn't support EFI_VARIABLE_APPEND_WRITE attiribut for now, and so should return an error.
--- lib/efi_loader/efi_variable.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
lib/efi_loader/efi_variable.c +2 -1
@@ -427,7 +427,8 @@ efi_status_t EFIAPI efi_set_variable(u16 *variable_name,EFI_ENTRY ("\"%ls\" %pUl %x %zu %p" , variable_name, vendor, attributes, data_size, data); -if (!variable_name || !vendor) { +if (!variable_name || !vendor || + (attributes &EFI_VARIABLE_APPEND_WRITE )) { ret =EFI_INVALID_PARAMETER ; goto out; }
Signature · 1 line
2.21.0
PATCH v2 2/3 efi_loader: variable: return error for APPEND_WRITE
Quoted 4 lines · AKASHI Takahiro
The current
efi_et_variable()doesn't supportEFI_VARIABLE_APPEND_WRITEattiribut for now, and so should return an error.Signed-off-by AKASHI Takahiro <[email protected]>
I will correct the typos in the commit message and add a TODO comment in the code.
Quoted 19 lines
--- lib/efi_loader/efi_variable.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)lib/efi_loader/efi_variable.c +2
-1@@ -427,7 +427,8 @@ efi_status_t EFIAPI efi_set_variable(u16 *variable_name,EFI_ENTRY ("\"%ls\" %pUl %x %zu %p" , variable_name, vendor, attributes, data_size, data); -if (!variable_name || !vendor) { +if (!variable_name || !vendor || + (attributes &EFI_VARIABLE_APPEND_WRITE )) { ret =EFI_INVALID_PARAMETER ; goto out; }
PATCH v2 3/3 efi_loader: variable: attributes may not be changed if a variable exists
In reply to AKASHI TakahiroIf a variable already exists, efi_set_variable() should not change the variable's attributes. This patch enforces it.
--- lib/efi_loader/efi_variable.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
lib/efi_loader/efi_variable.c +11 -2
@@ -450,12 +450,21 @@ efi_status_t EFIAPI efi_set_variable(u16 *variable_name,if (val) {parse_attr (val, &attr); +/* We should not free val */ + val =NULL ;if (attr &READ_ONLY ) { -/* We should not free val */ - val =NULL ; ret =EFI_WRITE_PROTECTED ; goto out; } + +/* +* attributes won't be changed +* TODO: take care of APPEND_WRITE once supported +*/ +if (attr != attributes) { + ret =EFI_INVALID_PARAMETER ; + goto out; + } } val =malloc (2 * data_size +strlen ("{ro,run,boot}(blob)" ) +1 );
Signature · 1 line
2.21.0
PATCH v2 3/3 efi_loader: variable: attributes may not be changed if a variable exists
Quoted 4 lines · AKASHI Takahiro
If a variable already exists,
efi_set_variable()should not change the variable's attributes. This patch enforces it.Signed-off-by AKASHI Takahiro <[email protected]>
Quoted 3 lines
--- lib/efi_loader/efi_variable.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)