ACPICA: Add detection of corrupted/replaced DSDT
authorLin Ming <ming.m.lin@intel.com>
Thu, 1 Apr 2010 02:47:56 +0000 (10:47 +0800)
committerLen Brown <len.brown@intel.com>
Tue, 20 Apr 2010 14:43:16 +0000 (10:43 -0400)
This change adds support to detect a DSDT that has been corrupted
and/or replaced from outside the OS (by firmware). This is
typically catastrophic for the system, but has been seen on
some machines.

https://bugzilla.kernel.org/show_bug.cgi?id=14679

Signed-off-by: Lin Ming <ming.m.lin@intel.com>
Signed-off-by: Bob Moore <robert.moore@intel.com>
Signed-off-by: Len Brown <len.brown@intel.com>
drivers/acpi/acpica/acglobal.h
drivers/acpi/acpica/actables.h
drivers/acpi/acpica/psxface.c
drivers/acpi/acpica/tbutils.c
drivers/acpi/acpica/tbxface.c

index 2b2e61ed373ee26e8fdfe3fca6239ee839c73d7f..a419fe98a5fcdad77811ac7d7b0b6ab4055d47dc 100644 (file)
@@ -165,6 +165,11 @@ ACPI_EXTERN struct acpi_generic_address acpi_gbl_xpm1a_enable;
 ACPI_EXTERN struct acpi_generic_address acpi_gbl_xpm1b_status;
 ACPI_EXTERN struct acpi_generic_address acpi_gbl_xpm1b_enable;
 
+/* DSDT information. Used to check for DSDT corruption */
+
+ACPI_EXTERN struct acpi_table_desc *acpi_gbl_DSDT;
+ACPI_EXTERN struct acpi_table_header acpi_gbl_original_dsdt_header;
+
 /*
  * Handle both ACPI 1.0 and ACPI 2.0 Integer widths. The integer width is
  * determined by the revision of the DSDT: If the DSDT revision is less than
index 8ff3b741df285527ae89729cfc1b38bbe6a58036..fc52b6f2d69c6a29904908edb3e8452aac1fb790 100644 (file)
@@ -107,6 +107,8 @@ u8 acpi_tb_checksum(u8 *buffer, u32 length);
 acpi_status
 acpi_tb_verify_checksum(struct acpi_table_header *table, u32 length);
 
+void acpi_tb_check_dsdt_header(void);
+
 void
 acpi_tb_install_table(acpi_physical_address address,
                      char *signature, u32 table_index);
index 6064dd4e94c25fdb7485ee2e782d4c601a4fe30f..67e7ad51705143e135a42cc91795da8ce983cb09 100644 (file)
@@ -220,6 +220,10 @@ acpi_status acpi_ps_execute_method(struct acpi_evaluate_info *info)
 
        ACPI_FUNCTION_TRACE(ps_execute_method);
 
+       /* Quick validation of DSDT header */
+
+       acpi_tb_check_dsdt_header();
+
        /* Validate the Info and method Node */
 
        if (!info || !info->resolved_node) {
index f47a70e20063263e8b7a283c148471d99ab6b2da..07bc7437f82bca5cd8bc5e1ee569cd8efbae5321 100644 (file)
@@ -347,6 +347,44 @@ u8 acpi_tb_checksum(u8 *buffer, u32 length)
        return sum;
 }
 
+/*******************************************************************************
+ *
+ * FUNCTION:    acpi_tb_check_dsdt_header
+ *
+ * PARAMETERS:  None
+ *
+ * RETURN:      None
+ *
+ * DESCRIPTION: Quick compare to check validity of the DSDT. This will detect
+ *              if the DSDT has been replaced from outside the OS and/or if
+ *              the DSDT header has been corrupted.
+ *
+ ******************************************************************************/
+
+void acpi_tb_check_dsdt_header(void)
+{
+
+       /* Compare original length and checksum to current values */
+
+       if (acpi_gbl_original_dsdt_header.length !=
+           acpi_gbl_DSDT->pointer->length
+           || acpi_gbl_original_dsdt_header.checksum !=
+           acpi_gbl_DSDT->pointer->checksum) {
+               ACPI_ERROR((AE_INFO,
+                           "The DSDT has been corrupted or replaced - old, new headers below"));
+               acpi_tb_print_table_header(0, &acpi_gbl_original_dsdt_header);
+               acpi_tb_print_table_header(acpi_gbl_DSDT->address,
+                                          acpi_gbl_DSDT->pointer);
+
+               /* Disable further error messages */
+
+               acpi_gbl_original_dsdt_header.length =
+                   acpi_gbl_DSDT->pointer->length;
+               acpi_gbl_original_dsdt_header.checksum =
+                   acpi_gbl_DSDT->pointer->checksum;
+       }
+}
+
 /*******************************************************************************
  *
  * FUNCTION:    acpi_tb_install_table
index 684614d0d327b958d8ccfdf95bfae891f92d7866..30565100b94c0bb843ebd4e307eeb210a64c2436 100644 (file)
@@ -518,33 +518,25 @@ static acpi_status acpi_tb_load_namespace(void)
 
        (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
 
+       acpi_gbl_DSDT = &acpi_gbl_root_table_list.tables[ACPI_TABLE_INDEX_DSDT];
+
        /*
-        * Load the namespace. The DSDT is required, but any SSDT and PSDT tables
-        * are optional.
+        * Load the namespace. The DSDT is required, but any SSDT and
+        * PSDT tables are optional. Verify the DSDT.
         */
        if (!acpi_gbl_root_table_list.count ||
-           !ACPI_COMPARE_NAME(&
-                              (acpi_gbl_root_table_list.
-                               tables[ACPI_TABLE_INDEX_DSDT].signature),
-                              ACPI_SIG_DSDT)
-           ||
-           ACPI_FAILURE(acpi_tb_verify_table
-                        (&acpi_gbl_root_table_list.
-                         tables[ACPI_TABLE_INDEX_DSDT]))) {
+           !ACPI_COMPARE_NAME(&acpi_gbl_DSDT->signature, ACPI_SIG_DSDT) ||
+           ACPI_FAILURE(acpi_tb_verify_table(acpi_gbl_DSDT))) {
                status = AE_NO_ACPI_TABLES;
                goto unlock_and_exit;
        }
 
-       /* A valid DSDT is required */
-
-       status =
-           acpi_tb_verify_table(&acpi_gbl_root_table_list.
-                                tables[ACPI_TABLE_INDEX_DSDT]);
-       if (ACPI_FAILURE(status)) {
-
-               status = AE_NO_ACPI_TABLES;
-               goto unlock_and_exit;
-       }
+       /*
+        * Save the original DSDT header for detection of table corruption
+        * and/or replacement of the DSDT from outside the OS.
+        */
+       ACPI_MEMCPY(&acpi_gbl_original_dsdt_header, acpi_gbl_DSDT->pointer,
+                   sizeof(struct acpi_table_header));
 
        (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);