]> git.ipfire.org Git - thirdparty/linux.git/commit
MIPS: ftrace: Fix memory corruption when kernel is located beyond 32 bits
authorGregory CLEMENT <gregory.clement@bootlin.com>
Fri, 28 Nov 2025 08:30:06 +0000 (09:30 +0100)
committerThomas Bogendoerfer <tsbogend@alpha.franken.de>
Mon, 1 Dec 2025 09:07:25 +0000 (10:07 +0100)
commit36dac9a3dda1f2bae343191bc16b910c603cac25
treed80b0d211bd96147c8108b3913113a9fe56a3bc9
parent4f0b3cd7b664e662e9c4480e8d58574ece8aea57
MIPS: ftrace: Fix memory corruption when kernel is located beyond 32 bits

Since commit e424054000878 ("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>
arch/mips/kernel/ftrace.c