]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Fix SM2 RISC-V64 crash from functions emitted into .rodata
authorMounir IDRASSI <mounir.idrassi@idrix.fr>
Tue, 7 Jul 2026 06:45:07 +0000 (15:45 +0900)
committerNorbert Pocs <norbertp@openssl.org>
Mon, 20 Jul 2026 09:47:26 +0000 (11:47 +0200)
The ecp_sm2p256-riscv64.pl generator switches to .section .rodata
to emit constant data (.Lpoly, .Lord, .Lpoly_div_2, .Lord_div_2), but
never switches back before emitting function code.

As a result, the function symbols defined by this file are assembled
into .rodata instead of executable .text. On systems enforcing NX for
.rodata, calling the RISC-V64 SM2 assembly faults immediately.

Fix this by adding .previous after the constant block, restoring the
initial .text section before function emission.

Verified with readelf: before the fix, .text is empty and the function
symbols are in .rodata; after the fix, constants remain in .rodata and
the function symbols are in executable .text.

Introduced in commit 05301b100f (PR #25918).

Reviewed-by: Paul Yang <paulyang.inf@gmail.com>
Reviewed-by: Saša Nedvědický <sashan@openssl.org>
MergeDate: Mon Jul 20 09:47:35 2026
(Merged from https://github.com/openssl/openssl/pull/31874)

crypto/ec/asm/ecp_sm2p256-riscv64.pl

index 2a17e124dc45b7c833bebc4a19a2750e0a474dc5..40938e75c06d3e53f769c4b33eb15efb415b68a0 100644 (file)
@@ -366,7 +366,7 @@ $code.=<<___;
 .type .Lord_div_2,\@object
 .Lord_div_2:
 .dword 0xa9ddfa049ceaa092,0xb901efb590e30295,0xffffffffffffffff,0x7fffffff7fffffff
-
+.previous
 
 // void bn_rshift1(BN_ULONG *a);
 .globl bn_rshift1