Skip to contentSkip to conversation

EFI: Fix getting EFI variable list on some systems

PATCH Superseded Ross Lagerwall 3 participants 3 messages Mar 9, 2015 – Mar 10, 2015

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 EFI: Fix getting EFI variable list on some systems

Copy the entire output buffer to the guest because it may contain data beyond the output size that the firmware requires on a subsequent GetNextVariableName() call (e.g. a NULL character).

The spec requires that on each call, "the previous results" be passed in.

Without this change, the following (simplified) sequence would occur:
GetNextVariableName: in \0, out AdminPw\0, size 7
GetNextVariableName: in AdminPw\0, out UserPw\0, size 6
GetNextVariableName: in UserPww\0, NOT FOUND

---
 xen/common/efi/runtime.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/common/efi/runtime.c +1 -1
index 7ed5bfa..20772f3 100644
@@ -518,7 +518,7 @@ int efi_runtime_call(struct xenpf_efi_runtime_call *op)
 
             if ( !EFI_ERROR(status) &&
                  copy_to_guest(op->u.get_next_variable_name.name,
-                               name.raw, size) )
+                               name.raw, op->u.get_next_variable_name.size) )
                 rc = -EFAULT;
             op->u.get_next_variable_name.size = size;
         }
Signature · 1 line
2.1.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Ross Lagerwall

Copy the entire output buffer to the guest because it may contain data beyond the output size that the firmware requires on a subsequent GetNextVariableName() call (e.g. a NULL character).

Quoted 8 lines

The spec requires that on each call, "the previous results" be passed in.

Without this change, the following (simplified) sequence would occur:
GetNextVariableName: in \0, out AdminPw\0, size 7
GetNextVariableName: in AdminPw\0, out UserPw\0, size 6
GetNextVariableName: in UserPww\0, NOT FOUND

Quoted 17 lines
---
 xen/common/efi/runtime.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/common/efi/runtime.c +1 -1
index 7ed5bfa..20772f3 100644
@@ -518,7 +518,7 @@ int efi_runtime_call(struct xenpf_efi_runtime_call *op)
 
             if ( !EFI_ERROR(status) &&
                  copy_to_guest(op->u.get_next_variable_name.name,
-                               name.raw, size) )
+                               name.raw, op->u.get_next_variable_name.size) )
                 rc = -EFAULT;
             op->u.get_next_variable_name.size = size;
         }
#2 lore raw
In reply to Ross Lagerwall
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 09.03.15 at 17:47, <[email protected]> wrote:

Copy the entire output buffer to the guest because it may contain data beyond the output size that the firmware requires on a subsequent GetNextVariableName() call (e.g. a NULL character).

The spec requires that on each call, "the previous results" be passed in.

Without this change, the following (simplified) sequence would occur:
GetNextVariableName: in \0, out AdminPw\0, size 7
GetNextVariableName: in AdminPw\0, out UserPw\0, size 6
GetNextVariableName: in UserPww\0, NOT FOUND

As such behavior is outside the specification, please name the system needing this workaround: The runtime services function is documented to update *VariableNameSize only upon EFI_BUFFER_TOO_SMALL. A code comment would also seem to be on order, as otherwise people like me might be tempted to undo this again, as it's sub-optimal code for spec conforming firmware.

And to save me from having to do an incremental patch on top, you may want to consider switching to __copy_to_user() at once.

Jan