linux/arch/mips
Paul Burton bbcc5672b0
MIPS: Avoid VDSO ABI breakage due to global register variable
Declaring __current_thread_info as a global register variable has the
effect of preventing GCC from saving & restoring its value in cases
where the ABI would typically do so.

To quote GCC documentation:

> If the register is a call-saved register, call ABI is affected: the
> register will not be restored in function epilogue sequences after the
> variable has been assigned. Therefore, functions cannot safely return
> to callers that assume standard ABI.

When our position independent VDSO is built for the n32 or n64 ABIs all
functions it exposes should be preserving the value of $gp/$28 for their
caller, but in the presence of the __current_thread_info global register
variable GCC stops doing so & simply clobbers $gp/$28 when calculating
the address of the GOT.

In cases where the VDSO returns success this problem will typically be
masked by the caller in libc returning & restoring $gp/$28 itself, but
that is by no means guaranteed. In cases where the VDSO returns an error
libc will typically contain a fallback path which will now fail
(typically with a bad memory access) if it attempts anything which
relies upon the value of $gp/$28 - eg. accessing anything via the GOT.

One fix for this would be to move the declaration of
__current_thread_info inside the current_thread_info() function,
demoting it from global register variable to local register variable &
avoiding inadvertently creating a non-standard calling ABI for the VDSO.
Unfortunately this causes issues for clang, which doesn't support local
register variables as pointed out by commit fe92da0f35 ("MIPS: Changed
current_thread_info() to an equivalent supported by both clang and GCC")
which introduced the global register variable before we had a VDSO to
worry about.

Instead, fix this by continuing to use the global register variable for
the kernel proper but declare __current_thread_info as a simple extern
variable when building the VDSO. It should never be referenced, and will
cause a link error if it is. This resolves the calling convention issue
for the VDSO without having any impact upon the build of the kernel
itself for either clang or gcc.

Signed-off-by: Paul Burton <paulburton@kernel.org>
Fixes: ebb5e78cc6 ("MIPS: Initial implementation of a VDSO")
Reported-by: Jason A. Donenfeld <Jason@zx2c4.com>
Reviewed-by: Jason A. Donenfeld <Jason@zx2c4.com>
Tested-by: Jason A. Donenfeld <Jason@zx2c4.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Christian Brauner <christian.brauner@canonical.com>
Cc: Vincenzo Frascino <vincenzo.frascino@arm.com>
Cc: <stable@vger.kernel.org> # v4.4+
Cc: linux-mips@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
2020-01-02 16:41:16 -08:00
..
alchemy treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 182 2019-05-30 11:29:20 -07:00
ar7 The main MIPS changes for a pretty light v5.3 cycle, including: 2019-07-17 09:42:03 -07:00
ath25 PCI: consolidate PCI config entry in drivers/pci 2018-11-23 11:45:34 +09:00
ath79 The main MIPS changes for a pretty light v5.3 cycle, including: 2019-07-17 09:42:03 -07:00
bcm47xx MIPS: BCM47XX: Add support for Netgear R6200 V1 2019-07-25 22:10:05 -07:00
bcm63xx MIPS: bmips: mark exception vectors as char arrays 2019-10-23 21:07:28 -07:00
bmips docs: arm: convert docs to ReST and rename to *.rst 2019-07-15 09:20:24 -03:00
boot MIPS: Prevent link failure with kcov instrumentation 2019-12-18 15:15:03 -08:00
cavium-octeon mips/cavium-octeon: Fix typo *must* in comment 2019-11-01 14:33:07 -07:00
cobalt treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 1 2019-05-21 11:28:39 +02:00
configs A few MIPS fixes: 2019-11-01 14:36:44 -07:00
crypto
dec treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
emma treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 156 2019-05-30 11:26:35 -07:00
fw A few MIPS fixes: 2019-11-01 14:36:44 -07:00
generic MIPS: generic: Use __initconst for const init data 2019-10-08 10:54:44 -07:00
include MIPS: Avoid VDSO ABI breakage due to global register variable 2020-01-02 16:41:16 -08:00
jazz dma-mapping: explicitly wire up ->mmap and ->get_sgtable 2019-09-04 11:13:18 +02:00
jz4740 Merge branch 'ingenic-tcu-v5.4' into mips-next 2019-08-08 15:33:16 -07:00
kernel mips: cacheinfo: report shared CPU map 2019-11-26 10:33:08 -08:00
kvm mips: add support for folded p4d page tables 2019-11-22 10:51:22 -08:00
lantiq MIPS: lantiq: update the clock alias' for the mainline PCIe PHY driver 2019-08-24 15:13:22 +01:00
lasat treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 182 2019-05-30 11:29:20 -07:00
lib MIPS: Loongson64: Rename CPU TYPES 2019-10-31 15:03:10 -07:00
loongson2ef MIPS: Loongson2ef: Convert to early_printk_8250 2019-11-11 10:45:00 -08:00
loongson32 MIPS: Loongson{2ef, 32, 64} convert to generic fw cmdline 2019-11-11 10:44:56 -08:00
loongson64 MIPS: Loongson64: Drop setup_pcimap 2019-11-11 10:45:01 -08:00
math-emu MIPS: math-emu: Reuse name array in debugfs_fpuemu() 2019-11-11 10:56:14 -08:00
mm mips: add support for folded p4d page tables 2019-11-22 10:51:22 -08:00
mti-malta MIPS: malta: Drop prom_free_prom_memory 2019-08-23 14:47:13 +01:00
net MIPS: BPF: eBPF JIT: check for MIPS ISA compliance in Kconfig 2019-12-18 15:15:04 -08:00
netlogic MIPS: xlp: Drop boot_mem_map 2019-08-23 14:47:21 +01:00
oprofile MIPS: Loongson: Rename LOONGSON1 to LOONGSON32 2019-11-11 10:43:13 -08:00
paravirt mips: unify prom_putchar() declarations 2018-07-17 09:40:17 -07:00
pci MIPS: SGI-IP27: Enable ethernet phy on second Origin 200 module 2019-11-23 14:20:30 -08:00
pic32 treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 445 2019-06-05 17:37:18 +02:00
pistachio A batch of MIPS fixes: 2019-06-08 13:09:31 -07:00
pmcs-msp71xx MIPS: pmcs-msp71xx: Remove unused addr variable 2019-10-03 15:47:17 -07:00
pnx833x A batch of MIPS fixes: 2019-06-08 13:09:31 -07:00
power mips: check for dsp presence only once before save/restore 2019-10-07 10:58:53 -07:00
ralink MIPS: ralink: deactivate PCI support for SOC_MT7621 2019-09-06 08:45:03 -07:00
rb532 treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 182 2019-05-30 11:29:20 -07:00
sgi-ip22 MIPS: SGI-IP22/28: Use PROM for memory detection 2019-10-09 14:55:57 -07:00
sgi-ip27 MIPS: SGI-IP27: Fix crash, when CPUs are disabled via nr_cpus parameter 2019-11-22 10:56:14 -08:00
sgi-ip30 MIPS: add support for SGI Octane (IP30) 2019-11-01 14:58:56 -07:00
sgi-ip32 Merge branch 'siginfo-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace 2019-07-08 21:48:15 -07:00
sibyte treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 156 2019-05-30 11:26:35 -07:00
sni treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 210 2019-05-30 11:29:53 -07:00
tools MIPS: Check Loongson3 LL/SC errata workaround correctness 2019-10-07 09:43:13 -07:00
txx9 A batch of MIPS fixes: 2019-06-08 13:09:31 -07:00
vdso mips: Fix gettimeofday() in the vdso library 2019-12-02 10:50:37 -08:00
vr41xx treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 156 2019-05-30 11:26:35 -07:00
Kbuild treewide: Add SPDX license identifier - Kbuild 2019-05-30 11:32:33 -07:00
Kbuild.platforms MIPS: add support for SGI Octane (IP30) 2019-11-01 14:58:56 -07:00
Kconfig MIPS: BPF: eBPF JIT: check for MIPS ISA compliance in Kconfig 2019-12-18 15:15:04 -08:00
Kconfig.debug MIPS: cmdline: Remove redundant Kconfig defaults 2019-10-09 15:53:16 -07:00
Makefile MIPS: Check Loongson3 LL/SC errata workaround correctness 2019-10-07 09:43:13 -07:00
Makefile.postlink MIPS: Check Loongson3 LL/SC errata workaround correctness 2019-10-07 09:43:13 -07:00