kernel_optimize_test/arch/arm64/kernel
Alexandru Elisei ad97425d23 arm64: compat: Do not treat syscall number as ESR_ELx for a bad syscall
[ Upstream commit 3fed9e551417b84038b15117732ea4505eee386b ]

If a compat process tries to execute an unknown system call above the
__ARM_NR_COMPAT_END number, the kernel sends a SIGILL signal to the
offending process. Information about the error is printed to dmesg in
compat_arm_syscall() -> arm64_notify_die() -> arm64_force_sig_fault() ->
arm64_show_signal().

arm64_show_signal() interprets a non-zero value for
current->thread.fault_code as an exception syndrome and displays the
message associated with the ESR_ELx.EC field (bits 31:26).
current->thread.fault_code is set in compat_arm_syscall() ->
arm64_notify_die() with the bad syscall number instead of a valid ESR_ELx
value. This means that the ESR_ELx.EC field has the value that the user set
for the syscall number and the kernel can end up printing bogus exception
messages*. For example, for the syscall number 0x68000000, which evaluates
to ESR_ELx.EC value of 0x1A (ESR_ELx_EC_FPAC) the kernel prints this error:

[   18.349161] syscall[300]: unhandled exception: ERET/ERETAA/ERETAB, ESR 0x68000000, Oops - bad compat syscall(2) in syscall[10000+50000]
[   18.350639] CPU: 2 PID: 300 Comm: syscall Not tainted 5.18.0-rc1 #79
[   18.351249] Hardware name: Pine64 RockPro64 v2.0 (DT)
[..]

which is misleading, as the bad compat syscall has nothing to do with
pointer authentication.

Stop arm64_show_signal() from printing exception syndrome information by
having compat_arm_syscall() set the ESR_ELx value to 0, as it has no
meaning for an invalid system call number. The example above now becomes:

[   19.935275] syscall[301]: unhandled exception: Oops - bad compat syscall(2) in syscall[10000+50000]
[   19.936124] CPU: 1 PID: 301 Comm: syscall Not tainted 5.18.0-rc1-00005-g7e08006d4102 #80
[   19.936894] Hardware name: Pine64 RockPro64 v2.0 (DT)
[..]

which although shows less information because the syscall number,
wrongfully advertised as the ESR value, is missing, it is better than
showing plainly wrong information. The syscall number can be easily
obtained with strace.

*A 32-bit value above or equal to 0x8000_0000 is interpreted as a negative
integer in compat_arm_syscal() and the condition scno < __ARM_NR_COMPAT_END
evaluates to true; the syscall will exit to userspace in this case with the
ENOSYS error code instead of arm64_notify_die() being called.

Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
Reviewed-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20220425114444.368693-3-alexandru.elisei@arm.com
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2022-06-09 10:20:53 +02:00
..
probes arm64: kprobes: Restore local irqflag if kprobes is cancelled 2021-04-28 13:40:02 +02:00
vdso arm64/vdso: Discard .note.gnu.property sections in vDSO 2021-05-11 14:47:33 +02:00
vdso32 arm64: vdso32: require CROSS_COMPILE_COMPAT for gcc+bfd 2021-12-29 12:25:53 +01:00
.gitignore
acpi_numa.c
acpi_parking_protocol.c
acpi.c
alternative.c arm64: alternatives: mark patch_alternative() as noinstr 2022-04-20 09:23:22 +02:00
armv8_deprecated.c
asm-offsets.c
cacheinfo.c drivers: base: cacheinfo: Get rid of DEFINE_SMP_CALL_CACHE_FUNCTION() 2021-09-26 14:08:59 +02:00
cpu_errata.c arm64: Enable repeat tlbi workaround on KRYO4XX gold CPUs 2022-05-25 09:18:01 +02:00
cpu_ops.c
cpu-reset.h
cpu-reset.S
cpufeature.c arm64: Use the clearbhb instruction in mitigations 2022-03-11 12:11:53 +01:00
cpuidle.c cpuidle: PSCI: Move the has_lpi check to the beginning of the function 2022-04-20 09:23:09 +02:00
cpuinfo.c arm64: cpufeature: add HWCAP for FEAT_RPRES 2022-03-11 12:11:51 +01:00
crash_core.c
crash_dump.c arm64: kdump: update ppos when reading elfcorehdr 2021-03-30 14:32:03 +02:00
debug-monitors.c
efi-entry.S
efi-header.S arm64: efi: increase EFI PE/COFF header padding to 64 KB 2020-10-28 14:02:03 +00:00
efi-rt-wrapper.S
efi.c treewide: Convert macro and uses of __section(foo) to __section("foo") 2020-10-25 14:51:49 -07:00
entry-common.c arm64: entry: always set GIC_PRIO_PSR_I_SET during entry 2021-05-19 10:13:07 +02:00
entry-fpsimd.S
entry-ftrace.S arm64: ftrace: add missing BTIs 2021-12-08 09:03:24 +01:00
entry.S arm64: Use the clearbhb instruction in mitigations 2022-03-11 12:11:53 +01:00
fpsimd.c arm64/sve: Use correct size when reinitialising SVE state 2021-09-22 12:27:54 +02:00
ftrace.c
head.S arm64: head: avoid over-mapping in map_memory 2021-09-18 13:40:08 +02:00
hibernate-asm.S
hibernate.c
hw_breakpoint.c
hyp-stub.S
image-vars.h KVM/arm64 fixes for 5.10, take #1 2020-10-30 13:25:09 -04:00
image.h
insn.c arm64: patch_text: Fixup last cpu should be master 2022-04-13 21:01:08 +02:00
io.c
irq.c arm64: entry: move el1 irq/nmi logic to C 2020-11-30 12:11:38 +00:00
jump_label.c
kaslr.c
kexec_image.c arm64: kexec_file: Fix sparse warning 2020-11-10 13:11:44 +00:00
kgdb.c
kuser32.S
machine_kexec_file.c arm64: kexec_file: fix memory leakage in create_dtb() when fdt_open_into() fails 2021-03-04 11:38:36 +01:00
machine_kexec.c
Makefile
module-plts.c
module.c
mte.c arm64: mte: Ensure the cleared tags are visible before setting the PTE 2022-05-25 09:17:56 +02:00
paravirt.c arm64: paravirt: Use RCU read locks to guard stolen_time 2022-05-25 09:17:56 +02:00
pci.c
perf_callchain.c perf: Protect perf_guest_cbs with RCU 2022-01-20 09:17:50 +01:00
perf_event.c arm64: perf: Convert snprintf to sysfs_emit 2021-07-14 16:55:52 +02:00
perf_regs.c perf/arch: Remove perf_sample_data::regs_user_copy 2020-11-09 18:12:34 +01:00
pointer_auth.c
process.c arm64: errata: Fix exec handling in erratum 1418040 workaround 2022-02-01 17:25:40 +01:00
proton-pack.c arm64: Add part number for Arm Cortex-A78AE 2022-04-13 21:01:07 +02:00
psci.c arm64: psci: Avoid printing in cpu_psci_cpu_die() 2020-11-10 13:11:44 +00:00
ptrace.c arm64: fix compat syscall return truncation 2021-08-12 13:22:20 +02:00
reloc_test_core.c
reloc_test_syms.S
relocate_kernel.S
return_address.c
scs.c
sdei.c arm64: entry: fix NMI {user, kernel}->kernel transitions 2020-11-30 12:11:38 +00:00
setup.c arm64/mm: Fix ttbr0 values stored in struct thread_info for software-pan 2021-07-14 16:56:07 +02:00
signal.c arm64: signal: nofpsimd: Do not allocate fp/simd context when not available 2022-04-08 14:39:54 +02:00
signal32.c
sigreturn32.S
sleep.S
smccc-call.S
smp_spin_table.c treewide: Convert macro and uses of __section(foo) to __section("foo") 2020-10-25 14:51:49 -07:00
smp.c sched/core: Initialize the idle task with preemption disabled 2021-07-14 16:55:50 +02:00
stacktrace.c arm64: stacktrace: avoid tracing arch_stack_walk() 2021-08-12 13:22:12 +02:00
suspend.c arm64: spectre: Prevent lockdep splat on v4 mitigation enable path 2021-03-04 11:38:36 +01:00
sys_compat.c arm64: compat: Do not treat syscall number as ESR_ELx for a bad syscall 2022-06-09 10:20:53 +02:00
sys.c
sys32.c
syscall.c arm64: fix compat syscall return truncation 2021-08-12 13:22:20 +02:00
time.c
topology.c
trace-events-emulation.h
traps.c arm64: entry: fix NMI {user, kernel}->kernel transitions 2020-11-30 12:11:38 +00:00
vdso.c
vmlinux.lds.S arm64: entry: Allow the trampoline text to occupy multiple pages 2022-03-11 12:11:52 +01:00