Skip to content

Commit f45812c

Browse files
timschumiardbiesheuvel
authored andcommitted
efivarfs: Request at most 512 bytes for variable names
Work around a quirk in a few old (2011-ish) UEFI implementations, where a call to `GetNextVariableName` with a buffer size larger than 512 bytes will always return EFI_INVALID_PARAMETER. There is some lore around EFI variable names being up to 1024 bytes in size, but this has no basis in the UEFI specification, and the upper bounds are typically platform specific, and apply to the entire variable (name plus payload). Given that Linux does not permit creating files with names longer than NAME_MAX (255) bytes, 512 bytes (== 256 UTF-16 characters) is a reasonable limit. Cc: <stable@vger.kernel.org> # 6.1+ Signed-off-by: Tim Schumacher <timschumi@gmx.de> Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
1 parent fccfa64 commit f45812c

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

fs/efivarfs/vars.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ int efivar_init(int (*func)(efi_char16_t *, efi_guid_t, unsigned long, void *,
373373
struct list_head *),
374374
void *data, bool duplicates, struct list_head *head)
375375
{
376-
unsigned long variable_name_size = 1024;
376+
unsigned long variable_name_size = 512;
377377
efi_char16_t *variable_name;
378378
efi_status_t status;
379379
efi_guid_t vendor_guid;
@@ -390,12 +390,13 @@ int efivar_init(int (*func)(efi_char16_t *, efi_guid_t, unsigned long, void *,
390390
goto free;
391391

392392
/*
393-
* Per EFI spec, the maximum storage allocated for both
394-
* the variable name and variable data is 1024 bytes.
393+
* A small set of old UEFI implementations reject sizes
394+
* above a certain threshold, the lowest seen in the wild
395+
* is 512.
395396
*/
396397

397398
do {
398-
variable_name_size = 1024;
399+
variable_name_size = 512;
399400

400401
status = efivar_get_next_variable(&variable_name_size,
401402
variable_name,
@@ -432,9 +433,13 @@ int efivar_init(int (*func)(efi_char16_t *, efi_guid_t, unsigned long, void *,
432433
break;
433434
case EFI_NOT_FOUND:
434435
break;
436+
case EFI_BUFFER_TOO_SMALL:
437+
pr_warn("efivars: Variable name size exceeds maximum (%lu > 512)\n",
438+
variable_name_size);
439+
status = EFI_NOT_FOUND;
440+
break;
435441
default:
436-
printk(KERN_WARNING "efivars: get_next_variable: status=%lx\n",
437-
status);
442+
pr_warn("efivars: get_next_variable: status=%lx\n", status);
438443
status = EFI_NOT_FOUND;
439444
break;
440445
}

0 commit comments

Comments
 (0)