Skip to content

Commit cda30c6

Browse files
timschumiardbiesheuvel
authored andcommitted
efi: Clear up misconceptions about a maximum variable name size
The UEFI specification does not make any mention of a maximum variable name size, so the headers and implementation shouldn't claim that one exists either. Comments referring to this limit have been removed or rewritten, as this is an implementation detail local to the Linux kernel. Where appropriate, the magic value of 1024 has been replaced with EFI_VAR_NAME_LEN, as this is used for the efi_variable struct definition. This in itself does not change any behavior, but should serve as points of interest when making future changes in the same area. A related build-time check has been added to ensure that the special 512 byte sized buffer will not overflow with a potentially decreased EFI_VAR_NAME_LEN. Signed-off-by: Tim Schumacher <timschumi@gmx.de> Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
1 parent 89ea21d commit cda30c6

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

drivers/firmware/efi/vars.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ efi_status_t efivar_set_variable_locked(efi_char16_t *name, efi_guid_t *vendor,
215215

216216
if (data_size > 0) {
217217
status = check_var_size(nonblocking, attr,
218-
data_size + ucs2_strsize(name, 1024));
218+
data_size + ucs2_strsize(name, EFI_VAR_NAME_LEN));
219219
if (status != EFI_SUCCESS)
220220
return status;
221221
}

fs/efivarfs/vars.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,9 @@ static bool variable_is_present(efi_char16_t *variable_name, efi_guid_t *vendor,
295295
unsigned long strsize1, strsize2;
296296
bool found = false;
297297

298-
strsize1 = ucs2_strsize(variable_name, 1024);
298+
strsize1 = ucs2_strsize(variable_name, EFI_VAR_NAME_LEN);
299299
list_for_each_entry_safe(entry, n, head, list) {
300-
strsize2 = ucs2_strsize(entry->var.VariableName, 1024);
300+
strsize2 = ucs2_strsize(entry->var.VariableName, EFI_VAR_NAME_LEN);
301301
if (strsize1 == strsize2 &&
302302
!memcmp(variable_name, &(entry->var.VariableName),
303303
strsize2) &&
@@ -396,6 +396,7 @@ int efivar_init(int (*func)(efi_char16_t *, efi_guid_t, unsigned long, void *,
396396

397397
do {
398398
variable_name_size = 512;
399+
BUILD_BUG_ON(EFI_VAR_NAME_LEN < 512);
399400

400401
status = efivar_get_next_variable(&variable_name_size,
401402
variable_name,

include/linux/efi.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,12 +1072,11 @@ static inline u64 efivar_reserved_space(void) { return 0; }
10721072
#endif
10731073

10741074
/*
1075-
* The maximum size of VariableName + Data = 1024
1076-
* Therefore, it's reasonable to save that much
1077-
* space in each part of the structure,
1078-
* and we use a page for reading/writing.
1075+
* There is no actual upper limit specified for the variable name size.
1076+
*
1077+
* This limit exists only for practical purposes, since name conversions
1078+
* are bounds-checked and name data is occasionally stored in-line.
10791079
*/
1080-
10811080
#define EFI_VAR_NAME_LEN 1024
10821081

10831082
int efivars_register(struct efivars *efivars,

0 commit comments

Comments
 (0)