linux-stable/arch/powerpc/kvm
Fabiano Rosas 5d7d6dac8f KVM: PPC: Book3S HV: Fix copy_tofrom_guest routines
The __kvmhv_copy_tofrom_guest_radix function was introduced along with
nested HV guest support. It uses the platform's Radix MMU quadrants to
provide a nested hypervisor with fast access to its nested guests
memory (H_COPY_TOFROM_GUEST hypercall). It has also since been added
as a fast path for the kvmppc_ld/st routines which are used during
instruction emulation.

The commit def0bfdbd6 ("powerpc: use probe_user_read() and
probe_user_write()") changed the low level copy function from
raw_copy_from_user to probe_user_read, which adds a check to
access_ok. In powerpc that is:

 static inline bool __access_ok(unsigned long addr, unsigned long size)
 {
         return addr < TASK_SIZE_MAX && size <= TASK_SIZE_MAX - addr;
 }

and TASK_SIZE_MAX is 0x0010000000000000UL for 64-bit, which means that
setting the two MSBs of the effective address (which correspond to the
quadrant) now cause access_ok to reject the access.

This was not caught earlier because the most common code path via
kvmppc_ld/st contains a fallback (kvm_read_guest) that is likely to
succeed for L1 guests. For nested guests there is no fallback.

Another issue is that probe_user_read (now __copy_from_user_nofault)
does not return the number of bytes not copied in case of failure, so
the destination memory is not being cleared anymore in
kvmhv_copy_from_guest_radix:

 ret = kvmhv_copy_tofrom_guest_radix(vcpu, eaddr, to, NULL, n);
 if (ret > 0)                            <-- always false!
         memset(to + (n - ret), 0, ret);

This patch fixes both issues by skipping access_ok and open-coding the
low level __copy_to/from_user_inatomic.

Fixes: def0bfdbd6 ("powerpc: use probe_user_read() and probe_user_write()")
Signed-off-by: Fabiano Rosas <farosas@linux.ibm.com>
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20210805212616.2641017-2-farosas@linux.ibm.com
2021-08-24 23:14:06 +10:00
..
book3s.c KVM: debugfs: Reuse binary stats descriptors 2021-06-24 18:00:29 -04:00
book3s.h KVM: PPC: Convert to the gfn-based MMU notifier callbacks 2021-04-17 08:31:07 -04:00
book3s_32_mmu.c KVM: PPC: Use fallthrough; 2020-03-19 16:39:52 +11:00
book3s_32_mmu_host.c powerpc/32s: move CTX_TO_VSID() into mmu-hash.h 2021-06-17 00:09:08 +10:00
book3s_32_sr.S treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 266 2019-06-05 17:30:28 +02:00
book3s_64_entry.S KVM: PPC: Book3S HV P9: implement hash host / hash guest support 2021-06-10 22:12:15 +10:00
book3s_64_mmu.c KVM: PPC: Use fallthrough; 2020-03-19 16:39:52 +11:00
book3s_64_mmu_host.c powerpc/kvm: Fix build error when PPC_MEM_KEYS/PPC_PSERIES=n 2021-04-27 10:48:37 +10:00
book3s_64_mmu_hv.c KVM: PPC: Book3S HV: Fix kvm_unmap_gfn_range_hv() for Hash MMU 2021-05-12 11:07:39 +10:00
book3s_64_mmu_radix.c KVM: PPC: Book3S HV: Fix copy_tofrom_guest routines 2021-08-24 23:14:06 +10:00
book3s_64_slb.S treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 266 2019-06-05 17:30:28 +02:00
book3s_64_vio.c KVM: PPC: Book3S: Fix symbol undeclared warnings 2020-09-22 11:53:55 +10:00
book3s_64_vio_hv.c KVM: PPC: Book3S HV: Remove virt mode checks from real mode handlers 2021-06-10 22:12:14 +10:00
book3s_emulate.c powerpc/32s: Change mfsrin() into a static inline function 2021-02-09 01:10:15 +11:00
book3s_exports.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 266 2019-06-05 17:30:28 +02:00
book3s_hv.c KVM: PPC: Book3S: Fix CONFIG_TRANSACTIONAL_MEM=n crash 2021-07-17 14:33:17 +10:00
book3s_hv_builtin.c KVM: PPC: Book3S HV: Fix TLB management on SMT8 POWER9 and POWER10 processors 2021-06-21 09:22:34 +10:00
book3s_hv_hmi.c
book3s_hv_interrupts.S KVM: PPC: Book3S HV: remove ISA v3.0 and v3.1 support from P7/8 path 2021-06-10 22:12:15 +10:00
book3s_hv_nested.c KVM: PPC: Book3S HV Nested: Sanitise H_ENTER_NESTED TM state 2021-07-23 16:19:38 +10:00
book3s_hv_p9_entry.c KVM: PPC: Book3S HV P9: Fix guest TM support 2021-07-15 21:53:37 +10:00
book3s_hv_ras.c KVM: PPC: Book3S HV: Don't attempt to recover machine checks for FWNMI enabled guests 2020-12-04 01:01:23 +11:00
book3s_hv_rm_mmu.c ARM: 2021-06-28 15:40:51 -07:00
book3s_hv_rm_xics.c KVM: PPC: Book3S HV: Remove unused nested HV tests in XICS emulation 2021-06-10 22:12:14 +10:00
book3s_hv_rm_xive.c mm: reorder includes after introduction of linux/pgtable.h 2020-06-09 09:39:13 -07:00
book3s_hv_rmhandlers.S KVM: PPC: Book3S HV: remove ISA v3.0 and v3.1 support from P7/8 path 2021-06-10 22:12:15 +10:00
book3s_hv_tm.c KVM: PPC: Book3S HV: Treat TM-related invalid form instructions on P9 like the valid ones 2020-03-19 16:39:52 +11:00
book3s_hv_tm_builtin.c KVM: PPC: Book3S HV: Treat TM-related invalid form instructions on P9 like the valid ones 2020-03-19 16:39:52 +11:00
book3s_hv_uvmem.c Merge branch 'akpm' (patches from Andrew) 2021-06-29 17:29:11 -07:00
book3s_interrupts.S PPC KVM update for 5.9 2020-08-09 13:24:02 -04:00
book3s_mmu_hpte.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 266 2019-06-05 17:30:28 +02:00
book3s_paired_singles.c KVM: PPC: Clean up redundant 'kvm_run' parameters 2020-05-27 11:39:31 +10:00
book3s_pr.c powerpc updates for 5.14 2021-07-02 12:54:34 -07:00
book3s_pr_papr.c KVM: stats: Separate generic stats from architecture specific ones 2021-06-24 11:47:56 -04:00
book3s_rmhandlers.S powerpc: Replace RFI by rfi on book3s/32 and booke 2020-11-19 16:56:54 +11:00
book3s_rtas.c KVM: PPC: Book3S: Fix H_RTAS rets buffer overflow 2021-07-23 16:14:31 +10:00
book3s_segment.S KVM: PPC: Book3S 64: move bad_host_intr check to HV handler 2021-06-10 22:12:12 +10:00
book3s_xics.c KVM: PPC: Book3S: Assign boolean values to a bool variable 2020-12-15 22:22:06 +11:00
book3s_xics.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
book3s_xive.c Updates for the interrupt subsystem: 2021-06-29 12:25:04 -07:00
book3s_xive.h KVM: PPC: Book3S HV: Remove virt mode checks from real mode handlers 2021-06-10 22:12:14 +10:00
book3s_xive_native.c Updates for the interrupt subsystem: 2021-06-29 12:25:04 -07:00
book3s_xive_template.c powerpc/xive: Remove P9 DD1 flag XIVE_IRQ_FLAG_EOI_FW 2020-12-11 09:53:10 +11:00
booke.c KVM: debugfs: Reuse binary stats descriptors 2021-06-24 18:00:29 -04:00
booke.h KVM: PPC: Clean up redundant 'kvm_run' parameters 2020-05-27 11:39:31 +10:00
booke_emulate.c KVM: PPC: Clean up redundant 'kvm_run' parameters 2020-05-27 11:39:31 +10:00
booke_interrupts.S KVM: PPC: Clean up redundant kvm_run parameters in assembly 2020-07-23 15:50:01 +10:00
bookehv_interrupts.S KVM: PPC: Clean up redundant kvm_run parameters in assembly 2020-07-23 15:50:01 +10:00
e500.c KVM: PPC: Kill kvmppc_ops::mmu_destroy() and kvmppc_mmu_destroy() 2020-03-19 16:43:07 +11:00
e500.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
e500_emulate.c KVM: PPC: Clean up redundant 'kvm_run' parameters 2020-05-27 11:39:31 +10:00
e500_mmu.c KVM: PPC: Kill kvmppc_ops::mmu_destroy() and kvmppc_mmu_destroy() 2020-03-19 16:43:07 +11:00
e500_mmu_host.c KVM: PPC: Convert to the gfn-based MMU notifier callbacks 2021-04-17 08:31:07 -04:00
e500_mmu_host.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
e500mc.c KVM: PPC: Kill kvmppc_ops::mmu_destroy() and kvmppc_mmu_destroy() 2020-03-19 16:43:07 +11:00
emulate.c KVM: PPC: Clean up redundant 'kvm_run' parameters 2020-05-27 11:39:31 +10:00
emulate_loadstore.c MIPS: 2020-06-12 11:05:52 -07:00
fpu.S mm: reorder includes after introduction of linux/pgtable.h 2020-06-09 09:39:13 -07:00
irq.h
Kconfig powerpc/kvm: Force selection of CONFIG_PPC_FPU 2021-01-30 11:39:32 +11:00
Makefile KVM: stats: Add fd-based API to read binary stats data 2021-06-24 11:47:57 -04:00
mpic.c KVM: Remove unnecessary asm/kvm_host.h includes 2020-03-16 17:57:34 +01:00
powerpc.c KVM: PPC: Fix kvm_arch_vcpu_ioctl vcpu_load leak 2021-07-17 14:33:18 +10:00
timing.c powerpc/kvm: no need to check return value of debugfs_create functions 2020-03-04 22:44:25 +11:00
timing.h KVM: Remove unnecessary asm/kvm_host.h includes 2020-03-16 17:57:34 +01:00
tm.S
trace.h
trace_book3s.h
trace_booke.h KVM: Move arm64's MMU notifier trace events to generic code 2021-04-17 08:30:56 -04:00
trace_hv.h KVM: PPC: Fix typo on H_DISABLE_AND_GET hcall 2020-07-23 17:43:35 +10:00
trace_pr.h