efi: Clear up misconceptions about a maximum variable name size
authorTim Schumacher <timschumi@gmx.de>
Thu, 28 Mar 2024 20:50:33 +0000 (21:50 +0100)
committerArd Biesheuvel <ardb@kernel.org>
Sat, 13 Apr 2024 08:33:02 +0000 (10:33 +0200)
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>
drivers/firmware/efi/vars.c
fs/efivarfs/vars.c
include/linux/efi.h

index f654e6f6af87380da72fa9cb7de45fa5c876e764..4056ba7f3440850f1d6785ec69fd9e49ed2d0a9b 100644 (file)
@@ -215,7 +215,7 @@ efi_status_t efivar_set_variable_locked(efi_char16_t *name, efi_guid_t *vendor,
 
        if (data_size > 0) {
                status = check_var_size(nonblocking, attr,
-                                       data_size + ucs2_strsize(name, 1024));
+                                       data_size + ucs2_strsize(name, EFI_VAR_NAME_LEN));
                if (status != EFI_SUCCESS)
                        return status;
        }
index 4d722af1014f2a18198cc3e831d1fea68d46e251..3cc89bb624f071d316a6923bdb83011b20adb69b 100644 (file)
@@ -295,9 +295,9 @@ static bool variable_is_present(efi_char16_t *variable_name, efi_guid_t *vendor,
        unsigned long strsize1, strsize2;
        bool found = false;
 
-       strsize1 = ucs2_strsize(variable_name, 1024);
+       strsize1 = ucs2_strsize(variable_name, EFI_VAR_NAME_LEN);
        list_for_each_entry_safe(entry, n, head, list) {
-               strsize2 = ucs2_strsize(entry->var.VariableName, 1024);
+               strsize2 = ucs2_strsize(entry->var.VariableName, EFI_VAR_NAME_LEN);
                if (strsize1 == strsize2 &&
                        !memcmp(variable_name, &(entry->var.VariableName),
                                strsize2) &&
@@ -396,6 +396,7 @@ int efivar_init(int (*func)(efi_char16_t *, efi_guid_t, unsigned long, void *,
 
        do {
                variable_name_size = 512;
+               BUILD_BUG_ON(EFI_VAR_NAME_LEN < 512);
 
                status = efivar_get_next_variable(&variable_name_size,
                                                  variable_name,
index d59b0947fba08ad5edd916feb32144ac0328d72b..418e555459da7c37f5e85896fa6b3feb8c8b30a1 100644 (file)
@@ -1072,12 +1072,11 @@ static inline u64 efivar_reserved_space(void) { return 0; }
 #endif
 
 /*
- * The maximum size of VariableName + Data = 1024
- * Therefore, it's reasonable to save that much
- * space in each part of the structure,
- * and we use a page for reading/writing.
+ * There is no actual upper limit specified for the variable name size.
+ *
+ * This limit exists only for practical purposes, since name conversions
+ * are bounds-checked and name data is occasionally stored in-line.
  */
-
 #define EFI_VAR_NAME_LEN       1024
 
 int efivars_register(struct efivars *efivars,