linux-brain/arch/s390
Christian Borntraeger 215d1f3928 s390/mm: fix page table upgrade vs 2ndary address mode accesses
commit 316ec154810960052d4586b634156c54d0778f74 upstream.

A page table upgrade in a kernel section that uses secondary address
mode will mess up the kernel instructions as follows:

Consider the following scenario: two threads are sharing memory.
On CPU1 thread 1 does e.g. strnlen_user().  That gets to
        old_fs = enable_sacf_uaccess();
        len = strnlen_user_srst(src, size);
and
                "   la    %2,0(%1)\n"
                "   la    %3,0(%0,%1)\n"
                "   slgr  %0,%0\n"
                "   sacf  256\n"
                "0: srst  %3,%2\n"
in strnlen_user_srst().  At that point we are in secondary space mode,
control register 1 points to kernel page table and instruction fetching
happens via c1, rather than usual c13.  Interrupts are not disabled, for
obvious reasons.

On CPU2 thread 2 does MAP_FIXED mmap(), forcing the upgrade of page table
from 3-level to e.g. 4-level one.  We'd allocated new top-level table,
set it up and now we hit this:
                notify = 1;
                spin_unlock_bh(&mm->page_table_lock);
        }
        if (notify)
                on_each_cpu(__crst_table_upgrade, mm, 0);
OK, we need to actually change over to use of new page table and we
need that to happen in all threads that are currently running.  Which
happens to include the thread 1.  IPI is delivered and we have
static void __crst_table_upgrade(void *arg)
{
        struct mm_struct *mm = arg;

        if (current->active_mm == mm)
                set_user_asce(mm);
        __tlb_flush_local();
}
run on CPU1.  That does
static inline void set_user_asce(struct mm_struct *mm)
{
        S390_lowcore.user_asce = mm->context.asce;
OK, user page table address updated...
        __ctl_load(S390_lowcore.user_asce, 1, 1);
... and control register 1 set to it.
        clear_cpu_flag(CIF_ASCE_PRIMARY);
}

IPI is run in home space mode, so it's fine - insns are fetched
using c13, which always points to kernel page table.  But as soon
as we return from the interrupt, previous PSW is restored, putting
CPU1 back into secondary space mode, at which point we no longer
get the kernel instructions from the kernel mapping.

The fix is to only fixup the control registers that are currently in use
for user processes during the page table update.  We must also disable
interrupts in enable_sacf_uaccess to synchronize the cr and
thread.mm_segment updates against the on_each-cpu.

Fixes: 0aaba41b58 ("s390: remove all code using the access register mode")
Cc: stable@vger.kernel.org # 4.15+
Reported-by: Al Viro <viro@zeniv.linux.org.uk>
Reviewed-by: Gerald Schaefer <gerald.schaefer@de.ibm.com>
References: CVE-2020-11884
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-04-29 16:31:35 +02:00
..
appldata s390/appldata: reuse generic proc handler functions 2018-07-06 08:48:08 +02:00
boot s390: make 'install' not depend on vmlinux 2020-03-11 14:14:53 +01:00
configs s390: update defconfigs 2018-04-27 06:51:31 +02:00
crypto s390/crypto: xts-aes-s390 fix extra run-time crypto self tests finding 2019-10-05 13:09:55 +02:00
hypfs hypfs: Fix error number left in struct pointer member 2019-10-07 18:57:15 +02:00
include s390/qdio: fill SL with absolute addresses 2020-03-11 14:14:54 +01:00
kernel s390/cpum_sf: Fix wrong page count in error message 2020-04-23 10:30:18 +02:00
kvm KVM: s390: Return last valid slot if approx index is out-of-bounds 2020-04-29 16:31:30 +02:00
lib s390/mm: fix page table upgrade vs 2ndary address mode accesses 2020-04-29 16:31:35 +02:00
mm s390/mm: fix page table upgrade vs 2ndary address mode accesses 2020-04-29 16:31:35 +02:00
net s390/bpf: use 32-bit index for tail calls 2019-09-21 07:16:51 +02:00
numa s390/mm: Fix ERROR: "__node_distance" undefined! 2018-11-27 16:13:03 +01:00
oprofile License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
pci s390/pci: Fix possible deadlock in recover_store() 2020-02-24 08:34:38 +01:00
purgatory s390/purgatory: do not build purgatory with kcov, kasan and friends 2020-01-12 12:17:21 +01:00
scripts s390/build: add *.o.chkbss files to targets list 2018-07-02 12:32:23 +02:00
tools Minor code cleanups for PPC. 2018-08-19 10:38:36 -07:00
Kbuild s390/kexec_file: Add purgatory 2018-04-16 09:10:22 +02:00
Kconfig Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux 2018-08-24 09:31:34 -07:00
Kconfig.debug Kconfig: consolidate the "Kernel hacking" menu 2018-08-02 08:06:48 +09:00
Makefile s390: make 'install' not depend on vmlinux 2020-03-11 14:14:53 +01:00
defconfig crypto: speck - remove Speck 2018-11-13 11:08:46 -08:00