Skip to content

Commit c21a05c

Browse files
authored
Address fips hash using adrp instead of adr to increase reach (#2053)
Extends #1332 to FIPS integrity hash.
1 parent 1be42a3 commit c21a05c

File tree

18 files changed

+545
-536
lines changed

18 files changed

+545
-536
lines changed

util/fipstools/delocate/delocate.go

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1959,8 +1959,24 @@ func transform(w stringWriter, includes []string, inputs []inputFile, startEndDe
19591959
w.WriteString(fmt.Sprintf(".file %d \"inserted_by_delocate.c\"%s\n", maxObservedFileNumber+1, fileTrailing))
19601960
w.WriteString(fmt.Sprintf(".loc %d 1 0\n", maxObservedFileNumber+1))
19611961
}
1962+
1963+
if d.processor == aarch64 {
1964+
// Grab the address of BORINGSSL_bcm_text_hash via a relocation
1965+
// from a redirector function. For this to work, need to add the markers
1966+
// to the symbol table.
1967+
w.WriteString(".global BORINGSSL_bcm_text_hash\n")
1968+
w.WriteString(".type BORINGSSL_bcm_text_hash, @function\n")
1969+
} else {
1970+
w.WriteString(".type BORINGSSL_bcm_text_hash, @object\n")
1971+
w.WriteString(".size BORINGSSL_bcm_text_hash, 32\n")
1972+
}
1973+
w.WriteString("BORINGSSL_bcm_text_hash:\n")
1974+
for _, b := range fipscommon.UninitHashValue {
1975+
w.WriteString(".byte 0x" + strconv.FormatUint(uint64(b), 16) + "\n")
1976+
}
1977+
19621978
if d.processor == aarch64 {
1963-
// Grab the address of BORINGSSL_bcm_test_[start,end] via a relocation
1979+
// Grab the address of BORINGSSL_bcm_text_[start,end] via a relocation
19641980
// from a redirector function. For this to work, need to add the markers
19651981
// to the symbol table.
19661982
w.WriteString(fmt.Sprintf(".global BORINGSSL_bcm_text_start\n"))
@@ -2139,13 +2155,6 @@ func transform(w stringWriter, includes []string, inputs []inputFile, startEndDe
21392155
}
21402156
}
21412157

2142-
w.WriteString(".type BORINGSSL_bcm_text_hash, @object\n")
2143-
w.WriteString(".size BORINGSSL_bcm_text_hash, 32\n")
2144-
w.WriteString("BORINGSSL_bcm_text_hash:\n")
2145-
for _, b := range fipscommon.UninitHashValue {
2146-
w.WriteString(".byte 0x" + strconv.FormatUint(uint64(b), 16) + "\n")
2147-
}
2148-
21492158
return nil
21502159
}
21512160

@@ -2417,8 +2426,7 @@ func localEntryName(name string) string {
24172426

24182427
func isSynthesized(symbol string, processor processorType) bool {
24192428
SymbolisSynthesized := strings.HasSuffix(symbol, "_bss_get") ||
2420-
symbol == "OPENSSL_ia32cap_get" ||
2421-
symbol == "BORINGSSL_bcm_text_hash"
2429+
symbol == "OPENSSL_ia32cap_get"
24222430

24232431
// While BORINGSSL_bcm_text_[start,end] are known symbols, on aarch64 we go
24242432
// through the GOT because adr doesn't have adequate reach.
@@ -2431,7 +2439,8 @@ func isSynthesized(symbol string, processor processorType) bool {
24312439

24322440
func isFipsScopeMarkers(symbol string) bool {
24332441
return symbol == "BORINGSSL_bcm_text_start" ||
2434-
symbol == "BORINGSSL_bcm_text_end"
2442+
symbol == "BORINGSSL_bcm_text_end" ||
2443+
symbol == "BORINGSSL_bcm_text_hash"
24352444
}
24362445

24372446
func redirectorName(symbol string) string {

util/fipstools/delocate/testdata/aarch64-Basic/out.s

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,41 @@
11
.text
22
.file 1 "inserted_by_delocate.c"
33
.loc 1 1 0
4+
.global BORINGSSL_bcm_text_hash
5+
.type BORINGSSL_bcm_text_hash, @function
6+
BORINGSSL_bcm_text_hash:
7+
.byte 0xae
8+
.byte 0x2c
9+
.byte 0xea
10+
.byte 0x2a
11+
.byte 0xbd
12+
.byte 0xa6
13+
.byte 0xf3
14+
.byte 0xec
15+
.byte 0x97
16+
.byte 0x7f
17+
.byte 0x9b
18+
.byte 0xf6
19+
.byte 0x94
20+
.byte 0x9a
21+
.byte 0xfc
22+
.byte 0x83
23+
.byte 0x68
24+
.byte 0x27
25+
.byte 0xcb
26+
.byte 0xa0
27+
.byte 0xa0
28+
.byte 0x9f
29+
.byte 0x6b
30+
.byte 0x6f
31+
.byte 0xde
32+
.byte 0x52
33+
.byte 0xcd
34+
.byte 0xe2
35+
.byte 0xcd
36+
.byte 0xff
37+
.byte 0x31
38+
.byte 0x80
439
.global BORINGSSL_bcm_text_start
540
.type BORINGSSL_bcm_text_start, @function
641
BORINGSSL_bcm_text_start:
@@ -261,38 +296,3 @@ bss_symbol_bss_get:
261296
ret
262297
.cfi_endproc
263298
.size .LOPENSSL_armcap_P_addr, .-.LOPENSSL_armcap_P_addr
264-
.type BORINGSSL_bcm_text_hash, @object
265-
.size BORINGSSL_bcm_text_hash, 32
266-
BORINGSSL_bcm_text_hash:
267-
.byte 0xae
268-
.byte 0x2c
269-
.byte 0xea
270-
.byte 0x2a
271-
.byte 0xbd
272-
.byte 0xa6
273-
.byte 0xf3
274-
.byte 0xec
275-
.byte 0x97
276-
.byte 0x7f
277-
.byte 0x9b
278-
.byte 0xf6
279-
.byte 0x94
280-
.byte 0x9a
281-
.byte 0xfc
282-
.byte 0x83
283-
.byte 0x68
284-
.byte 0x27
285-
.byte 0xcb
286-
.byte 0xa0
287-
.byte 0xa0
288-
.byte 0x9f
289-
.byte 0x6b
290-
.byte 0x6f
291-
.byte 0xde
292-
.byte 0x52
293-
.byte 0xcd
294-
.byte 0xe2
295-
.byte 0xcd
296-
.byte 0xff
297-
.byte 0x31
298-
.byte 0x80

util/fipstools/delocate/testdata/generic-FileDirectives-no-start-end/out.s

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,4 @@
11
.text
2-
BORINGSSL_bcm_text_start:
3-
.file 10 "some/path/file.c" "file.c"
4-
.file 1000 "some/path/file2.c" "file2.c"
5-
.file 1001 "some/path/file_with_md5.c" "other_name.c" md5 0x5eba7844df6449a7f2fff1556fe7ba8d239f8e2f
6-
7-
# An instruction is needed to satisfy the architecture auto-detection.
8-
movq %rax, %rbx
9-
.text
10-
BORINGSSL_bcm_text_end:
11-
.type OPENSSL_ia32cap_get, @function
12-
.globl OPENSSL_ia32cap_get
13-
.LOPENSSL_ia32cap_get_local_target:
14-
OPENSSL_ia32cap_get:
15-
leaq OPENSSL_ia32cap_P(%rip), %rax
16-
ret
172
.type BORINGSSL_bcm_text_hash, @object
183
.size BORINGSSL_bcm_text_hash, 32
194
BORINGSSL_bcm_text_hash:
@@ -49,3 +34,18 @@ BORINGSSL_bcm_text_hash:
4934
.byte 0xff
5035
.byte 0x31
5136
.byte 0x80
37+
BORINGSSL_bcm_text_start:
38+
.file 10 "some/path/file.c" "file.c"
39+
.file 1000 "some/path/file2.c" "file2.c"
40+
.file 1001 "some/path/file_with_md5.c" "other_name.c" md5 0x5eba7844df6449a7f2fff1556fe7ba8d239f8e2f
41+
42+
# An instruction is needed to satisfy the architecture auto-detection.
43+
movq %rax, %rbx
44+
.text
45+
BORINGSSL_bcm_text_end:
46+
.type OPENSSL_ia32cap_get, @function
47+
.globl OPENSSL_ia32cap_get
48+
.LOPENSSL_ia32cap_get_local_target:
49+
OPENSSL_ia32cap_get:
50+
leaq OPENSSL_ia32cap_P(%rip), %rax
51+
ret

util/fipstools/delocate/testdata/generic-FileDirectives/out.s

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,6 @@
11
.text
22
.file 1002 "inserted_by_delocate.c" md5 0x00000000000000000000000000000000
33
.loc 1002 1 0
4-
BORINGSSL_bcm_text_start:
5-
.file 10 "some/path/file.c" "file.c"
6-
.file 1000 "some/path/file2.c" "file2.c"
7-
.file 1001 "some/path/file_with_md5.c" "other_name.c" md5 0x5eba7844df6449a7f2fff1556fe7ba8d239f8e2f
8-
9-
# An instruction is needed to satisfy the architecture auto-detection.
10-
movq %rax, %rbx
11-
.text
12-
.loc 1002 2 0
13-
BORINGSSL_bcm_text_end:
14-
.type OPENSSL_ia32cap_get, @function
15-
.globl OPENSSL_ia32cap_get
16-
.LOPENSSL_ia32cap_get_local_target:
17-
OPENSSL_ia32cap_get:
18-
leaq OPENSSL_ia32cap_P(%rip), %rax
19-
ret
204
.type BORINGSSL_bcm_text_hash, @object
215
.size BORINGSSL_bcm_text_hash, 32
226
BORINGSSL_bcm_text_hash:
@@ -52,3 +36,19 @@ BORINGSSL_bcm_text_hash:
5236
.byte 0xff
5337
.byte 0x31
5438
.byte 0x80
39+
BORINGSSL_bcm_text_start:
40+
.file 10 "some/path/file.c" "file.c"
41+
.file 1000 "some/path/file2.c" "file2.c"
42+
.file 1001 "some/path/file_with_md5.c" "other_name.c" md5 0x5eba7844df6449a7f2fff1556fe7ba8d239f8e2f
43+
44+
# An instruction is needed to satisfy the architecture auto-detection.
45+
movq %rax, %rbx
46+
.text
47+
.loc 1002 2 0
48+
BORINGSSL_bcm_text_end:
49+
.type OPENSSL_ia32cap_get, @function
50+
.globl OPENSSL_ia32cap_get
51+
.LOPENSSL_ia32cap_get_local_target:
52+
OPENSSL_ia32cap_get:
53+
leaq OPENSSL_ia32cap_P(%rip), %rax
54+
ret

util/fipstools/delocate/testdata/generic-Includes/out.s

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,6 @@
33
.text
44
.file 1002 "inserted_by_delocate.c" md5 0x00000000000000000000000000000000
55
.loc 1002 1 0
6-
BORINGSSL_bcm_text_start:
7-
.file 10 "some/path/file.c" "file.c"
8-
.file 1000 "some/path/file2.c" "file2.c"
9-
.file 1001 "some/path/file_with_md5.c" "other_name.c" md5 0x5eba7844df6449a7f2fff1556fe7ba8d239f8e2f
10-
11-
# An instruction is needed to satisfy the architecture auto-detection.
12-
movq %rax, %rbx
13-
.text
14-
.loc 1002 2 0
15-
BORINGSSL_bcm_text_end:
16-
.type OPENSSL_ia32cap_get, @function
17-
.globl OPENSSL_ia32cap_get
18-
.LOPENSSL_ia32cap_get_local_target:
19-
OPENSSL_ia32cap_get:
20-
leaq OPENSSL_ia32cap_P(%rip), %rax
21-
ret
226
.type BORINGSSL_bcm_text_hash, @object
237
.size BORINGSSL_bcm_text_hash, 32
248
BORINGSSL_bcm_text_hash:
@@ -54,3 +38,19 @@ BORINGSSL_bcm_text_hash:
5438
.byte 0xff
5539
.byte 0x31
5640
.byte 0x80
41+
BORINGSSL_bcm_text_start:
42+
.file 10 "some/path/file.c" "file.c"
43+
.file 1000 "some/path/file2.c" "file2.c"
44+
.file 1001 "some/path/file_with_md5.c" "other_name.c" md5 0x5eba7844df6449a7f2fff1556fe7ba8d239f8e2f
45+
46+
# An instruction is needed to satisfy the architecture auto-detection.
47+
movq %rax, %rbx
48+
.text
49+
.loc 1002 2 0
50+
BORINGSSL_bcm_text_end:
51+
.type OPENSSL_ia32cap_get, @function
52+
.globl OPENSSL_ia32cap_get
53+
.LOPENSSL_ia32cap_get_local_target:
54+
OPENSSL_ia32cap_get:
55+
leaq OPENSSL_ia32cap_P(%rip), %rax
56+
ret

util/fipstools/delocate/testdata/ppc64le-GlobalEntry/out.s

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,6 @@
11
.text
22
.file 1 "inserted_by_delocate.c"
33
.loc 1 1 0
4-
BORINGSSL_bcm_text_start:
5-
.text
6-
.Lfoo_local_target:
7-
foo:
8-
.LCF0:
9-
10-
0:
11-
12-
999:
13-
addis 2, 12, .LBORINGSSL_external_toc-999b@ha
14-
addi 2, 2, .LBORINGSSL_external_toc-999b@l
15-
ld 12, 0(2)
16-
add 2, 2, 12
17-
# WAS addi 2,2,.TOC.-.LCF0@l
18-
.localentry foo,.-foo
19-
.Lfoo_local_entry:
20-
.LVL0:
21-
22-
bl
23-
.text
24-
.loc 1 2 0
25-
BORINGSSL_bcm_text_end:
26-
.LBORINGSSL_external_toc:
27-
.quad .TOC.-.LBORINGSSL_external_toc
284
.type BORINGSSL_bcm_text_hash, @object
295
.size BORINGSSL_bcm_text_hash, 32
306
BORINGSSL_bcm_text_hash:
@@ -60,3 +36,27 @@ BORINGSSL_bcm_text_hash:
6036
.byte 0xff
6137
.byte 0x31
6238
.byte 0x80
39+
BORINGSSL_bcm_text_start:
40+
.text
41+
.Lfoo_local_target:
42+
foo:
43+
.LCF0:
44+
45+
0:
46+
47+
999:
48+
addis 2, 12, .LBORINGSSL_external_toc-999b@ha
49+
addi 2, 2, .LBORINGSSL_external_toc-999b@l
50+
ld 12, 0(2)
51+
add 2, 2, 12
52+
# WAS addi 2,2,.TOC.-.LCF0@l
53+
.localentry foo,.-foo
54+
.Lfoo_local_entry:
55+
.LVL0:
56+
57+
bl
58+
.text
59+
.loc 1 2 0
60+
BORINGSSL_bcm_text_end:
61+
.LBORINGSSL_external_toc:
62+
.quad .TOC.-.LBORINGSSL_external_toc

0 commit comments

Comments
 (0)