linux/arch/mips
Gregory CLEMENT 7f39b9d0e8 MIPS: ftrace: Fix memory corruption when kernel is located beyond 32 bits
[ Upstream commit 36dac9a3dd ]

Since commit e424054000 ("MIPS: Tracing: Reduce the overhead of
dynamic Function Tracer"), the macro UASM_i_LA_mostly has been used,
and this macro can generate more than 2 instructions. At the same
time, the code in ftrace assumes that no more than 2 instructions can
be generated, which is why it stores them in an int[2] array. However,
as previously noted, the macro UASM_i_LA_mostly (and now UASM_i_LA)
causes a buffer overflow when _mcount is beyond 32 bits. This leads to
corruption of the variables located in the __read_mostly section.

This corruption was observed because the variable
__cpu_primary_thread_mask was corrupted, causing a hang very early
during boot.

This fix prevents the corruption by avoiding the generation of
instructions if they could exceed 2 instructions in
length. Fortunately, insn_la_mcount is only used if the instrumented
code is located outside the kernel code section, so dynamic ftrace can
still be used, albeit in a more limited scope. This is still
preferable to corrupting memory and/or crashing the kernel.

Signed-off-by: Gregory CLEMENT <gregory.clement@bootlin.com>
Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
History 2026-01-02 12:57:03 +01:00
..
alchemy MIPS: Alchemy: convert from round_rate() to determine_rate() 2025-08-29 22:34:29 +02:00
ath25 MIPS: Switch to irq_domain_create_*() 2025-05-16 21:06:10 +02:00
ath79 MIPS: ath79: remove obsolete ATH79_DEV_* configs 2023-03-17 10:28:04 +01:00
bcm47xx net: phy: fixed: let fixed_phy_add always use addr 0 and remove return value 2025-08-26 17:19:02 -07:00
bcm63xx treewide: rename GPIO set callbacks back to their original names 2025-08-07 10:07:06 +02:00
bmips mips: bmips: setup: make CBR address configurable 2024-06-27 10:44:32 +02:00
boot mips: dts: econet: fix EN751221 core type 2025-11-11 12:59:30 +01:00
cavium-octeon - switch longson32 platform to DT and use MIPS_GENERIC framework 2025-10-05 10:09:55 -07:00
cobalt MIPS: Cobalt: Fix missing prototypes 2024-01-22 10:32:21 +01:00
configs Ext4 bug fixes for 6.18-rc2, including 2025-10-15 07:51:57 -07:00
crypto lib/crypto: mips/md5: Migrate optimized code into library 2025-08-26 12:52:28 -04:00
dec MIPS: dec: Declare which_prom() as static 2025-02-27 10:40:45 +01:00
econet mips: dts: Add EcoNet DTS with EN751221 and SmartFiber XP8421-B board 2025-05-20 08:47:07 +02:00
fw MIPS: arc: Replace deprecated strcpy() with memcpy() 2025-08-29 22:34:30 +02:00
generic MIPS: generic: Replace deprecated strcpy() in ocelot_detect() 2025-08-29 22:34:30 +02:00
include - switch longson32 platform to DT and use MIPS_GENERIC framework 2025-10-05 10:09:55 -07:00
ingenic MIPS: Kconfig: ingenic: Ensure MACH_INGENIC_GENERIC selects all SoCs 2021-06-01 11:44:47 +02:00
jazz mips/jazz: remove unused jazz_handle_int() declaration 2024-08-29 10:39:00 +02:00
kernel MIPS: ftrace: Fix memory corruption when kernel is located beyond 32 bits 2026-01-02 12:57:03 +01:00
kvm MIPS: Don't use %pK through printk 2025-07-28 09:58:49 +02:00
lantiq mips: lantiq: xway: sysctrl: rename stp clock 2025-08-29 22:34:30 +02:00
lib Crypto library updates for 6.17 2025-07-28 17:58:52 -07:00
loongson2ef MIPS: Loongson2ef: Replace deprecated strncpy() with strscpy() 2025-02-27 10:40:01 +01:00
loongson32 MIPS: loongson32: Switch to generic core 2025-08-29 22:34:31 +02:00
loongson64 MIPS: Loongson64: Replace deprecated strcpy() with strscpy_pad() 2025-08-29 22:34:30 +02:00
math-emu mips: math-emu: replace deprecated strcpy() in me-debugfs 2025-09-12 11:56:06 +02:00
mm MIPS: mm: kmalloc tlb_vpn array to avoid stack overflow 2025-11-29 13:36:05 +01:00
mobileye MIPS: mobileye: Add EyeQ6H support 2024-06-11 10:15:50 +02:00
mti-malta MIPS: Malta: Fix !EVA SOC-it PCI MMIO 2025-11-11 12:58:49 +01:00
n64 mips: Add N64 machine type 2021-01-22 11:40:00 +01:00
net bpf: Take return from set_memory_rox() into account with bpf_jit_binary_lock_ro() 2024-03-14 19:28:52 -07:00
pci MIPS: Malta: Use pcibios_align_resource() to block io range 2025-10-22 11:06:31 -05:00
pic32 MIPS: Fixup explicit DT include clean-up 2023-07-28 11:41:09 +02:00
power mips: suspend: include linux/suspend.h as needed 2023-12-10 17:21:41 -08:00
ralink MIPS: ralink: add missing header include 2025-07-02 13:23:01 +02:00
rb532 MIPS: RB532: Replace deprecated strcpy() with memcpy() and strscpy() 2025-08-29 22:34:30 +02:00
sgi-ip22 MIPS: Fix a reference leak bug in ip22_check_gio() 2026-01-02 12:56:52 +01:00
sgi-ip27 MIPS: SGI-IP27: Delete an unnecessary check before kfree() in hub_domain_free() 2025-07-16 18:54:16 +02:00
sgi-ip30 MIPS: Update Joshua Kinard's e-mail address 2025-07-28 09:57:24 +02:00
sgi-ip32 MIPS: sgi-ip32: Replace deprecated strcpy() in plat_mem_setup() 2025-08-29 22:34:30 +02:00
sibyte mips: sibyte: add missing MODULE_DESCRIPTION() macro 2024-07-23 09:47:40 +02:00
sni MIPS: sni: Replace deprecated strcpy() in sni_console_setup() 2025-08-29 22:34:30 +02:00
tools MIPS: fix typos in comments 2022-05-04 22:22:59 +02:00
txx9 MIPS: txx9: Replace deprecated strcpy() with strscpy() 2025-08-29 22:34:30 +02:00
vdso mips: Add -std= flag specified in KBUILD_CFLAGS to vdso CFLAGS 2025-04-27 09:37:10 +02:00
Kbuild MIPS: Share generic kernel code with other architecture 2024-02-20 13:36:25 +01:00
Kbuild.platforms mips: Add EcoNet MIPS platform support 2025-05-20 08:46:58 +02:00
Kconfig - switch longson32 platform to DT and use MIPS_GENERIC framework 2025-10-05 10:09:55 -07:00
Kconfig.debug tracing: Refactor TRACE_IRQFLAGS_SUPPORT in Kconfig 2021-08-16 11:37:21 -04:00
Makefile kbuild: Introduce Kconfig symbol for linking vmlinux with relocations 2025-03-17 00:29:50 +09:00
Makefile.postlink kbuild: Create intermediate vmlinux build with relocations preserved 2025-03-17 00:29:50 +09:00