Skip to content

Push error onto the stack when malloc fails in scrypt #5781

Closed

Description

@alex

https://github.com/openssl/openssl/blob/master/crypto/evp/pbe_scrypt.c#L232-L234

It's currently very difficult to debug if you get a malloc failure from scrypt because nothing is pushed onto the openssl error stack

Activity

  1. mspncp commented on Mar 28, 2018

    @mspncp
    Contributor

    Whoever fixes this issue might want to skim over the other locations where no error is pushed after a malloc failure. Maybe one or the other location deserves an error message, too. To find them, just run the following command from the OpenSSL source directory:

    pcregrep -rnM 'OPENSSL_.?alloc.*\n.*if.*NULL.*\n.*return'  crypto ssl
    
  2. richsalz commented on Mar 28, 2018

    @richsalz
    Contributor

    It would be nice if we could push the error down into the CRYPTO_alloc routines. We'd lose the function name, but we could preserve the source file/line numbers.

  3. mspncp commented on Mar 28, 2018

    @mspncp
    Contributor

    You mean, preserve file/line numbers of the caller, right? That sounds like a good idea. Initially, I also thought about pushing the error in CRYPTO_*alloc() itself, but then I discarded that thought because the line information of the alloc function itself would have been practically useless.

  4. richsalz commented on Mar 28, 2018

    @richsalz
    Contributor

    Look at the define's for OPENSSL_malloc and friends, and the body of CRYPTO_malloc and friends.
    Would still lose the function name tho.

  5. mspncp commented on Mar 28, 2018

    @mspncp
    Contributor

    I‘ll think about it. But for today I‘m offline now.

  6. bernd-edlinger commented on Mar 28, 2018

    @bernd-edlinger
    Member

    Pushing something on the error stack is likely to fail when there is no more memory left.

  7. bernd-edlinger commented on Mar 28, 2018

    @bernd-edlinger
    Member

    OTOH this function seems to have numerous error exits without instrumentation.

  8. alex commented on Mar 28, 2018

    @alex
    ContributorAuthor
  9. FdaSilvaYY commented on Mar 28, 2018

    @FdaSilvaYY
    Contributor

    @bernd-edlinger : there is no allocation in ERR_put_error function. storage is allocated at startup.
    @mspncp : your grep is retrieving 87 occurrences ...

  10. mspncp commented on Mar 28, 2018

    @mspncp
    Contributor

    I know. That‘s why I didn‘t post them ;-)

  11. bernd-edlinger commented on Mar 29, 2018

    @bernd-edlinger
    Member

    Well @FdaSilvaYY maybe not in ERR_put_error, but look at ERR_get_state.

  12. added this to the 1.1.1 milestone on Mar 29, 2018
  13. FdaSilvaYY commented on Mar 29, 2018

    @FdaSilvaYY
    Contributor

    @bernd-edlinger : you are right, it better that the app push an error as soon as possible to init the error-storage start ERR_STATE, or call directly ERR_get_state from each thread startup.
    I remenber that CRL loading trigger systematically some errors ...
    May-be add a word about this in documentation ?


    BTW this issue is fixed in
    master : 3484236

  14. mspncp commented on Mar 29, 2018

    @mspncp
    Contributor

    BTW this issue is fixed in master : 3484236

    This issue was not closed automatically, because the commit did not contain a 'Fixes #5781' line. Never mind, I'll close it now.

  15. DDvO commented on May 14, 2018

    @DDvO
    Contributor

    Further, more general discussion on this topic has been started in issue #6251.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions