recordmcount/MIPS: Fix possible incorrect mcount_loc table entries in modules
Alex Smith authored
commit 91ad11d7

 upstream.

On MIPS calls to _mcount in modules generate 2 instructions to load
the _mcount address (and therefore 2 relocations). The mcount_loc
table should only reference the first of these, so the second is
filtered out by checking the relocation offset and ignoring ones that
immediately follow the previous one seen.

However if a module has an _mcount call at offset 0, the second
relocation would not be filtered out due to old_r_offset == 0
being taken to mean that the current relocation is the first one
seen, and both would end up in the mcount_loc table.

This results in ftrace_make_nop() patching both (adjacent)
instructions to branches over the _mcount call sequence like so:

  0xffffffffc08a8000:  04 00 00 10     b       0xffffffffc08a8014
  0xffffffffc08a8004:  04 00 00 10     b       0xffffffffc08a8018
  0xffffffffc08a8008:  2d 08 e0 03     move    at,ra
  ...

The second branch is in the delay slot of the first, which is
defined to be unpredictable - on the platform on which this bug was
encountered, it triggers a reserved instruction exception.

Fix by initializing old_r_offset to ~0 and using that instead of 0
to determine whether the current relocation is the first seen.
Signed-off-by: default avatarAlex Smith <alex.smith@imgtec.com>
Cc: linux-kernel@vger.kernel.org
Cc: linux-mips@linux-mips.org
Patchwork: https://patchwork.linux-mips.org/patch/7098/

Signed-off-by: default avatarRalf Baechle <ralf@linux-mips.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
e1604683
Name Last commit Last update
..
basic kbuild: fixdep: support concatenated dep files
coccinelle Merge branch 'misc' of git://git.kernel.org/pub/scm/linux/kernel/git/mmarek/kbuild
dtc dtc: ensure #line directives don't consume data from the next line
genksyms genksyms: pass symbol-prefix instead of arch
kconfig kconfig/menu.c: fix multiple references to expressions in menu_add_prop()
ksymoops Linux-2.6.12-rc2
mod powerpc: Add vr save/restore functions
package deb-pkg: Fix cross-building linux-headers package
rt-tester Fix common misspellings
selinux Create Documentation/security/,
tracing tracing, perf: Convert the power tracer into an event tracer
.gitignore X.509: Add simple ASN.1 grammar compiler
Kbuild.include kbuild: fix ld-option function
Lindent scripts/Lindent: support gnu indent v2.2.10
Makefile X.509: Add simple ASN.1 grammar compiler
Makefile.asm-generic uapi: Allow automatic generation of uapi/asm/ header files
Makefile.build genksyms: pass symbol-prefix instead of arch
Makefile.clean kbuild: Really don't clean bounds.h and asm-offsets.h
Makefile.fwinst kbuild: Fix accidental revert in commit fe04ddf7
Makefile.headersinst kbuild: fix make headers_install when path is too long
Makefile.help Add a target to use the Coccinelle checker
Makefile.host kbuild: fix some minor typoes
Makefile.lib kbuild: make sure we clean up DTB temporary files
Makefile.modbuiltin kbuild: Create output directory in Makefile.modbuiltin
Makefile.modinst modules: don't break modules_install on external modules with no key.
Makefile.modpost
Makefile.modsign
asn1_compiler.c
bin2c.c
bloat-o-meter
bootgraph.pl
checkincludes.pl
checkkconfigsymbols.sh
checkpatch.pl
checkstack.pl
checksyscalls.sh
checkversion.pl
cleanfile
cleanpatch
coccicheck
config
conmakehash.c
decodecode
depmod.sh
diffconfig
docproc.c
export_report.pl
extract-ikconfig
extract-vmlinux
gcc-goto.sh
gcc-version.sh
gcc-x86_32-has-stack-protector.sh
gcc-x86_64-has-stack-protector.sh
gen_initramfs_list.sh
get_maintainer.pl
gfp-translate
headerdep.pl
headers.sh
headers_check.pl
headers_install.sh
kallsyms.c
kernel-doc
link-vmlinux.sh
makelst
markup_oops.pl
mkcompile_h
mkmakefile
mksysmap
mkuboot.sh
mkversion
module-common.lds
namespace.pl
patch-kernel
pnmtologo.c
profile2linkerlist.pl
recordmcount.c
recordmcount.h
recordmcount.pl
setlocalversion
show_delta
sign-file
sortextable.c
sortextable.h
tags.sh
unifdef.c
ver_linux
xz_wrap.sh