Skip to content

Commit ad12c2f

Browse files
ardbiesheuvelRussell King (Oracle)
authored andcommitted
ARM: 9201/1: spectre-bhb: rely on linker to emit cross-section literal loads
The assembler does not permit 'LDR PC, <sym>' when the symbol lives in a different section, which is why we have been relying on rather fragile open-coded arithmetic to load the address of the vector_swi routine into the program counter using a single LDR instruction in the SWI slot in the vector table. The literal was moved to a different section to in commit 19accfd ("ARM: move vector stubs") to ensure that the vector stubs page does not need to be mapped readable for user space, which is the case for the vector page itself, as it carries the kuser helpers as well. So the cross-section literal load is open-coded, and this relies on the address of vector_swi to be at the very start of the vector stubs page, and we won't notice if we got it wrong until booting the kernel and see it break. Fortunately, it was guaranteed to break, so this was fragile but not problematic. Now that we have added two other variants of the vector table, we have 3 occurrences of the same trick, and so the size of our ISA/compiler/CPU validation space has tripled, in a way that may cause regressions to only be observed once booting the image in question on a CPU that exercises a particular vector table. So let's switch to true cross section references, and let the linker fix them up like it fixes up all the other cross section references in the vector page. Signed-off-by: Ard Biesheuvel <[email protected]> Signed-off-by: Russell King (Oracle) <[email protected]>
1 parent 1290c70 commit ad12c2f

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

arch/arm/kernel/entry-armv.S

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,10 +1146,15 @@ ENDPROC(vector_bhb_loop8_\name)
11461146
.endm
11471147

11481148
.section .stubs, "ax", %progbits
1149-
@ This must be the first word
1149+
@ These need to remain at the start of the section so that
1150+
@ they are in range of the 'SWI' entries in the vector tables
1151+
@ located 4k down.
1152+
.L__vector_swi:
11501153
.word vector_swi
11511154
#ifdef CONFIG_HARDEN_BRANCH_HISTORY
1155+
.L__vector_bhb_loop8_swi:
11521156
.word vector_bhb_loop8_swi
1157+
.L__vector_bhb_bpiall_swi:
11531158
.word vector_bhb_bpiall_swi
11541159
#endif
11551160

@@ -1292,10 +1297,11 @@ vector_addrexcptn:
12921297
.globl vector_fiq
12931298

12941299
.section .vectors, "ax", %progbits
1295-
.L__vectors_start:
12961300
W(b) vector_rst
12971301
W(b) vector_und
1298-
W(ldr) pc, .L__vectors_start + 0x1000
1302+
ARM( .reloc ., R_ARM_LDR_PC_G0, .L__vector_swi )
1303+
THUMB( .reloc ., R_ARM_THM_PC12, .L__vector_swi )
1304+
W(ldr) pc, .
12991305
W(b) vector_pabt
13001306
W(b) vector_dabt
13011307
W(b) vector_addrexcptn
@@ -1304,21 +1310,23 @@ vector_addrexcptn:
13041310

13051311
#ifdef CONFIG_HARDEN_BRANCH_HISTORY
13061312
.section .vectors.bhb.loop8, "ax", %progbits
1307-
.L__vectors_bhb_loop8_start:
13081313
W(b) vector_rst
13091314
W(b) vector_bhb_loop8_und
1310-
W(ldr) pc, .L__vectors_bhb_loop8_start + 0x1004
1315+
ARM( .reloc ., R_ARM_LDR_PC_G0, .L__vector_bhb_loop8_swi )
1316+
THUMB( .reloc ., R_ARM_THM_PC12, .L__vector_bhb_loop8_swi )
1317+
W(ldr) pc, .
13111318
W(b) vector_bhb_loop8_pabt
13121319
W(b) vector_bhb_loop8_dabt
13131320
W(b) vector_addrexcptn
13141321
W(b) vector_bhb_loop8_irq
13151322
W(b) vector_bhb_loop8_fiq
13161323

13171324
.section .vectors.bhb.bpiall, "ax", %progbits
1318-
.L__vectors_bhb_bpiall_start:
13191325
W(b) vector_rst
13201326
W(b) vector_bhb_bpiall_und
1321-
W(ldr) pc, .L__vectors_bhb_bpiall_start + 0x1008
1327+
ARM( .reloc ., R_ARM_LDR_PC_G0, .L__vector_bhb_bpiall_swi )
1328+
THUMB( .reloc ., R_ARM_THM_PC12, .L__vector_bhb_bpiall_swi )
1329+
W(ldr) pc, .
13221330
W(b) vector_bhb_bpiall_pabt
13231331
W(b) vector_bhb_bpiall_dabt
13241332
W(b) vector_addrexcptn

0 commit comments

Comments
 (0)