lkml.org 
[lkml]   [2015]   [Oct]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 2/3] x86/apic: Make apic_version[] smaller
Date
apic_version[] array is changed from int to u8 -
APIC version values as of year 2015 are no larger than 0x1f
on all known CPUs.

A bit of code added to ensure that the statement
apic_version[apicid] = version;
in generic_processor_info() is safe wrt bad values in both
'apicid' and 'version' variables.

This reduces apic_version[] from 128 kbytes to 32.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
CC: Ingo Molnar <mingo@kernel.org>
CC: Daniel J Blueman <daniel@numascale.com>
CC: Jiang Liu <jiang.liu@linux.intel.com>
CC: Thomas Gleixner <tglx@linutronix.de>
CC: Len Brown <len.brown@intel.com>
CC: x86@kernel.org
CC: linux-kernel@vger.kernel.org
---
arch/x86/include/asm/mpspec.h | 2 +-
arch/x86/kernel/apic/apic.c | 19 ++++++++++++++++++-
2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/arch/x86/include/asm/mpspec.h b/arch/x86/include/asm/mpspec.h
index e84e542..83140ab 100644
--- a/arch/x86/include/asm/mpspec.h
+++ b/arch/x86/include/asm/mpspec.h
@@ -6,7 +6,7 @@
#include <asm/x86_init.h>
#include <asm/apicdef.h>

-extern int apic_version[];
+extern u8 apic_version[];
extern int pic_mode;

#ifdef CONFIG_X86_32
diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
index b08b447..d0f135c 100644
--- a/arch/x86/kernel/apic/apic.c
+++ b/arch/x86/kernel/apic/apic.c
@@ -1798,7 +1798,7 @@ void __init register_lapic_address(unsigned long address)
}
}

-int apic_version[MAX_LOCAL_APICID];
+u8 apic_version[MAX_LOCAL_APICID];

/*
* Local APIC interrupts
@@ -2054,6 +2054,23 @@ int generic_processor_info(int apicid, int version)
return -EINVAL;
}

+ if ((unsigned)apicid >= ARRAY_SIZE(apic_version)) {
+ int thiscpu = max + disabled_cpus;
+ pr_warning("APIC: APIC id 0x%x is too large."
+ " Processor %d ignored.\n",
+ apicid, thiscpu);
+ disabled_cpus++;
+ return -EINVAL;
+ }
+ if ((unsigned)version > 255) {
+ int thiscpu = max + disabled_cpus;
+ pr_warning("APIC: APIC version 0x%x is too large."
+ " Processor %d ignored.\n",
+ version, thiscpu);
+ disabled_cpus++;
+ return -EINVAL;
+ }
+
num_processors++;
if (apicid == boot_cpu_physical_apicid) {
/*
--
1.8.1.4


\
 
 \ /
  Last update: 2015-10-02 21:41    [W:0.113 / U:0.312 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site