Skip to content

x86: Harden syscall dispatch

Peter Zijlstra lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest6 patches 7 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/6x86_64/entry: Unconditionally use -fno-jump-tablearch/x86/Kconfig arch/x86/Makefile arch/x86/entry/syscall_32.c +1 more+11 -242 replies
2/6objtool: Add instrumentation_weak()include/linux/annotate.h include/linux/instrumentation.h include/linux/objtool_types.h +2 more+32 -51 reply
3/6x86_64/entry: Make syscall dispatch noinstrarch/x86/entry/syscall_32.c arch/x86/entry/syscall_64.c+13 -30 replies
4/6x86_64/entry: Mark all syscalls __noendbrarch/x86/entry/syscall_32.c arch/x86/entry/syscall_64.c arch/x86/include/asm/syscall_wrapper.h +1 more+27 -174 replies
5/6objtool: Allow EXPORT_SYMBOL() of __noendbr functionsarch/x86/entry/calling.h arch/x86/entry/entry_64.S arch/x86/entry/entry_64_compat.S +7 more+16 -220 replies
6/6x86_64/entry: Mark C noinstr __noendbrarch/x86/entry/common.c arch/x86/entry/entry_fred.c arch/x86/entry/syscall_32.c +4 more+21 -210 replies

Reviews trailers per patch

None of the 6 patches has a Reviewed-by or Acked-by.

PatchBreno Leitao
1/6T-b
2/6
3/6
4/6
5/6
6/6

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH 0/6] x86: Harden syscall dispatch

Hi!

These few patches harden the syscall dispatch by making -fno-jump-table unconditional for x86_64 and then having all SYSCALL*() macros mark the actual syscall entry points with __noendbr.

Notably, we already have -fno-jump-table for KERNEL_IBT || RETPOLINE, which means effectively everybody already has this. However, making this unconditional has the nice side effect that the compilers must never generate array accesses and it is safe to remove array_index_nospec().

Additionally, since dispatch is now forced to be a binary decision tree with direct (tail) calls, there are no valid indirect calls to any of the syscall functions and they can be marked __noendbr.

This means anything trying to use the sys_call_table[] will fail (on hardware sporting IBT).

All this makes the normal system call hijack a lot more difficult.

Patches also at:

git://git.kernel.org/pub/scm/linux/kernel/git/peterz/queue.git x86/syscall

---
 arch/x86/Kconfig                       |  4 +---
 arch/x86/Makefile                      | 27 +++++++---------------
 arch/x86/entry/calling.h               |  1 -
 arch/x86/entry/common.c                |  2 +-
 arch/x86/entry/entry_64.S              |  2 +-
 arch/x86/entry/entry_64_compat.S       |  6 ++---
 arch/x86/entry/entry_fred.c            |  6 ++---
 arch/x86/entry/syscall_32.c            | 20 ++++++++++-------
 arch/x86/entry/syscall_64.c            | 24 +++++++++++++-------
 arch/x86/include/asm/entry-common.h    |  2 +-
 arch/x86/include/asm/fred.h            |  6 ++---
 arch/x86/include/asm/syscall.h         | 10 ++++-----
 arch/x86/include/asm/syscall_wrapper.h | 23 ++++++++++---------
 arch/x86/lib/clear_page_64.S           |  1 -
 arch/x86/lib/copy_user_64.S            |  1 -
 arch/x86/lib/copy_user_uncached_64.S   |  1 -
 arch/x86/lib/getuser.S                 |  4 ----
 arch/x86/lib/hweight.S                 |  3 ---
 arch/x86/lib/putuser.S                 |  4 ----
 include/linux/annotate.h               |  1 +
 include/linux/instrumentation.h        | 17 ++++++++++++++
 include/linux/objtool_types.h          |  1 +
 tools/include/linux/objtool_types.h    |  1 +
 tools/objtool/check.c                  | 41 ++++++++++++++++++++++++++--------
 24 files changed, 118 insertions(+), 90 deletions(-)