Commit a5b3f8863f for openssl.org
commit a5b3f8863fcefe98c0baeaf954f84a1f8017eba2
Author: Mounir IDRASSI <mounir.idrassi@idrix.fr>
Date: Tue Jul 7 15:45:07 2026 +0900
Fix SM2 RISC-V64 crash from functions emitted into .rodata
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)
diff --git a/crypto/ec/asm/ecp_sm2p256-riscv64.pl b/crypto/ec/asm/ecp_sm2p256-riscv64.pl
index 2a17e124dc..40938e75c0 100644
--- a/crypto/ec/asm/ecp_sm2p256-riscv64.pl
+++ b/crypto/ec/asm/ecp_sm2p256-riscv64.pl
@@ -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