Skip to content

Commit bad267f

Browse files
jhovoldardbiesheuvel
authored andcommitted
efi: verify that variable services are supported
Current Qualcomm UEFI firmware does not implement the variable services but not all revisions clear the corresponding bits in the RT_PROP table services mask and instead the corresponding calls return EFI_UNSUPPORTED. This leads to efi core registering the generic efivar ops even when the variable services are not supported or when they are accessed through some other interface (e.g. Google SMI or the upcoming Qualcomm SCM implementation). Instead of playing games with init call levels to make sure that the custom implementations are registered after the generic one, make sure that get_next_variable() is actually supported before registering the generic ops. Signed-off-by: Johan Hovold <[email protected]> Signed-off-by: Ard Biesheuvel <[email protected]>
1 parent 301de9a commit bad267f

File tree

1 file changed

+22
-0
lines changed
  • drivers/firmware/efi

1 file changed

+22
-0
lines changed

drivers/firmware/efi/efi.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,27 @@ static const struct attribute_group efi_subsys_attr_group = {
187187
static struct efivars generic_efivars;
188188
static struct efivar_operations generic_ops;
189189

190+
static bool generic_ops_supported(void)
191+
{
192+
unsigned long name_size;
193+
efi_status_t status;
194+
efi_char16_t name;
195+
efi_guid_t guid;
196+
197+
name_size = sizeof(name);
198+
199+
status = efi.get_next_variable(&name_size, &name, &guid);
200+
if (status == EFI_UNSUPPORTED)
201+
return false;
202+
203+
return true;
204+
}
205+
190206
static int generic_ops_register(void)
191207
{
208+
if (!generic_ops_supported())
209+
return 0;
210+
192211
generic_ops.get_variable = efi.get_variable;
193212
generic_ops.get_next_variable = efi.get_next_variable;
194213
generic_ops.query_variable_store = efi_query_variable_store;
@@ -202,6 +221,9 @@ static int generic_ops_register(void)
202221

203222
static void generic_ops_unregister(void)
204223
{
224+
if (!generic_ops.get_variable)
225+
return;
226+
205227
efivars_unregister(&generic_efivars);
206228
}
207229

0 commit comments

Comments
 (0)