Browse Source

[LibOS, Pal/Linux-SGX] Clean Trap Flag on PUSHF (for GDB)

Graphene stores EFLAGS contents on syscall-emulation and enclave-exit
(via PUSHF instruction). Under GDB, single-stepping sets Trap Flag (TP)
of EFLAGS, and TP=1 is stored on PUSHF. Upon consequent POPF, TP is set
and leads to a seemingly spurious trap. This commit sets TP=0 on PUSHF
to elide this surprising behavior.
Dmitrii Kuvaiskii 6 years ago
parent
commit
57b17cb869
2 changed files with 12 additions and 0 deletions
  1. 6 0
      LibOS/shim/src/syscallas.S
  2. 6 0
      Pal/src/host/Linux-SGX/enclave_entry.S

+ 6 - 0
LibOS/shim/src/syscallas.S

@@ -38,6 +38,12 @@ syscalldb:
 
 
         # Create shim_regs struct on the stack.
         # Create shim_regs struct on the stack.
         pushfq
         pushfq
+
+        # Under GDB, single-stepping sets Trap Flag (TP) of EFLAGS,
+        # thus TP=1 is stored on pushfq above. Upon consequent popfq,
+        # TP is 1, resulting in spurious trap. Reset TP here.
+        andq $~0x100, (%rsp)
+
         cld
         cld
         pushq %rbp
         pushq %rbp
         pushq %rbx
         pushq %rbx

+ 6 - 0
Pal/src/host/Linux-SGX/enclave_entry.S

@@ -361,6 +361,12 @@ sgx_ocall:
 	movq 8(%rbp), %rax
 	movq 8(%rbp), %rax
 	pushq %rax	# previous RIP
 	pushq %rax	# previous RIP
 	pushfq
 	pushfq
+
+	# Under GDB, single-stepping sets Trap Flag (TP) of EFLAGS,
+	# thus TP=1 is stored on pushfq above. Upon consequent popfq,
+	# TP is 1, resulting in spurious trap. Reset TP here.
+	andq $~0x100, (%rsp)
+
 	pushq %r15
 	pushq %r15
 	pushq %r14
 	pushq %r14
 	pushq %r13
 	pushq %r13