python / cpython

The Python programming language
https://www.python.org
Other
63.42k stars 30.37k forks source link

Declaration of EVP_MD_CTX causes crash when switching between OpenSSL 0.9 and 1.0 #65763

Closed 33e511b4-e212-460e-8961-959c6b524946 closed 3 years ago

33e511b4-e212-460e-8961-959c6b524946 commented 10 years ago
BPO 21564
Nosy @gpshead, @tiran, @iritkatriel
Files
  • EVP_MD_CTX-python3.4.patch: Patch for _hashlib.c to change EVP_MD_CTX declaration
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields: ```python assignee = None closed_at = created_at = labels = ['extension-modules', 'type-crash'] title = 'Declaration of EVP_MD_CTX causes crash when switching between OpenSSL 0.9 and 1.0' updated_at = user = 'https://bugs.python.org/RyanCalhoun' ``` bugs.python.org fields: ```python activity = actor = 'christian.heimes' assignee = 'none' closed = True closed_date = closer = 'christian.heimes' components = ['Extension Modules'] creation = creator = 'Ryan.Calhoun' dependencies = [] files = ['35330'] hgrepos = [] issue_num = 21564 keywords = ['patch'] message_count = 3.0 messages = ['218995', '381858', '381863'] nosy_count = 4.0 nosy_names = ['gregory.p.smith', 'christian.heimes', 'Ryan.Calhoun', 'iritkatriel'] pr_nums = [] priority = 'normal' resolution = 'fixed' stage = 'resolved' status = 'closed' superseder = None type = 'crash' url = 'https://bugs.python.org/issue21564' versions = ['Python 2.7', 'Python 3.4'] ```

    33e511b4-e212-460e-8961-959c6b524946 commented 10 years ago

    OpenSSL, specifically libcrypto, includes functions EVP_MD_CTX_create() and EVP_MD_CTX_destroy(), such that the application code only needs to forward declare the EVP_MD_CTX* pointer type.

    Declaring the EVP_MD_CTX variable type directly requires compile-time knowledge of the size of the structure. This knowledge will be wrong when compiling with headers from OpenSSL 0.9.8 and dynamically linking at run time against OpenSSL 1.0.1. Result is a SIGSEGV as follows:

    (gdb) bt

    0 0x00007ffff03b71a0 in EVP_PKEY_CTX_dup () from /usr/lib64/libcrypto.so

    1 0x00007ffff03a90cd in EVP_MD_CTX_copy_ex () from /usr/lib64/libcrypto.so

    2 0x00007ffff110da8a in EVPnew (name_obj=0x7ffff7ef45a8, digest=0x0, initial_ctx=0x7ffff130fbc0, cp=0x0, len=0)

    at /home/ryan/vaas/python/2.7.6/build/src/Python-2.7.6/Modules/_hashopenssl.c:436

    3 0x00007ffff110de10 in EVP_new_md5 (self=\<value optimized out>, args=\<value optimized out>)

    at /home/ryan/vaas/python/2.7.6/build/src/Python-2.7.6/Modules/_hashopenssl.c:540

    The attached patch updates all declarations in _hashopenssl.c to be pointers initialized by calling EVP_MD_CTX_create(). The patch is done against source version 3.4.1. I have a similar patch for version 2.7.6, but can only attach one file here?

    iritkatriel commented 3 years ago

    This patch is out of date with the code, but comparing it with the code I think the fixes were made. Christian, can you confirm?

    tiran commented 3 years ago

    The code has changed a lot since this bug was opened. It's no longer an issue. Thanks for checking!