Skip to contentSkip to conversation

efivars: Respect "block" flag in efivar_entry_set_safe()

PATCH In review Jann Horn 2 participants 2 messages Feb 18, 2022 EFI

lore
Share & tools
lore

Jann Horn

author
#0 lore raw

PATCH 1/1 efivars: Respect "block" flag in efivar_entry_set_safe()

When the "block" flag is false, the old code would sometimes still call check_var_size(), which wrongly tells ->query_variable_store() that it can block.

As far as I can tell, this can't really materialize as a bug at the moment, because ->query_variable_store only does something on X86 with generic EFI, and in that configuration we always take the efivar_entry_set_nonblocking() path. So I'm not marking this for stable backporting.

Fixes ca0e30dcaa53 ("efi: Add nonblocking option to efi_query_variable_store()")

---

 drivers/firmware/efi/vars.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/firmware/efi/vars.c +4 -1
index abdc8a6a3963..cae590bd08f2 100644
@@ -742,6 +742,7 @@ int efivar_entry_set_safe(efi_char16_t *name, efi_guid_t vendor, u32 attributes,
 {
 	const struct efivar_operations *ops;
 	efi_status_t status;
+	unsigned long varsize;
 
 	if (!__efivars)
 		return -EINVAL;
@@ -764,15 +765,17 @@ int efivar_entry_set_safe(efi_char16_t *name, efi_guid_t vendor, u32 attributes,
 		return efivar_entry_set_nonblocking(name, vendor, attributes,
 						    size, data);
 
+	varsize = size + ucs2_strsize(name, 1024);
 	if (!block) {
 		if (down_trylock(&efivars_lock))
 			return -EBUSY;
+		status = check_var_size_nonblocking(attributes, varsize);
 	} else {
 		if (down_interruptible(&efivars_lock))
 			return -EINTR;
+		status = check_var_size(attributes, varsize);
 	}
 
-	status = check_var_size(attributes, size + ucs2_strsize(name, 1024));
 	if (status != EFI_SUCCESS) {
 		up(&efivars_lock);
 		return -ENOSPC;

base-commit: 83e396641110663d3c7bb25b9bc0c6a750359ecf

Signature · 1 line
2.35.1.473.g83b2b277ed-goog
maintainer
#1 lore raw
Quoted 5 lines · Jann Horn

When the "block" flag is false, the old code would sometimes still call check_var_size(), which wrongly tells ->query_variable_store() that it can block.

Quoted 7 lines

As far as I can tell, this can't really materialize as a bug at the moment, because ->query_variable_store only does something on X86 with generic EFI, and in that configuration we always take the efivar_entry_set_nonblocking() path. So I'm not marking this for stable backporting.

Fixes ca0e30dcaa53 ("efi: Add nonblocking option to efi_query_variable_store()")

Thanks Jann. I'll queue this up.

Quoted 41 lines

---

 drivers/firmware/efi/vars.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/firmware/efi/vars.c +4 -1
index abdc8a6a3963..cae590bd08f2 100644
@@ -742,6 +742,7 @@ int efivar_entry_set_safe(efi_char16_t *name, efi_guid_t vendor, u32 attributes,
 {
        const struct efivar_operations *ops;
        efi_status_t status;
+       unsigned long varsize;
 
        if (!__efivars)
                return -EINVAL;
@@ -764,15 +765,17 @@ int efivar_entry_set_safe(efi_char16_t *name, efi_guid_t vendor, u32 attributes,
                return efivar_entry_set_nonblocking(name, vendor, attributes,
                                                    size, data);
 
+       varsize = size + ucs2_strsize(name, 1024);
        if (!block) {
                if (down_trylock(&efivars_lock))
                        return -EBUSY;
+               status = check_var_size_nonblocking(attributes, varsize);
        } else {
                if (down_interruptible(&efivars_lock))
                        return -EINTR;
+               status = check_var_size(attributes, varsize);
        }
 
-       status = check_var_size(attributes, size + ucs2_strsize(name, 1024));
        if (status != EFI_SUCCESS) {
                up(&efivars_lock);
                return -ENOSPC;

base-commit: 83e396641110663d3c7bb25b9bc0c6a750359ecf --
2.35.1.473.g83b2b277ed-goog