summaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorAlexandr Nedvedicky <sashan@openssl.org>2024-04-21 09:41:58 +0200
committerTomas Mraz <tomas@openssl.org>2024-05-22 15:15:04 +0200
commit7884bedc04b90bcdd46cb52e525ebe6aa1bedae5 (patch)
tree594254a6d4665e7ce967c6443c776b544ef0a72a /crypto
parenta73e07dbb7df4795c4ec537f19516b541fb8dd3c (diff)
fix crash in ecp_nistz256_point_add_affine()
The .rodata section with precomputed constant `ecp_nistz256_precomputed` needs to be terminated by .text, because the ecp_nistz256_precomputed' happens to be the first section in the file. The lack of .text makes code to arrive into the same .rodata section where ecp_nistz256_precomputed is found. The exception is raised as soon as CPU attempts to execute the code from read only section. Fixes #24184 Reviewed-by: Paul Dale <ppzgs1@gmail.com> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/24192)
Diffstat (limited to 'crypto')
-rwxr-xr-xcrypto/perlasm/x86_64-xlate.pl28
1 files changed, 27 insertions, 1 deletions
diff --git a/crypto/perlasm/x86_64-xlate.pl b/crypto/perlasm/x86_64-xlate.pl
index 80fe1ff197..3befbde019 100755
--- a/crypto/perlasm/x86_64-xlate.pl
+++ b/crypto/perlasm/x86_64-xlate.pl
@@ -909,21 +909,38 @@ my %globals;
# to deal with nasm/masm assembly.
#
$self->{value} =~ s/(.+)\s+align\s*=.*$/$1/;
+ $current_segment = pop(@segment_stack);
+ if (not $current_segment) {
+ # if no previous section is defined, then assume .text
+ # so code does not land in .data section by accident.
+ # this deals with inconsistency of perl-assembly files.
+ push(@segment_stack, ".text");
+ }
#
# $$line may still contains align= option. We do care
# about section type here.
#
$current_segment = $$line;
$current_segment =~ s/([^\s]+).*$/$1/;
+ push(@segment_stack, $current_segment);
if (!$elf && $current_segment eq ".rodata") {
if ($flavour eq "macosx") { $self->{value} = ".section\t__DATA,__const"; }
+ elsif ($flavour eq "mingw64") { $self->{value} = ".section\t.rodata"; }
}
if (!$elf && $current_segment eq ".init") {
if ($flavour eq "macosx") { $self->{value} = ".mod_init_func"; }
elsif ($flavour eq "mingw64") { $self->{value} = ".section\t.ctors"; }
}
} elsif ($dir =~ /\.(text|data)/) {
+ $current_segment = pop(@segment_stack);
+ if (not $current_segment) {
+ # if no previous section is defined, then assume .text
+ # so code does not land in .data section by accident.
+ # this deals with inconsistency of perl-assembly files.
+ push(@segment_stack, ".text");
+ }
$current_segment=".$1";
+ push(@segment_stack, $current_segment);
} elsif ($dir =~ /\.hidden/) {
if ($flavour eq "macosx") { $self->{value} = ".private_extern\t$prefix$$line"; }
elsif ($flavour eq "mingw64") { $self->{value} = ""; }
@@ -931,7 +948,16 @@ my %globals;
$self->{value} = "$dir\t$prefix$$line";
$self->{value} =~ s|,([0-9]+),([0-9]+)$|",$1,".log($2)/log(2)|e if ($flavour eq "macosx");
} elsif ($dir =~ /\.previous/) {
- $self->{value} = "" if ($flavour eq "mingw64");
+ pop(@segment_stack); #pop ourselves
+ # just peek at the top of the stack here
+ $current_segment = @segment_stack[0];
+ if (not $current_segment) {
+ # if no previous segment was defined assume .text so
+ # the code does not accidentally land in .data section.
+ $current_segment = ".text";
+ push(@segment_stack, $current_segment);
+ }
+ $self->{value} = $current_segment if ($flavour eq "mingw64");
}
$$line = "";
return $self;