]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
x86/apic: Fix integer overflow on 10 bit left shift of cpu_khz
authorColin Ian King <colin.king@canonical.com>
Wed, 19 Jun 2019 18:14:46 +0000 (19:14 +0100)
committerKleber Sacilotto de Souza <kleber.souza@canonical.com>
Wed, 14 Aug 2019 09:18:49 +0000 (11:18 +0200)
BugLink: https://bugs.launchpad.net/bugs/1839036
[ Upstream commit ea136a112d89bade596314a1ae49f748902f4727 ]

The left shift of unsigned int cpu_khz will overflow for large values of
cpu_khz, so cast it to a long long before shifting it to avoid overvlow.
For example, this can happen when cpu_khz is 4194305, i.e. ~4.2 GHz.

Addresses-Coverity: ("Unintentional integer overflow")
Fixes: 8c3ba8d04924 ("x86, apic: ack all pending irqs when crashed/on kexec")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Borislav Petkov <bp@alien8.de>
Cc: "H . Peter Anvin" <hpa@zytor.com>
Cc: kernel-janitors@vger.kernel.org
Link: https://lkml.kernel.org/r/20190619181446.13635-1-colin.king@canonical.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
arch/x86/kernel/apic/apic.c

index 84d3e8541304a60cc41780dfa5fa85bcbc73a898..6001fdacc2e5f036b7db58e3cc516a63d91aa5fa 100644 (file)
@@ -1512,7 +1512,8 @@ void setup_local_APIC(void)
                if (queued) {
                        if (boot_cpu_has(X86_FEATURE_TSC) && cpu_khz) {
                                ntsc = rdtsc();
-                               max_loops = (cpu_khz << 10) - (ntsc - tsc);
+                               max_loops = (long long)cpu_khz << 10;
+                               max_loops -= ntsc - tsc;
                        } else
                                max_loops--;
                }