This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: test_constructor (test.test_ssl.ContextTests) ... Fatal Python error: Segmentation fault
Type: crash Stage: resolved
Components: SSL, Tests Versions: Python 3.9, Python 3.8
process
Status: closed Resolution: third party
Dependencies: Superseder:
Assigned To: Nosy List: christian.heimes, sxt1001
Priority: normal Keywords: patch

Created on 2021-07-11 16:19 by sxt1001, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
log thatiparthy, 2021-07-19 07:46
Makefile.certificate sxt1001, 2021-12-23 10:53
openssl.spec sxt1001, 2021-12-23 10:54
openssl-1.1.1-fips.patch sxt1001, 2021-12-23 10:54
openssl-1.1.1-build.patch sxt1001, 2021-12-23 10:54
python3.spec sxt1001, 2021-12-23 11:25
Messages (11)
msg397254 - (view) Author: tongxiaoge (sxt1001) Date: 2021-07-11 16:19
I have reproduced this problem in the latest versions of Python 3.8.11 and 3.9.6. Python 3.8.5 does not have this problem, other versions are not tested. The failure log is as follows:
[  613s] 0:02:27 load avg: 4.66 Re-running failed tests in verbose mode
[  613s] 0:02:27 load avg: 4.66 Re-running test_ssl in verbose mode
[  613s] test_ssl: testing with 'OpenSSL 1.1.1f  31 Mar 2020' (1, 1, 1, 6, 15)
[  613s]           under 'Linux-5.4.6-x86_64-with-glibc2.2.5'
[  613s]           HAS_SNI = True
[  613s]           OP_ALL = 0x80000054
[  613s]           OP_NO_TLSv1_1 = 0x10000000
[  613s] test__create_stdlib_context (test.test_ssl.ContextTests) ... ok
[  613s] test_cert_store_stats (test.test_ssl.ContextTests) ... ok
[  613s] test_check_hostname (test.test_ssl.ContextTests) ... ok
[  613s] test_ciphers (test.test_ssl.ContextTests) ... ok
[  613s] test_constructor (test.test_ssl.ContextTests) ... Fatal Python error: Segmentation fault
[  613s] 
[  613s] Current thread 0x00007ff433b90740 (most recent call first):
[  613s]   File "/home/abuild/rpmbuild/BUILD/Python-3.8.11/Lib/ssl.py", line 483 in __new__
[  613s]   File "/home/abuild/rpmbuild/BUILD/Python-3.8.11/Lib/test/test_ssl.py", line 1126 in test_constructor
[  613s]   File "/home/abuild/rpmbuild/BUILD/Python-3.8.11/Lib/unittest/case.py", line 650 in _callTestMethod
[  613s]   File "/home/abuild/rpmbuild/BUILD/Python-3.8.11/Lib/unittest/case.py", line 693 in run
[  613s]   File "/home/abuild/rpmbuild/BUILD/Python-3.8.11/Lib/unittest/case.py", line 753 in __call__
[  613s]   File "/home/abuild/rpmbuild/BUILD/Python-3.8.11/Lib/unittest/suite.py", line 122 in run
[  613s]   File "/home/abuild/rpmbuild/BUILD/Python-3.8.11/Lib/unittest/suite.py", line 84 in __call__
[  613s]   File "/home/abuild/rpmbuild/BUILD/Python-3.8.11/Lib/unittest/suite.py", line 122 in run
[  613s]   File "/home/abuild/rpmbuild/BUILD/Python-3.8.11/Lib/unittest/suite.py", line 84 in __call__
[  613s]   File "/home/abuild/rpmbuild/BUILD/Python-3.8.11/Lib/unittest/runner.py", line 176 in run
[  613s]   File "/home/abuild/rpmbuild/BUILD/Python-3.8.11/Lib/test/support/__init__.py", line 2030 in _run_suite
[  613s]   File "/home/abuild/rpmbuild/BUILD/Python-3.8.11/Lib/test/support/__init__.py", line 2152 in run_unittest
[  613s]   File "/home/abuild/rpmbuild/BUILD/Python-3.8.11/Lib/test/test_ssl.py", line 4848 in test_main
[  613s]   File "/home/abuild/rpmbuild/BUILD/Python-3.8.11/Lib/test/libregrtest/runtest.py", line 234 in _runtest_inner2
[  613s]   File "/home/abuild/rpmbuild/BUILD/Python-3.8.11/Lib/test/libregrtest/runtest.py", line 270 in _runtest_inner
[  613s]   File "/home/abuild/rpmbuild/BUILD/Python-3.8.11/Lib/test/libregrtest/runtest.py", line 153 in _runtest
[  613s]   File "/home/abuild/rpmbuild/BUILD/Python-3.8.11/Lib/test/libregrtest/runtest.py", line 193 in runtest
[  613s]   File "/home/abuild/rpmbuild/BUILD/Python-3.8.11/Lib/test/libregrtest/main.py", line 318 in rerun_failed_tests
[  613s]   File "/home/abuild/rpmbuild/BUILD/Python-3.8.11/Lib/test/libregrtest/main.py", line 694 in _main
[  613s]   File "/home/abuild/rpmbuild/BUILD/Python-3.8.11/Lib/test/libregrtest/main.py", line 637 in main
[  613s]   File "/home/abuild/rpmbuild/BUILD/Python-3.8.11/Lib/test/libregrtest/main.py", line 715 in main
[  613s]   File "/home/abuild/rpmbuild/BUILD/Python-3.8.11/Lib/test/regrtest.py", line 46 in _main
[  613s]   File "/home/abuild/rpmbuild/BUILD/Python-3.8.11/Lib/test/regrtest.py", line 50 in <module>
[  613s]   File "/home/abuild/rpmbuild/BUILD/Python-3.8.11/Lib/runpy.py", line 87 in _run_code
[  613s]   File "/home/abuild/rpmbuild/BUILD/Python-3.8.11/Lib/runpy.py", line 194 in _run_module_as_main
[  613s] /var/tmp/rpm-tmp.lFeeM8: line 50: 15891 Segmentation fault      WITHIN_PYTHON_RPM_BUILD= LD_LIBRARY_PATH=$(pwd)/build/debug $(pwd)/build/debug/python -m test.regrtest -wW --slowest -j0 -x test_distutils -x test_bdist_rpm -x test_gdb -x test_socket -x test_asyncio
[  613s] error: Bad exit status from /var/tmp/rpm-tmp.lFeeM8 (%check)

What is the reason for this? and is there a plan to fix it?
msg397256 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2021-07-11 16:37
Python 3.9.5 and OpenSSL 1.1.1f are both outdated. Can you reproduce the problem with 3.9.6 and 1.1.1k?

Can you tel us more about your system (distribution, CPU arch, compiler) and provide a C stacktrace with debug symbols?
msg397780 - (view) Author: Srinivas Reddy Thatiparthy(శ్రీనివాస్ రెడ్డి తాటిపర్తి) (thatiparthy) * Date: 2021-07-19 07:46
ran on 3.9.6 branch with OpenSSL 1.1.1k  25 Mar 2021. I see this warning in the console. Please also see the attached log for full details.


/Users/srini/workspace/consulting/cpython/Lib/test/support/__init__.py:3105: ResourceWarning: unclosed <ssl.SSLSocket fd=7, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('127.0.0.1', 60533), raddr=('127.0.0.1', 60534)>
  del self.thread
ResourceWarning: Enable tracemalloc to get the object allocation traceback
msg399266 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-08-09 13:24
tongxiaoge: Without more information, we cannot help you. See Christian's questions.
msg401950 - (view) Author: tongxiaoge (sxt1001) Date: 2021-09-16 14:53
I'm sorry I haven't replied for a long time. I found that the OpenSSL version I use is 1.1.1f, which is probably caused by this. Today, I tried to upgrade Python 3 to 3.8.12, and the same problem occurred. I'll try again after upgrading the OpenSSL version tomorrow. If there are still problems, I'll give a reply at that time.
msg402428 - (view) Author: tongxiaoge (sxt1001) Date: 2021-09-22 12:39
I installed OpenSSL version 1.1.1l and tested it again. The problem disappeared. It should be the reason why the OpenSSL version I used before is too low. The current issue is closed
msg409084 - (view) Author: tongxiaoge (sxt1001) Date: 2021-12-23 10:49
Today, I upgraded my version of Python3 to 3.9.9. When running test_ ssl,It has a segment error again. The version of OpenSSL I use is 1.1.1l, here is part of the stack information (the complete one is too long):

```
(gdb) bt
#0  0x0000ffff9e563830 in raise () from /lib64/libpthread.so.0
#1  <signal handler called>
#2  SSL_CTX_new (meth=0xffffffff9076cc30) at ssl/ssl_lib.c:3046
#3  0x0000ffff90799f38 in _ssl__SSLContext_impl () from /home/abuild/rpmbuild/BUILD/Python-3.9.9/build/debug/build/lib.linux-aarch64-3.9-pydebug/_ssl.cpython-39d-aarch64-linux-gnu.so
#4  0x0000ffff9079a3ac in _ssl__SSLContext () from /home/abuild/rpmbuild/BUILD/Python-3.9.9/build/debug/build/lib.linux-aarch64-3.9-pydebug/_ssl.cpython-39d-aarch64-linux-gnu.so
#5  0x0000ffff9e76d034 in tp_new_wrapper (self=0xffff907c0510 <PySSLContext_Type>, args=0xffff8ff4db90, kwds=0x0) at /home/abuild/rpmbuild/BUILD/Python-3.9.9/Objects/typeobject.c:6247
#6  0x0000ffff9e748ae8 in cfunction_call (func=0xffff907d60b0, args=<optimized out>, kwargs=<optimized out>) at /home/abuild/rpmbuild/BUILD/Python-3.9.9/Objects/methodobject.c:543
#7  0x0000ffff9e6f18a8 in _PyObject_MakeTpCall (tstate=tstate@entry=0xaaadd8db33b0, callable=callable@entry=0xffff907d60b0, args=args@entry=0xffff8fcb45b0, nargs=nargs@entry=2, keywords=keywords@entry=0x0)
    at /home/abuild/rpmbuild/BUILD/Python-3.9.9/Objects/call.c:191
#8  0x0000ffff9e670fd8 in _PyObject_VectorcallTstate (kwnames=<optimized out>, nargsf=<optimized out>, args=<optimized out>, callable=<optimized out>, tstate=<optimized out>)
    at /home/abuild/rpmbuild/BUILD/Python-3.9.9/Include/cpython/abstract.h:116
#9  PyObject_Vectorcall (kwnames=<optimized out>, nargsf=<optimized out>, args=<optimized out>, callable=<optimized out>) at /home/abuild/rpmbuild/BUILD/Python-3.9.9/Include/cpython/abstract.h:127
#10 call_function (tstate=0xaaadd8db33b0, pp_stack=0xffffc5ebf240, oparg=<optimized out>, kwnames=0x0) at /home/abuild/rpmbuild/BUILD/Python-3.9.9/Python/ceval.c:5075
#11 0x0000ffff9e67a7e8 in _PyEval_EvalFrameDefault (tstate=<optimized out>, f=<optimized out>, throwflag=<optimized out>) at /home/abuild/rpmbuild/BUILD/Python-3.9.9/Python/ceval.c:3487
#12 0x0000ffff9e80c52c in _PyEval_EvalFrame (throwflag=0, f=0xffff8fcb4410, tstate=0xffff903e2050) at /home/abuild/rpmbuild/BUILD/Python-3.9.9/Include/internal/pycore_ceval.h:40
#13 _PyEval_EvalCode (tstate=0xffff903e2050, _co=0xffff908b3110, globals=<optimized out>, locals=locals@entry=0x0, args=<optimized out>, argcount=281473096927744, kwnames=0xaaadd8db33b0,
    kwargs=0xffffc5ebf4a0, kwcount=281473343352832, kwstep=kwstep@entry=1, defs=0xffff903dd798, defcount=<optimized out>, kwdefs=0x0, closure=<optimized out>, name=<optimized out>, qualname=<optimized out>)
    at /home/abuild/rpmbuild/BUILD/Python-3.9.9/Python/ceval.c:4327
#14 0x0000ffff9e6f13f0 in _PyFunction_Vectorcall (func=<optimized out>, stack=<optimized out>, nargsf=<optimized out>, kwnames=<optimized out>) at /home/abuild/rpmbuild/BUILD/Python-3.9.9/Objects/call.c:396
#15 0x0000ffff9e6f1c5c in _PyObject_FastCallDictTstate (tstate=tstate@entry=0xaaadd8db33b0, callable=callable@entry=0xffff903e2050, args=args@entry=0xffffc5ebf4a0, nargsf=nargsf@entry=2,
    kwargs=kwargs@entry=0x0) at /home/abuild/rpmbuild/BUILD/Python-3.9.9/Objects/call.c:118
#16 0x0000ffff9e6f2004 in _PyObject_Call_Prepend (tstate=tstate@entry=0xaaadd8db33b0, callable=callable@entry=0xffff903e2050, obj=obj@entry=0xaaadd8f8fe00, args=args@entry=0xffff8ff4ca00,
    kwargs=kwargs@entry=0x0) at /home/abuild/rpmbuild/BUILD/Python-3.9.9/Objects/call.c:489
#17 0x0000ffff9e769960 in slot_tp_new (type=0xaaadd8f8fe00, args=0xffff8ff4ca00, kwds=0x0) at /home/abuild/rpmbuild/BUILD/Python-3.9.9/Objects/typeobject.c:6994
#18 0x0000ffff9e76d438 in type_call (type=0xaaadd8f8fe00, args=0xffff8ff4ca00, kwds=0x0) at /home/abuild/rpmbuild/BUILD/Python-3.9.9/Objects/typeobject.c:1014
#19 0x0000ffff9e6f18a8 in _PyObject_MakeTpCall (tstate=tstate@entry=0xaaadd8db33b0, callable=callable@entry=0xaaadd8f8fe00, args=args@entry=0xffff8fcf7f08, nargs=nargs@entry=1, keywords=keywords@entry=0x0)
    at /home/abuild/rpmbuild/BUILD/Python-3.9.9/Objects/call.c:191
#20 0x0000ffff9e670fd8 in _PyObject_VectorcallTstate (kwnames=<optimized out>, nargsf=<optimized out>, args=<optimized out>, callable=<optimized out>, tstate=<optimized out>)
    at /home/abuild/rpmbuild/BUILD/Python-3.9.9/Include/cpython/abstract.h:116
#21 PyObject_Vectorcall (kwnames=<optimized out>, nargsf=<optimized out>, args=<optimized out>, callable=<optimized out>) at /home/abuild/rpmbuild/BUILD/Python-3.9.9/Include/cpython/abstract.h:127
#22 call_function (tstate=0xaaadd8db33b0, pp_stack=0xffffc5ebf730, oparg=<optimized out>, kwnames=0x0) at /home/abuild/rpmbuild/BUILD/Python-3.9.9/Python/ceval.c:5075
#23 0x0000ffff9e67a7e8 in _PyEval_EvalFrameDefault (tstate=<optimized out>, f=<optimized out>, throwflag=<optimized out>) at /home/abuild/rpmbuild/BUILD/Python-3.9.9/Python/ceval.c:3487
#24 0x0000ffff9e66f024 in _PyEval_EvalFrame (throwflag=0, f=0xffff8fcf7d70, tstate=0xaaadd8db33b0) at /home/abuild/rpmbuild/BUILD/Python-3.9.9/Include/internal/pycore_ceval.h:40
#25 function_code_fastcall (tstate=0xaaadd8db33b0, co=<optimized out>, args=<optimized out>, nargs=1, globals=<optimized out>) at /home/abuild/rpmbuild/BUILD/Python-3.9.9/Objects/call.c:330
#26 0x0000ffff9e6f55f0 in _PyObject_VectorcallTstate (kwnames=0x0, nargsf=1, args=0xffff8fcc6f48, callable=<optimized out>, tstate=<optimized out>)
    at /home/abuild/rpmbuild/BUILD/Python-3.9.9/Include/cpython/abstract.h:118
#27 method_vectorcall (method=<optimized out>, args=0xffff8fcc6f50, nargsf=<optimized out>, kwnames=0x0) at /home/abuild/rpmbuild/BUILD/Python-3.9.9/Objects/classobject.c:53
#28 0x0000ffff9e670be4 in _PyObject_VectorcallTstate (kwnames=<optimized out>, nargsf=<optimized out>, args=<optimized out>, callable=<optimized out>, tstate=<optimized out>)
    at /home/abuild/rpmbuild/BUILD/Python-3.9.9/Include/cpython/abstract.h:118
#29 PyObject_Vectorcall (kwnames=<optimized out>, nargsf=<optimized out>, args=<optimized out>, callable=<optimized out>) at /home/abuild/rpmbuild/BUILD/Python-3.9.9/Include/cpython/abstract.h:127
#30 call_function (tstate=0xaaadd8db33b0, pp_stack=0xffffc5ebfa28, oparg=<optimized out>, kwnames=0x0) at /home/abuild/rpmbuild/BUILD/Python-3.9.9/Python/ceval.c:5075
#31 0x0000ffff9e6783f0 in _PyEval_EvalFrameDefault (tstate=<optimized out>, f=<optimized out>, throwflag=<optimized out>) at /home/abuild/rpmbuild/BUILD/Python-3.9.9/Python/ceval.c:3518
#32 0x0000ffff9e66f024 in _PyEval_EvalFrame (throwflag=0, f=0xffff8fcc6dd0, tstate=0xaaadd8db33b0) at /home/abuild/rpmbuild/BUILD/Python-3.9.9/Include/internal/pycore_ceval.h:40
#33 function_code_fastcall (tstate=0xaaadd8db33b0, co=<optimized out>, args=<optimized out>, nargs=2, globals=<optimized out>) at /home/abuild/rpmbuild/BUILD/Python-3.9.9/Objects/call.c:330
#34 0x0000ffff9e670be4 in _PyObject_VectorcallTstate (kwnames=<optimized out>, nargsf=<optimized out>, args=<optimized out>, callable=<optimized out>, tstate=<optimized out>)
    at /home/abuild/rpmbuild/BUILD/Python-3.9.9/Include/cpython/abstract.h:118
#35 PyObject_Vectorcall (kwnames=<optimized out>, nargsf=<optimized out>, args=<optimized out>, callable=<optimized out>) at /home/abuild/rpmbuild/BUILD/Python-3.9.9/Include/cpython/abstract.h:127
#36 call_function (tstate=0xaaadd8db33b0, pp_stack=0xffffc5ebfc70, oparg=<optimized out>, kwnames=0x0) at /home/abuild/rpmbuild/BUILD/Python-3.9.9/Python/ceval.c:5075
#37 0x0000ffff9e677238 in _PyEval_EvalFrameDefault (tstate=<optimized out>, f=<optimized out>, throwflag=<optimized out>) at /home/abuild/rpmbuild/BUILD/Python-3.9.9/Python/ceval.c:3504
#38 0x0000ffff9e80c52c in _PyEval_EvalFrame (throwflag=0, f=0xaaadd90b9cd0, tstate=0xffff90e395f0) at /home/abuild/rpmbuild/BUILD/Python-3.9.9/Include/internal/pycore_ceval.h:40
#39 _PyEval_EvalCode (tstate=0xffff90e395f0, _co=0xffff90e39380, globals=<optimized out>, locals=locals@entry=0x0, args=<optimized out>, argcount=281473093368048, kwnames=0xaaadd8db33b0, kwargs=0x1,
    kwcount=281473343352832, kwstep=kwstep@entry=1, defs=0xffff9106d108, defcount=<optimized out>, kwdefs=0x0, closure=<optimized out>, name=<optimized out>, qualname=<optimized out>)
    at /home/abuild/rpmbuild/BUILD/Python-3.9.9/Python/ceval.c:4327
#40 0x0000ffff9e6f13f0 in _PyFunction_Vectorcall (func=<optimized out>, stack=<optimized out>, nargsf=<optimized out>, kwnames=<optimized out>) at /home/abuild/rpmbuild/BUILD/Python-3.9.9/Objects/call.c:396
#41 0x0000ffff9e6f5468 in _PyObject_VectorcallTstate (kwnames=0x0, nargsf=2, args=0xffffc5ebfe70, callable=<optimized out>, tstate=<optimized out>)
    at /home/abuild/rpmbuild/BUILD/Python-3.9.9/Include/cpython/abstract.h:118
```

The attachment is the OpenSSL source file I use.
msg409085 - (view) Author: tongxiaoge (sxt1001) Date: 2021-12-23 10:52
Other information:
```
(gdb) f 2
#2  SSL_CTX_new (meth=0xffffffffe222cc30) at ssl/ssl_lib.c:3046
warning: Source file is more recent than executable.
3046        ret->session_timeout = meth->get_timeout();
(gdb) l
3041        ret->max_proto_version = 0;
3042        ret->mode = SSL_MODE_AUTO_RETRY;
3043        ret->session_cache_mode = SSL_SESS_CACHE_SERVER;
3044        ret->session_cache_size = SSL_SESSION_CACHE_MAX_SIZE_DEFAULT;
3045        /* We take the system default. */
3046        ret->session_timeout = meth->get_timeout();
3047        ret->references = 1;
3048        ret->lock = CRYPTO_THREAD_lock_new();
3049        if (ret->lock == NULL) {
3050            SSLerr(SSL_F_SSL_CTX_NEW, ERR_R_MALLOC_FAILURE);
```
msg409086 - (view) Author: tongxiaoge (sxt1001) Date: 2021-12-23 10:59
I want to know whether this is an OpenSSL problem or a python 3 problem, and how to fix it? Thanks.
(The OpenSSL source package is large and has not been uploaded successfully. We can download it from the OpenSSL official website)
msg409094 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2021-12-23 15:24
You are using a OpenSSL build with custom, additional patches and your code is crashing somewhere in OpenSSL. It is likely that your patches are causing issue. I'm not going to provide free service for custom builds.
msg409226 - (view) Author: tongxiaoge (sxt1001) Date: 2021-12-27 05:06
We make SSL3 disappear to newly built dependencies, the test_ssl success. Refer to the modification of OpenSSL on fedoras (address: https://src.fedoraproject.org/rpms/openssl/tree/f34 )

```
 rm -f $RPM_BUILD_ROOT%{_sysconfdir}/pki/tls/*.dist
 
+# Next step of gradual disablement of SSL3.
+# Make SSL3 disappear to newly built dependencies.
+sed -i '/^\#ifndef OPENSSL_NO_SSL_TRACE/i\
+#ifndef OPENSSL_NO_SSL3\
+# define OPENSSL_NO_SSL3\
+#endif' $RPM_BUILD_ROOT/%{_prefix}/include/openssl/opensslconf.h
+
 %check
```
History
Date User Action Args
2022-04-11 14:59:47adminsetgithub: 88764
2021-12-27 05:06:52sxt1001setnosy: + sxt1001
messages: + msg409226
2021-12-23 15:24:17christian.heimessetstatus: open -> closed

nosy: + christian.heimes
messages: + msg409094

assignee: christian.heimes ->
resolution: third party
2021-12-23 11:25:06sxt1001setfiles: + python3.spec
nosy: - vstinner, christian.heimes, thatiparthy, sxt1001
-> (no value)
2021-12-23 10:59:42sxt1001setstatus: closed -> open

messages: + msg409086
2021-12-23 10:54:28sxt1001setfiles: + openssl-1.1.1-build.patch
2021-12-23 10:54:18sxt1001setfiles: + openssl-1.1.1-fips.patch
keywords: + patch
2021-12-23 10:54:03sxt1001setfiles: + openssl.spec
2021-12-23 10:53:54sxt1001setfiles: + Makefile.certificate
2021-12-23 10:52:46sxt1001setmessages: + msg409085
2021-12-23 10:49:47sxt1001setmessages: + msg409084
2021-09-22 12:39:51sxt1001setstatus: open -> closed

messages: + msg402428
stage: resolved
2021-09-16 14:53:42sxt1001setmessages: + msg401950
2021-08-09 13:24:08vstinnersetmessages: + msg399266
2021-07-19 07:46:48thatiparthysetfiles: + log
nosy: + thatiparthy
messages: + msg397780

2021-07-11 16:37:45christian.heimessetnosy: - Guido.van.Rossum
messages: + msg397256
2021-07-11 16:19:41sxt1001create