linux-stable/arch/x86/lib
Linus Torvalds b805d212c3 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 14:02:08 +02:00
..
.gitignore
atomic64_32.c
atomic64_386_32.S
atomic64_cx8_32.S
cache-smp.c
checksum_32.S
clear_page_64.S x86: fix clear_user_rep_good() exception handling annotation 2023-05-17 14:02:08 +02:00
cmdline.c x86/lib: Fix compiler and kernel-doc warnings 2023-01-03 18:46:21 +01:00
cmpxchg8b_emu.S
cmpxchg16b_emu.S
copy_mc.c
copy_mc_64.S
copy_page_64.S
copy_user_64.S x86/uaccess: Don't jump between functions 2022-04-19 21:58:53 +02:00
cpu.c
csum-copy_64.S
csum-partial_64.c uml/x86: use x86 load_unaligned_zeropad() 2022-01-30 21:26:39 -05:00
csum-wrappers_64.c net: unexport csum_and_copy_{from,to}_user 2022-04-29 14:37:59 -07:00
delay.c x86/delay: Fix the wrong asm constraint in delay_loop() 2022-04-05 21:21:57 +02:00
error-inject.c x86/error_inject: Align function properly 2022-10-17 16:40:59 +02:00
getuser.S
hweight.S
inat.c
insn-eval.c x86/insn: Avoid namespace clash by separating instruction decoder MMIO type from MMIO trace type 2023-01-03 18:46:06 +01:00
insn.c
iomap_copy_64.S x86/asm: Fix an assembler warning with current binutils 2023-01-03 17:55:11 +01:00
iomem.c x86: kmsan: handle open-coded assembly in lib/iomem.c 2022-10-03 14:03:24 -07:00
kaslr.c x86/kaslr: Fix build warning in KASLR code in boot stub 2022-04-11 09:41:12 +02:00
Makefile x86/mem: Move memmove to out of line assembler 2022-11-01 15:44:07 -07:00
memcpy_32.c x86/mem: Move memmove to out of line assembler 2022-11-01 15:44:07 -07:00
memcpy_64.S entry, kasan, x86: Disallow overriding mem*() functions 2023-01-13 11:48:17 +01:00
memmove_32.S x86/mem: Move memmove to out of line assembler 2022-11-01 15:44:07 -07:00
memmove_64.S entry, kasan, x86: Disallow overriding mem*() functions 2023-01-13 11:48:17 +01:00
memset_64.S entry, kasan, x86: Disallow overriding mem*() functions 2023-01-13 11:48:17 +01:00
misc.c x86/lib: Include <asm/misc.h> to fix a missing prototypes warning at build time 2023-01-03 11:11:03 +01:00
msr-reg-export.c
msr-reg.S
msr-smp.c
msr.c
pc-conf-reg.c
putuser.S x86/putuser: Provide room for padding 2022-10-17 16:41:10 +02:00
retpoline.S x86/retbleed: Fix return thunk alignment 2023-05-17 14:01:51 +02:00
string_32.c
strstr_32.c
usercopy.c x86/uaccess: instrument copy_from_user_nmi() 2022-11-08 15:57:24 -08:00
usercopy_32.c
usercopy_64.c x86/clear_user: Make it faster 2022-08-18 12:36:42 +02:00
x86-opcode-map.txt x86/opcode: Add the LKGS instruction to x86-opcode-map 2023-01-12 13:06:36 +01:00