Skip to content

Commit 257801c

Browse files
dvdgomezPlaidCat
authored andcommitted
x86/speculation: Add LFENCE to RSB fill sequence
jira LE-958 cve CVE-2022-26373 commit ba6e31a RSB fill sequence does not have any protection for miss-prediction of conditional branch at the end of the sequence. CPU can speculatively execute code immediately after the sequence, while RSB filling hasn't completed yet. #define __FILL_RETURN_BUFFER(reg, nr, sp) \ mov $(nr/2), reg; \ 771: \ ANNOTATE_INTRA_FUNCTION_CALL; \ call 772f; \ 773: /* speculation trap */ \ UNWIND_HINT_EMPTY; \ pause; \ lfence; \ jmp 773b; \ 772: \ ANNOTATE_INTRA_FUNCTION_CALL; \ call 774f; \ 775: /* speculation trap */ \ UNWIND_HINT_EMPTY; \ pause; \ lfence; \ jmp 775b; \ 774: \ add $(BITS_PER_LONG/8) * 2, sp; \ dec reg; \ jnz 771b; <----- CPU can miss-predict here. Before RSB is filled, RETs that come in program order after this macro can be executed speculatively, making them vulnerable to RSB-based attacks. Mitigate it by adding an LFENCE after the conditional branch to prevent speculation while RSB is being filled. Suggested-by: Andrew Cooper <andrew.cooper3@citrix.com> Signed-off-by: Pawan Gupta <pawan.kumar.gupta@linux.intel.com> Signed-off-by: Borislav Petkov <bp@suse.de> (cherry picked from commit ba6e31a) Signed-off-by: David Gomez <dgomez@ciq.com>
1 parent 7c1282f commit 257801c

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

arch/x86/include/asm/nospec-branch.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@
6767
774: \
6868
add $(BITS_PER_LONG/8) * 2, sp; \
6969
dec reg; \
70-
jnz 771b;
70+
jnz 771b; \
71+
/* barrier for jnz misprediction */ \
72+
lfence;
7173

7274
#ifdef __ASSEMBLY__
7375

0 commit comments

Comments
 (0)