grub-devel.gnu.org archive mirror
 help / color / mirror / Atom feed
From: Qiumiao Zhang via Grub-devel <grub-devel@gnu.org>
To: <grub-devel@gnu.org>
Cc: Qiumiao Zhang <zhangqiumiao1@huawei.com>,
	fengtao40@huawei.com, yanan@huawei.com
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	[thread overview]
Message-ID: <20231211092025.1672-1-zhangqiumiao1@huawei.com> (raw)

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

             reply	other threads:[~2023-12-11  9:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-11  9:20 Qiumiao Zhang via Grub-devel [this message]
2023-12-11 19:50 ` [PATCH] commands/acpi: Fix furthering address the tables based upon the Entry field of XSDT Daniel Kiper

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231211092025.1672-1-zhangqiumiao1@huawei.com \
    --to=grub-devel@gnu.org \
    --cc=fengtao40@huawei.com \
    --cc=yanan@huawei.com \
    --cc=zhangqiumiao1@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).