Skip to content

RSA implementation in FIPS module not thread safe #4180

Closed

Description

@srahul123

I have a server application in which a global SSL_CTX is used by multiple threads for creating SSL session objects. The session establishment fails randomly when FIPS mode is turned on. I debugged the issue and found that the problem is happening because the RSA key associated with the SSL_CTX object is being used by multiple threads and the RSA decryption functionality is not thread safe. I have attached sample code to reproduce this failure.
rsa-op.cpp.txt

Activity

  1. richsalz commented on Aug 17, 2017

    @richsalz
    Contributor

    yes. most OpenSSL objects are not designed for concurrent use in multiple threads.

    and also this is FIPS code which we cannot change.

    Sorry, closing the issue.

  2. srahul123 commented on Aug 17, 2017

    @srahul123
    Author

    most OpenSSL objects are not designed for concurrent use in multiple threads.

    I just want to point out that this is not a case of incorrect usage of OpenSSL API. TLS handshake is failing because of this bug.

    this is FIPS code which we cannot change.

    I get that

  3. richsalz commented on Aug 17, 2017

    @richsalz
    Contributor

    no, you are using an SSL object in multiple threads and that is also not allowed

  4. mattcaswell commented on Aug 17, 2017

    @mattcaswell
    Member

    My understanding from the original post was that SSL_CTX was used in multiple threads (not SSL). This is allowed.

  5. srahul123 commented on Aug 17, 2017

    @srahul123
    Author

    My understanding from the original post was that SSL_CTX was used in multiple threads (not SSL). This is allowed.

    That is correct.

    no, you are using an SSL object in multiple threads and that is also not allowed

    The attached code is a simplified version of the original code I am attaching below. The SSL object is not shared between threads. A global SSL_CTX object is used to create multiple SSL objects by different threads. And I have defined locking callbacks using CRYPTO_set_locking_callback().
    ssl-server-rsa.cpp.txt

    Also note that neither of these sample codes fail when FIPS mode is off.

  6. richsalz commented on Aug 17, 2017

    @richsalz
    Contributor

    So this fails in FIPS which cannot be changed. Why is this re-opened?

  7. mattcaswell commented on Aug 17, 2017

    @mattcaswell
    Member

    It's not entirely clear to me that this is a problem in the FIPS module. Where is the locking supposed to be happening here? In libssl or in the RSA implementation? I would have expected the former rather than the latter. If so then its not a bug in the FIPS module and can be fixed. If it is a bug in the FIPS module then you're right and we can't fix it. But until we establish that I think it should remain open.

  8. richsalz commented on Aug 17, 2017

    @richsalz
    Contributor

    From the original poster: "Also note that neither of these sample codes fail when FIPS mode is off."

  9. snhenson commented on Aug 18, 2017

    @snhenson
    Contributor

    Though just because something fails in FIPS mode doesn't necessarily mean it is a bug in the FIPS module: it could be in the glue code in OpenSSL that uses the FIPS module. Even if it is a bug in the FIPS module itself there may be a way to work around it in the glue code without modifying the FIPS module.

    It isn't obvious which is the case here though.

  10. added a commit that references this issue on Aug 18, 2017
    2d228de
  11. snhenson commented on Aug 18, 2017

    @snhenson
    Contributor

    Right looks like the FIPS thread ID callback isn't being set. If the deprecated CRYPTO_set_id_callback() function is used then everything works as expected.

    #4192 should fix it.

  12. added a commit that references this issue on Aug 18, 2017
    0ab2408
  13. mattcaswell commented on Aug 18, 2017

    @mattcaswell
    Member

    It amazes me that this hasn't been discovered before.

  14. snhenson commented on Aug 18, 2017

    @snhenson
    Contributor

    I think it's down to the fact that the defaults often work as does the deprecated id callback: it was only the newer interface that wasn't passed through.

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

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions