android_kernel_motorola_sm6375/arch/x86
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Colin Ian King 555a2f09a6 x86/lib: Fix overflow when counting digits
[ Upstream commit a24d61c609813963aacc9f6ec8343f4fcaac7243 ]

tl;dr: The num_digits() function has a theoretical overflow issue.
But it doesn't affect any actual in-tree users.  Fix it by using
a larger type for one of the local variables.

Long version:

There is an overflow in variable m in function num_digits when val
is >= 1410065408 which leads to the digit calculation loop to
iterate more times than required. This results in either more
digits being counted or in some cases (for example where val is
1932683193) the value of m eventually overflows to zero and the
while loop spins forever).

Currently the function num_digits is currently only being used for
small values of val in the SMP boot stage for digit counting on the
number of cpus and NUMA nodes, so the overflow is never encountered.
However it is useful to fix the overflow issue in case the function
is used for other purposes in the future. (The issue was discovered
while investigating the digit counting performance in various
kernel helper functions rather than any real-world use-case).

The simplest fix is to make m a long long, the overhead in
multiplication speed for a long long is very minor for small values
of val less than 10000 on modern processors. The alternative
fix is to replace the multiplication with a constant division
by 10 loop (this compiles down to an multiplication and shift)
without needing to make m a long long, but this is slightly slower
than the fix in this commit when measured on a range of x86
processors).

[ dhansen: subject and changelog tweaks ]

Fixes: 646e29a178 ("x86: Improve the printout of the SMP bootup CPU table")
Signed-off-by: Colin Ian King <[email protected]>
Signed-off-by: Dave Hansen <[email protected]>
Link: https://lore.kernel.org/all/20231102174901.2590325-1-colin.i.king%40gmail.com
Signed-off-by: Sasha Levin <[email protected]>
2024-01-25 14:34:21 -08:00
..
boot x86/decompressor: Don't rely on upper 32 bits of GPRs being preserved 2023-09-23 10:59:41 +02:00
configs vgacon: remove software scrollback support 2020-09-17 13:47:54 +02:00
crypto crypto: x86/ghash - fix unaligned access in ghash_setkey() 2023-03-11 16:43:38 +01:00
entry x86/asm: Make more symbols local 2023-09-23 10:59:40 +02:00
events perf/x86/amd: fix potential integer overflow on shift of a int 2023-02-06 07:52:47 +01:00
hyperv x86/hyperv: Fix NULL deref in set_hv_tscchange_cb() if Hyper-V setup fails 2021-11-26 10:47:21 +01:00
ia32 binfmt: Move install_exec_creds after setup_new_exec to match binfmt_elf 2023-01-18 11:41:46 +01:00
include KVM: x86: Ignore MSR_AMD64_TW_CFG access 2023-11-28 16:50:18 +00:00
kernel x86/alternatives: Sync core before enabling interrupts 2024-01-08 11:29:47 +01:00
kvm KVM: x86: Ignore MSR_AMD64_TW_CFG access 2023-11-28 16:50:18 +00:00
lib x86/lib: Fix overflow when counting digits 2024-01-25 14:34:21 -08:00
math-emu
mm x86/mm: Drop the 4 MB restriction on minimal NUMA node memory size 2023-11-28 16:50:13 +00:00
net bpf: Introduce BPF nospec instruction for mitigating Spectre v4 2021-09-15 09:47:38 +02:00
oprofile
pci x86/PCI: Add quirk for AMD XHCI controller that loses MSI-X state in D3hot 2023-04-20 12:07:32 +02:00
platform x86/olpc: fix 'logical not is only applied to the left hand side' 2022-08-25 11:18:10 +02:00
power x86/pm: Add enumeration check before spec MSRs save/restore setup 2022-12-08 11:23:05 +01:00
purgatory x86/purgatory: remove PGO flags 2023-06-28 10:18:35 +02:00
ras
realmode x86/asm: Make more symbols local 2023-09-23 10:59:40 +02:00
tools x86/tools: Fix objdump version check again 2021-08-18 08:57:01 +02:00
um x86: um: vdso: Add '%rcx' and '%r11' to the syscall clobber list 2023-03-11 16:44:10 +01:00
video
xen x86/xen: Fix secondary processors' FPU initialization 2023-08-08 19:56:35 +02:00
.gitignore
Kbuild
Kconfig x86/speculation: Add Kconfig option for GDS 2023-08-08 19:56:35 +02:00
Kconfig.cpu
Kconfig.debug
Makefile x86/build: Propagate $(CLANG_FLAGS) to $(REALMODE_FLAGS) 2021-05-11 14:04:06 +02:00
Makefile.um
Makefile_32.cpu