Skip to content

Commit f7feb2d

Browse files
botovqSashan
authored andcommitted
[aarch64] move constants to rodata
The 3.6.0 has new assembly which again has constants in .text. This breaks on platforms enforcing execute-only memory. See, e.g., #24137 and PRs linked therein, among others. Reviewed-by: Paul Dale <paul.dale@oracle.com> Reviewed-by: Saša Nedvědický <sashan@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Tim Hudson <tjh@openssl.org> Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com> (Merged from #28726)
1 parent 521ae4a commit f7feb2d

3 files changed

Lines changed: 60 additions & 27 deletions

File tree

crypto/aes/asm/aes-sha1-armv8.pl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,14 @@ ()
217217
.global asm_aescbc_sha1_hmac
218218
.type asm_aescbc_sha1_hmac,%function
219219
220+
.rodata
220221
.align 4
221222
.Lrcon:
222223
.word 0x5a827999, 0x5a827999, 0x5a827999, 0x5a827999
223224
.word 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1
224225
.word 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc
225226
.word 0xca62c1d6, 0xca62c1d6, 0xca62c1d6, 0xca62c1d6
227+
.text
226228
227229
asm_aescbc_sha1_hmac:
228230
AARCH64_VALID_CALL_TARGET
@@ -276,7 +278,8 @@ ()
276278
ldp q10,q11,[x9],32 /* rk[2],rk[3] */
277279
prfm PLDL1KEEP,[x0,64] /* pref next aes_ptr_in */
278280
/* base address for sha round consts */
279-
adr x8,.Lrcon
281+
adrp x8,.Lrcon
282+
add x8,x8,:lo12:.Lrcon
280283
aese v0.16b,v9.16b
281284
aesmc v0.16b,v0.16b
282285
prfm PLDL1KEEP,[x1,64] /* pref next aes_ptr_out */
@@ -1524,7 +1527,8 @@ ()
15241527
*/
15251528
.Lenc_short_cases:
15261529
ldp q8,q9,[x9],32
1527-
adr x8,.Lrcon /* rcon */
1530+
adrp x8,.Lrcon /* rcon */
1531+
add x8,x8,:lo12:.Lrcon
15281532
mov w15,0x80 /* sha padding word */
15291533
ldp q10,q11,[x9],32
15301534
lsl x11,x10,4 /* len = aes_blocks*16 */
@@ -2426,7 +2430,8 @@ ()
24262430
blt .Ldec_short_cases /* branch if < 12 */
24272431
24282432
/* base address for sha round consts */
2429-
adr x8,.Lrcon
2433+
adrp x8,.Lrcon
2434+
add x8,x8,:lo12:.Lrcon
24302435
ldp q4,q5,[x8],32 /* key0,key1 */
24312436
ldp q6,q7,[x8],32 /* key2,key3 */
24322437
@@ -3866,7 +3871,8 @@ ()
38663871
*/
38673872
.Ldec_short_cases:
38683873
ldp q8,q9,[x9],32
3869-
adr x8,.Lrcon /* rcon */
3874+
adrp x8,.Lrcon /* rcon */
3875+
add x8,x8,:lo12:.Lrcon
38703876
ldp q10,q11,[x9],32
38713877
lsl x11,x10,4 /* len = aes_blocks*16 */
38723878

crypto/aes/asm/aes-sha256-armv8.pl

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ ()
216216
.global asm_aescbc_sha256_hmac
217217
.type asm_aescbc_sha256_hmac,%function
218218
219+
.rodata
219220
.align 4
220221
.Lrcon:
221222
.word 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5
@@ -238,6 +239,7 @@ ()
238239
.Linit_sha_state:
239240
.word 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a
240241
.word 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
242+
.text
241243
242244
asm_aescbc_sha256_hmac:
243245
AARCH64_VALID_CALL_TARGET
@@ -253,7 +255,8 @@ ()
253255
stp d10,d11,[sp,#16]
254256
255257
/* address of sha init state consts */
256-
adr x12,.Linit_sha_state
258+
adrp x12,.Linit_sha_state
259+
add x12,x12,:lo12:.Linit_sha_state
257260
prfm PLDL1KEEP,[x1,0] /* pref next aes_ptr_out */
258261
lsr x10,x2,4 /* aes_blocks = len/16 */
259262
@@ -296,7 +299,8 @@ ()
296299
aesmc v0.16b,v0.16b
297300
prfm PLDL1KEEP,[x1,64] /* pref next aes_ptr_out */
298301
/* base address for sha round consts */
299-
adr x8,.Lrcon
302+
adrp x8,.Lrcon
303+
add x8,x8,:lo12:.Lrcon
300304
ld1 {v12.16b},[x9],16 /* rk[4] */
301305
aese v0.16b,v10.16b
302306
aesmc v0.16b,v0.16b
@@ -435,7 +439,8 @@ ()
435439
*/
436440
.Lenc_main_loop:
437441
/* base address for sha round consts */
438-
adr x8,.Lrcon
442+
adrp x8,.Lrcon
443+
add x8,x8,:lo12:.Lrcon
439444
/*
440445
* Because both mov, rev32 and eor have a busy cycle,this takes longer
441446
* than it looks. That's OK since there are 6 cycles before we can use
@@ -703,7 +708,8 @@ ()
703708
*/
704709
ld1 {v0.16b},[x0],16
705710
/* base address for sha round consts */
706-
adr x8,.Lrcon
711+
adrp x8,.Lrcon
712+
add x8,x8,:lo12:.Lrcon
707713
ld1 {v4.16b},[x8],16 /* key0 */
708714
ld1 {v5.16b},[x8],16 /* key1 */
709715
ld1 {v6.16b},[x8],16 /* key2 */
@@ -893,7 +899,8 @@ ()
893899
/* quad 0 */
894900
.Lbm2fromQ0:
895901
/* base address for sha round consts */
896-
adr x8,.Lrcon
902+
adrp x8,.Lrcon
903+
add x8,x8,:lo12:.Lrcon
897904
898905
ld1 {v4.16b},[x8],16 /* key0 */
899906
ld1 {v5.16b},[x8],16 /* key1 */
@@ -1164,7 +1171,8 @@ ()
11641171
*/
11651172
1:
11661173
/* base address for sha round consts */
1167-
adr x8,.Lrcon
1174+
adrp x8,.Lrcon
1175+
add x8,x8,:lo12:.Lrcon
11681176
11691177
ld1 {v4.16b},[x8],16 /* key0 */
11701178
ld1 {v5.16b},[x8],16 /* key1 */
@@ -1323,7 +1331,8 @@ ()
13231331
* do last sha of pad block
13241332
*/
13251333
/* base address for sha round consts */
1326-
adr x8,.Lrcon
1334+
adrp x8,.Lrcon
1335+
add x8,x8,:lo12:.Lrcon
13271336
13281337
/* quad 0 */
13291338
ld1 {v4.16b},[x8],16 /* key0 */
@@ -1460,7 +1469,8 @@ ()
14601469
eor v28.16b, v28.16b, v28.16b
14611470
eor v29.16b, v29.16b, v29.16b
14621471
/* base address for sha round consts */
1463-
adr x8,.Lrcon
1472+
adrp x8,.Lrcon
1473+
add x8,x8,:lo12:.Lrcon
14641474
/* load o_key_pad partial hash */
14651475
ldp q24,q25,[x7]
14661476
@@ -1641,7 +1651,8 @@ ()
16411651
* already in place excepting the final word.
16421652
*/
16431653
.Lenc_short_loop:
1644-
adr x8,.Lrcon /* rcon */
1654+
adrp x8,.Lrcon /* rcon */
1655+
add x8,x8,:lo12:.Lrcon
16451656
/* read next aes block, update aes_ptr_in */
16461657
ld1 {v0.16b},[x0],16
16471658
eor v0.16b,v0.16b,v3.16b /* xor w/prev value */
@@ -2019,7 +2030,8 @@ ()
20192030
*/
20202031
1:
20212032
/* base address for sha round consts */
2022-
adr x8,.Lrcon
2033+
adrp x8,.Lrcon
2034+
add x8,x8,:lo12:.Lrcon
20232035
20242036
ld1 {v4.16b},[x8],16 /* key0 */
20252037
ld1 {v5.16b},[x8],16 /* key1 */
@@ -2180,7 +2192,8 @@ ()
21802192
/* do final block */
21812193
21822194
/* base address for sha round consts */
2183-
adr x8,.Lrcon /* top of rcon */
2195+
adrp x8,.Lrcon /* top of rcon */
2196+
add x8,x8,:lo12:.Lrcon
21842197
21852198
/* quad 0 */
21862199
ld1 {v4.16b},[x8],16 /* key0 */
@@ -2317,7 +2330,8 @@ ()
23172330
eor v28.16b, v28.16b, v28.16b
23182331
eor v29.16b, v29.16b, v29.16b
23192332
/* base address for sha round consts */
2320-
adr x8,.Lrcon
2333+
adrp x8,.Lrcon
2334+
add x8,x8,:lo12:.Lrcon
23212335
/* load o_key_pad partial hash */
23222336
ldp q24,q25,[x7]
23232337
@@ -2562,7 +2576,8 @@ ()
25622576
lsr x10,x2,4 /* aes_blocks = len/16 */
25632577
stp d14,d15,[sp,#48]
25642578
/* address of sha init state consts */
2565-
adr x12,.Linit_sha_state
2579+
adrp x12,.Linit_sha_state
2580+
add x12,x12,:lo12:.Linit_sha_state
25662581
stp x19,x20,[sp,#64]
25672582
25682583
ldr x9, [x6, #CIPHER_KEY]
@@ -2598,7 +2613,8 @@ ()
25982613
prfm PLDL1KEEP,[x0,64] /* pref next aes_ptr_in */
25992614
prfm PLDL1KEEP,[x1,64] /* pref next aes_ptr_out */
26002615
/* base address for sha round consts */
2601-
adr x8,.Lrcon
2616+
adrp x8,.Lrcon
2617+
add x8,x8,:lo12:.Lrcon
26022618
/*
26032619
* do the first sha256 block on the plaintext
26042620
*/
@@ -2781,7 +2797,8 @@ ()
27812797
prfm PLDL1KEEP,[x1,64]
27822798
mov v23.16b,v25.16b /* working EFGH <- EFGH */
27832799
/* base address for sha round consts */
2784-
adr x8,.Lrcon
2800+
adrp x8,.Lrcon
2801+
add x8,x8,:lo12:.Lrcon
27852802
27862803
/*
27872804
* aes xform 0, sha quad 0
@@ -3035,7 +3052,8 @@ ()
30353052
prfm PLDL1KEEP,[x1,64]
30363053
mov v23.16b,v25.16b /* working EFGH <- EFGH */
30373054
/* base address for sha round consts */
3038-
adr x8,.Lrcon
3055+
adrp x8,.Lrcon
3056+
add x8,x8,:lo12:.Lrcon
30393057
ld1 {v4.16b},[x8],16 /* key0 */
30403058
ld1 {v5.16b},[x8],16 /* key1 */
30413059
@@ -3398,7 +3416,8 @@ ()
33983416
*/
33993417
.Ljoin_common:
34003418
/* base address for sha round consts */
3401-
adr x8,.Lrcon
3419+
adrp x8,.Lrcon
3420+
add x8,x8,:lo12:.Lrcon
34023421
mov w15,0x80 /* that's the 1 of the pad */
34033422
.Lpost_loop_Q0:
34043423
/* assume this was final block */
@@ -3663,7 +3682,8 @@ ()
36633682
/* read first aes block, bump aes_ptr_in */
36643683
ld1 {v0.16b},[x0]
36653684
ld1 {v31.16b},[x0],16
3666-
adr x8,.Lrcon
3685+
adrp x8,.Lrcon
3686+
add x8,x8,:lo12:.Lrcon
36673687
ld1 {v4.16b},[x8],16 /* key0 */
36683688
aesd v0.16b,v8.16b
36693689
aesimc v0.16b,v0.16b
@@ -3844,7 +3864,8 @@ ()
38443864
38453865
.Lzero_aes_blocks_left:
38463866
/* base address for sha round consts */
3847-
adr x8,.Lrcon
3867+
adrp x8,.Lrcon
3868+
add x8,x8,:lo12:.Lrcon
38483869
ld1 {v4.16b},[x8],16 /* key0 */
38493870
ld1 {v5.16b},[x8],16 /* key1 */
38503871
@@ -3990,7 +4011,8 @@ ()
39904011
* Calculate final HMAC
39914012
*/
39924013
/* base address for sha round consts */
3993-
adr x8,.Lrcon
4014+
adrp x8,.Lrcon
4015+
add x8,x8,:lo12:.Lrcon
39944016
/* load o_key_pad partial hash */
39954017
ld1 {v24.16b},[x7],16
39964018
ld1 {v25.16b},[x7]
@@ -4163,7 +4185,8 @@ ()
41634185
*/
41644186
.Ldec_short_cases:
41654187
ldp q8,q9,[x9],32
4166-
adr x8,.Lrcon /* rcon */
4188+
adrp x8,.Lrcon /* rcon */
4189+
add x8,x8,:lo12:.Lrcon
41674190
ldp q10,q11,[x9],32
41684191
lsl x11,x10,4 /* len=aes_blocks*16 */
41694192

crypto/aes/asm/aes-sha512-armv8.pl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ ()
310310
.global asm_aescbc_sha512_hmac
311311
.type asm_aescbc_sha512_hmac,%function
312312
313+
.rodata
313314
.align 6
314315
.LK512:
315316
.quad 0x428a2f98d728ae22,0x7137449123ef65cd
@@ -354,6 +355,7 @@ ()
354355
.quad 0x5fcb6fab3ad6faec,0x6c44198c4a475817
355356
.quad 0 // terminator
356357
358+
.text
357359
.align 4
358360
asm_aescbc_sha512_hmac:
359361
AARCH64_VALID_CALL_TARGET
@@ -372,7 +374,8 @@ ()
372374
ldr x9, [x6, #CIPHER_KEY_ROUNDS]
373375
mov x12, x7 /* backup x7 */
374376
375-
adr x10, .LK512
377+
adrp x10, .LK512
378+
add x10, x10, :lo12:.LK512
376379
377380
lsr x11, x2, #4 /* aes_block = len/16 */
378381
cbz x11, .Lret /* return if aes_block = 0 */
@@ -2087,7 +2090,8 @@ ()
20872090
ldr x9, [x6, #CIPHER_KEY_ROUNDS]
20882091
mov x12, x7 /* backup x7 */
20892092
2090-
adr x10, .LK512
2093+
adrp x10, .LK512
2094+
add x10, x10, :lo12:.LK512
20912095
20922096
lsr x11, x2, #4 /* aes_block = len/16 */
20932097
cbz x11, .Ldec_ret /* return if aes_block = 0 */

0 commit comments

Comments
 (0)