ACPI: fix APEI related table size checking
authorHuang Ying <ying.huang@intel.com>
Tue, 16 Oct 2012 15:26:36 +0000 (17:26 +0200)
committerHuang Ying <ying.huang@intel.com>
Tue, 16 Oct 2012 15:26:36 +0000 (17:26 +0200)
On Huang Ying's machine:

erst_tab->header_length == sizeof(struct acpi_table_einj)

but Yinghai reported that on his machine,

erst_tab->header_length == sizeof(struct acpi_table_einj) -
sizeof(struct acpi_table_header)

To make erst table size checking code works on all systems, both
testing are treated as PASS.

Same situation applies to einj_tab->header_length, so corresponding
table size checking is changed in similar way too.

Originally-by: Yinghai Lu <yinghai@kernel.org>
Signed-off-by: Huang Ying <ying.huang@intel.com>
- use switch() for better readability
- add comment explaining why a formally invalid size it also being
  accepted
- check erst_tab->header.length before even looking at
  erst_tab->header_length
- prefer sizeof(*erst_tab) over sizeof(struct acpi_table_erst)

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Keir Fraser <keir@xen.org>
Committed-by: Jan Beulich <jbeulich@suse.com>
xen/drivers/acpi/apei/erst.c

index eb666a6fcab8e7c8cc9fc3c558116b4c357782a9..31ce50d73c9581a40dc16dd8903704c334e6bfff 100644 (file)
@@ -715,12 +715,23 @@ int erst_clear(u64 record_id)
 
 static int __init erst_check_table(struct acpi_table_erst *erst_tab)
 {
-       if (erst_tab->header_length != sizeof(struct acpi_table_erst))
+       if (erst_tab->header.length < sizeof(*erst_tab))
                return -EINVAL;
-       if (erst_tab->header.length < sizeof(struct acpi_table_erst))
+
+       switch (erst_tab->header_length) {
+       case sizeof(*erst_tab) - sizeof(erst_tab->header):
+       /*
+        * While invalid per specification, there are (early?) systems
+        * indicating the full header size here, so accept that value too.
+        */
+       case sizeof(*erst_tab):
+               break;
+       default:
                return -EINVAL;
+       }
+
        if (erst_tab->entries !=
-           (erst_tab->header.length - sizeof(struct acpi_table_erst)) /
+           (erst_tab->header.length - sizeof(*erst_tab)) /
            sizeof(struct acpi_erst_entry))
                return -EINVAL;