Skip to contentSkip to conversation

EFI: Fix relocating ESRT for dom0

PATCH In review Marek Marczykowski-Górecki 3 participants 4 messages Feb 11

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 EFI: Fix relocating ESRT for dom0

Fix calculating the table size - it consists of a header + entries, not just entries.
This bug caused the last entry to have garbage in its final fields, including LowestSupportedFwVersion and CapsuleFlags, which (usually) made fwupd to detect firmware update availability, but refuse actually installing it.

Fixes dc7da0874ba4 ("EFI: preserve the System Resource Table for dom0")
---
 xen/common/efi/boot.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
xen/common/efi/boot.c +2 -1
index 5b84dbf26e5e..45015a0dd583 100644
@@ -675,7 +675,8 @@ static size_t __init get_esrt_size(const EFI_MEMORY_DESCRIPTOR *desc)
     if ( esrt_ptr->FwResourceCount > available_len / sizeof(esrt_ptr->Entries[0]) )
         return 0;
 
-    return esrt_ptr->FwResourceCount * sizeof(esrt_ptr->Entries[0]);
+    return offsetof(EFI_SYSTEM_RESOURCE_TABLE, Entries) +
+        esrt_ptr->FwResourceCount * sizeof(esrt_ptr->Entries[0]);
 }
 
 static EFI_GUID __initdata esrt_guid = EFI_SYSTEM_RESOURCE_TABLE_GUID;
Signature · 1 line
2.51.0
#1 lore raw
Quoted 5 lines · Marek Marczykowski-Górecki

Fix calculating the table size - it consists of a header + entries, not just entries.
This bug caused the last entry to have garbage in its final fields, including LowestSupportedFwVersion and CapsuleFlags, which (usually) made fwupd to detect firmware update availability, but refuse actually

"made fwupd able to"

Quoted 13 lines

installing it.

Fixes dc7da0874ba4 ("EFI: preserve the System Resource Table for dom0")
---
 xen/common/efi/boot.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
xen/common/efi/boot.c +0 -0
index 5b84dbf26e5e..45015a0dd583 100644

xen/common/efi/boot.c static size_t __init get_esrt_size(const EFI_MEMORY_DESCRIPTOR *desc) · line 679

Quoted 6 lines
xen/common/efi/boot.c +2 -1
@@ -675,7 +675,8 @@ static size_t __init get_esrt_size(const EFI_MEMORY_DESCRIPTOR *desc)
     if ( esrt_ptr->FwResourceCount > available_len / sizeof(esrt_ptr->Entries[0]) )
         return 0;
 
-    return esrt_ptr->FwResourceCount * sizeof(esrt_ptr->Entries[0]);
+    return offsetof(EFI_SYSTEM_RESOURCE_TABLE, Entries) +
+        esrt_ptr->FwResourceCount * sizeof(esrt_ptr->Entries[0]);

offsetof(EFI_SYSTEM_RESOURCE_TABLE, Entries[esrt_ptr->FwResourceCount])

is a shorter expression with the same answer, and a pattern we use elsewhere.  I can fix on commit if you're happy.

~Andrew

#2 lore raw
Quoted 25 lines · Andrew Cooper
Quoted 5 lines · Marek Marczykowski-Górecki

Fix calculating the table size - it consists of a header + entries, not just entries.
This bug caused the last entry to have garbage in its final fields, including LowestSupportedFwVersion and CapsuleFlags, which (usually) made fwupd to detect firmware update availability, but refuse actually

"made fwupd able to"

Quoted 16 lines

installing it.

Fixes dc7da0874ba4 ("EFI: preserve the System Resource Table for dom0")
---
 xen/common/efi/boot.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
xen/common/efi/boot.c +0 -0
index 5b84dbf26e5e..45015a0dd583 100644
@@ -675,7 +675,8 @@ static size_t __init get_esrt_size(const EFI_MEMORY_DESCRIPTOR *desc)
     if ( esrt_ptr->FwResourceCount > available_len / sizeof(esrt_ptr->Entries[0]) )
         return 0;
 
Quoted 8 lines

xen/common/efi/boot.c static size_t __init get_esrt_size(const EFI_MEMORY_DESCRIPTOR *desc) · line 679

Quoted 3 lines
xen/common/efi/boot.c +2 -1
-    return esrt_ptr->FwResourceCount * sizeof(esrt_ptr->Entries[0]);
+    return offsetof(EFI_SYSTEM_RESOURCE_TABLE, Entries) +
+        esrt_ptr->FwResourceCount * sizeof(esrt_ptr->Entries[0]);

offsetof(EFI_SYSTEM_RESOURCE_TABLE, Entries[esrt_ptr->FwResourceCount])

is a shorter expression with the same answer, and a pattern we use elsewhere.  I can fix on commit if you're happy.

Fine with me, thanks.

Signature · 3 lines
Best Regards,
Marek Marczykowski-Górecki
Invisible Things Lab
Acked-by on v1 1/1
#3 lore raw
In reply to Marek Marczykowski-Górecki
Quoted 18 lines · Marek Marczykowski-Górecki

Fix calculating the table size - it consists of a header + entries, not just entries.
This bug caused the last entry to have garbage in its final fields, including LowestSupportedFwVersion and CapsuleFlags, which (usually) made fwupd to detect firmware update availability, but refuse actually installing it.

Fixes dc7da0874ba4 ("EFI: preserve the System Resource Table for dom0")

---
xen/common/efi/boot.c | 3 ++-

1 file changed, 2 insertions(+), 1 deletion(-)
xen/common/efi/boot.c +0 -0
index 5b84dbf26e5e..45015a0dd583 100644

xen/common/efi/boot.c static size_t __init get_esrt_size(const EFI_MEMORY_DESCRIPTOR *desc) · line 682

Quoted 9 lines
xen/common/efi/boot.c +2 -1
@@ -675,7 +675,8 @@ static size_t __init get_esrt_size(const EFI_MEMORY_DESCRIPTOR *desc)
    if ( esrt_ptr->FwResourceCount > available_len / sizeof(esrt_ptr->Entries[0]) )
        return 0;
 
-    return esrt_ptr->FwResourceCount * sizeof(esrt_ptr->Entries[0]);
+    return offsetof(EFI_SYSTEM_RESOURCE_TABLE, Entries) +
+        esrt_ptr->FwResourceCount * sizeof(esrt_ptr->Entries[0]);
 }
 
 static EFI_GUID __initdata esrt_guid = EFI_SYSTEM_RESOURCE_TABLE_GUID;

With Andy's suggestions,