summaryrefslogtreecommitdiffstats
path: root/crypto
AgeCommit message (Collapse)Author
2024-04-02Remove handling of NULL sig param in ossl_ecdsa_deterministic_signBernd Edlinger
The handling of sig=NULL was broken in this function, but since it is only used internally and was never called with sig=NULL, it is better to return an error in that case. Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/23529) (cherry picked from commit 294782f3b5c4b81d682e6e8608bb6e851177494d)
2024-04-02Fix handling of NULL sig parameter in ECDSA_sign and similarBernd Edlinger
The problem is, that it almost works to pass sig=NULL to the ECDSA_sign, ECDSA_sign_ex and DSA_sign, to compute the necessary space for the resulting signature. But since the ECDSA signature is non-deterministic (except when ECDSA_sign_setup/ECDSA_sign_ex are used) the resulting length may be different when the API is called again. This can easily cause random memory corruption. Several internal APIs had the same issue, but since they are never called with sig=NULL, it is better to make them return an error in that case, instead of making the code more complex. Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/23529) (cherry picked from commit 1fa2bf9b1885d2e87524421fea5041d40149cffa)
2024-03-25Correct OSSL_sleep for NonStop PUT model by introducing sleep().Randall S. Becker
This fix also removes SPT model support as it was previously deprecated. Upcoming threading models on the platform should be supportable without change to this method. Fixes: #23923 Fixes: #23927 Fixes: #23928 Signed-off-by: Randall S. Becker <randall.becker@nexbridge.ca> Reviewed-by: Neil Horman <nhorman@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/23926) (cherry picked from commit 4a9e48f727ce7ad924c53a55b301e426d7e43863)
2024-03-22Don’t use the recvmmsg dgram method on Android <5Yavor Georgiev
recvmmsg and sendmmsg were only added to Android’s C library in version 5, starting with API Level 21. Reviewed-by: Neil Horman <nhorman@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/23754) (cherry picked from commit 24109dca5a793d58c68a346db5b21746079ec317)
2024-03-15Fix unbounded memory growth when using no-cached-fetchMatt Caswell
When OpenSSL has been compiled with no-cached-fetch we do not cache algorithms fetched from a provider. When we export an EVP_PKEY to a provider we cache the details of that export in the operation cache for that EVP_PKEY. Amoung the details we cache is the EVP_KEYMGMT that we used for the export. When we come to reuse the key in the same provider that we have previously exported the key to, we check the operation cache for the cached key data. However because the EVP_KEYMGMT instance was not cached then instance will be different every time and we were not recognising that we had already exported the key to the provider. This causes us to re-export the key to the same provider everytime the key is used. Since this consumes memory we end up with unbounded memory growth. The fix is to be more intelligent about recognising that we have already exported key data to a given provider even if the EVP_KEYMGMT instance is different. Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Neil Horman <nhorman@openssl.org> Reviewed-by: Paul Dale <ppzgs1@gmail.com> (Merged from https://github.com/openssl/openssl/pull/23841) (cherry picked from commit dc9bc6c8e1bd329ead703417a2235ab3e97557ec)
2024-03-08Fix a memory leak on successful load of CRLDmitry Belyavskiy
Fixes #23693 Reviewed-by: David von Oheimb <david.von.oheimb@siemens.com> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/23770)
2024-03-07Gate setting of ipi_spec_dst on not building for freebsdNeil Horman
some variants of FreeBSD (notably Dells OneFS) implement IP_PKTINFO partially, and as such the build breaks for those variants. specifically, it supports IP_PKTINFO, but the in_pktinfo struct has no defined ipi_spec_dst field. Work around this by gating the setting of that variable on not building for FreeBSD Fixes #23739 Reviewed-by: Hugo Landau <hlandau@openssl.org> Reviewed-by: Tim Hudson <tjh@openssl.org> (Merged from https://github.com/openssl/openssl/pull/23753) (cherry picked from commit b5e076bee3c0445c108a6a35f077083ee42f9d80)
2024-03-01Fix off by one issue in buf2hexstr_sep()shridhar kalavagunta
Fixes #23363 Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/23404) (cherry picked from commit c5cc9c419a0a8d97a44f01f95f0e213f56da4574)
2024-02-22chachap10-ppc.pl: Fix truncated relocation响马
Fix error: relocation truncated to fit: R_PPC64_REL14 (stub) against symbol `ChaCha20_ctr32_vsx_8x' CLA: trivial Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/23618) (cherry picked from commit 1afb326da4b3a781dc0d7cd91262d81126783b07)
2024-02-22Add atexit configuration option to using atexit() in libcrypto at build-time.Randall S. Becker
This fixes an issue with a mix of atexit() usage in DLL and statically linked libcrypto that came out in the test suite on NonStop, which has slightly different DLL unload processing semantics compared to Linux. The change allows a build configuration to select whether to register OPENSSL_cleanup() with atexit() or not, so avoid situations where atexit() registration causes SIGSEGV. INSTALL.md and CHANGES.md have been modified to include and describe this option. Signed-off-by: Randall S. Becker <randall.becker@nexbridge.ca> Signed-off-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com> Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/23642)
2024-02-19OpenSSL License is applied for some source files, change to Apache 2Shakti Shah
The following files include/openssl/hpke.h crypto/hpke/hpke.c crypto/ec/asm/ecp_sm2p256-armv8.pl crypto/chacha/asm/chacha-loongarch64.pl still seem to be released under the OpenSSL License instead of the Apache 2 license. Fixes #23570 Reviewed-by: Shane Lontis <shane.lontis@oracle.com> Reviewed-by: Richard Levitte <levitte@openssl.org> (Merged from https://github.com/openssl/openssl/pull/23576) (cherry picked from commit e5313f20486f86be42059fce6b0d9e43a35e8655)
2024-02-16Fixed Visual Studio 2008 compiler errorsMarcel Gosmann
CLA: trivial Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/23586) (cherry picked from commit c3e8d67885c0c4295cfd1df35a41bf1f3fa9dc37)
2024-02-16Check for NULL cleanup function before using it in encoder_processNeil Horman
encoder_process assumes a cleanup function has been set in the currently in-use encoder during processing, which can lead to segfaults if said function hasn't been set Add a NULL check for this condition, returning -1 if it is not set Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/23069) (cherry picked from commit cf57c3ecfa416afbc47d36633981034809ee6792)
2024-02-09Rearrange terms in gf_mul to prevent segfaultAngel Baez
CLA: trivial Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/23512) (cherry picked from commit 76cecff5e9bedb2bafc60062283f99722697082a)
2024-02-08Fix sm4-xts aarch64 assembly implementation bugLiu-Ermeng
Tested on kunpeng920, to turn on 'VPSM4_EX_CAPABLE'. Signed-off-by: Liu-Ermeng <liuermeng2@huawei.com> Reviewed-by: Shane Lontis <shane.lontis@oracle.com> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/23317) (cherry picked from commit 2a2561709ab316584d8b0a6220e244094fe507f5)
2024-02-06Fix SM2 test failures on Apple SiliconXu Yizhou
This patch is to fix #23368. Signed-off-by: Xu Yizhou <xuyizhou1@huawei.com> Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/23472) (cherry picked from commit 1751185154ab1f1a796e0f39567fe51c8e24b78d)
2024-02-02Fix a few incorrect paths in some build.info filesRichard Levitte
The following files referred to ../liblegacy.a when they should have referred to ../../liblegacy.a. This cause the creation of a mysterious directory 'crypto/providers', and because of an increased strictness with regards to where directories are created, configuration failure on some platforms. Fixes #23436 Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com> (Merged from https://github.com/openssl/openssl/pull/23452)
2024-01-31Revert "Improved detection of engine-provided private "classic" keys"Tomas Mraz
This reverts commit 2b74e75331a27fc89cad9c8ea6a26c70019300b5. The commit was wrong. With 3.x versions the engines must be themselves responsible for creating their EVP_PKEYs in a way that they are treated as legacy - either by using the respective set1 calls or by setting non-default EVP_PKEY_METHOD. The workaround has caused more problems than it solved. Fixes #22945 Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com> Reviewed-by: Neil Horman <nhorman@openssl.org> (Merged from https://github.com/openssl/openssl/pull/23063) (cherry picked from commit 39ea78379826fa98e8dc8c0d2b07e2c17cd68380)
2024-01-31Fix error reporting in EVP_PKEY_{sign,verify,verify_recover}Richard Levitte
For some reason, those functions (and the _init functions too) would raise EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE when the passed ctx is NULL, and then not check if the provider supplied the function that would support these libcrypto functions. This corrects the situation, and has all those libcrypto functions raise ERR_R_PASS_NULL_PARAMETER if ctx is NULL, and then check for the corresponding provider supplied, and only when that one is missing, raise EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE. Because 0 doesn't mean error for EVP_PKEY_verify(), -1 is returned when ERR_R_PASSED_NULL_PARAMETER is raised. This is done consistently for all affected functions. Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com> Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/23411) (cherry picked from commit 5a25177d1b07ef6e754fec1747b57ee90ab1e028)
2024-01-30Copyright year updatesMatt Caswell
Reviewed-by: Richard Levitte <levitte@openssl.org> Release: yes
2024-01-25Have OSSL_PARAM_allocate_from_text() fail on odd number of hex digitsRichard Levitte
The failure would be caught later on, so this went unnoticed, until someone tried with just one hex digit, which was simply ignored. Fixes #23373 Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/23374) (cherry picked from commit ea6268cfceaba24328d66bd14bfc97c4fac14a58)
2024-01-25Add NULL checks where ContentInfo data can be NULLMatt Caswell
PKCS12 structures contain PKCS7 ContentInfo fields. These fields are optional and can be NULL even if the "type" is a valid value. OpenSSL was not properly accounting for this and a NULL dereference can occur causing a crash. CVE-2024-0727 Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Hugo Landau <hlandau@openssl.org> Reviewed-by: Neil Horman <nhorman@openssl.org> (Merged from https://github.com/openssl/openssl/pull/23361) (cherry picked from commit 041962b429ebe748c8b6b7922980dfb6decfef26)
2024-01-18prevent integer overflow in ossl_asn1_time_from_tmPaul Dreik
this could be triggered by the following code (assuming 64 bit time_t): time_t t = 67768011791126057ULL; ASN1_TIME* at = ASN1_TIME_set(NULL, t); Reviewed-by: Hugo Landau <hlandau@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/22976) (cherry picked from commit 5b2d8bc28a8ff59689da98f31459819db09a9099)
2024-01-17Fix performance regression of ChaCha20 on LoongArch64Lin Runze
The regression was introduced in PR #22817. In that pull request, the input length check was moved forward, but the related ori instruction was missing, and it will cause input of any length down to the much slower scalar implementation. Fixes #23300 CLA: trivial Reviewed-by: Shane Lontis <shane.lontis@oracle.com> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/23301) (cherry picked from commit 971028535e6531c89449e06b1f6862c18f04ff91)
2024-01-16hurd: Fix dgram_sendmmsgSamuel Thibault
GNU/Hurd does not have IP_PKTINFO yet, thus SUPPORT_LOCAL_ADDR is undef, data->local_addr_enabled never set to 1, and thus the M_METHOD_RECVMSG method would end up raising BIO_R_LOCAL_ADDR_NOT_AVAILABLE immediately. Fixes #22872 Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Hugo Landau <hlandau@openssl.org> (Merged from https://github.com/openssl/openssl/pull/23293) (cherry picked from commit 2f85736e9c66248528f132d46508f06a0bb8dd88)
2024-01-16Check whether the pubkey exists in ossl_ecx_key_duplan1120
Signed-off-by: lan1120 <lanming@huawei.com> Reviewed-by: Shane Lontis <shane.lontis@oracle.com> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/22984) (cherry picked from commit aac531e5daa2edec5d47e702a7f115cf77fe07f9)
2024-01-15Limit the execution time of RSA public key checkTomas Mraz
Fixes CVE-2023-6237 If a large and incorrect RSA public key is checked with EVP_PKEY_public_check() the computation could take very long time due to no limit being applied to the RSA public key size and unnecessarily high number of Miller-Rabin algorithm rounds used for non-primality check of the modulus. Now the keys larger than 16384 bits (OPENSSL_RSA_MAX_MODULUS_BITS) will fail the check with RSA_R_MODULUS_TOO_LARGE error reason. Also the number of Miller-Rabin rounds was set to 5. Reviewed-by: Neil Horman <nhorman@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/23243) (cherry picked from commit e09fc1d746a4fd15bb5c3d7bbbab950aadd005db)
2024-01-15Fix arithmetic expression overflowDrokov Pavel
If the value of a->length is large (>= 2^12), then an integer overflow will occur for the signed type, which according to the C standard is UB. CLA: trivial Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/23274) (cherry picked from commit 486ab0fb003d05f89620662260486d31bd3faa8c)
2024-01-15Check ASN1_OBJECT_new resultDrokov Pavel
CLA: trivial Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/23270) (cherry picked from commit 6b92a966e0de3ad848fcf11fbcab7ee8cae24ba1)
2024-01-12Fix NULL pointer deref when parsing the stable sectionNeil Horman
When parsing the stable section of a config such as this: openssl_conf = openssl_init [openssl_init] stbl_section = mstbl [mstbl] id-tc26 = min Can lead to a SIGSEGV, as the parsing code doesnt recognize min as a proper section name without a trailing colon to associate it with a value. As a result the stack of configuration values has an entry with a null value in it, which leads to the SIGSEGV in do_tcreate when we attempt to pass NULL to strtoul. Fix it by skipping any entry in the config name/value list that has a null value, prior to passing it to stroul Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/22988) (cherry picked from commit 0981c20f8efa68bf9d68d7715280f83812c19a7e)
2024-01-12Fix partial block encryption in cfb and ofb for s390x (legacy)Holger Dengler
Use the number of processed bytes information (num) from the generic cipher context for the partial block handling in cfb and ofb also in s390x-legacy code. For more details see 4df92c1a14 ("Fix partial block encryption in cfb and ofb for s390x"). Signed-off-by: Holger Dengler <dengler@linux.ibm.com> Reviewed-by: Shane Lontis <shane.lontis@oracle.com> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/23201) (cherry picked from commit f9ccd209c3d121668c51a992613c698f2a774cb3)
2024-01-11Disable build of HWAES on PPC MacsTomas Mraz
Fixes #22818 Reviewed-by: Neil Horman <nhorman@openssl.org> Reviewed-by: Todd Short <todd.short@me.com> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/22860) (cherry picked from commit 493ad484e9312b54d177d85e2f4aa0b636e708f0)
2024-01-11evp_fetch.c: Check meth_id instead of name_idsashan
Fixes #23226 Reviewed-by: Shane Lontis <shane.lontis@oracle.com> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/23238) (cherry picked from commit da840c3775f52fc9766c654b5ad6ee031ffc9fd9)
2024-01-10Fix a similar memory leak in SXNET_add_id_INTEGERBernd Edlinger
Even in the good case there was memory leak here. Add a simple test case to have at least some test coverage. Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/23234) (cherry picked from commit 398011848468c7e8e481b295f7904afc30934217)
2024-01-10Fix a possible memory leak in sxnet_v2iBernd Edlinger
When a subsequent call to SXNET_add_id_asc fails e.g. because user is a string larger than 64 char or the zone is a duplicate zone id, or the zone is not an integer, a memory leak may be the result. Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/23234) (cherry picked from commit 0151e772195fc03cce0f12e5e266e51dc15243a0)
2024-01-09Check appropriate OSSL_PARAM_get_* functions for NULLNeil Horman
The base type OSSL_PARAM getters will NULL deref if they are initalized as null. Add NULL checks for those parameters that have no expectation of returning null (int32/64/uint32/64/BN). Other types can be left as allowing NULL, as a NULL setting may be meaningful (string, utf8str, octet string, etc). Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Richard Levitte <levitte@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/23083) (cherry picked from commit 806bbafe2df5b699feac6ef26e50c14e701950cf)
2024-01-09poly1305-ppc.pl: Fix vector register clobberingRohan McLure
Fixes CVE-2023-6129 The POLY1305 MAC (message authentication code) implementation in OpenSSL for PowerPC CPUs saves the the contents of vector registers in different order than they are restored. Thus the contents of some of these vector registers is corrupted when returning to the caller. The vulnerable code is used only on newer PowerPC processors supporting the PowerISA 2.07 instructions. Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Richard Levitte <levitte@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/23200) (cherry picked from commit 8d847a3ffd4f0b17ee33962cf69c36224925b34f)
2024-01-08Avoid memory leak if SXNET_add_id_INTEGER() failsTomas Mraz
Fixes Coverity 1560046 Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Tim Hudson <tjh@openssl.org> (Merged from https://github.com/openssl/openssl/pull/23211) (cherry picked from commit 7054fc1ca3945342777f588fba43b77f669509ad)
2024-01-05Validate config options during x509 extension creationNeil Horman
There are several points during x509 extension creation which rely on configuration options which may have been incorrectly parsed due to invalid settings. Preform a value check for null in those locations to avoid various crashes/undefined behaviors Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/23183) (cherry picked from commit bac7e687d71b124b09ad6ad3e15be9b38c08a1ba)
2024-01-03Add missing documentation for X509_ATTRIBUTE related functions.slontis
Partial fix for #8026 Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com> Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/22656) (cherry picked from commit f1f0731ddf6cb31d62a2c0f406b009ae9817ed7f)
2024-01-03Allow duplicate CMS attributesTomas Mraz
Fixes regression introduced with https://github.com/openssl/openssl/pull/21505 Fixes #22266 Reviewed-by: Shane Lontis <shane.lontis@oracle.com> Reviewed-by: Richard Levitte <levitte@openssl.org> (Merged from https://github.com/openssl/openssl/pull/23029) (cherry picked from commit d7e707cb4983a35b1a265c6042da410d829f3b19)
2024-01-01gate calling of evp_method_id on having a non-zero name idNeil Horman
If a name is passed to EVP_<OBJ>_fetch of the form: name1:name2:name3 The names are parsed on the separator ':' and added to the store, but during the lookup in inner_evp_generic_fetch, the subsequent search of the store uses the full name1:name2:name3 string, which fails lookup, and causes subsequent assertion failures in evp_method_id. instead catch the failure in inner_evp_generic_fetch and return an error code if the name_id against a colon separated list of names fails. This provides a graceful error return path without asserts, and leaves room for a future feature in which such formatted names can be parsed and searched for iteratively Add a simple test to verify that providing a colon separated name results in an error indicating an invalid lookup. Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Todd Short <todd.short@me.com> (Merged from https://github.com/openssl/openssl/pull/23110) (cherry picked from commit 94be985cbcc1f0a5cf4f172d4a8d06c5c623122b)
2023-12-29Limit RSA-OAEP related functions to RSA keys onlyslontis
Make EVP_PKEY_CTX_set_rsa_oaep_md() and EVP_PKEY_CTX_get_rsa_oaep_md_name() only work for RSA keys. Since these calls use "digest" as a OSSL_PARAM, they should not work for other key types. Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/20319) (cherry picked from commit 0c3eb31b55d3c1544e4e044c2e3c939655bac93d)
2023-12-29Fix memleak in rsa_cms_decryptslontis
If a call to EVP_PKEY_CTX_set_rsa_mgf1_md() fails then the caller needs to free the label. Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/20319) (cherry picked from commit d32dd65053431ee744d213b336b9a03a035807e6)
2023-12-29Fix error handling in ASN1_mbstring_ncopyBernd Edlinger
Sometimes the error handling returns an ASN1_STRING object in *out although that was not passed in by the caller, and sometimes the error handling deletes the ASN1_STRING but forgets to clear the *out parameter. Therefore the caller has no chance to know, if the leaked object in *out shall be deleted or not. This may cause a use-after-free error e.g. in asn1_str2type: ==63312==ERROR: AddressSanitizer: heap-use-after-free on address 0x603000073280 at pc 0x7f2652e93b08 bp 0x7ffe0e1951c0 sp 0x7ffe0e1951b0 READ of size 8 at 0x603000073280 thread T0 #0 0x7f2652e93b07 in asn1_string_embed_free crypto/asn1/asn1_lib.c:354 #1 0x7f2652eb521a in asn1_primitive_free crypto/asn1/tasn_fre.c:204 #2 0x7f2652eb50a9 in asn1_primitive_free crypto/asn1/tasn_fre.c:199 #3 0x7f2652eb5b67 in ASN1_item_free crypto/asn1/tasn_fre.c:20 #4 0x7f2652e8e13b in asn1_str2type crypto/asn1/asn1_gen.c:740 #5 0x7f2652e8e13b in generate_v3 crypto/asn1/asn1_gen.c:137 #6 0x7f2652e9166c in ASN1_generate_v3 crypto/asn1/asn1_gen.c:92 #7 0x7f2653307b9b in do_othername crypto/x509v3/v3_alt.c:577 #8 0x7f2653307b9b in a2i_GENERAL_NAME crypto/x509v3/v3_alt.c:492 #9 0x7f26533087c2 in v2i_subject_alt crypto/x509v3/v3_alt.c:327 #10 0x7f26533107fc in do_ext_nconf crypto/x509v3/v3_conf.c:100 #11 0x7f2653310f33 in X509V3_EXT_nconf crypto/x509v3/v3_conf.c:45 #12 0x7f2653311426 in X509V3_EXT_add_nconf_sk crypto/x509v3/v3_conf.c:312 #13 0x7f265331170c in X509V3_EXT_REQ_add_nconf crypto/x509v3/v3_conf.c:360 #14 0x564ed19d5f25 in req_main apps/req.c:806 #15 0x564ed19b8de0 in do_cmd apps/openssl.c:564 #16 0x564ed1985165 in main apps/openssl.c:183 #17 0x7f2651c4a082 in __libc_start_main ../csu/libc-start.c:308 #18 0x564ed1985acd in _start (/home/ed/OPCToolboxV5/Source/Core/OpenSSL/openssl/apps/openssl+0x139acd) 0x603000073280 is located 16 bytes inside of 24-byte region [0x603000073270,0x603000073288) freed by thread T0 here: #0 0x7f265413440f in __interceptor_free ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:122 #1 0x7f265315a429 in CRYPTO_free crypto/mem.c:311 #2 0x7f265315a429 in CRYPTO_free crypto/mem.c:300 #3 0x7f2652e757b9 in ASN1_mbstring_ncopy crypto/asn1/a_mbstr.c:191 #4 0x7f2652e75ec5 in ASN1_mbstring_copy crypto/asn1/a_mbstr.c:38 #5 0x7f2652e8e227 in asn1_str2type crypto/asn1/asn1_gen.c:681 #6 0x7f2652e8e227 in generate_v3 crypto/asn1/asn1_gen.c:137 #7 0x7f2652e9166c in ASN1_generate_v3 crypto/asn1/asn1_gen.c:92 #8 0x7f2653307b9b in do_othername crypto/x509v3/v3_alt.c:577 #9 0x7f2653307b9b in a2i_GENERAL_NAME crypto/x509v3/v3_alt.c:492 #10 0x7f26533087c2 in v2i_subject_alt crypto/x509v3/v3_alt.c:327 #11 0x7f26533107fc in do_ext_nconf crypto/x509v3/v3_conf.c:100 #12 0x7f2653310f33 in X509V3_EXT_nconf crypto/x509v3/v3_conf.c:45 #13 0x7f2653311426 in X509V3_EXT_add_nconf_sk crypto/x509v3/v3_conf.c:312 #14 0x7f265331170c in X509V3_EXT_REQ_add_nconf crypto/x509v3/v3_conf.c:360 #15 0x564ed19d5f25 in req_main apps/req.c:806 #16 0x564ed19b8de0 in do_cmd apps/openssl.c:564 #17 0x564ed1985165 in main apps/openssl.c:183 #18 0x7f2651c4a082 in __libc_start_main ../csu/libc-start.c:308 previously allocated by thread T0 here: #0 0x7f2654134808 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:144 #1 0x7f265315a4fd in CRYPTO_malloc crypto/mem.c:221 #2 0x7f265315a4fd in CRYPTO_malloc crypto/mem.c:198 #3 0x7f265315a945 in CRYPTO_zalloc crypto/mem.c:236 #4 0x7f2652e939a4 in ASN1_STRING_type_new crypto/asn1/asn1_lib.c:341 #5 0x7f2652e74e51 in ASN1_mbstring_ncopy crypto/asn1/a_mbstr.c:150 #6 0x7f2652e75ec5 in ASN1_mbstring_copy crypto/asn1/a_mbstr.c:38 #7 0x7f2652e8e227 in asn1_str2type crypto/asn1/asn1_gen.c:681 #8 0x7f2652e8e227 in generate_v3 crypto/asn1/asn1_gen.c:137 #9 0x7f2652e9166c in ASN1_generate_v3 crypto/asn1/asn1_gen.c:92 #10 0x7f2653307b9b in do_othername crypto/x509v3/v3_alt.c:577 #11 0x7f2653307b9b in a2i_GENERAL_NAME crypto/x509v3/v3_alt.c:492 #12 0x7f26533087c2 in v2i_subject_alt crypto/x509v3/v3_alt.c:327 #13 0x7f26533107fc in do_ext_nconf crypto/x509v3/v3_conf.c:100 #14 0x7f2653310f33 in X509V3_EXT_nconf crypto/x509v3/v3_conf.c:45 #15 0x7f2653311426 in X509V3_EXT_add_nconf_sk crypto/x509v3/v3_conf.c:312 #16 0x7f265331170c in X509V3_EXT_REQ_add_nconf crypto/x509v3/v3_conf.c:360 #17 0x564ed19d5f25 in req_main apps/req.c:806 #18 0x564ed19b8de0 in do_cmd apps/openssl.c:564 #19 0x564ed1985165 in main apps/openssl.c:183 #20 0x7f2651c4a082 in __libc_start_main ../csu/libc-start.c:308 Reviewed-by: Paul Yang <kaishen.yy@antfin.com> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/23138) (cherry picked from commit 73ebaac827180bb51ccf807673758d7d06d5db21)
2023-12-22Detect and prevent recursive config parsingNeil Horman
If a malformed config file is provided such as the following: openssl_conf = openssl_init [openssl_init] providers = provider_sect [provider_sect] = provider_sect The config parsing library will crash overflowing the stack, as it recursively parses the same provider_sect ad nauseum. Prevent this by maintaing a list of visited nodes as we recurse through referenced sections, and erroring out in the event we visit any given section node more than once. Note, adding the test for this revealed that our diagnostic code inadvertently pops recorded errors off the error stack because provider_conf_load returns success even in the event that a configuration parse failed. The call path to provider_conf_load has been updated in this commit to address that shortcoming, allowing recorded errors to be visibile to calling applications. Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/22898) (cherry picked from commit 682fd21afb5428b5716e62eaefb09a7419f9cfd7)
2023-12-19LoongArch64 assembly pack: Fix ChaCha20 ABI breakageXi Ruoyao
The [LP64D ABI][1] requires the floating-point registers f24-f31 (aka fs0-fs7) callee-saved. The low 64 bits of a LSX/LASX vector register aliases with the corresponding FPR, so we must save and restore the callee-saved FPR when we writes into the corresponding vector register. This ABI breakage can be easily demonstrated by injecting the use of a saved FPR into the test in bio_enc_test.c: static int test_bio_enc_chacha20(int idx) { register double fs7 asm("f31") = 114.514; asm("#optimize barrier":"+f"(fs7)); return do_test_bio_cipher(EVP_chacha20(), idx) && fs7 == 114.514; } So fix it. To make the logic simpler, jump into the scalar implementation earlier when LSX and LASX are not enumerated in AT_HWCAP, or the input is too short. [1]: https://github.com/loongson/la-abi-specs/blob/v2.20/lapcs.adoc#floating-point-registers Reviewed-by: Neil Horman <nhorman@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/22817) (cherry picked from commit b46de72c260e7c4d9bfefa35b02295ba32ad2ac6)
2023-12-19Fix declspec align syntaxKai Pastor
Reviewed-by: Hugo Landau <hlandau@openssl.org> Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com> (Merged from https://github.com/openssl/openssl/pull/23072) (cherry picked from commit dfd986b6f5402e5646e42425d14f098ed6bc4544)
2023-12-19Fix comment syntaxKai Pastor
Reviewed-by: Hugo Landau <hlandau@openssl.org> Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com> (Merged from https://github.com/openssl/openssl/pull/23072) (cherry picked from commit 1fda942e8cd425263433094bf8714a80c05bcb2c)
2023-12-13Harden asn1 oid loader to invalid inputsNeil Horman
In the event that a config file contains this sequence: ======= openssl_conf = openssl_init config_diagnostics = 1 [openssl_init] oid_section = oids [oids] testoid1 = 1.2.3.4.1 testoid2 = A Very Long OID Name, 1.2.3.4.2 testoid3 = ,1.2.3.4.3 ====== The leading comma in testoid3 can cause a heap buffer overflow, as the parsing code will move the string pointer back 1 character, thereby pointing to an invalid memory space correct the parser to detect this condition and handle it by treating it as if the comma doesn't exist (i.e. an empty long oid name) Reviewed-by: Hugo Landau <hlandau@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/22957) (cherry picked from commit a552c23c6502592c1b3c67d93dd7e5ffbe958aa4)