forked from opnsense/src
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mitigations for Microarchitectural Data Sampling.
Approved by: so Security: FreeBSD-SA-19:07.mds Security: CVE-2018-12126 Security: CVE-2018-12127 Security: CVE-2018-12130 Security: CVE-2019-11091
- Loading branch information
Showing
15 changed files
with
661 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
/*- | ||
* Copyright (c) 2018-2019 The FreeBSD Foundation | ||
* Copyright (c) 2003 Peter Wemm. | ||
* Copyright (c) 1993 The Regents of the University of California. | ||
* All rights reserved. | ||
* | ||
* Portions of this software were developed by | ||
* Konstantin Belousov <[email protected]> under sponsorship from | ||
* the FreeBSD Foundation. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
|
@@ -892,3 +897,246 @@ ENTRY(handle_ibrs_exit_rs) | |
END(handle_ibrs_exit_rs) | ||
|
||
.noaltmacro | ||
|
||
ENTRY(mds_handler_void) | ||
retq | ||
END(mds_handler_void) | ||
|
||
ENTRY(mds_handler_verw) | ||
subq $8, %rsp | ||
movw %ds, (%rsp) | ||
verw (%rsp) | ||
addq $8, %rsp | ||
retq | ||
END(mds_handler_verw) | ||
|
||
ENTRY(mds_handler_ivb) | ||
pushq %rax | ||
pushq %rdx | ||
pushq %rcx | ||
|
||
movq %cr0, %rax | ||
testb $CR0_TS, %al | ||
je 1f | ||
clts | ||
1: movq PCPU(MDS_BUF), %rdx | ||
movdqa %xmm0, PCPU(MDS_TMP) | ||
pxor %xmm0, %xmm0 | ||
|
||
lfence | ||
orpd (%rdx), %xmm0 | ||
orpd (%rdx), %xmm0 | ||
mfence | ||
movl $40, %ecx | ||
addq $16, %rdx | ||
2: movntdq %xmm0, (%rdx) | ||
addq $16, %rdx | ||
decl %ecx | ||
jnz 2b | ||
mfence | ||
|
||
movdqa PCPU(MDS_TMP),%xmm0 | ||
testb $CR0_TS, %al | ||
je 3f | ||
movq %rax, %cr0 | ||
3: popq %rcx | ||
popq %rdx | ||
popq %rax | ||
retq | ||
END(mds_handler_ivb) | ||
|
||
ENTRY(mds_handler_bdw) | ||
pushq %rax | ||
pushq %rbx | ||
pushq %rcx | ||
pushq %rdi | ||
pushq %rsi | ||
|
||
movq %cr0, %rax | ||
testb $CR0_TS, %al | ||
je 1f | ||
clts | ||
1: movq PCPU(MDS_BUF), %rbx | ||
movdqa %xmm0, PCPU(MDS_TMP) | ||
pxor %xmm0, %xmm0 | ||
|
||
movq %rbx, %rdi | ||
movq %rbx, %rsi | ||
movl $40, %ecx | ||
2: movntdq %xmm0, (%rbx) | ||
addq $16, %rbx | ||
decl %ecx | ||
jnz 2b | ||
mfence | ||
movl $1536, %ecx | ||
rep; movsb | ||
lfence | ||
|
||
movdqa PCPU(MDS_TMP),%xmm0 | ||
testb $CR0_TS, %al | ||
je 3f | ||
movq %rax, %cr0 | ||
3: popq %rsi | ||
popq %rdi | ||
popq %rcx | ||
popq %rbx | ||
popq %rax | ||
retq | ||
END(mds_handler_bdw) | ||
|
||
ENTRY(mds_handler_skl_sse) | ||
pushq %rax | ||
pushq %rdx | ||
pushq %rcx | ||
pushq %rdi | ||
|
||
movq %cr0, %rax | ||
testb $CR0_TS, %al | ||
je 1f | ||
clts | ||
1: movq PCPU(MDS_BUF), %rdi | ||
movq PCPU(MDS_BUF64), %rdx | ||
movdqa %xmm0, PCPU(MDS_TMP) | ||
pxor %xmm0, %xmm0 | ||
|
||
lfence | ||
orpd (%rdx), %xmm0 | ||
orpd (%rdx), %xmm0 | ||
xorl %eax, %eax | ||
2: clflushopt 5376(%rdi, %rax, 8) | ||
addl $8, %eax | ||
cmpl $8 * 12, %eax | ||
jb 2b | ||
sfence | ||
movl $6144, %ecx | ||
xorl %eax, %eax | ||
rep; stosb | ||
mfence | ||
|
||
movdqa PCPU(MDS_TMP), %xmm0 | ||
testb $CR0_TS, %al | ||
je 3f | ||
movq %rax, %cr0 | ||
3: popq %rdi | ||
popq %rcx | ||
popq %rdx | ||
popq %rax | ||
retq | ||
END(mds_handler_skl_sse) | ||
|
||
ENTRY(mds_handler_skl_avx) | ||
pushq %rax | ||
pushq %rdx | ||
pushq %rcx | ||
pushq %rdi | ||
|
||
movq %cr0, %rax | ||
testb $CR0_TS, %al | ||
je 1f | ||
clts | ||
1: movq PCPU(MDS_BUF), %rdi | ||
movq PCPU(MDS_BUF64), %rdx | ||
vmovdqa %ymm0, PCPU(MDS_TMP) | ||
vpxor %ymm0, %ymm0, %ymm0 | ||
|
||
lfence | ||
vorpd (%rdx), %ymm0, %ymm0 | ||
vorpd (%rdx), %ymm0, %ymm0 | ||
xorl %eax, %eax | ||
2: clflushopt 5376(%rdi, %rax, 8) | ||
addl $8, %eax | ||
cmpl $8 * 12, %eax | ||
jb 2b | ||
sfence | ||
movl $6144, %ecx | ||
xorl %eax, %eax | ||
rep; stosb | ||
mfence | ||
|
||
vmovdqa PCPU(MDS_TMP), %ymm0 | ||
testb $CR0_TS, %al | ||
je 3f | ||
movq %rax, %cr0 | ||
3: popq %rdi | ||
popq %rcx | ||
popq %rdx | ||
popq %rax | ||
retq | ||
END(mds_handler_skl_avx) | ||
|
||
ENTRY(mds_handler_skl_avx512) | ||
pushq %rax | ||
pushq %rdx | ||
pushq %rcx | ||
pushq %rdi | ||
|
||
movq %cr0, %rax | ||
testb $CR0_TS, %al | ||
je 1f | ||
clts | ||
1: movq PCPU(MDS_BUF), %rdi | ||
movq PCPU(MDS_BUF64), %rdx | ||
/* vmovdqa64 %zmm0, PCPU(MDS_TMP) */ | ||
.byte 0x65, 0x62, 0xf1, 0xfd, 0x48, 0x7f, 0x04, 0x25 | ||
.long PC_MDS_TMP | ||
/* vpxor %zmm0, %zmm0, %zmm0 */ | ||
.byte 0x62, 0xf1, 0xfd, 0x48, 0xef, 0xc0 | ||
|
||
lfence | ||
/* vorpd (%rdx), %zmm0, %zmm0 */ | ||
.byte 0x62, 0xf1, 0xfd, 0x48, 0x56, 0x02 | ||
/* vorpd (%rdx), %zmm0, %zmm0 */ | ||
.byte 0x62, 0xf1, 0xfd, 0x48, 0x56, 0x02 | ||
xorl %eax, %eax | ||
2: clflushopt 5376(%rdi, %rax, 8) | ||
addl $8, %eax | ||
cmpl $8 * 12, %eax | ||
jb 2b | ||
sfence | ||
movl $6144, %ecx | ||
xorl %eax, %eax | ||
rep; stosb | ||
mfence | ||
|
||
/* vmovdqa64 PCPU(MDS_TMP), %zmm0 */ | ||
.byte 0x65, 0x62, 0xf1, 0xfd, 0x48, 0x6f, 0x04, 0x25 | ||
.long PC_MDS_TMP | ||
testb $CR0_TS, %al | ||
je 3f | ||
movq %rax, %cr0 | ||
3: popq %rdi | ||
popq %rcx | ||
popq %rdx | ||
popq %rax | ||
retq | ||
END(mds_handler_skl_avx512) | ||
|
||
ENTRY(mds_handler_silvermont) | ||
pushq %rax | ||
pushq %rdx | ||
pushq %rcx | ||
|
||
movq %cr0, %rax | ||
testb $CR0_TS, %al | ||
je 1f | ||
clts | ||
1: movq PCPU(MDS_BUF), %rdx | ||
movdqa %xmm0, PCPU(MDS_TMP) | ||
pxor %xmm0, %xmm0 | ||
|
||
movl $16, %ecx | ||
2: movntdq %xmm0, (%rdx) | ||
addq $16, %rdx | ||
decl %ecx | ||
jnz 2b | ||
mfence | ||
|
||
movdqa PCPU(MDS_TMP),%xmm0 | ||
testb $CR0_TS, %al | ||
je 3f | ||
movq %rax, %cr0 | ||
3: popq %rcx | ||
popq %rdx | ||
popq %rax | ||
retq | ||
END(mds_handler_silvermont) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -406,6 +406,7 @@ doreti_ast: | |
*/ | ||
doreti_exit: | ||
MEXITCOUNT | ||
call *mds_handler | ||
|
||
.globl doreti_popl_fs | ||
doreti_popl_fs: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -768,6 +768,7 @@ initializecpu(void) | |
elf32_nxstack = 1; | ||
} | ||
#endif | ||
hw_mds_recalculate(); | ||
} | ||
|
||
void | ||
|
Oops, something went wrong.