Patchwork [RFC,7/7] acpi: fix bug in acpi_checksum() caused by garbage in checksum field

login
register
mail settings
Submitter Eduard - Gabriel Munteanu
Date March 30, 2010, 8:20 a.m.
Message ID <7498607873ad7c9ff59d0a24d35391c0e4ba0a11.1269936879.git.eduard.munteanu@linux360.ro>
Download mbox | patch
Permalink /patch/48972/
State New
Headers show

Comments

Eduard - Gabriel Munteanu - March 30, 2010, 8:20 a.m.
The whole table must sum to zero. We need to ignore garbage in the
checksum field (i.e. consider it zero) when checksumming. It is
legitimate to have garbage there, as the checksum makes sense only when
the table has been filled.

Signed-off-by: Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro>
---
 hw/acpi.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
Richard Henderson - March 30, 2010, 3:10 p.m.
On 03/30/2010 01:20 AM, Eduard - Gabriel Munteanu wrote:
> +    /* Ignore preexisting garbage in checksum. */
> +    acpi_hdr = (struct acpi_table_header *) data;
> +    sum -= acpi_hdr->checksum;
> +
>      return (-sum) & 0xff;

Wouldn't it be cleaner to adjust the acpi_checksum definition to take
and acpi_table_header operand instead of uint8_t?  And given it's only
usage, perhaps update the checksum instead of returning it?  E.g.

-    ((struct acpi_table_header*)p)->checksum = acpi_checksum((uint8_t*)p, off);
+    acpi_update_checksum((struct acpi_table_header *)p, off);


r~

Patch

diff --git a/hw/acpi.c b/hw/acpi.c
index f067f85..bb015f3 100644
--- a/hw/acpi.c
+++ b/hw/acpi.c
@@ -832,11 +832,16 @@  size_t acpi_tables_len, acpi_tables_prev_len;
 static int acpi_checksum(const uint8_t *data, int len)
 {
     int sum, i;
+    struct acpi_table_header *acpi_hdr;
 
     sum = 0;
     for(i = 0; i < len; i++)
         sum += data[i];
 
+    /* Ignore preexisting garbage in checksum. */
+    acpi_hdr = (struct acpi_table_header *) data;
+    sum -= acpi_hdr->checksum;
+
     return (-sum) & 0xff;
 }