Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"import ctypes" segfaults on Python 3.6 and Ubuntu 21.10 #89911

Closed
ThomasTrummer mannequin opened this issue Nov 8, 2021 · 7 comments
Closed

"import ctypes" segfaults on Python 3.6 and Ubuntu 21.10 #89911

ThomasTrummer mannequin opened this issue Nov 8, 2021 · 7 comments

Comments

@ThomasTrummer
Copy link
Mannequin

ThomasTrummer mannequin commented Nov 8, 2021

BPO 45748
Nosy @ned-deily, @erlend-aasland

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:

assignee = None
closed_at = <Date 2021-11-09.04:15:20.607>
created_at = <Date 2021-11-08.13:54:44.629>
labels = ['ctypes']
title = '"import ctypes" segfaults on Python 3.6 and Ubuntu 21.10'
updated_at = <Date 2021-11-09.04:15:20.604>
user = 'https://bugs.python.org/ThomasTrummer'

bugs.python.org fields:

activity = <Date 2021-11-09.04:15:20.604>
actor = 'ned.deily'
assignee = 'none'
closed = True
closed_date = <Date 2021-11-09.04:15:20.607>
closer = 'ned.deily'
components = ['ctypes']
creation = <Date 2021-11-08.13:54:44.629>
creator = 'Thomas Trummer'
dependencies = []
files = []
hgrepos = []
issue_num = 45748
keywords = []
message_count = 3.0
messages = ['405950', '405952', '405996']
nosy_count = 3.0
nosy_names = ['ned.deily', 'Thomas Trummer', 'erlendaasland']
pr_nums = []
priority = 'normal'
resolution = 'wont fix'
stage = 'resolved'
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue45748'
versions = ['Python 3.6']

@ThomasTrummer
Copy link
Mannequin Author

ThomasTrummer mannequin commented Nov 8, 2021

3.7 and later are all working fine.

First good commit: 55fe1ae
First bad commit: fdbd011

git checkout v3.6.15

#0 0x00007ffff6cc52a0 in PyCFuncPtr_new (type=0x5555559157f8, args=0x7ffff6ce6dd8, kwds=0x0)

at /home/tom/pydev/cpython/Modules/_ctypes/_ctypes.c:3557

#1 0x00005555556400f9 in type_call (type=0x5555559157f8, args=0x7ffff6ce6dd8, kwds=0x0) at Objects/typeobject.c:895

#2 0x00005555555db4ca in _PyObject_FastCallDict (func=0x5555559157f8, args=0x7ffff6dc1f48, nargs=1, kwargs=0x0) at Objects/abstract.c:2331

#3 0x00005555556b8e7c in call_function (pp_stack=pp_stack@entry=0x7fffffffcb58, oparg=<optimized out>, kwnames=kwnames@entry=0x0)

at [Python/ceval.c:4875](https://github.com/python/cpython/blob/main/Python/ceval.c#L4875)

#4 0x00005555556bc9d3 in _PyEval_EvalFrameDefault (f=<optimized out>, throwflag=<optimized out>) at Python/ceval.c:3335

#5 0x00005555556b774c in PyEval_EvalFrameEx (throwflag=0, f=0x7ffff6dc1dc8) at Python/ceval.c:754

#6 _PyFunction_FastCall (co=<optimized out>, args=<optimized out>, nargs=nargs@entry=0, globals=<optimized out>) at Python/ceval.c:4933

#7 0x00005555556b9269 in fast_function (kwnames=0x0, nargs=0, stack=<optimized out>, func=0x7ffff6d78378) at Python/ceval.c:4968

#8 call_function (pp_stack=pp_stack@entry=0x7fffffffccf8, oparg=<optimized out>, kwnames=kwnames@entry=0x0) at Python/ceval.c:4872

#9 0x00005555556bc9d3 in _PyEval_EvalFrameDefault (f=<optimized out>, throwflag=<optimized out>) at Python/ceval.c:3335

#10 0x00005555556b83c7 in PyEval_EvalFrameEx (throwflag=0, f=0x5555558d2248) at Python/ceval.c:754

#11 _PyEval_EvalCodeWithName (_co=_co@entry=0x7ffff6cdf660, globals=globals@entry=0x7ffff6dfa438, locals=locals@entry=0x7ffff6dfa438,

    args=args@entry=0x0, argcount=argcount@entry=0, kwnames=kwnames@entry=0x0, kwargs=0x0, kwcount=0, defs=0x0, defcount=0, kwdefs=0x0, 

    closure=0x0, name=0x0, qualname=0x0, kwstep=2) at Python/ceval.c:4166

#12 0x00005555556b9a25 in PyEval_EvalCodeEx (closure=0x0, kwdefs=0x0, defcount=0, defs=0x0, kwcount=0, kws=0x0, argcount=0, args=0x0,

    locals=0x7ffff6dfa438, globals=0x7ffff6dfa438, _co=0x7ffff6cdf660) at Python/ceval.c:4187

#13 PyEval_EvalCode (co=co@entry=0x7ffff6cdf660, globals=globals@entry=0x7ffff6dfa438, locals=locals@entry=0x7ffff6dfa438)

at [Python/ceval.c:731](https://github.com/python/cpython/blob/main/Python/ceval.c#L731)

#14 0x00005555556b611d in builtin_exec_impl (module=<optimized out>, locals=0x7ffff6dfa438, globals=0x7ffff6dfa438, source=0x7ffff6cdf660)

at [Python/bltinmodule.c:983](https://github.com/python/cpython/blob/main/Python/bltinmodule.c#L983)

#15 builtin_exec (module=<optimized out>, args=<optimized out>) at Python/clinic/bltinmodule.c.h:283

#16 0x000055555562b651 in PyCFunction_Call (func=func@entry=0x7ffff6eb7990, args=args@entry=0x7ffff6cdcd08, kwds=kwds@entry=0x7ffff6d6b288)

at [Objects/methodobject.c:126](https://github.com/python/cpython/blob/main/Objects/methodobject.c#L126)

#17 0x00005555556c11af in do_call_core (kwdict=0x7ffff6d6b288, callargs=0x7ffff6cdcd08, func=0x7ffff6eb7990) at Python/ceval.c:5116

#18 _PyEval_EvalFrameDefault (f=<optimized out>, throwflag=<optimized out>) at Python/ceval.c:3404

#19 0x00005555556b8d17 in PyEval_EvalFrameEx (throwflag=0, f=0x7ffff6dc2930) at Python/ceval.c:754

#20 _PyEval_EvalCodeWithName (_co=0x7ffff6eabdb0, globals=<optimized out>, locals=<optimized out>, args=<optimized out>, argcount=3,

    kwnames=0x0, kwargs=0x7ffff6d913c8, kwcount=0, kwstep=1, defs=0x0, defcount=0, kwdefs=0x0, closure=0x0, name=0x7ffff6e53ad0, 

    qualname=0x7ffff6e53ad0) at Python/ceval.c:4166

@erlend-aasland
Copy link
Contributor

Python 3.6 is in security-fix only mode. I'm sorry, but I don't think this counts as a security issue.

@ned-deily
Copy link
Member

Python 3.6 is in security-fix only mode.

And besides that, it's not clear what problem you are reporting without more context. As far as I can tell, neither the "good" nor the "bad" commit ids you reference are in or were backported to the 3.6 branch. Without more information, it is hard to speculate, however one thing that *might* be relevant is the version of libffi you are trying to use. There have been several issues reported against other branches of Python when trying to use libffi's recent 3.4.2 release. In any case, as Erlend noted, this doesn't appear to be a security-related issue; in general, changes for newer versions of operating systems or third-party libraries are out-of-scope for Python versions in the security-fix phase of their life cycles.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
@da4089
Copy link

da4089 commented Aug 2, 2022

FWIW, I'm seeing what I think is this problem on Ubuntu 22.04 LTS, using Python 3.6.15, and Ubuntu's libffi 3.4.2-4.

The simple repro is to start the interpreter, and import setuptools.

(venv) d@ubuntu22-04:~/work/pywinsparkle$ python
Python 3.6.15 (default, Aug  3 2022, 00:05:41) 
[GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import setuptools
Segmentation fault (core dumped)
(venv) d@ubuntu22-04:~/work/pywinsparkle$

I haven't yet dug through 3.7+ to see what might have fixed it: if I manage to find a solution, I'll report it here.

@arhadthedev
Copy link
Member

@da4089 3.7 got its last bugfix release on June, 2020. Nowadays, only security vulnerabilities are fixed; the rest is set in stone.

However, the fix (if applied) will be welcomed on 3.10, the oldest version with bugs being fixed until June, 2023.

@erlend-aasland
Copy link
Contributor

However, the fix (if applied) will be welcomed on 3.10, the oldest version with bugs being fixed until June, 2023.

Quoting #89911 (comment):

3.7 and later are all working fine.

First good commit: 55fe1ae
First bad commit: fdbd011

@da4089
Copy link

da4089 commented Aug 2, 2022

Hi @arhadthedev -- yes, I understand 3.6 is not supported, but some people are required to use it for various reasons, and this issue seemed like the best place to record both confirmations of the issue, and potential fixes or workarounds. I hope that's ok?

FWIW, I have found a workaround that works for my problem: import ctypes before setuptools. This seems potentially useful, since it appears to work while not requiring a change to the interpreter (which, as you point out, isn't going to get a new release).

d@ubuntu22-04:~$ /opt/PythonVersions/3.6.15/bin/python3
Python 3.6.15 (default, Aug  3 2022, 00:05:41) 
[GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import setuptools
Segmentation fault (core dumped)
d@ubuntu22-04:~$ /opt/PythonVersions/3.6.15/bin/python3

But, if ctypes is imported first ...

d@ubuntu22-04:~$ /opt/PythonVersions/3.6.15/bin/python3
Python 3.6.15 (default, Aug  3 2022, 00:05:41) 
[GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ctypes
>>> import setuptools
>>> print("w00t -- workaround!")
w00t -- workaround!
>>> 
d@ubuntu22-04:~$ 

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

No branches or pull requests

4 participants