Skip to content

Commit 3329249

Browse files
author
Peter Zijlstra
committed
x86/nospec: Fix i386 RSB stuffing
Turns out that i386 doesn't unconditionally have LFENCE, as such the loop in __FILL_RETURN_BUFFER isn't actually speculation safe on such chips. Fixes: ba6e31a ("x86/speculation: Add LFENCE to RSB fill sequence") Reported-by: Ben Hutchings <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 4e3aa92 commit 3329249

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
* the optimal version - two calls, each with their own speculation
5151
* trap should their return address end up getting used, in a loop.
5252
*/
53+
#ifdef CONFIG_X86_64
5354
#define __FILL_RETURN_BUFFER(reg, nr) \
5455
mov $(nr/2), reg; \
5556
771: \
@@ -60,6 +61,17 @@
6061
jnz 771b; \
6162
/* barrier for jnz misprediction */ \
6263
lfence;
64+
#else
65+
/*
66+
* i386 doesn't unconditionally have LFENCE, as such it can't
67+
* do a loop.
68+
*/
69+
#define __FILL_RETURN_BUFFER(reg, nr) \
70+
.rept nr; \
71+
__FILL_RETURN_SLOT; \
72+
.endr; \
73+
add $(BITS_PER_LONG/8) * nr, %_ASM_SP;
74+
#endif
6375

6476
/*
6577
* Stuff a single RSB slot.

0 commit comments

Comments
 (0)