Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for ELFv2 ABI on big endian ppc64 #8883

Closed
wants to merge 2 commits into from

Conversation

q66
Copy link

@q66 q66 commented May 6, 2019

While big endian ppc64 has traditionally used the ELFv1 ABI, it is possible to use the same ELFv2 ABI as on little endian on big endian too. Some distributions are doing this now, too - particularly any big endian distro using the musl libc uses ELFv2 unconditionally (e.g. Adélie Linux) and glibc can also use it (Void Linux provides both glibc and musl with ELFv2).

Previously, compiling OpenSSL with asm on those platforms has resulted in miscompilation and crashes. Fortunately, all that is really necessary is to modify xlate to do the same stuff on ELFv2 big endian as on little endian, while keeping the endianness checks in the actual crypto assembly code the same. Whether we're compiling OpenSSL for ELFv1 or ELFv2 can be decided based on the value of the _CALL_ELF macro in C.

All tests are passing. I also re-checked this on little endian just in case, where it also passes.

bash-5.0# file libcrypto.so.3
libcrypto.so.3: ELF 64-bit MSB shared object, 64-bit PowerPC or cisco 7500, version 1 (SYSV), dynamically linked, BuildID[sha1]=d1107b36159ac7474646111e4f03b06bc2ebc526, with debug_info, not stripped
bash-5.0# readelf -h libcrypto.so.3|grep abiv
  Flags:                             0x2, abiv2
bash-5.0# uname -a
Linux bevoid 5.0.10_1 #1 SMP Tue Apr 30 10:05:02 UTC 2019 ppc64 GNU/Linux
bash-5.0# perl configdata.pm --dump|grep perlasm
    perlasm_scheme => "linux64v2",
../../test/recipes/01-test_abort.t .................... ok   
../../test/recipes/01-test_sanity.t ................... ok   
../../test/recipes/01-test_symbol_presence.t .......... ok   
../../test/recipes/01-test_test.t ..................... ok   
../../test/recipes/02-test_errstr.t ................... ok     
../../test/recipes/02-test_internal_context.t ......... ok   
../../test/recipes/02-test_internal_ctype.t ........... ok   
../../test/recipes/02-test_internal_provider.t ........ ok   
../../test/recipes/02-test_lhash.t .................... ok   
../../test/recipes/02-test_ordinals.t ................. ok   
../../test/recipes/02-test_sparse_array.t ............. ok   
../../test/recipes/02-test_stack.t .................... ok   
../../test/recipes/03-test_exdata.t ................... ok   
../../test/recipes/03-test_internal_asn1.t ............ ok   
../../test/recipes/03-test_internal_bn.t .............. ok   
../../test/recipes/03-test_internal_chacha.t .......... ok   
../../test/recipes/03-test_internal_curve448.t ........ ok   
../../test/recipes/03-test_internal_ec.t .............. ok   
../../test/recipes/03-test_internal_mdc2.t ............ ok   
../../test/recipes/03-test_internal_modes.t ........... ok   
../../test/recipes/03-test_internal_poly1305.t ........ ok   
../../test/recipes/03-test_internal_rsa_sp800_56b.t ... ok   
../../test/recipes/03-test_internal_siphash.t ......... ok   
../../test/recipes/03-test_internal_sm2.t ............. ok   
../../test/recipes/03-test_internal_sm4.t ............. ok   
../../test/recipes/03-test_internal_ssl_cert_table.t .. ok   
../../test/recipes/03-test_internal_x509.t ............ ok   
../../test/recipes/03-test_params_api.t ............... ok   
../../test/recipes/03-test_property.t ................. ok   
../../test/recipes/03-test_ui.t ....................... ok   
../../test/recipes/04-test_asn1_decode.t .............. ok   
../../test/recipes/04-test_asn1_encode.t .............. ok   
../../test/recipes/04-test_asn1_string_table.t ........ ok   
../../test/recipes/04-test_bio_callback.t ............. ok   
../../test/recipes/04-test_bioprint.t ................. ok   
../../test/recipes/04-test_err.t ...................... ok   
../../test/recipes/04-test_params.t ................... ok   
../../test/recipes/04-test_pem.t ...................... ok     
../../test/recipes/04-test_provider.t ................. ok   
../../test/recipes/05-test_bf.t ....................... ok   
../../test/recipes/05-test_cast.t ..................... ok   
../../test/recipes/05-test_des.t ...................... ok   
../../test/recipes/05-test_hmac.t ..................... ok   
../../test/recipes/05-test_idea.t ..................... ok   
../../test/recipes/05-test_md2.t ...................... skipped: md2 is not supported by this OpenSSL build
../../test/recipes/05-test_mdc2.t ..................... ok   
../../test/recipes/05-test_rand.t ..................... ok   
../../test/recipes/05-test_rc2.t ...................... ok   
../../test/recipes/05-test_rc4.t ...................... ok   
../../test/recipes/05-test_rc5.t ...................... skipped: rc5 is not supported by this OpenSSL build
../../test/recipes/06-test-rdrand.t ................... ok   
../../test/recipes/10-test_bn.t ....................... ok   
../../test/recipes/10-test_exp.t ...................... ok   
../../test/recipes/15-test_dh.t ....................... ok   
../../test/recipes/15-test_dsa.t ...................... ok   
../../test/recipes/15-test_ec.t ....................... ok   
../../test/recipes/15-test_ecdsa.t .................... ok   
../../test/recipes/15-test_ecparam.t .................. ok       
../../test/recipes/15-test_genrsa.t ................... ok   
../../test/recipes/15-test_mp_rsa.t ................... ok     
../../test/recipes/15-test_out_option.t ............... ok   
../../test/recipes/15-test_rsa.t ...................... ok   
../../test/recipes/15-test_rsapss.t ................... ok   
../../test/recipes/20-test_enc.t ...................... ok       
../../test/recipes/20-test_enc_more.t ................. ok       
../../test/recipes/20-test_kdf.t ...................... ok   
../../test/recipes/20-test_mac.t ...................... ok     
../../test/recipes/20-test_passwd.t ................... ok     
../../test/recipes/20-test_pkeyutl.t .................. ok   
../../test/recipes/25-test_crl.t ...................... ok   
../../test/recipes/25-test_d2i.t ...................... ok     
../../test/recipes/25-test_pkcs7.t .................... ok   
../../test/recipes/25-test_req.t ...................... ok   
../../test/recipes/25-test_sid.t ...................... ok   
../../test/recipes/25-test_verify.t ................... ok       
../../test/recipes/25-test_x509.t ..................... ok     
../../test/recipes/30-test_aesgcm.t ................... ok   
../../test/recipes/30-test_afalg.t .................... ok   
../../test/recipes/30-test_engine.t ................... ok   
../../test/recipes/30-test_evp.t ...................... ok     
../../test/recipes/30-test_evp_extra.t ................ ok   
../../test/recipes/30-test_evp_kdf.t .................. ok   
../../test/recipes/30-test_pbelu.t .................... ok   
../../test/recipes/30-test_pkey_meth.t ................ ok   
../../test/recipes/30-test_pkey_meth_kdf.t ............ ok   
../../test/recipes/40-test_rehash.t ................... ok   
../../test/recipes/60-test_x509_check_cert_pkey.t ..... ok   
../../test/recipes/60-test_x509_dup_cert.t ............ ok   
../../test/recipes/60-test_x509_store.t ............... ok   
../../test/recipes/60-test_x509_time.t ................ ok   
../../test/recipes/70-test_asyncio.t .................. ok   
../../test/recipes/70-test_bad_dtls.t ................. ok   
../../test/recipes/70-test_clienthello.t .............. ok   
../../test/recipes/70-test_comp.t ..................... ok   
../../test/recipes/70-test_key_share.t ................ ok    
../../test/recipes/70-test_packet.t ................... ok   
../../test/recipes/70-test_recordlen.t ................ ok   
../../test/recipes/70-test_renegotiation.t ............ ok   
../../test/recipes/70-test_servername.t ............... ok   
../../test/recipes/70-test_sslcbcpadding.t ............ ok   
../../test/recipes/70-test_sslcertstatus.t ............ ok   
../../test/recipes/70-test_sslextension.t ............. ok   
../../test/recipes/70-test_sslmessages.t .............. ok    
../../test/recipes/70-test_sslrecords.t ............... ok    
../../test/recipes/70-test_sslsessiontick.t ........... ok    
../../test/recipes/70-test_sslsigalgs.t ............... ok    
../../test/recipes/70-test_sslsignature.t ............. ok   
../../test/recipes/70-test_sslskewith0p.t ............. ok   
../../test/recipes/70-test_sslversions.t .............. ok   
../../test/recipes/70-test_sslvertol.t ................ ok   
../../test/recipes/70-test_tls13alerts.t .............. ok   
../../test/recipes/70-test_tls13cookie.t .............. ok   
../../test/recipes/70-test_tls13downgrade.t ........... ok   
../../test/recipes/70-test_tls13hrr.t ................. ok   
../../test/recipes/70-test_tls13kexmodes.t ............ ok    
../../test/recipes/70-test_tls13messages.t ............ ok    
../../test/recipes/70-test_tls13psk.t ................. ok   
../../test/recipes/70-test_tlsextms.t ................. ok    
../../test/recipes/70-test_verify_extra.t ............. ok   
../../test/recipes/70-test_wpacket.t .................. ok   
../../test/recipes/80-test_ca.t ....................... ok   
../../test/recipes/80-test_cipherbytes.t .............. ok   
../../test/recipes/80-test_cipherlist.t ............... ok   
../../test/recipes/80-test_ciphername.t ............... ok   
../../test/recipes/80-test_cms.t ...................... ok   
../../test/recipes/80-test_cmsapi.t ................... ok   
../../test/recipes/80-test_ct.t ....................... ok   
../../test/recipes/80-test_dane.t ..................... ok   
../../test/recipes/80-test_dtls.t ..................... ok   
../../test/recipes/80-test_dtls_mtu.t ................. ok   
../../test/recipes/80-test_dtlsv1listen.t ............. ok   
../../test/recipes/80-test_ocsp.t ..................... ok     
../../test/recipes/80-test_pkcs12.t ................... ok   
../../test/recipes/80-test_ssl_new.t .................. ok     
../../test/recipes/80-test_ssl_old.t .................. ok   
../../test/recipes/80-test_ssl_test_ctx.t ............. ok   
../../test/recipes/80-test_sslcorrupt.t ............... ok   
../../test/recipes/80-test_tsa.t ...................... ok     
../../test/recipes/80-test_x509aux.t .................. ok   
../../test/recipes/90-test_asn1_time.t ................ ok   
../../test/recipes/90-test_async.t .................... ok   
../../test/recipes/90-test_bio_enc.t .................. ok   
../../test/recipes/90-test_bio_memleak.t .............. ok   
../../test/recipes/90-test_constant_time.t ............ ok   
../../test/recipes/90-test_fatalerr.t ................. ok   
../../test/recipes/90-test_gmdiff.t ................... ok   
../../test/recipes/90-test_gost.t ..................... skipped: No test GOST engine found
../../test/recipes/90-test_ige.t ...................... ok   
../../test/recipes/90-test_includes.t ................. ok   
../../test/recipes/90-test_memleak.t .................. ok   
../../test/recipes/90-test_overhead.t ................. skipped: Only supported in no-shared builds
../../test/recipes/90-test_secmem.t ................... ok   
../../test/recipes/90-test_shlibload.t ................ ok     
../../test/recipes/90-test_srp.t ...................... ok   
../../test/recipes/90-test_sslapi.t ................... ok   
../../test/recipes/90-test_sslbuffers.t ............... ok   
../../test/recipes/90-test_store.t .................... ok       
../../test/recipes/90-test_sysdefault.t ............... ok   
../../test/recipes/90-test_threads.t .................. ok   
../../test/recipes/90-test_time_offset.t .............. ok   
../../test/recipes/90-test_tls13ccs.t ................. ok   
../../test/recipes/90-test_tls13encryption.t .......... ok   
../../test/recipes/90-test_tls13secrets.t ............. ok   
../../test/recipes/90-test_v3name.t ................... ok   
../../test/recipes/95-test_external_boringssl.t ....... skipped: No external tests in this configuration
../../test/recipes/95-test_external_krb5.t ............ skipped: No external tests in this configuration
../../test/recipes/95-test_external_pyca.t ............ skipped: No external tests in this configuration
../../test/recipes/99-test_ecstress.t ................. ok   
../../test/recipes/99-test_fuzz.t ..................... ok     
All tests successful.
Files=169, Tests=1636, 131 wallclock secs ( 2.15 usr  0.11 sys + 132.23 cusr  4.84 csys = 139.33 CPU)
Result: PASS

This fixes #8858.

@dot-asm @awilfox

@openssl-machine openssl-machine added the hold: cla required The contributor needs to submit a license agreement label May 6, 2019
@q66
Copy link
Author

q66 commented May 6, 2019

@dot-asm since there were no changes necessary compared to your original suggestions, maybe you could commit them yourself so I don't have to deal with the CLA stuff?

@dot-asm
Copy link
Contributor

dot-asm commented May 6, 2019

Oh! I haven't thought of the CLA thing. I apologize. Well, as far as I recall 'cla-check' can actually be removed manually, so it should be sufficient if I simply state that my CLA effectively covers this. Which I hereby do. Let's give @openssl opportunity to say if they're ok with that, and if not, then I'll resubmit this.

@q66
Copy link
Author

q66 commented May 6, 2019

Perfect, thanks.

@mattcaswell
Copy link
Member

There are two commits in this PR. One is showing the author as @dot-asm, and the other has the author as @q66. If the author of both is actually @dot-asm then please amend the author of the second commit and force push (git commit --amend --author=...). Since @dot-asm already has a CLA on file that should be sufficient for the cla-check bot to go "green".

@q66
Copy link
Author

q66 commented May 7, 2019

Okay. I wrote the second commit shortly before @dot-asm independently suggested an identical change. I will switch the author to @dot-asm as I don't really mind either way, as long as it gets the changes in :)

@openssl-machine openssl-machine removed the hold: cla required The contributor needs to submit a license agreement label May 7, 2019
@q66
Copy link
Author

q66 commented May 7, 2019

All done.

Andy Polyakov added 2 commits August 10, 2019 03:55
This is a big endian ELFv2 configuration. ELFv2 was already being
used for little endian, and big endian was traditionally ELFv1
but there are practical configurations that use ELFv2 with big
endian nowadays (Adélie Linux, Void Linux, possibly Gentoo, etc.)
If _CALL_ELF is defined to be 2, it's an ELFv2 system.
Conditionally switch to the v2 perlasm scheme.
@q66
Copy link
Author

q66 commented Aug 10, 2019

Rebased against master; any chance of getting this merged? I'll give it another test later.

Copy link
Member

@levitte levitte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@levitte levitte added approval: done This pull request has the required number of approvals branch: master Merge to master branch approval: review pending This pull request needs review by a committer and removed approval: done This pull request has the required number of approvals labels Nov 19, 2019
@levitte
Copy link
Member

levitte commented Nov 19, 2019

Ping @openssl/committers. This has been hanging for a bit too long, really

@paulidale paulidale added approval: done This pull request has the required number of approvals and removed approval: review pending This pull request needs review by a committer labels Nov 19, 2019
@q66
Copy link
Author

q66 commented Nov 19, 2019

Alright, I re-ran the testsuite on latest master and it's still okay and passing.

@levitte levitte added approval: ready to merge The 24 hour grace period has passed, ready to merge and removed approval: done This pull request has the required number of approvals labels Dec 11, 2019
openssl-machine pushed a commit that referenced this pull request Dec 11, 2019
This is a big endian ELFv2 configuration. ELFv2 was already being
used for little endian, and big endian was traditionally ELFv1
but there are practical configurations that use ELFv2 with big
endian nowadays (Adélie Linux, Void Linux, possibly Gentoo, etc.)

Reviewed-by: Paul Dale <paul.dale@oracle.com>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from #8883)
openssl-machine pushed a commit that referenced this pull request Dec 11, 2019
If _CALL_ELF is defined to be 2, it's an ELFv2 system.
Conditionally switch to the v2 perlasm scheme.

Reviewed-by: Paul Dale <paul.dale@oracle.com>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from #8883)
@levitte
Copy link
Member

levitte commented Dec 11, 2019

Merged.

34ab13b crypto/perlasm/ppc-xlate.pl: add linux64v2 flavour
0984041 Configure: use ELFv2 ABI on some ppc64 big endian systems

@levitte levitte closed this Dec 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approval: ready to merge The 24 hour grace period has passed, ready to merge branch: master Merge to master branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ppc64 ELFv2 ABI should not be determined from endianness
6 participants