improve EVP cipher param diagnostics on unsupported cipher modes and malloc failure#6217
improve EVP cipher param diagnostics on unsupported cipher modes and malloc failure#6217DDvO wants to merge 4 commits intoopenssl:masterfrom
Conversation
mattcaswell
left a comment
There was a problem hiding this comment.
Approved assuming CIs pass
richsalz
left a comment
There was a problem hiding this comment.
that if/test is indented wrong :) but okay.
|
A related general question also here: I wonder why malloc failures are not simply reported once and for all by |
I suppose, in theory, a malloc failure could either be because the system is running low on memory, or the call to CRYPTO_malloc() was erroneous (e.g. because it incorrectly attempts to allocate a vast amount of memory). In the second case this kind of problem would be difficult to find if all you have is the error code in CRYPTO_malloc itself. |
|
Thanks Matt for your response. In my question I should have consistently written 'malloc failure' (and not partly written 'out-of-memory') because I was not after a distinction between specific failure reasons. |
|
If we had an error API that let you specify the file and line number we could use that in malloc, since it gets those line/file as parameters. But there's also the issue in that the ERR code uses malloc, and we need to avoid the loop. |
ERR_PUT_error()? |
That's a point, Yet one could implement the ERR queue such that there is always an element pre-allocated&reserved for use by CRYPTO_malloc, such that in case this function adds an entry (possibly by using a specific function) there is no need to (recursively) allocate it. |
|
With the approach I just sketched, of course the queue cell should be reserved for actual out-of-memory situations only (and not any other potential failures of CRYPTO_malloc). When this reserved cell has been filled, any further requests to add elements to the ERR queue should be ignored in case the queue is full and would need re-allocation - I think this would be acceptable because at least from the lib's point of view an out-of-memory condition would be fatal anyway. |
|
Too late for 1.1.1 to change the ERR queue stuff. Can you copy the relevant comments about that into a new issue? |
|
Sure, will do soon. |
FYI: Many of them were added only recently: fe1128d Fix last(?) batch of malloc-NULL places |
IIRC, the entire discussion about the malloc error codes started way back in #5781, which triggered a sequence of pull requests. There was even a discussion in that thread about doing the reporting in CRYPTO_malloc() itself, using file and line information provided by the caller. I don't really remember, why that thought was discarded at that time. |
|
Thanks a lot @mspncp for pointing out this related discussion and the number of recent commits. who should have known better that ...
|
|
Further, more general discussion on this topic has been started in issue #6251. |
|
What is the status of this PR? Can it be merged? |
|
Good reminder. Looks like the actual PR got buried under the more general discussion that it brought up, which has then been moved to a new thread. |
|
Pushed. Thanks. |
…2_SAFEBAG_create_pkcs8_encrypt Reviewed-by: Rich Salz <rsalz@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from #6217)
Reviewed-by: Rich Salz <rsalz@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from #6217)
…architecture Reviewed-by: Rich Salz <rsalz@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from #6217)
When trying to use
PKCS12_create()withNID_aes_256_gcmI got rather inaccurate and even misleading diagnostics:It took me a little while to find out that the actual problem is that GCM (and also some other block cipher modes) are simply not supported here, which is a long-standing issue reported and discussed for instance at https://security.stackexchange.com/questions/83384/creating-a-private-key-with-openssl-and-encrypting-it-with-aes-gcm and https://groups.google.com/forum/#!topic/mailing.openssl.users/hGggWxfrZbA
This PR adds a distinction between unsupported cipher modes and other errors when converting between EVP cipher params and ASN.1, updating and slightly extending the documentation. It also replaces in the
genpkeyapp these low-level error(s) by a more telling high-level error message and fixes the comparisons for error detection in a couple of calls toEVP_CIPHER_asn1_to_param()andEVP_CIPHER_param_to_asn1().I also removed two needless and misleading malloc failure error messages of
PKCS12_SAFEBAG_create_pkcs8_encrypt().BTW, I wonder why malloc failures are not simply reported once and for all by
CRYPTO_malloc()itself and instead the burden is put on the callers. There are presumably many instances like the ones I fixed here where a NULL pointer result is misinterpreted to be due to an out-of-memory condition, and very likely there are even much more cases where malloc failures are caught but not reported.I also added a type cast in
setup_tests()oftest/x509aux.cpreventing a compiler warning for the VC-WIN64A architecture (which is an unrelated very minor issue for which I thought it is not worth providing a separate PR).Checklist