================
@@ -98,6 +101,57 @@ 
DEFINE_LIBUNWIND_FUNCTION(__libunwind_Registers_x86_64_jumpto)
   movq  %rbx, 0(%rax)
   movq  128(%rdi), %rbx # store new rip on new stack
   movq  %rbx, 8(%rax)
+  # Segment selectors are 16 bits. In particular, do not reload unchanged
+  # FS/GS selectors: doing so can clear their hidden base addresses.
+  movw  %fs,%ax
+  cmpw  148(%rdi),%ax
+  je    1f
+  movw  148(%rdi),%fs
+1:
+  movw  %gs,%ax
+  cmpw  150(%rdi),%ax
+  je    2f
+  movw  150(%rdi),%gs
+2:
+  movw  146(%rdi),%es
+  movw  142(%rdi),%ss
+  movw  144(%rdi),%ds
+  movw  %cs,%ax
+  cmpw  140(%rdi),%ax
+  je    3f
+  # An indirect far jump changes CS without consuming a shadow-stack entry.
+  movzwq 140(%rdi),%rax
+  pushq %rax
+  leaq  3f(%rip),%rax
+  pushq %rax
+  rex64 ljmp *(%rsp)
+3:
+  _LIBUNWIND_CET_ENDBR
+  # The far-jump path used a temporary 16-byte far pointer on the old stack.
+  # The old stack is discarded below.
+
+#if defined(X86_64_BASE_SYSCALL)
+  movq  %rdi,%r8
+  movq  $X86_64_BASE_SYSCALL,%rax
+  movq  $X86_64_SET_FSBASE,%rdi
+  movq  152(%r8),%rsi
+  syscall
+  testq %rax,%rax
----------------
aokblast wrote:

Then why we don't need the same handling over here?

https://github.com/llvm/llvm-project/pull/229176
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to