Skip to contentSkip to conversation

acpi: Fix out of bounds access in grub_acpi_xsdt_find_table()

PATCH In review Benjamin Herrenschmidt 6 participants 7 messages Oct 16, 2024 – Oct 17, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 acpi: Fix out of bounds access in grub_acpi_xsdt_find_table()

The calculation of the size of the table was incorrect (copy/pasta from grub_acpi_rsdt_find_table() I assume...). The entries are 64-bit long.

This causes us to access beyond the end of the table which is causing crashes during boot on some systems. Typically this is causing a crash on VMWare when using UEFI and enabling serial autodetection, as

grub_acpi_find_table (GRUB_ACPI_SPCR_SIGNATURE);

Will goes past the end of the table (the SPCR table doesn't exits)

---
 grub-core/kern/acpi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
grub-core/kern/acpi.c +0 -0
index 48ded4e2e..8ff0835d5 100644
@@ -75,7 +75,7 @@ grub_acpi_xsdt_find_table (struct

grub_acpi_table_header *xsdt, const char *sig)

     return 0;

ptr = (grub_unaligned_uint64_t *) (xsdt + 1);
- s = (xsdt->length - sizeof (*xsdt)) / sizeof (grub_uint32_t);
+ s = (xsdt->length - sizeof (*xsdt)) / sizeof (grub_uint64_t); for (; s; s--, ptr++)

     {
       struct grub_acpi_table_header *tbl;

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

Reviewed-by on v1 1/1
#1 lore raw
Quoted 32 lines · Benjamin Herrenschmidt

The calculation of the size of the table was incorrect (copy/pasta from grub_acpi_rsdt_find_table() I assume...). The entries are 64-bit long.

This causes us to access beyond the end of the table which is causing crashes during boot on some systems. Typically this is causing a crash on VMWare when using UEFI and enabling serial autodetection, as

grub_acpi_find_table (GRUB_ACPI_SPCR_SIGNATURE);

Will goes past the end of the table (the SPCR table doesn't exits)

---
 grub-core/kern/acpi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
grub-core/kern/acpi.c +1 -1
index 48ded4e2e..8ff0835d5 100644
@@ -75,7 +75,7 @@ grub_acpi_xsdt_find_table (struct
 grub_acpi_table_header *xsdt, const char *sig)
     return 0;
 
   ptr = (grub_unaligned_uint64_t *) (xsdt + 1);
-  s = (xsdt->length - sizeof (*xsdt)) / sizeof (grub_uint32_t);
+  s = (xsdt->length - sizeof (*xsdt)) / sizeof (grub_uint64_t);
   for (; s; s--, ptr++)
     {
       struct grub_acpi_table_header *tbl;
Quoted 5 lines

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#3 lore raw
In reply to Benjamin Herrenschmidt

We have reverted the SPCR table patches in Debian due to crashes, I guess this might have been the reason.

Quoted 30 lines · Benjamin Herrenschmidt

The calculation of the size of the table was incorrect (copy/pasta from grub_acpi_rsdt_find_table() I assume...). The entries are 64-bit long.

This causes us to access beyond the end of the table which is causing crashes during boot on some systems. Typically this is causing a crash on VMWare when using UEFI and enabling serial autodetection, as

grub_acpi_find_table (GRUB_ACPI_SPCR_SIGNATURE);

Will goes past the end of the table (the SPCR table doesn't exits)

---
 grub-core/kern/acpi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
grub-core/kern/acpi.c +1 -1
index 48ded4e2e..8ff0835d5 100644
@@ -75,7 +75,7 @@ grub_acpi_xsdt_find_table (struct
 grub_acpi_table_header *xsdt, const char *sig)
     return 0;
 
   ptr = (grub_unaligned_uint64_t *) (xsdt + 1);
-  s = (xsdt->length - sizeof (*xsdt)) / sizeof (grub_uint32_t);
+  s = (xsdt->length - sizeof (*xsdt)) / sizeof (grub_uint64_t);
   for (; s; s--, ptr++)
     {
Quoted 2 lines
       struct grub_acpi_table_header *tbl;

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

Reviewed-by Ross Philipson on v1 1/1
#5 lore raw
In reply to Benjamin Herrenschmidt
Quoted 2 lines · Benjamin Herrenschmidt

The calculation of the size of the table was incorrect (copy/pasta from grub_acpi_rsdt_find_table() I assume...). The entries are 64-bit long.

Yup that is correct for XSDT entries, the are 64b each.

Quoted 30 lines

This causes us to access beyond the end of the table which is causing crashes during boot on some systems. Typically this is causing a crash on VMWare when using UEFI and enabling serial autodetection, as

grub_acpi_find_table (GRUB_ACPI_SPCR_SIGNATURE);

Will goes past the end of the table (the SPCR table doesn't exits)

---
  grub-core/kern/acpi.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
grub-core/kern/acpi.c +1 -1
index 48ded4e2e..8ff0835d5 100644
@@ -75,7 +75,7 @@ grub_acpi_xsdt_find_table (struct
 grub_acpi_table_header *xsdt, const char *sig)
      return 0;
 
    ptr = (grub_unaligned_uint64_t *) (xsdt + 1);
-  s = (xsdt->length - sizeof (*xsdt)) / sizeof (grub_uint32_t);
+  s = (xsdt->length - sizeof (*xsdt)) / sizeof (grub_uint64_t);
    for (; s; s--, ptr++)
      {
        struct grub_acpi_table_header *tbl;
Quoted 4 lines

_______________________________________________
Grub-devel mailing list
[email protected]
https://urldefense.com/v3/__https://lists.gnu.org/mailman/listinfo/grub-devel__;!!ACWV5N9M2RV99hQ!LZzJNevc29nuiPlTkhDXJRkXuWKLUkb0jxeBN_xft2rReT26AZmn6hIklTw9WDYSLkPDPGGJ1DXZ-RVYDd-Y0e8$

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

Tested-by Renata Ravanelli on v1 1/1
#6 lore raw
In reply to Benjamin Herrenschmidt
Quoted 7 lines · Benjamin Herrenschmidt

The calculation of the size of the table was incorrect (copy/pasta from grub_acpi_rsdt_find_table() I assume...). The entries are 64-bit long.

This causes us to access beyond the end of the table which is causing crashes during boot on some systems. Typically this is causing a crash on VMWare when using UEFI and enabling serial autodetection, as

Quoted 5 lines

grub_acpi_find_table (GRUB_ACPI_SPCR_SIGNATURE);

Will goes past the end of the table (the SPCR table doesn't exits)

This can be marked as:

per https://bugzilla.redhat.com/show_bug.cgi?id=2317048#c35 .

Signature · 13 lines
Adam Williamson (he/him/his)
Fedora QA
Fedora Chat: @adamwill:fedora.im | Mastodon: @[email protected]
https://www.happyassassin.net





_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#4 lore raw
In reply to Mate Kukri
Quoted 2 lines · Mate Kukri

We have reverted the SPCR table patches in Debian due to crashes, I guess this might have been the reason.

Quite likely !

The bug would be triggered by trying to search for a table that doesn't exist, which I think in grub today mostly happens with SPCR which may or may not be there.

It might be worth re-enabling in Debian after that fix. The SPCR is the only realistic way of getting a serial console on EC2 metal instances for example :)

Cheers,
Ben.

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel