Blame SOURCES/0045-CSRT-fixed-use-of-optional-ResourceInfo.patch

9897bb
From 0d87ee42adda7837bec3cc0ff86e40c2f2e8dc4f Mon Sep 17 00:00:00 2001
9897bb
From: Al Stone <ahs3@redhat.com>
9897bb
Date: Fri, 9 Jul 2021 14:52:55 -0600
9897bb
Subject: [PATCH 45/45] CSRT: fixed use of optional ResourceInfo
9897bb
9897bb
In a resource sub-sub-table, there may be a ResourceInfo entry.  Neither
9897bb
the compiler nor disassembler accounted for that possibility properly.
9897bb
9897bb
Signed-off-by: Al Stone <ahs3@redhat.com>
9897bb
---
9897bb
 source/common/dmtbdump1.c  | 43 +++++++++++++++++++++-----------------
9897bb
 source/compiler/dttable1.c | 28 +++++++++++++------------
9897bb
 2 files changed, 39 insertions(+), 32 deletions(-)
9897bb
9897bb
Index: acpica-unix2-20210604/source/common/dmtbdump1.c
9897bb
===================================================================
9897bb
--- acpica-unix2-20210604.orig/source/common/dmtbdump1.c
9897bb
+++ acpica-unix2-20210604/source/common/dmtbdump1.c
9897bb
@@ -374,11 +374,13 @@ AcpiDmDumpCsrt (
9897bb
     ACPI_CSRT_GROUP         *Subtable;
9897bb
     ACPI_CSRT_SHARED_INFO   *SharedInfoTable;
9897bb
     ACPI_CSRT_DESCRIPTOR    *SubSubtable;
9897bb
-    UINT32                  Length = AcpiUtReadUint32 (&Table->Length);
9897bb
+    UINT32                  TableLength = AcpiUtReadUint32 (&Table->Length);
9897bb
     UINT32                  Offset = sizeof (ACPI_TABLE_CSRT);
9897bb
     UINT32                  SubOffset;
9897bb
     UINT32                  SubSubOffset;
9897bb
     UINT32                  InfoLength;
9897bb
+    UINT32                  SubtableLength;
9897bb
+    UINT32                  SubSubtableLength;
9897bb
 
9897bb
 
9897bb
     /* The main table only contains the ACPI header, thus already handled */
9897bb
@@ -386,13 +388,14 @@ AcpiDmDumpCsrt (
9897bb
     /* Subtables (Resource Groups) */
9897bb
 
9897bb
     Subtable = ACPI_ADD_PTR (ACPI_CSRT_GROUP, Table, Offset);
9897bb
-    while (Offset < Length)
9897bb
+    while (Offset < TableLength)
9897bb
     {
9897bb
         /* Resource group subtable */
9897bb
 
9897bb
+        SubtableLength = AcpiUtReadUint32 (&Subtable->Length);
9897bb
         AcpiOsPrintf ("\n");
9897bb
-        Status = AcpiDmDumpTable (Length, Offset, Subtable,
9897bb
-            Subtable->Length, AcpiDmTableInfoCsrt0);
9897bb
+        Status = AcpiDmDumpTable (TableLength, Offset, Subtable,
9897bb
+            SubtableLength, AcpiDmTableInfoCsrt0);
9897bb
         if (ACPI_FAILURE (Status))
9897bb
         {
9897bb
             return;
9897bb
@@ -405,26 +408,28 @@ AcpiDmDumpCsrt (
9897bb
             Offset + SubOffset);
9897bb
 
9897bb
         AcpiOsPrintf ("\n");
9897bb
-        Status = AcpiDmDumpTable (Length, Offset + SubOffset, SharedInfoTable,
9897bb
-            sizeof (ACPI_CSRT_SHARED_INFO), AcpiDmTableInfoCsrt1);
9897bb
+        Status = AcpiDmDumpTable (TableLength, Offset + SubOffset,
9897bb
+	    SharedInfoTable, sizeof (ACPI_CSRT_SHARED_INFO),
9897bb
+	    AcpiDmTableInfoCsrt1);
9897bb
         if (ACPI_FAILURE (Status))
9897bb
         {
9897bb
             return;
9897bb
         }
9897bb
 
9897bb
-        SubOffset += Subtable->SharedInfoLength;
9897bb
+        SubOffset += AcpiUtReadUint32 (&Subtable->SharedInfoLength);
9897bb
 
9897bb
         /* Sub-Subtables (Resource Descriptors) */
9897bb
 
9897bb
         SubSubtable = ACPI_ADD_PTR (ACPI_CSRT_DESCRIPTOR, Table,
9897bb
             Offset + SubOffset);
9897bb
 
9897bb
-        while ((SubOffset < Subtable->Length) &&
9897bb
-              ((Offset + SubOffset) < Length))
9897bb
+        while ((SubOffset < SubtableLength) &&
9897bb
+              ((Offset + SubOffset) < TableLength))
9897bb
         {
9897bb
+	    SubSubtableLength = AcpiUtReadUint32 (&SubSubtable->Length);
9897bb
             AcpiOsPrintf ("\n");
9897bb
-            Status = AcpiDmDumpTable (Length, Offset + SubOffset, SubSubtable,
9897bb
-                SubSubtable->Length, AcpiDmTableInfoCsrt2);
9897bb
+            Status = AcpiDmDumpTable (TableLength, Offset + SubOffset,
9897bb
+	        SubSubtable, SubSubtableLength, AcpiDmTableInfoCsrt2);
9897bb
             if (ACPI_FAILURE (Status))
9897bb
             {
9897bb
                 return;
9897bb
@@ -434,11 +439,12 @@ AcpiDmDumpCsrt (
9897bb
 
9897bb
             /* Resource-specific info buffer */
9897bb
 
9897bb
-            InfoLength = SubSubtable->Length - SubSubOffset;
9897bb
+            InfoLength = SubSubtableLength - SubSubOffset;
9897bb
             if (InfoLength)
9897bb
             {
9897bb
-                Status = AcpiDmDumpTable (Length,
9897bb
-                    Offset + SubOffset + SubSubOffset, Table,
9897bb
+                Status = AcpiDmDumpTable (TableLength,
9897bb
+		    Offset + SubOffset + SubSubOffset,
9897bb
+		    (UINT8 *)SubSubtable + SubSubOffset,
9897bb
                     InfoLength, AcpiDmTableInfoCsrt2a);
9897bb
                 if (ACPI_FAILURE (Status))
9897bb
                 {
9897bb
@@ -448,16 +454,15 @@ AcpiDmDumpCsrt (
9897bb
 
9897bb
             /* Point to next sub-subtable */
9897bb
 
9897bb
-            SubOffset += SubSubtable->Length;
9897bb
+            SubOffset += SubSubtableLength;
9897bb
             SubSubtable = ACPI_ADD_PTR (ACPI_CSRT_DESCRIPTOR, SubSubtable,
9897bb
-                SubSubtable->Length);
9897bb
+                SubSubtableLength);
9897bb
         }
9897bb
 
9897bb
         /* Point to next subtable */
9897bb
 
9897bb
-        Offset += Subtable->Length;
9897bb
-        Subtable = ACPI_ADD_PTR (ACPI_CSRT_GROUP, Subtable,
9897bb
-            Subtable->Length);
9897bb
+        Offset += SubtableLength;
9897bb
+        Subtable = ACPI_ADD_PTR (ACPI_CSRT_GROUP, Subtable, SubtableLength);
9897bb
     }
9897bb
 }
9897bb
 
9897bb
Index: acpica-unix2-20210604/source/compiler/dttable1.c
9897bb
===================================================================
9897bb
--- acpica-unix2-20210604.orig/source/compiler/dttable1.c
9897bb
+++ acpica-unix2-20210604/source/compiler/dttable1.c
9897bb
@@ -353,14 +353,16 @@ DtCompileCsrt (
9897bb
     DT_SUBTABLE             *Subtable;
9897bb
     DT_SUBTABLE             *ParentTable;
9897bb
     DT_FIELD                **PFieldList = (DT_FIELD **) List;
9897bb
-    UINT32                  DescriptorCount;
9897bb
+    UINT32                  DescriptorLength;
9897bb
     UINT32                  GroupLength;
9897bb
     UINT32                  Tmp;
9897bb
+    UINT32                  Offset;
9897bb
 
9897bb
 
9897bb
     /* Subtables (Resource Groups) */
9897bb
 
9897bb
     ParentTable = DtPeekSubtable ();
9897bb
+                               
9897bb
     while (*PFieldList)
9897bb
     {
9897bb
         /* Resource group subtable */
9897bb
@@ -375,16 +377,13 @@ DtCompileCsrt (
9897bb
         /* Compute the number of resource descriptors */
9897bb
 
9897bb
         Tmp = AcpiUtReadUint32 (&(ACPI_CAST_PTR (ACPI_CSRT_GROUP,
9897bb
-                                Subtable->Buffer))->Length);
9897bb
+                  Subtable->Buffer))->Length);
9897bb
         GroupLength = Tmp;
9897bb
         Tmp = AcpiUtReadUint32 (&(ACPI_CAST_PTR (ACPI_CSRT_GROUP,
9897bb
-                                Subtable->Buffer))->SharedInfoLength);
9897bb
+                  Subtable->Buffer))->SharedInfoLength);
9897bb
         GroupLength -= Tmp;
9897bb
         GroupLength -= sizeof (ACPI_CSRT_GROUP);
9897bb
 
9897bb
-        DescriptorCount = (GroupLength  /
9897bb
-            sizeof (ACPI_CSRT_DESCRIPTOR));
9897bb
-
9897bb
         DtInsertSubtable (ParentTable, Subtable);
9897bb
         DtPushSubtable (Subtable);
9897bb
         ParentTable = DtPeekSubtable ();
9897bb
@@ -399,10 +398,13 @@ DtCompileCsrt (
9897bb
         }
9897bb
 
9897bb
         DtInsertSubtable (ParentTable, Subtable);
9897bb
+        DtPushSubtable (Subtable);
9897bb
+        ParentTable = DtPeekSubtable ();
9897bb
 
9897bb
         /* Sub-Subtables (Resource Descriptors) */
9897bb
 
9897bb
-        while (*PFieldList && DescriptorCount)
9897bb
+        Offset = 0;
9897bb
+        while (*PFieldList && (Offset < GroupLength))
9897bb
         {
9897bb
 
9897bb
             Status = DtCompileTable (PFieldList, AcpiDmTableInfoCsrt2,
9897bb
@@ -411,6 +413,10 @@ DtCompileCsrt (
9897bb
             {
9897bb
                 return (Status);
9897bb
             }
9897bb
+	    DescriptorLength = AcpiUtReadUint32 (
9897bb
+	                           &(ACPI_CAST_PTR (ACPI_CSRT_GROUP,
9897bb
+                                   Subtable->Buffer))->Length);
9897bb
+
9897bb
 
9897bb
             DtInsertSubtable (ParentTable, Subtable);
9897bb
 
9897bb
@@ -420,11 +426,7 @@ DtCompileCsrt (
9897bb
             {
9897bb
                 Status = DtCompileTable (PFieldList, AcpiDmTableInfoCsrt2a,
9897bb
                     &Subtable);
9897bb
-                if (ACPI_FAILURE (Status))
9897bb
-                {
9897bb
-                    return (Status);
9897bb
-                }
9897bb
-                if (Subtable)
9897bb
+                if (ACPI_SUCCESS (Status) && Subtable)
9897bb
                 {
9897bb
                     DtInsertSubtable (ParentTable, Subtable);
9897bb
                 }
9897bb
@@ -432,7 +434,7 @@ DtCompileCsrt (
9897bb
 
9897bb
             DtPopSubtable ();
9897bb
             ParentTable = DtPeekSubtable ();
9897bb
-            DescriptorCount--;
9897bb
+            Offset += DescriptorLength;
9897bb
         }
9897bb
 
9897bb
         DtPopSubtable ();