OpenCloudOS-Kernel/arch/arm
Andre Przywara a92882a4d2 ARM: 9159/1: decompressor: Avoid UNPREDICTABLE NOP encoding
In the decompressor's head.S we need to start with an instruction that
is some kind of NOP, but also mimics as the PE/COFF header, when the
kernel is linked as an UEFI application. The clever solution here is
"tstne r0, #0x4d000", which in the worst case just clobbers the
condition flags, and bears the magic "MZ" signature in the lowest 16 bits.

However the encoding used (0x13105a4d) is actually not valid, since bits
[15:12] are supposed to be 0 (written as "(0)" in the ARM ARM).
Violating this is UNPREDICTABLE, and *can* trigger an UNDEFINED
exception. Common Cortex cores seem to ignore those bits, but QEMU
chooses to trap, so the code goes fishing because of a missing exception
handler at this point. We are just saved by the fact that commonly (with
-kernel or when running from U-Boot) the "Z" bit is set, so the
instruction is never executed. See [0] for more details.

To make things more robust and avoid UNPREDICTABLE behaviour in the
kernel code, lets replace this with a "two-instruction NOP":
The first instruction is an exclusive OR, the effect of which the second
instruction reverts. This does not leave any trace, neither in a
register nor in the condition flags. Also it's a perfectly valid
encoding. Kudos to Peter Maydell for coming up with this gem.

[0] https://lore.kernel.org/qemu-devel/YTPIdbUCmwagL5%2FD@os.inf.tu-dresden.de/T/

Link: https://lore.kernel.org/linux-arm-kernel/20210908162617.104962-1-andre.przywara@arm.com/T/

Fixes: 81a0bc39ea ("ARM: add UEFI stub support")
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Reported-by: Adam Lackorzynski <adam@l4re.org>
Suggested-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
2021-12-17 11:34:32 +00:00
..
boot ARM: 9159/1: decompressor: Avoid UNPREDICTABLE NOP encoding 2021-12-17 11:34:32 +00:00
common Merge branches 'devel-stable' and 'misc' into for-linus 2021-11-02 09:04:22 +00:00
configs ARM: defconfig updates for 5.16 2021-11-03 17:07:02 -07:00
crypto
include ARM: 9158/1: leave it to core code to manage thread_info::cpu 2021-12-17 11:34:31 +00:00
kernel ARM: 9158/1: leave it to core code to manage thread_info::cpu 2021-12-17 11:34:31 +00:00
lib
mach-actions
mach-alpine
mach-artpec
mach-asm9260
mach-aspeed
mach-at91 ARM: SoC updates for v5.16 2021-11-03 16:48:32 -07:00
mach-axxia
mach-bcm Devicetree updates for v5.16: 2021-11-02 22:22:13 -07:00
mach-berlin
mach-clps711x
mach-cns3xxx
mach-davinci
mach-digicolor
mach-dove
mach-ep93xx ep93xx: clock: convert in-place to COMMON_CLK 2021-10-20 17:46:36 +02:00
mach-exynos rtc: s3c: remove HAVE_S3C_RTC in favor of direct dependencies 2021-10-17 19:15:12 +02:00
mach-footbridge
mach-gemini
mach-highbank
mach-hisi memblock: rename memblock_free to memblock_phys_free 2021-11-06 13:30:41 -07:00
mach-imx ARM development for 5.16: 2021-11-02 11:33:15 -07:00
mach-integrator clk: versatile: Rename ICST to CLK_ICST 2021-10-14 18:00:25 -07:00
mach-iop32x
mach-ixp4xx
mach-keystone
mach-lpc18xx
mach-lpc32xx
mach-mediatek
mach-meson
mach-milbeaut
mach-mmp
mach-moxart
mach-mstar
mach-mv78xx0
mach-mvebu
mach-mxs
mach-nomadik
mach-npcm
mach-nspire
mach-omap1 Updates for the interrupt subsystem: 2021-11-01 13:09:10 -07:00
mach-omap2 ARM: SoC updates for v5.16 2021-11-03 16:48:32 -07:00
mach-orion5x
mach-oxnas
mach-pxa
mach-qcom ARM: SoC drivers for 5.16 2021-11-03 17:00:52 -07:00
mach-rda
mach-realtek
mach-realview clk: versatile: Rename ICST to CLK_ICST 2021-10-14 18:00:25 -07:00
mach-rockchip
mach-rpc
mach-s3c ARM: SoC updates for v5.16 2021-11-03 16:48:32 -07:00
mach-s5pv210 rtc: s3c: remove HAVE_S3C_RTC in favor of direct dependencies 2021-10-17 19:15:12 +02:00
mach-sa1100 ARM: 9101/1: sa1100/assabet: convert LEDs to gpiod APIs 2021-10-25 13:11:54 +01:00
mach-shmobile
mach-socfpga
mach-spear
mach-sti
mach-stm32
mach-sunxi
mach-tegra
mach-uniphier
mach-ux500 clk: ux500: Add driver for the reset portions of PRCC 2021-10-26 18:06:05 -07:00
mach-versatile clk: versatile: Rename ICST to CLK_ICST 2021-10-14 18:00:25 -07:00
mach-vexpress clk: versatile: Rename ICST to CLK_ICST 2021-10-14 18:00:25 -07:00
mach-vt8500
mach-zynq
mm ARM fixes for 5.16-rc1: 2021-11-14 11:30:50 -08:00
net Merge https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next 2021-11-01 19:59:46 -07:00
nwfpe
plat-omap
plat-orion
plat-pxa
plat-versatile
probes ARM development for 5.16: 2021-11-02 11:33:15 -07:00
tools futex,arm: Wire up sys_futex_waitv() 2021-10-07 13:51:12 +02:00
vdso
vfp
xen xen: allow pv-only hypercalls only with CONFIG_XEN_PV 2021-11-02 08:11:01 -05:00
Kbuild kbuild: use more subdir- for visiting subdirectories while cleaning 2021-10-24 13:49:46 +09:00
Kconfig ARM: SoC drivers for 5.16 2021-11-03 17:00:52 -07:00
Kconfig-nommu
Kconfig.assembler
Kconfig.debug
Makefile ARM fixes for 5.16-rc1: 2021-11-14 11:30:50 -08:00