Skip to content

Commit 2883f01

Browse files
hjl-toolsIngo Molnar
authored andcommitted
x86/shstk: Enable shadow stacks for x32
1. Add shadow stack support to x32 signal. 2. Use the 64-bit map_shadow_stack syscall for x32. 3. Set up shadow stack for x32. Tested with shadow stack enabled x32 glibc on Intel Tiger Lake: I configured x32 glibc with --enable-cet, build glibc and run all glibc tests with shadow stack enabled. There are no regressions. I verified that shadow stack is enabled via /proc/pid/status. Signed-off-by: H.J. Lu <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Tested-by: H.J. Lu <[email protected]> Cc: "Edgecombe, Rick P" <[email protected]> Cc: "H. Peter Anvin" <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Andy Lutomirski <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 4ae3dc8 commit 2883f01

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

arch/x86/entry/syscalls/syscall_64.tbl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@
374374
450 common set_mempolicy_home_node sys_set_mempolicy_home_node
375375
451 common cachestat sys_cachestat
376376
452 common fchmodat2 sys_fchmodat2
377-
453 64 map_shadow_stack sys_map_shadow_stack
377+
453 common map_shadow_stack sys_map_shadow_stack
378378
454 common futex_wake sys_futex_wake
379379
455 common futex_wait sys_futex_wait
380380
456 common futex_requeue sys_futex_requeue

arch/x86/kernel/shstk.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ static int shstk_setup(void)
163163
if (features_enabled(ARCH_SHSTK_SHSTK))
164164
return 0;
165165

166-
/* Also not supported for 32 bit and x32 */
167-
if (!cpu_feature_enabled(X86_FEATURE_USER_SHSTK) || in_32bit_syscall())
166+
/* Also not supported for 32 bit */
167+
if (!cpu_feature_enabled(X86_FEATURE_USER_SHSTK) || in_ia32_syscall())
168168
return -EOPNOTSUPP;
169169

170170
size = adjust_shstk_size(0);

arch/x86/kernel/signal_64.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,9 @@ int x32_setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
315315

316316
uc_flags = frame_uc_flags(regs);
317317

318+
if (setup_signal_shadow_stack(ksig))
319+
return -EFAULT;
320+
318321
if (!user_access_begin(frame, sizeof(*frame)))
319322
return -EFAULT;
320323

@@ -377,6 +380,9 @@ COMPAT_SYSCALL_DEFINE0(x32_rt_sigreturn)
377380
if (!restore_sigcontext(regs, &frame->uc.uc_mcontext, uc_flags))
378381
goto badframe;
379382

383+
if (restore_signal_shadow_stack())
384+
goto badframe;
385+
380386
if (compat_restore_altstack(&frame->uc.uc_stack))
381387
goto badframe;
382388

0 commit comments

Comments
 (0)