History

efi: efivars: Fix variable writes without query_variable_store()

Commit bbc6d2c6ef22 ("efi: vars: Switch to new wrapper layer") refactored the efivars layer so that the 'business logic' related to which UEFI variables affect the boot flow in which way could be moved out of it, and into the efivarfs driver. This inadvertently broke setting variables on firmware implementations that lack the QueryVariableInfo() boot service, because we no longer tolerate a EFI_UNSUPPORTED result from check_var_size() when calling efivar_entry_set_get_size(), which now ends up calling check_var_size() a second time inadvertently. If QueryVariableInfo() is missing, we support writes of up to 64k - let's move that logic into check_var_size(), and drop the redundant call.

Ard Biesheuvel committed 4 years ago

Commit 8a254d91 parent 4b017e53 files · +5 −24Browse files

Unified · Split

3 files
  1. drivers/firmware/efi/vars.c +5 −5
  2. fs/efivarfs/vars.c +0 −16
  3. include/linux/efi.h +0 −3
drivers/firmware/efi/vars.c+5−5
@@ -7,6 +7,7 @@ · 6 unmodified lines
7 */7 */
8 8
9#include <linux/types.h>9#include <linux/types.h>
10#include <linux/sizes.h>
10#include <linux/errno.h>11#include <linux/errno.h>
11#include <linux/init.h>12#include <linux/init.h>
12#include <linux/module.h>13#include <linux/module.h>
@@ -20,19 +21,19 @@ static struct efivars *__efivars; · 7 unmodified lines
20 21
21static DEFINE_SEMAPHORE(efivars_lock);22static DEFINE_SEMAPHORE(efivars_lock);
22 23
23efi_status_t check_var_size(u32 attributes, unsigned long size)24static efi_status_t check_var_size(u32 attributes, unsigned long size)
24{25{
25 const struct efivar_operations *fops;26 const struct efivar_operations *fops;
26 27
27 fops = __efivars->ops;28 fops = __efivars->ops;
28 29
29 if (!fops->query_variable_store)30 if (!fops->query_variable_store)
30 return EFI_UNSUPPORTED;31 return (size <= SZ_64K) ? EFI_SUCCESS : EFI_OUT_OF_RESOURCES;
31 32
32 return fops->query_variable_store(attributes, size, false);33 return fops->query_variable_store(attributes, size, false);
33}34}
34EXPORT_SYMBOL_NS_GPL(check_var_size, EFIVAR);
35 35
36static
36efi_status_t check_var_size_nonblocking(u32 attributes, unsigned long size)37efi_status_t check_var_size_nonblocking(u32 attributes, unsigned long size)
37{38{
38 const struct efivar_operations *fops;39 const struct efivar_operations *fops;
@@ -40,11 +41,10 @@ efi_status_t check_var_size_nonblocking(u32 attributes, unsigned long size) · 1 unmodified line
40 fops = __efivars->ops;41 fops = __efivars->ops;
41 42
42 if (!fops->query_variable_store)43 if (!fops->query_variable_store)
43 return EFI_UNSUPPORTED;44 return (size <= SZ_64K) ? EFI_SUCCESS : EFI_OUT_OF_RESOURCES;
44 45
45 return fops->query_variable_store(attributes, size, true);46 return fops->query_variable_store(attributes, size, true);
46}47}
47EXPORT_SYMBOL_NS_GPL(check_var_size_nonblocking, EFIVAR);
48 48
49/**49/**
50 * efivars_kobject - get the kobject for the registered efivars50 * efivars_kobject - get the kobject for the registered efivars
fs/efivarfs/vars.c+0−16
@@ -651,22 +651,6 @@ int efivar_entry_set_get_size(struct efivar_entry *entry, u32 attributes, · 650 unmodified lines
651 if (err)651 if (err)
652 return err;652 return err;
653 653
654 /*
655 * Ensure that the available space hasn't shrunk below the safe level
656 */
657 status = check_var_size(attributes, *size + ucs2_strsize(name, 1024));
658 if (status != EFI_SUCCESS) {
659 if (status != EFI_UNSUPPORTED) {
660 err = efi_status_to_err(status);
661 goto out;
662 }
663
664 if (*size > 65536) {
665 err = -ENOSPC;
666 goto out;
667 }
668 }
669
670 status = efivar_set_variable_locked(name, vendor, attributes, *size,654 status = efivar_set_variable_locked(name, vendor, attributes, *size,
671 data, false);655 data, false);
672 if (status != EFI_SUCCESS) {656 if (status != EFI_SUCCESS) {
include/linux/efi.h+0−3
@@ -1085,9 +1085,6 @@ efi_status_t efivar_set_variable_locked(efi_char16_t *name, efi_guid_t *vendor, · 1084 unmodified lines
1085efi_status_t efivar_set_variable(efi_char16_t *name, efi_guid_t *vendor,1085efi_status_t efivar_set_variable(efi_char16_t *name, efi_guid_t *vendor,
1086 u32 attr, unsigned long data_size, void *data);1086 u32 attr, unsigned long data_size, void *data);
1087 1087
1088efi_status_t check_var_size(u32 attributes, unsigned long size);
1089efi_status_t check_var_size_nonblocking(u32 attributes, unsigned long size);
1090
1091#if IS_ENABLED(CONFIG_EFI_CAPSULE_LOADER)1088#if IS_ENABLED(CONFIG_EFI_CAPSULE_LOADER)
1092extern bool efi_capsule_pending(int *reset_type);1089extern bool efi_capsule_pending(int *reset_type);
1093 1090