From 84203fed6bace55a9e7f89d83cf74bd81603e91e Mon Sep 17 00:00:00 2001 From: kib Date: Tue, 5 Feb 2019 17:49:27 +0000 Subject: [PATCH] amd64: clear callee-preserved registers on syscall exit. %r8, %r10, and on non-KPTI configuration %r9 were not restored on fast return from a syscall. Reviewed by: markj Approved by: so Security: CVE-2019-5595 Sponsored by: The FreeBSD Foundation MFC after: 0 minutes --- sys/amd64/amd64/exception.S | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sys/amd64/amd64/exception.S b/sys/amd64/amd64/exception.S index 91767094954b..c0f57ad4babc 100644 --- a/sys/amd64/amd64/exception.S +++ b/sys/amd64/amd64/exception.S @@ -521,12 +521,14 @@ fast_syscall_common: movq TF_RFLAGS(%rsp),%r11 /* original %rflags */ movq TF_RIP(%rsp),%rcx /* original %rip */ movq TF_RSP(%rsp),%rsp /* user stack pointer */ + xorl %r8d,%r8d /* zero the rest of GPRs */ + xorl %r10d,%r10d cmpq $~0,PCPU(UCR3) je 2f movq PCPU(UCR3),%r9 movq %r9,%cr3 - xorl %r9d,%r9d -2: swapgs +2: xorl %r9d,%r9d + swapgs sysretq 3: /* AST scheduled. */