Skip to content

Commit 697977d

Browse files
konradwilksuryasaimadhu
authored andcommitted
x86/kexec: Disable RET on kexec
All the invocations unroll to __x86_return_thunk and this file must be PIC independent. This fixes kexec on 64-bit AMD boxes. [ bp: Fix 32-bit build. ] Reported-by: Edward Tran <[email protected]> Reported-by: Awais Tanveer <[email protected]> Suggested-by: Ankur Arora <[email protected]> Signed-off-by: Konrad Rzeszutek Wilk <[email protected]> Signed-off-by: Alexandre Chartre <[email protected]> Signed-off-by: Borislav Petkov <[email protected]>
1 parent 2259da1 commit 697977d

File tree

2 files changed

+36
-12
lines changed

2 files changed

+36
-12
lines changed

arch/x86/kernel/relocate_kernel_32.S

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
#include <linux/linkage.h>
88
#include <asm/page_types.h>
99
#include <asm/kexec.h>
10+
#include <asm/nospec-branch.h>
1011
#include <asm/processor-flags.h>
1112

1213
/*
13-
* Must be relocatable PIC code callable as a C function
14+
* Must be relocatable PIC code callable as a C function, in particular
15+
* there must be a plain RET and not jump to return thunk.
1416
*/
1517

1618
#define PTR(x) (x << 2)
@@ -91,7 +93,9 @@ SYM_CODE_START_NOALIGN(relocate_kernel)
9193
movl %edi, %eax
9294
addl $(identity_mapped - relocate_kernel), %eax
9395
pushl %eax
94-
RET
96+
ANNOTATE_UNRET_SAFE
97+
ret
98+
int3
9599
SYM_CODE_END(relocate_kernel)
96100

97101
SYM_CODE_START_LOCAL_NOALIGN(identity_mapped)
@@ -159,12 +163,15 @@ SYM_CODE_START_LOCAL_NOALIGN(identity_mapped)
159163
xorl %edx, %edx
160164
xorl %esi, %esi
161165
xorl %ebp, %ebp
162-
RET
166+
ANNOTATE_UNRET_SAFE
167+
ret
168+
int3
163169
1:
164170
popl %edx
165171
movl CP_PA_SWAP_PAGE(%edi), %esp
166172
addl $PAGE_SIZE, %esp
167173
2:
174+
ANNOTATE_RETPOLINE_SAFE
168175
call *%edx
169176

170177
/* get the re-entry point of the peer system */
@@ -190,7 +197,9 @@ SYM_CODE_START_LOCAL_NOALIGN(identity_mapped)
190197
movl %edi, %eax
191198
addl $(virtual_mapped - relocate_kernel), %eax
192199
pushl %eax
193-
RET
200+
ANNOTATE_UNRET_SAFE
201+
ret
202+
int3
194203
SYM_CODE_END(identity_mapped)
195204

196205
SYM_CODE_START_LOCAL_NOALIGN(virtual_mapped)
@@ -208,7 +217,9 @@ SYM_CODE_START_LOCAL_NOALIGN(virtual_mapped)
208217
popl %edi
209218
popl %esi
210219
popl %ebx
211-
RET
220+
ANNOTATE_UNRET_SAFE
221+
ret
222+
int3
212223
SYM_CODE_END(virtual_mapped)
213224

214225
/* Do the copies */
@@ -271,7 +282,9 @@ SYM_CODE_START_LOCAL_NOALIGN(swap_pages)
271282
popl %edi
272283
popl %ebx
273284
popl %ebp
274-
RET
285+
ANNOTATE_UNRET_SAFE
286+
ret
287+
int3
275288
SYM_CODE_END(swap_pages)
276289

277290
.globl kexec_control_code_size

arch/x86/kernel/relocate_kernel_64.S

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
#include <asm/unwind_hints.h>
1414

1515
/*
16-
* Must be relocatable PIC code callable as a C function
16+
* Must be relocatable PIC code callable as a C function, in particular
17+
* there must be a plain RET and not jump to return thunk.
1718
*/
1819

1920
#define PTR(x) (x << 3)
@@ -105,7 +106,9 @@ SYM_CODE_START_NOALIGN(relocate_kernel)
105106
/* jump to identity mapped page */
106107
addq $(identity_mapped - relocate_kernel), %r8
107108
pushq %r8
108-
RET
109+
ANNOTATE_UNRET_SAFE
110+
ret
111+
int3
109112
SYM_CODE_END(relocate_kernel)
110113

111114
SYM_CODE_START_LOCAL_NOALIGN(identity_mapped)
@@ -200,7 +203,9 @@ SYM_CODE_START_LOCAL_NOALIGN(identity_mapped)
200203
xorl %r14d, %r14d
201204
xorl %r15d, %r15d
202205

203-
RET
206+
ANNOTATE_UNRET_SAFE
207+
ret
208+
int3
204209

205210
1:
206211
popq %rdx
@@ -219,7 +224,9 @@ SYM_CODE_START_LOCAL_NOALIGN(identity_mapped)
219224
call swap_pages
220225
movq $virtual_mapped, %rax
221226
pushq %rax
222-
RET
227+
ANNOTATE_UNRET_SAFE
228+
ret
229+
int3
223230
SYM_CODE_END(identity_mapped)
224231

225232
SYM_CODE_START_LOCAL_NOALIGN(virtual_mapped)
@@ -241,7 +248,9 @@ SYM_CODE_START_LOCAL_NOALIGN(virtual_mapped)
241248
popq %r12
242249
popq %rbp
243250
popq %rbx
244-
RET
251+
ANNOTATE_UNRET_SAFE
252+
ret
253+
int3
245254
SYM_CODE_END(virtual_mapped)
246255

247256
/* Do the copies */
@@ -298,7 +307,9 @@ SYM_CODE_START_LOCAL_NOALIGN(swap_pages)
298307
lea PAGE_SIZE(%rax), %rsi
299308
jmp 0b
300309
3:
301-
RET
310+
ANNOTATE_UNRET_SAFE
311+
ret
312+
int3
302313
SYM_CODE_END(swap_pages)
303314

304315
.globl kexec_control_code_size

0 commit comments

Comments
 (0)