All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] commands/acpi: Fix furthering address the tables based upon the Entry field of XSDT
@ 2023-12-11  9:20 Qiumiao Zhang via Grub-devel
  2023-12-11 19:50 ` Daniel Kiper
  0 siblings, 1 reply; 2+ messages in thread
From: Qiumiao Zhang via Grub-devel @ 2023-12-11  9:20 UTC (permalink / raw)
  To: grub-devel; +Cc: Qiumiao Zhang, fengtao40, yanan

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


_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] commands/acpi: Fix furthering address the tables based upon the Entry field of XSDT
  2023-12-11  9:20 [PATCH] commands/acpi: Fix furthering address the tables based upon the Entry field of XSDT Qiumiao Zhang via Grub-devel
@ 2023-12-11 19:50 ` Daniel Kiper
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Kiper @ 2023-12-11 19:50 UTC (permalink / raw)
  To: Qiumiao Zhang; +Cc: grub-devel, fengtao40, yanan

On Mon, Dec 11, 2023 at 05:20:25PM +0800, Qiumiao Zhang via Grub-devel wrote:
> 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>

Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com> but I will fix some
minor things before push. This is an exception because it would be nice
to have this patch in the release and we are behind the schedule. Next
time I will ask you to do that...

Daniel

_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-12-11 19:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-11  9:20 [PATCH] commands/acpi: Fix furthering address the tables based upon the Entry field of XSDT Qiumiao Zhang via Grub-devel
2023-12-11 19:50 ` Daniel Kiper

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.