android_kernel_xiaomi_sm7250/arch
Paul Burton 9b8a065de9 MIPS: Avoid VDSO ABI breakage due to global register variable
commit bbcc5672b0063b0e9d65dc8787a4f09c3b5bb5cc upstream.

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
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-01-09 10:18:59 +01:00
..
alpha alpha: Fix Eiger NR_IRQS to 128 2019-02-20 10:25:47 +01:00
arc ARC: IOC: panic if kernel was started with previously enabled IOC 2019-12-13 08:51:12 +01:00
arm libfdt: define INT32_MAX and UINT32_MAX in libfdt_env.h 2020-01-04 19:13:15 +01:00
arm64 KVM: arm64: Ensure 'params' is initialised when looking up sys register 2019-12-31 16:36:28 +01:00
c6x kbuild: rename LDFLAGS to KBUILD_LDFLAGS 2018-08-24 08:22:08 +09:00
h8300 h8300: use cc-cross-prefix instead of hardcoding h8300-unknown-linux- 2019-04-05 22:32:55 +02:00
hexagon hexagon: modify ffs() and fls() to return int 2018-09-10 19:42:15 -05:00
ia64 ia64:unwind: fix double free for mod->arch.init_unw_table 2019-10-05 13:09:38 +02:00
m68k m68k: fix command-line parsing when passed from u-boot 2019-12-01 09:16:22 +01:00
microblaze microblaze: fix multiple bugs in arch/microblaze/boot/Makefile 2019-12-05 09:20:13 +01:00
mips MIPS: Avoid VDSO ABI breakage due to global register variable 2020-01-09 10:18:59 +01:00
nds32 nds32: Fix the items of hwcap_str ordering issue. 2019-12-13 08:51:35 +01:00
nios2 nios2: kconfig: remove duplicate DEBUG_STACK_USAGE symbol defintions 2018-08-27 09:47:20 +08:00
openrisc openrisc: Fix broken paths to arch/or32 2019-12-05 09:20:40 +01:00
parisc parisc: Fix vmap memory leak in ioremap()/iounmap() 2019-10-29 09:20:00 +01:00
powerpc Revert "powerpc/vcpu: Assume dedicated processors as non-preempt" 2020-01-04 19:13:18 +01:00
riscv RISC-V: Avoid corrupting the upper 32-bit of phys_addr_t in ioremap 2019-12-01 09:16:53 +01:00
s390 s390/cpum_sf: Avoid SBD overflow condition in irq handler 2020-01-09 10:18:58 +01:00
sh pinctrl: sh-pfc: sh7734: Fix duplicate TCLK1_B 2019-12-31 16:35:32 +01:00
sparc sparc: Correct ctx->saw_frame_pointer logic. 2019-12-13 08:51:52 +01:00
um um: Make GCOV depend on !KCOV 2019-12-05 09:20:52 +01:00
unicore32 mm: convert return type of handle_mm_fault() caller to vm_fault_t 2018-08-17 16:20:28 -07:00
x86 x86/mce: Fix possibly incorrect severity calculation on AMD 2020-01-04 19:13:19 +01:00
xtensa xtensa: fix TLB sanity checker 2019-12-21 10:57:25 +01:00
.gitignore
Kconfig jump_label: move 'asm goto' support test to Kconfig 2019-06-04 08:02:34 +02:00