]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
fix crash in ecp_nistz256_point_add_affine()
authorAlexandr Nedvedicky <sashan@openssl.org>
Sun, 21 Apr 2024 07:41:58 +0000 (09:41 +0200)
committerTomas Mraz <tomas@openssl.org>
Wed, 22 May 2024 13:15:04 +0000 (15:15 +0200)
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)

crypto/perlasm/x86_64-xlate.pl

index 80fe1ff1977a79c62c9b92c6039ebdf8019173cb..3befbde019418e6798a7997c6d2a2f88f0107b26 100755 (executable)
@@ -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;