diff options
| author | Li RongQing <lirongqing@baidu.com> | 2018-04-09 21:16:06 -0400 |
|---|---|---|
| committer | Thomas Gleixner <tglx@linutronix.de> | 2018-04-10 10:46:39 -0400 |
| commit | a774635db5c430cbf21fa5d2f2df3d23aaa8e782 (patch) | |
| tree | 901a79ca1293a6ef62e57de71e74496347f1ad35 | |
| parent | d94a155c59c98c19b98ee949eaab6a0312bbd6be (diff) | |
x86/apic: Fix signedness bug in APIC ID validity checks
The APIC ID as parsed from ACPI MADT is validity checked with the
apic->apic_id_valid() callback, which depends on the selected APIC type.
For non X2APIC types APIC IDs >= 0xFF are invalid, but values > 0x7FFFFFFF
are detected as valid. This happens because the 'apicid' argument of the
apic_id_valid() callback is type 'int'. So the resulting comparison
apicid < 0xFF
evaluates to true for all unsigned int values > 0x7FFFFFFF which are handed
to default_apic_id_valid(). As a consequence, invalid APIC IDs in !X2APIC
mode are considered valid and accounted as possible CPUs.
Change the apicid argument type of the apic_id_valid() callback to u32 so
the evaluation is unsigned and returns the correct result.
[ tglx: Massaged changelog ]
Signed-off-by: Li RongQing <lirongqing@baidu.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: stable@vger.kernel.org
Cc: jgross@suse.com
Cc: Dou Liyang <douly.fnst@cn.fujitsu.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: hpa@zytor.com
Link: https://lkml.kernel.org/r/1523322966-10296-1-git-send-email-lirongqing@baidu.com
| -rw-r--r-- | arch/x86/include/asm/apic.h | 4 | ||||
| -rw-r--r-- | arch/x86/kernel/acpi/boot.c | 13 | ||||
| -rw-r--r-- | arch/x86/kernel/apic/apic_common.c | 2 | ||||
| -rw-r--r-- | arch/x86/kernel/apic/apic_numachip.c | 2 | ||||
| -rw-r--r-- | arch/x86/kernel/apic/x2apic.h | 2 | ||||
| -rw-r--r-- | arch/x86/kernel/apic/x2apic_phys.c | 2 | ||||
| -rw-r--r-- | arch/x86/kernel/apic/x2apic_uv_x.c | 2 | ||||
| -rw-r--r-- | arch/x86/xen/apic.c | 2 |
8 files changed, 16 insertions, 13 deletions
diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h index 98722773391d..f01eef8b392e 100644 --- a/arch/x86/include/asm/apic.h +++ b/arch/x86/include/asm/apic.h | |||
| @@ -319,7 +319,7 @@ struct apic { | |||
| 319 | /* Probe, setup and smpboot functions */ | 319 | /* Probe, setup and smpboot functions */ |
| 320 | int (*probe)(void); | 320 | int (*probe)(void); |
| 321 | int (*acpi_madt_oem_check)(char *oem_id, char *oem_table_id); | 321 | int (*acpi_madt_oem_check)(char *oem_id, char *oem_table_id); |
| 322 | int (*apic_id_valid)(int apicid); | 322 | int (*apic_id_valid)(u32 apicid); |
| 323 | int (*apic_id_registered)(void); | 323 | int (*apic_id_registered)(void); |
| 324 | 324 | ||
| 325 | bool (*check_apicid_used)(physid_mask_t *map, int apicid); | 325 | bool (*check_apicid_used)(physid_mask_t *map, int apicid); |
| @@ -492,7 +492,7 @@ static inline unsigned int read_apic_id(void) | |||
| 492 | return apic->get_apic_id(reg); | 492 | return apic->get_apic_id(reg); |
| 493 | } | 493 | } |
| 494 | 494 | ||
| 495 | extern int default_apic_id_valid(int apicid); | 495 | extern int default_apic_id_valid(u32 apicid); |
| 496 | extern int default_acpi_madt_oem_check(char *, char *); | 496 | extern int default_acpi_madt_oem_check(char *, char *); |
| 497 | extern void default_setup_apic_routing(void); | 497 | extern void default_setup_apic_routing(void); |
| 498 | 498 | ||
diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c index 2aa92094b59d..5ee33a6e33bb 100644 --- a/arch/x86/kernel/acpi/boot.c +++ b/arch/x86/kernel/acpi/boot.c | |||
| @@ -200,7 +200,7 @@ acpi_parse_x2apic(struct acpi_subtable_header *header, const unsigned long end) | |||
| 200 | { | 200 | { |
| 201 | struct acpi_madt_local_x2apic *processor = NULL; | 201 | struct acpi_madt_local_x2apic *processor = NULL; |
| 202 | #ifdef CONFIG_X86_X2APIC | 202 | #ifdef CONFIG_X86_X2APIC |
| 203 | int apic_id; | 203 | u32 apic_id; |
| 204 | u8 enabled; | 204 | u8 enabled; |
| 205 | #endif | 205 | #endif |
| 206 | 206 | ||
| @@ -222,10 +222,13 @@ acpi_parse_x2apic(struct acpi_subtable_header *header, const unsigned long end) | |||
| 222 | * to not preallocating memory for all NR_CPUS | 222 | * to not preallocating memory for all NR_CPUS |
| 223 | * when we use CPU hotplug. | 223 | * when we use CPU hotplug. |
| 224 | */ | 224 | */ |
| 225 | if (!apic->apic_id_valid(apic_id) && enabled) | 225 | if (!apic->apic_id_valid(apic_id)) { |
| 226 | printk(KERN_WARNING PREFIX "x2apic entry ignored\n"); | 226 | if (enabled) |
| 227 | else | 227 | pr_warn(PREFIX "x2apic entry ignored\n"); |
| 228 | acpi_register_lapic(apic_id, processor->uid, enabled); | 228 | return 0; |
| 229 | } | ||
| 230 | |||
| 231 | acpi_register_lapic(apic_id, processor->uid, enabled); | ||
| 229 | #else | 232 | #else |
| 230 | printk(KERN_WARNING PREFIX "x2apic entry ignored\n"); | 233 | printk(KERN_WARNING PREFIX "x2apic entry ignored\n"); |
| 231 | #endif | 234 | #endif |
diff --git a/arch/x86/kernel/apic/apic_common.c b/arch/x86/kernel/apic/apic_common.c index a360801779ae..02b4839478b1 100644 --- a/arch/x86/kernel/apic/apic_common.c +++ b/arch/x86/kernel/apic/apic_common.c | |||
| @@ -40,7 +40,7 @@ int default_check_phys_apicid_present(int phys_apicid) | |||
| 40 | return physid_isset(phys_apicid, phys_cpu_present_map); | 40 | return physid_isset(phys_apicid, phys_cpu_present_map); |
| 41 | } | 41 | } |
| 42 | 42 | ||
| 43 | int default_apic_id_valid(int apicid) | 43 | int default_apic_id_valid(u32 apicid) |
| 44 | { | 44 | { |
| 45 | return (apicid < 255); | 45 | return (apicid < 255); |
| 46 | } | 46 | } |
diff --git a/arch/x86/kernel/apic/apic_numachip.c b/arch/x86/kernel/apic/apic_numachip.c index 134e04506ab4..78778b54f904 100644 --- a/arch/x86/kernel/apic/apic_numachip.c +++ b/arch/x86/kernel/apic/apic_numachip.c | |||
| @@ -56,7 +56,7 @@ static u32 numachip2_set_apic_id(unsigned int id) | |||
| 56 | return id << 24; | 56 | return id << 24; |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | static int numachip_apic_id_valid(int apicid) | 59 | static int numachip_apic_id_valid(u32 apicid) |
| 60 | { | 60 | { |
| 61 | /* Trust what bootloader passes in MADT */ | 61 | /* Trust what bootloader passes in MADT */ |
| 62 | return 1; | 62 | return 1; |
diff --git a/arch/x86/kernel/apic/x2apic.h b/arch/x86/kernel/apic/x2apic.h index b107de381cb5..a49b3604027f 100644 --- a/arch/x86/kernel/apic/x2apic.h +++ b/arch/x86/kernel/apic/x2apic.h | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* Common bits for X2APIC cluster/physical modes. */ | 1 | /* Common bits for X2APIC cluster/physical modes. */ |
| 2 | 2 | ||
| 3 | int x2apic_apic_id_valid(int apicid); | 3 | int x2apic_apic_id_valid(u32 apicid); |
| 4 | int x2apic_apic_id_registered(void); | 4 | int x2apic_apic_id_registered(void); |
| 5 | void __x2apic_send_IPI_dest(unsigned int apicid, int vector, unsigned int dest); | 5 | void __x2apic_send_IPI_dest(unsigned int apicid, int vector, unsigned int dest); |
| 6 | unsigned int x2apic_get_apic_id(unsigned long id); | 6 | unsigned int x2apic_get_apic_id(unsigned long id); |
diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c index f8d9d69994e6..e972405eb2b5 100644 --- a/arch/x86/kernel/apic/x2apic_phys.c +++ b/arch/x86/kernel/apic/x2apic_phys.c | |||
| @@ -101,7 +101,7 @@ static int x2apic_phys_probe(void) | |||
| 101 | } | 101 | } |
| 102 | 102 | ||
| 103 | /* Common x2apic functions, also used by x2apic_cluster */ | 103 | /* Common x2apic functions, also used by x2apic_cluster */ |
| 104 | int x2apic_apic_id_valid(int apicid) | 104 | int x2apic_apic_id_valid(u32 apicid) |
| 105 | { | 105 | { |
| 106 | return 1; | 106 | return 1; |
| 107 | } | 107 | } |
diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c index f11910b44638..efaf2d4f9c3c 100644 --- a/arch/x86/kernel/apic/x2apic_uv_x.c +++ b/arch/x86/kernel/apic/x2apic_uv_x.c | |||
| @@ -557,7 +557,7 @@ static void uv_send_IPI_all(int vector) | |||
| 557 | uv_send_IPI_mask(cpu_online_mask, vector); | 557 | uv_send_IPI_mask(cpu_online_mask, vector); |
| 558 | } | 558 | } |
| 559 | 559 | ||
| 560 | static int uv_apic_id_valid(int apicid) | 560 | static int uv_apic_id_valid(u32 apicid) |
| 561 | { | 561 | { |
| 562 | return 1; | 562 | return 1; |
| 563 | } | 563 | } |
diff --git a/arch/x86/xen/apic.c b/arch/x86/xen/apic.c index de58533d3664..2fa79e2e73ea 100644 --- a/arch/x86/xen/apic.c +++ b/arch/x86/xen/apic.c | |||
| @@ -112,7 +112,7 @@ static int xen_madt_oem_check(char *oem_id, char *oem_table_id) | |||
| 112 | return xen_pv_domain(); | 112 | return xen_pv_domain(); |
| 113 | } | 113 | } |
| 114 | 114 | ||
| 115 | static int xen_id_always_valid(int apicid) | 115 | static int xen_id_always_valid(u32 apicid) |
| 116 | { | 116 | { |
| 117 | return 1; | 117 | return 1; |
| 118 | } | 118 | } |
