linux/arch/arm64/include/asm
Mark Rutland 94902d849e arm64: uaccess: avoid blocking within critical sections
As Vincent reports in:

  https://lore.kernel.org/r/20211118163417.21617-1-vincent.whitchurch@axis.com

The put_user() in schedule_tail() can get stuck in a livelock, similar
to a problem recently fixed on riscv in commit:

  285a76bb2c ("riscv: evaluate put_user() arg before enabling user access")

In __raw_put_user() we have a critical section between
uaccess_ttbr0_enable() and uaccess_ttbr0_disable() where we cannot
safely call into the scheduler without having taken an exception, as
schedule() and other scheduling functions will not save/restore the
TTBR0 state. If either of the `x` or `ptr` arguments to __raw_put_user()
contain a blocking call, we may call into the scheduler within the
critical section. This can result in two problems:

1) The access within the critical section will occur without the
   required TTBR0 tables installed. This will fault, and where the
   required tables permit access, the access will be retried without the
   required tables, resulting in a livelock.

2) When TTBR0 SW PAN is in use, check_and_switch_context() does not
   modify TTBR0, leaving a stale value installed. The mappings of the
   blocked task will erroneously be accessible to regular accesses in
   the context of the new task. Additionally, if the tables are
   subsequently freed, local TLB maintenance required to reuse the ASID
   may be lost, potentially resulting in TLB corruption (e.g. in the
   presence of CnP).

The same issue exists for __raw_get_user() in the critical section
between uaccess_ttbr0_enable() and uaccess_ttbr0_disable().

A similar issue exists for __get_kernel_nofault() and
__put_kernel_nofault() for the critical section between
__uaccess_enable_tco_async() and __uaccess_disable_tco_async(), as the
TCO state is not context-switched by direct calls into the scheduler.
Here the TCO state may be lost from the context of the current task,
resulting in unexpected asynchronous tag check faults. It may also be
leaked to another task, suppressing expected tag check faults.

To fix all of these cases, we must ensure that we do not directly call
into the scheduler in their respective critical sections. This patch
reworks __raw_put_user(), __raw_get_user(), __get_kernel_nofault(), and
__put_kernel_nofault(), ensuring that parameters are evaluated outside
of the critical sections. To make this requirement clear, comments are
added describing the problem, and line spaces added to separate the
critical sections from other portions of the macros.

For __raw_get_user() and __raw_put_user() the `err` parameter is
conditionally assigned to, and we must currently evaluate this in the
critical section. This behaviour is relied upon by the signal code,
which uses chains of put_user_error() and get_user_error(), checking the
return value at the end. In all cases, the `err` parameter is a plain
int rather than a more complex expression with a blocking call, so this
is safe.

In future we should try to clean up the `err` usage to remove the
potential for this to be a problem.

Aside from the changes to time of evaluation, there should be no
functional change as a result of this patch.

Reported-by: Vincent Whitchurch <vincent.whitchurch@axis.com>
Link: https://lore.kernel.org/r/20211118163417.21617-1-vincent.whitchurch@axis.com
Fixes: f253d827f3 ("arm64: uaccess: refactor __{get,put}_user")
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Link: https://lore.kernel.org/r/20211122125820.55286-1-mark.rutland@arm.com
Signed-off-by: Will Deacon <will@kernel.org>
2021-11-24 09:16:26 +00:00
..
vdso arm64: vdso32: drop test for -march=armv8-a 2021-10-21 10:31:38 +01:00
xen xen/arm: introduce XENFEAT_direct_mapped and XENFEAT_not_direct_mapped 2021-04-23 11:33:50 +02:00
Kbuild set_memory: allow querying whether set_direct_map_*() is actually enabled 2021-07-08 11:48:20 -07:00
acenv.h
acpi.h Revert "ACPI: Add memory semantics to acpi_os_map_memory()" 2021-09-23 20:39:36 +02:00
alternative-macros.h Merge branch 'for-next/insn' into for-next/core 2021-06-24 14:03:24 +01:00
alternative.h arm64: alternatives: Split up alternative.h 2020-11-09 21:49:34 +00:00
arch_gicv3.h arm64: Rename arm64-internal cache maintenance functions 2021-05-25 19:27:49 +01:00
arch_timer.h arm64: Add CNT{P,V}CTSS_EL0 alternatives to cnt{p,v}ct_el0 2021-10-19 10:56:20 +01:00
archrandom.h arm64: Add support for SMCCC TRNG entropy source 2021-01-21 17:42:46 +00:00
arm-cci.h
arm_dsu_pmu.h
asm-bug.h
asm-extable.h arm64: extable: add load_unaligned_zeropad() handler 2021-10-21 10:45:22 +01:00
asm-offsets.h
asm-prototypes.h kasan: arm64: support specialized outlined tag mismatch checks 2021-05-26 23:31:26 +01:00
asm-uaccess.h arm64: extable: consolidate definitions 2021-10-21 10:45:22 +01:00
asm_pointer_auth.h arm64: Conditionally configure PTR_AUTH key of the kernel. 2021-06-15 11:32:31 +01:00
assembler.h Merge branch 'for-next/kexec' into for-next/core 2021-10-29 12:24:47 +01:00
atomic.h locking/atomic: make ARCH_ATOMIC a Kconfig symbol 2021-05-26 13:20:49 +02:00
atomic_ll_sc.h
atomic_lse.h
barrier.h arm64: errata: Add workaround for TSB flush failures 2021-10-21 17:49:16 +01:00
bitops.h
bitrev.h
boot.h arm64: get rid of TEXT_OFFSET 2020-09-07 15:00:52 +01:00
brk-imm.h arm64: kprobes: Use BRK instead of single-step when executing instructions out-of-line 2020-11-03 14:03:38 +00:00
bug.h
cache.h Revert "arm64: cache: Lower ARCH_DMA_MINALIGN to 64 (L1_CACHE_BYTES)" 2021-07-12 13:37:34 +01:00
cacheflush.h set_memory: allow querying whether set_direct_map_*() is actually enabled 2021-07-08 11:48:20 -07:00
checksum.h arm64: csum: cast to the proper type 2021-03-15 10:57:21 +00:00
clocksource.h
cmpxchg.h
compat.h arch: remove compat_alloc_user_space 2021-09-08 15:32:35 -07:00
compiler.h CFI: Move function_nocfi() into compiler.h 2021-06-14 09:12:09 -07:00
cpu.h arm64: cpuinfo: Split AArch32 registers out into a separate struct 2021-06-11 13:25:40 +01:00
cpu_ops.h arm64: fix some spelling mistakes in the comments by codespell 2020-09-07 14:18:50 +01:00
cpufeature.h ARM: 2021-09-07 13:40:51 -07:00
cpuidle.h arm64: Add cpuidle context save/restore helpers 2021-06-17 18:00:39 +01:00
cputype.h arm64: Add Neoverse-N2, Cortex-A710 CPU part definition 2021-10-21 17:49:16 +01:00
current.h
daifflags.h arm64: entry: always set GIC_PRIO_PSR_I_SET during entry 2021-05-05 18:13:58 +01:00
dcc.h
debug-monitors.h arm64: kprobes: Use BRK instead of single-step when executing instructions out-of-line 2020-11-03 14:03:38 +00:00
device.h
dmi.h
efi.h drm-misc-next for v5.15-rc1: 2021-07-23 11:32:43 +10:00
el2_setup.h arm64 updates for 5.15: 2021-09-01 15:04:29 -07:00
elf.h arm64: exec: Adjust affinity for compat tasks with mismatched 32-bit EL0 2021-08-20 12:33:06 +02:00
esr.h KVM/arm64 fixes for 5.16, take #1 2021-11-12 16:01:55 -05:00
exception.h arm64: entry: move bulk of ret_to_user to C 2021-08-05 14:09:49 +01:00
exec.h arm64: uaccess: remove set_fs() 2020-12-02 19:49:11 +00:00
extable.h arm64: extable: add `type` and `data` fields 2021-10-21 10:45:22 +01:00
fb.h
fixmap.h arm64/fixmap: make notes of fixed_addresses more precisely 2020-08-08 19:25:04 +01:00
fpsimd.h arm64/sve: Add stub for sve_max_virtualisable_vl() 2021-10-26 10:15:46 +01:00
fpsimdmacros.h arm64/sve: Explicitly load vector length when restoring SVE state 2021-10-21 10:18:17 +01:00
ftrace.h arm64: ftrace: use HAVE_FUNCTION_GRAPH_RET_ADDR_PTR 2021-11-16 09:47:54 +00:00
futex.h arm64: extable: add a dedicated uaccess handler 2021-10-21 10:45:22 +01:00
gpr-num.h arm64: gpr-num: support W registers 2021-10-21 10:45:22 +01:00
hardirq.h arm64: irqstat: Get rid of duplicated declaration 2020-11-23 10:31:05 +01:00
hugetlb.h mm/hugetlb: change parameters of arch_make_huge_pte() 2021-06-30 20:47:26 -07:00
hw_breakpoint.h
hwcap.h arm64: Add HWCAP for self-synchronising virtual counter 2021-10-19 10:56:20 +01:00
hyp_image.h KVM: arm64: Allow using kvm_nvhe_sym() in hyp code 2021-03-19 12:01:20 +00:00
hyperv-tlfs.h arm64: hyperv: Add Hyper-V hypercall and register access utilities 2021-08-04 16:54:36 +00:00
hypervisor.h arm/arm64: Probe for the presence of KVM hypervisor 2021-03-31 09:16:55 +01:00
image.h
insn-def.h arm64: insn: avoid circular include dependency 2021-06-21 11:58:03 +01:00
insn.h arm64: insn: avoid circular include dependency 2021-06-21 11:58:03 +01:00
io.h asm-generic/io.h: implement pci_remap_cfgspace using ioremap_np 2021-04-08 20:18:38 +09:00
irq.h arm64: irq: allow FIQs to be handled 2021-03-24 20:19:30 +00:00
irq_work.h arm64: smp: Add missing prototype for some smp.c functions 2021-03-29 10:41:42 +01:00
irqflags.h arm64: Always keep DAIF.[IF] in sync 2021-03-24 20:19:30 +00:00
jump_label.h
kasan.h arm64: kasan: simplify and inline MTE functions 2021-02-26 09:41:03 -08:00
kernel-pgtable.h arm64: head: avoid over-mapping in map_memory 2021-08-24 16:44:23 +01:00
kexec.h arm64: kexec: remove cpu-reset.h 2021-10-01 13:31:00 +01:00
kfence.h set_memory: allow querying whether set_direct_map_*() is actually enabled 2021-07-08 11:48:20 -07:00
kgdb.h
kprobes.h kprobes: treewide: Make it harder to refer kretprobe_trampoline directly 2021-09-30 21:24:06 -04:00
kvm_arm.h KVM: arm64: Add missing field descriptor for MDCR_EL2 2021-10-11 14:57:28 +01:00
kvm_asm.h ARM: 2021-11-02 11:24:14 -07:00
kvm_emulate.h KVM: arm64: Fix reporting of endianess when the access originates at EL0 2021-10-12 15:47:25 +01:00
kvm_host.h KVM/arm64 fixes for 5.16, take #1 2021-11-12 16:01:55 -05:00
kvm_hyp.h KVM: arm64: Add handlers for protected VM System Registers 2021-10-11 14:57:29 +01:00
kvm_mmu.h KVM: arm64: Upgrade VMID accesses to {READ,WRITE}_ONCE 2021-08-20 09:12:24 +01:00
kvm_mte.h KVM: arm64: Save/restore MTE registers 2021-06-22 14:08:05 +01:00
kvm_pgtable.h KVM: arm64: Enable retrieving protections attributes of PTEs 2021-08-11 11:39:51 +01:00
kvm_ptrauth.h KVM: arm64: Update context references from host to hyp 2020-09-15 18:39:02 +01:00
kvm_ras.h
kvm_types.h
linkage.h arm64: Add assembly annotations for weak-PI-alias madness 2021-06-01 18:34:38 +01:00
lse.h
memory.h arm64: mte: Add asymmetric mode support 2021-10-07 09:30:24 +01:00
mman.h arm64: mte: Validate the PROT_MTE request via arch_validate_flags() 2020-09-04 12:46:07 +01:00
mmu.h arm64: mm: Fix TLBI vs ASID rollover 2021-08-06 13:52:03 +01:00
mmu_context.h arm64: hibernate: abstract ttrb0 setup function 2021-10-01 13:30:59 +01:00
mmzone.h
module.h
module.lds.h kasan: arm64: support specialized outlined tag mismatch checks 2021-05-26 23:31:26 +01:00
mshyperv.h arm64: hyperv: Add Hyper-V hypercall and register access utilities 2021-08-04 16:54:36 +00:00
mte-def.h KVM: arm64: Add ioctl to fetch/store tags in a guest 2021-06-22 14:08:06 +01:00
mte-kasan.h arm64: mte: Add asymmetric mode support 2021-10-07 09:30:24 +01:00
mte.h arm64: mte: Add asymmetric mode support 2021-10-07 09:30:24 +01:00
neon-intrinsics.h
neon.h
numa.h numa: Move numa implementation to common code 2021-01-14 15:08:55 -08:00
page-def.h arm64/mm: Unify CONT_PTE_SHIFT 2020-09-11 16:33:43 +01:00
page.h arm64/mm: drop HAVE_ARCH_PFN_VALID 2021-10-01 14:54:45 +01:00
paravirt.h x86/paravirt: Switch time pvops functions to use static_call() 2021-03-11 16:17:52 +01:00
patching.h arm64: insn: decouple patching from insn code 2021-06-11 11:19:27 +01:00
pci.h arm64: Enable PCI write-combine resources under sysfs 2020-09-18 14:05:13 +01:00
percpu.h KVM: arm64: Support per_cpu_ptr in nVHE hyp code 2020-12-04 10:08:34 +00:00
perf_event.h arm64: perf: Add more support on caps under sysfs 2021-06-03 09:53:17 +01:00
pgalloc.h arm64: mm: Fix VM_BUG_ON(mm != &init_mm) for trans_pgd 2021-11-16 10:12:57 +00:00
pgtable-hwdef.h arm64/mm: Drop SECTION_[SHIFT|SIZE|MASK] 2021-06-15 12:08:39 +01:00
pgtable-prot.h arm64: mm: Remove unused support for Normal-WT memory type 2021-06-01 18:53:53 +01:00
pgtable-types.h
pgtable.h arm64: pgtable: make __pte_to_phys/__phys_to_pte_val inline functions 2021-11-08 10:05:54 +00:00
pointer_auth.h arm64: move preemption disablement to prctl handlers 2021-07-28 18:33:49 +01:00
preempt.h sched/core: Initialize the idle task with preemption disabled 2021-05-12 13:01:45 +02:00
probes.h arm64/fpsimd: add <asm/insn.h> to <asm/kprobes.h> to fix fpsimd build 2020-11-23 10:59:00 +00:00
proc-fns.h
processor.h arm64 updates for 5.16 2021-11-01 16:33:53 -07:00
ptdump.h arm64: Add __init section marker to some functions 2021-04-08 17:45:10 +01:00
ptrace.h arm64: fix compat syscall return truncation 2021-08-03 10:35:03 +01:00
pvclock-abi.h
rwonce.h arm64: lto: Strengthen READ_ONCE() to acquire when CONFIG_LTO=y 2020-11-09 21:49:34 +00:00
scs.h arm64: scs: Drop unused 'tmp' argument to scs_{load, save} asm macros 2021-05-27 17:55:33 +01:00
sdei.h Merge branch 'for-next/entry' into for-next/core 2021-06-24 14:01:55 +01:00
seccomp.h arm64: Enable seccomp architecture tracking 2020-11-20 11:16:34 -08:00
sections.h arm64: kexec: use ld script for relocation function 2021-10-01 13:31:00 +01:00
set_memory.h set_memory: allow querying whether set_direct_map_*() is actually enabled 2021-07-08 11:48:20 -07:00
setup.h arm64: asm: setup.h: export common variables 2021-10-12 09:22:33 +01:00
shmparam.h
signal.h arm64: expose FAR_EL1 tag bits in siginfo 2020-11-23 18:17:39 +00:00
signal32.h
simd.h arm64: replace in_irq() with in_hardirq() 2021-08-20 19:49:38 +01:00
smp.h arm64: smp: remove stack from secondary_data 2021-05-26 22:45:46 +01:00
smp_plat.h arm64: Add missing header <asm/smp.h> in two files 2021-07-12 13:37:34 +01:00
sparsemem.h arm64: Force SPARSEMEM_VMEMMAP as the only memory management model 2021-04-23 14:18:21 +01:00
spectre.h Merge remote-tracking branch 'origin/kvm-arm64/csv3' into kvmarm-master/queue 2020-12-03 19:12:24 +00:00
spinlock.h locking/arch: Move qrwlock.h include after qspinlock.h 2021-02-11 07:59:54 -05:00
spinlock_types.h
stack_pointer.h
stackprotector.h arm64: Defer enabling pointer authentication on boot core 2021-02-09 13:50:57 +00:00
stacktrace.h arm64: ftrace: use HAVE_FUNCTION_GRAPH_RET_ADDR_PTR 2021-11-16 09:47:54 +00:00
stage2_pgtable.h KVM: arm64: Remove unused page-table code 2020-09-11 15:51:15 +01:00
stat.h
string.h arm64: Mitigate MTE issues with str{n}cmp() 2021-09-21 14:50:19 +01:00
suspend.h
sync_bitops.h
syscall.h arch: remove unused function syscall_set_arguments() 2021-09-14 16:06:20 +02:00
syscall_wrapper.h
sysreg.h ARM: 2021-11-02 11:24:14 -07:00
system_misc.h ARM: 9095/1: ARM64: Remove arm_pm_restart() 2021-06-13 18:16:47 +01:00
thread_info.h cpu-to-thread_info update for v5.16-rc1 2021-11-01 17:00:05 -07:00
timex.h
tlb.h arm64: tlb: fix the TTL value of tlb_get_level 2021-06-23 14:52:57 +01:00
tlbflush.h arm64: mm: Fix TLBI vs ASID rollover 2021-08-06 13:52:03 +01:00
topology.h arch_topology: Allow multiple entities to provide sched_freq_tick() callback 2021-03-10 10:55:37 +05:30
trans_pgd.h arm64: trans_pgd: remove trans_pgd_map_page() 2021-10-01 13:31:01 +01:00
traps.h arm64: expose FAR_EL1 tag bits in siginfo 2020-11-23 18:17:39 +00:00
uaccess.h arm64: uaccess: avoid blocking within critical sections 2021-11-24 09:16:26 +00:00
unistd.h futex,arm: Wire up sys_futex_waitv() 2021-10-07 13:51:12 +02:00
unistd32.h futex,arm: Wire up sys_futex_waitv() 2021-10-07 13:51:12 +02:00
uprobes.h
vdso.h
vermagic.h
virt.h arm64: trans_pgd: hibernate: Add trans_pgd_copy_el2_vectors 2021-10-01 13:30:59 +01:00
vmalloc.h arm64/mm: Add pud_sect_supported() 2021-09-29 16:54:33 +01:00
vmap_stack.h
word-at-a-time.h arm64: extable: add load_unaligned_zeropad() handler 2021-10-21 10:45:22 +01:00
xor.h