[PATCH 3.16 036/294] x86/acpi: Prevent out of bound access caused by broken ACPI tables

2017-11-06 Thread Ben Hutchings
3.16.50-rc1 review patch.  If anyone has any objections, please let me know.

--

From: Seunghun Han 

commit dad5ab0db8deac535d03e3fe3d8f2892173fa6a4 upstream.

The bus_irq argument of mp_override_legacy_irq() is used as the index into
the isa_irq_to_gsi[] array. The bus_irq argument originates from
ACPI_MADT_TYPE_IO_APIC and ACPI_MADT_TYPE_INTERRUPT items in the ACPI
tables, but is nowhere sanity checked.

That allows broken or malicious ACPI tables to overwrite memory, which
might cause malfunction, panic or arbitrary code execution.

Add a sanity check and emit a warning when that triggers.

[ tglx: Added warning and rewrote changelog ]

Signed-off-by: Seunghun Han 
Signed-off-by: Thomas Gleixner 
Cc: secur...@kernel.org
Cc: "Rafael J. Wysocki" 
Signed-off-by: Ingo Molnar 
Signed-off-by: Ben Hutchings 
---
 arch/x86/kernel/acpi/boot.c | 8 
 1 file changed, 8 insertions(+)

--- a/arch/x86/kernel/acpi/boot.c
+++ b/arch/x86/kernel/acpi/boot.c
@@ -910,6 +910,14 @@ void __init mp_override_legacy_irq(u8 bu
struct mpc_intsrc mp_irq;
 
/*
+* Check bus_irq boundary.
+*/
+   if (bus_irq >= NR_IRQS_LEGACY) {
+   pr_warn("Invalid bus_irq %u for legacy override\n", bus_irq);
+   return;
+   }
+
+   /*
 * Convert 'gsi' to 'ioapic.pin'.
 */
ioapic = mp_find_ioapic(gsi);



[PATCH 3.16 036/294] x86/acpi: Prevent out of bound access caused by broken ACPI tables

2017-11-06 Thread Ben Hutchings
3.16.50-rc1 review patch.  If anyone has any objections, please let me know.

--

From: Seunghun Han 

commit dad5ab0db8deac535d03e3fe3d8f2892173fa6a4 upstream.

The bus_irq argument of mp_override_legacy_irq() is used as the index into
the isa_irq_to_gsi[] array. The bus_irq argument originates from
ACPI_MADT_TYPE_IO_APIC and ACPI_MADT_TYPE_INTERRUPT items in the ACPI
tables, but is nowhere sanity checked.

That allows broken or malicious ACPI tables to overwrite memory, which
might cause malfunction, panic or arbitrary code execution.

Add a sanity check and emit a warning when that triggers.

[ tglx: Added warning and rewrote changelog ]

Signed-off-by: Seunghun Han 
Signed-off-by: Thomas Gleixner 
Cc: secur...@kernel.org
Cc: "Rafael J. Wysocki" 
Signed-off-by: Ingo Molnar 
Signed-off-by: Ben Hutchings 
---
 arch/x86/kernel/acpi/boot.c | 8 
 1 file changed, 8 insertions(+)

--- a/arch/x86/kernel/acpi/boot.c
+++ b/arch/x86/kernel/acpi/boot.c
@@ -910,6 +910,14 @@ void __init mp_override_legacy_irq(u8 bu
struct mpc_intsrc mp_irq;
 
/*
+* Check bus_irq boundary.
+*/
+   if (bus_irq >= NR_IRQS_LEGACY) {
+   pr_warn("Invalid bus_irq %u for legacy override\n", bus_irq);
+   return;
+   }
+
+   /*
 * Convert 'gsi' to 'ioapic.pin'.
 */
ioapic = mp_find_ioapic(gsi);