Skip to content

s390/kfence: fix page fault reporting

Baoquan He requested to merge baoquan_he/centos-stream-9:bz2148793 into main

Bugzilla: https://bugzilla.redhat.com/2148793

Upstream Status: Linus.git

This is back ported from upstream, no conflict.

commit d9c2cf67b9cfd643ba85d51bc865a89a92e4f979
Author: Heiko Carstens <hca@linux.ibm.com>
Date:   Mon Feb 13 19:38:58 2023 +0100

    s390/kfence: fix page fault reporting

    Baoquan He reported lots of KFENCE reports when /proc/kcore is read,
    e.g. with crash or even simpler with dd:

     BUG: KFENCE: invalid read in copy_from_kernel_nofault+0x5e/0x120
     Invalid read at 0x00000000f4f5149f:
      copy_from_kernel_nofault+0x5e/0x120
      read_kcore+0x6b2/0x870
      proc_reg_read+0x9a/0xf0
      vfs_read+0x94/0x270
      ksys_read+0x70/0x100
      __do_syscall+0x1d0/0x200
      system_call+0x82/0xb0

    The reason for this is that read_kcore() simply reads memory that might
    have been unmapped by KFENCE with copy_from_kernel_nofault(). Any fault due
    to pages being unmapped by KFENCE would be handled gracefully by the fault
    handler (exception table fixup).

    However the s390 fault handler first reports the fault, and only afterwards
    would perform the exception table fixup. Most architectures have this in
    reversed order, which also avoids the false positive KFENCE reports when an
    unmapped page is accessed.

    Therefore change the s390 fault handler so it handles exception table
    fixups before KFENCE page faults are reported.

    Reported-by: Baoquan He <bhe@redhat.com>
    Tested-by: Baoquan He <bhe@redhat.com>
    Acked-by: Alexander Potapenko <glider@google.com>
    Link: https://lore.kernel.org/r/20230213183858.1473681-1-hca@linux.ibm.com
    Signed-off-by: Heiko Carstens <hca@linux.ibm.com>

Signed-off-by: Baoquan He <bhe@redhat.com>
Edited by Baoquan He

Merge request reports