Re: [PATCH] s390/kfence: fix page fault reporting

Alexander Potapenko
2023-02-14T13:34:15Z

On Mon, Feb 13, 2023 at 7:39 PM Heiko Carstens <hca@linux.ibm.com> wrote:
>
> 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>
> Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
Acked-by: Alexander Potapenko <glider@google.com>