[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] commands/acpi: Fix furthering address the tables based upon the
From: |
Qiumiao Zhang |
Subject: |
[PATCH] commands/acpi: Fix furthering address the tables based upon the Entry field of XSDT |
Date: |
Mon, 11 Dec 2023 17:20:25 +0800 |
According to the ACPI specification, the Entry field of XSDT containsts an
array of 64-bit physical addresses that point to other DESCRIPTION_HEADERs.
But entry_ptr is defined as a 32-bit pointer, which result in mistakenly
treating each 64-bit length address as two 32-bit length addresses when
iterating through the Entry field of XSDT.
Fix the issue by using the correct address length during the iteration process.
Signed-off-by: Qiumiao Zhang <zhangqiumiao1@huawei.com>
---
grub-core/commands/acpi.c | 34 +++++++++++++++++++++++-----------
1 file changed, 23 insertions(+), 11 deletions(-)
diff --git a/grub-core/commands/acpi.c b/grub-core/commands/acpi.c
index 1c034463c..12b4a84eb 100644
--- a/grub-core/commands/acpi.c
+++ b/grub-core/commands/acpi.c
@@ -490,12 +490,12 @@ grub_cmd_acpi (struct grub_extcmd_context *ctxt, int
argc, char **args)
if (rsdp)
{
- grub_uint32_t *entry_ptr;
+ grub_uint8_t *entry_ptr;
char *exclude = 0;
char *load_only = 0;
char *ptr;
- /* RSDT consists of header and an array of 32-bit pointers. */
- struct grub_acpi_table_header *rsdt;
+ int offset = 0;
+ struct grub_acpi_table_header *table_head;
exclude = state[0].set ? grub_strdup (state[0].arg) : 0;
if (exclude)
@@ -515,20 +515,32 @@ grub_cmd_acpi (struct grub_extcmd_context *ctxt, int
argc, char **args)
rev1 = ! rsdp->revision;
rev2 = rsdp->revision;
if (rev2 && ((struct grub_acpi_table_header *) (grub_addr_t) ((struct
grub_acpi_rsdp_v20 *) rsdp)->xsdt_addr) != NULL)
- rsdt = (struct grub_acpi_table_header *) (grub_addr_t) ((struct
grub_acpi_rsdp_v20 *) rsdp)->xsdt_addr;
+ {
+ /* XSDT consists of header and an array of 64-bit pointers. */
+ table_head = (struct grub_acpi_table_header *) (grub_addr_t) ((struct
grub_acpi_rsdp_v20 *) rsdp)->xsdt_addr;
+ offset = sizeof(((struct grub_acpi_rsdp_v20 *) rsdp)->xsdt_addr);
+ }
else
- rsdt = (struct grub_acpi_table_header *) (grub_addr_t) rsdp->rsdt_addr;
+ {
+ /* RSDT consists of header and an array of 32-bit pointers. */
+ table_head = (struct grub_acpi_table_header *) (grub_addr_t)
rsdp->rsdt_addr;
+ offset = sizeof(rsdp->rsdt_addr);
+ }
/* Load host tables. */
- for (entry_ptr = (grub_uint32_t *) (rsdt + 1);
- entry_ptr < (grub_uint32_t *) (((grub_uint8_t *) rsdt)
- + rsdt->length);
- entry_ptr++)
+ for (entry_ptr = (grub_uint8_t *) (table_head + 1);
+ entry_ptr < (grub_uint8_t *) (((grub_uint8_t *) table_head)
+ + table_head->length);
+ entry_ptr += offset)
{
char signature[5];
struct efiemu_acpi_table *table;
- struct grub_acpi_table_header *curtable
- = (struct grub_acpi_table_header *) (grub_addr_t) *entry_ptr;
+ struct grub_acpi_table_header *curtable;
+ if (offset == sizeof(rsdp->rsdt_addr))
+ curtable = (struct grub_acpi_table_header *) (grub_addr_t)
*((grub_uint32_t *)entry_ptr);
+ else
+ curtable = (struct grub_acpi_table_header *) (grub_addr_t)
*((grub_uint64_t *)entry_ptr);
+
signature[4] = 0;
for (i = 0; i < 4;i++)
signature[i] = grub_tolower (curtable->signature[i]);
--
2.28.0.windows.1
- [PATCH] commands/acpi: Fix furthering address the tables based upon the Entry field of XSDT,
Qiumiao Zhang <=