linux-stable/arch
Linus Torvalds 90510aed20 x86: fix clear_user_rep_good() exception handling annotation
This code no longer exists in mainline, because it was removed in
commit d2c95f9d68 ("x86: don't use REP_GOOD or ERMS for user memory
clearing") upstream.

However, rather than backport the full range of x86 memory clearing and
copying cleanups, fix the exception table annotation placement for the
final 'rep movsb' in clear_user_rep_good(): rather than pointing at the
actual instruction that did the user space access, it pointed to the
register move just before it.

That made sense from a code flow standpoint, but not from an actual
usage standpoint: it means that if user access takes an exception, the
exception handler won't actually find the instruction in the exception
tables.

As a result, rather than fixing it up and returning -EFAULT, it would
then turn it into a kernel oops report instead, something like:

    BUG: unable to handle page fault for address: 0000000020081000
    #PF: supervisor write access in kernel mode
    #PF: error_code(0x0002) - not-present page
    ...
    RIP: 0010:clear_user_rep_good+0x1c/0x30 arch/x86/lib/clear_page_64.S:147
    ...
    Call Trace:
      __clear_user arch/x86/include/asm/uaccess_64.h:103 [inline]
      clear_user arch/x86/include/asm/uaccess_64.h:124 [inline]
      iov_iter_zero+0x709/0x1290 lib/iov_iter.c:800
      iomap_dio_hole_iter fs/iomap/direct-io.c:389 [inline]
      iomap_dio_iter fs/iomap/direct-io.c:440 [inline]
      __iomap_dio_rw+0xe3d/0x1cd0 fs/iomap/direct-io.c:601
      iomap_dio_rw+0x40/0xa0 fs/iomap/direct-io.c:689
      ext4_dio_read_iter fs/ext4/file.c:94 [inline]
      ext4_file_read_iter+0x4be/0x690 fs/ext4/file.c:145
      call_read_iter include/linux/fs.h:2183 [inline]
      do_iter_readv_writev+0x2e0/0x3b0 fs/read_write.c:733
      do_iter_read+0x2f2/0x750 fs/read_write.c:796
      vfs_readv+0xe5/0x150 fs/read_write.c:916
      do_preadv+0x1b6/0x270 fs/read_write.c:1008
      __do_sys_preadv2 fs/read_write.c:1070 [inline]
      __se_sys_preadv2 fs/read_write.c:1061 [inline]
      __x64_sys_preadv2+0xef/0x150 fs/read_write.c:1061
      do_syscall_x64 arch/x86/entry/common.c:50 [inline]
      do_syscall_64+0x39/0xb0 arch/x86/entry/common.c:80
      entry_SYSCALL_64_after_hwframe+0x63/0xcd

which then looks like a filesystem bug rather than the incorrect
exception annotation that it is.

[ The alternative to this one-liner fix is to take the upstream series
  that cleans this all up:

    68674f94ff ("x86: don't use REP_GOOD or ERMS for small memory copies")
    20f3337d35 ("x86: don't use REP_GOOD or ERMS for small memory clearing")
    adfcf4231b ("x86: don't use REP_GOOD or ERMS for user memory copies")
  * d2c95f9d68 ("x86: don't use REP_GOOD or ERMS for user memory clearing")
    3639a53558 ("x86: move stac/clac from user copy routines into callers")
    577e6a7fd5 ("x86: inline the 'rep movs' in user copies for the FSRM case")
    8c9b6a88b7 ("x86: improve on the non-rep 'clear_user' function")
    427fda2c8a ("x86: improve on the non-rep 'copy_user' function")
  * e046fe5a36 ("x86: set FSRS automatically on AMD CPUs that have FSRM")
    e1f2750edc ("x86: remove 'zerorest' argument from __copy_user_nocache()")
    034ff37d34 ("x86: rewrite '__copy_user_nocache' function")

  with either the whole series or at a minimum the two marked commits
  being needed to fix this issue ]

Reported-by: syzbot <syzbot+401145a9a237779feb26@syzkaller.appspotmail.com>
Link: https://syzkaller.appspot.com/bug?extid=401145a9a237779feb26
Fixes: 0db7058e8e ("x86/clear_user: Make it faster")
Cc: Borislav Petkov <bp@alien8.de>
Cc: stable@kernel.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-05-17 13:59:12 +02:00
..
alpha alpha: fix R_ALPHA_LITERAL reloc for large modules 2023-03-17 08:58:02 +01:00
arc MM patches for 6.2-rc1. 2022-12-13 19:29:45 -08:00
arm ARM: dts: aspeed: romed8hm3: Fix GPIO polarity of system-fault LED 2023-05-17 13:59:02 +02:00
arm64 arm64: kgdb: Set PSTATE.SS to 1 to re-enable single-step 2023-05-11 23:11:06 +09:00
csky arch/csky patches for 6.2-rc1 2022-12-19 07:51:30 -06:00
hexagon MM patches for 6.2-rc1. 2022-12-13 19:29:45 -08:00
ia64 ia64: fix an addr to taddr in huge_pte_offset() 2023-05-11 23:11:35 +09:00
loongarch LoongArch: Make WriteCombine configurable for ioremap() 2023-04-26 14:30:07 +02:00
m68k m68k: Only force 030 bus error if PC not in exception table 2023-03-30 12:51:28 +02:00
microblaze MM patches for 6.2-rc1. 2022-12-13 19:29:45 -08:00
mips MIPS: fw: Allow firmware to pass a empty env 2023-05-11 23:10:51 +09:00
nios2 MM patches for 6.2-rc1. 2022-12-13 19:29:45 -08:00
openrisc openrisc: Properly store r31 to pt_regs on unhandled exceptions 2023-05-11 23:11:29 +09:00
parisc parisc: Ensure page alignment in flush functions 2023-05-11 23:11:32 +09:00
powerpc powerpc/rtas: use memmove for potentially overlapping buffer copy 2023-05-11 23:11:25 +09:00
riscv riscv: compat_syscall_table: Fixup compile warning 2023-05-17 13:58:47 +02:00
s390 KVM: s390: fix race in gmap_make_secure() 2023-05-17 13:58:50 +02:00
sh sh: nmi_debug: fix return value of __setup handler 2023-05-17 13:59:00 +02:00
sparc sparc: allow PM configs for sparc32 COMPILE_TEST 2023-03-10 09:28:44 +01:00
um UML: define RUNTIME_DISCARD_EXIT 2023-03-17 08:58:03 +01:00
x86 x86: fix clear_user_rep_good() exception handling annotation 2023-05-17 13:59:12 +02:00
xtensa xtensa: fix KASAN report for show_stack 2023-04-06 12:12:45 +02:00
.gitignore
Kconfig arm64 fixes for -rc1 2022-12-16 13:46:41 -06:00