Bug 1244261 - [abrt] fros: XCloseDisplay(): python3.4 killed by SIGSEGV
Summary: [abrt] fros: XCloseDisplay(): python3.4 killed by SIGSEGV
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Fedora
Classification: Fedora
Component: fros
Version: rawhide
Hardware: x86_64
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Jakub Filak
QA Contact: Fedora Extras Quality Assurance
URL: https://retrace.fedoraproject.org/faf...
Whiteboard: abrt_hash:601f7547a3eb2c5f398db62891d...
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2015-07-17 15:23 UTC by Ilia Gradina
Modified: 2016-12-01 00:48 UTC (History)
21 users (show)

Fixed In Version: fros-1.1-4.fc24, fros-1.1-4.fc23
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2015-07-29 15:29:16 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)
File: backtrace (35.75 KB, text/plain)
2015-07-17 15:23 UTC, Ilia Gradina
no flags Details
File: cgroup (190 bytes, text/plain)
2015-07-17 15:23 UTC, Ilia Gradina
no flags Details
File: core_backtrace (4.31 KB, text/plain)
2015-07-17 15:23 UTC, Ilia Gradina
no flags Details
File: dso_list (3.54 KB, text/plain)
2015-07-17 15:23 UTC, Ilia Gradina
no flags Details
File: environ (1.73 KB, text/plain)
2015-07-17 15:23 UTC, Ilia Gradina
no flags Details
File: limits (1.29 KB, text/plain)
2015-07-17 15:23 UTC, Ilia Gradina
no flags Details
File: maps (16.55 KB, text/plain)
2015-07-17 15:23 UTC, Ilia Gradina
no flags Details
File: mountinfo (3.61 KB, text/plain)
2015-07-17 15:23 UTC, Ilia Gradina
no flags Details
File: namespaces (85 bytes, text/plain)
2015-07-17 15:23 UTC, Ilia Gradina
no flags Details
File: open_fds (298 bytes, text/plain)
2015-07-17 15:23 UTC, Ilia Gradina
no flags Details
File: proc_pid_status (1006 bytes, text/plain)
2015-07-17 15:23 UTC, Ilia Gradina
no flags Details

Description Ilia Gradina 2015-07-17 15:23:17 UTC
Version-Release number of selected component:
fros-1.1-3.fc23

Additional info:
reporter:       libreport-2.6.1
backtrace_rating: 4
cmdline:        /usr/bin/python3 /usr/bin/fros --is-available
crash_function: XCloseDisplay
executable:     /usr/bin/python3.4
global_pid:     12827
kernel:         4.2.0-0.rc2.git1.1.fc24.x86_64
runlevel:       N 5
type:           CCpp
uid:            1000

Truncated backtrace:
Thread no. 1 (10 frames)
 #0 XCloseDisplay at ClDisplay.c:51
 #1 ffi_call_unix64 at ../src/x86/unix64.S:76
 #2 ffi_call at ../src/x86/ffi64.c:525
 #3 _call_function_pointer at /usr/src/debug/Python-3.4.3/Modules/_ctypes/callproc.c:811
 #4 _ctypes_callproc at /usr/src/debug/Python-3.4.3/Modules/_ctypes/callproc.c:1149
 #5 PyCFuncPtr_call at /usr/src/debug/Python-3.4.3/Modules/_ctypes/_ctypes.c:3848
 #6 PyObject_Call at /usr/src/debug/Python-3.4.3/Objects/abstract.c:2040
 #7 do_call at /usr/src/debug/Python-3.4.3/Python/ceval.c:4495
 #8 call_function at /usr/src/debug/Python-3.4.3/Python/ceval.c:4293
 #9 PyEval_EvalFrameEx at /usr/src/debug/Python-3.4.3/Python/ceval.c:2862

Potential duplicate: bug 1231482

Comment 1 Ilia Gradina 2015-07-17 15:23:20 UTC
Created attachment 1053133 [details]
File: backtrace

Comment 2 Ilia Gradina 2015-07-17 15:23:24 UTC
Created attachment 1053134 [details]
File: cgroup

Comment 3 Ilia Gradina 2015-07-17 15:23:26 UTC
Created attachment 1053135 [details]
File: core_backtrace

Comment 4 Ilia Gradina 2015-07-17 15:23:27 UTC
Created attachment 1053136 [details]
File: dso_list

Comment 5 Ilia Gradina 2015-07-17 15:23:28 UTC
Created attachment 1053137 [details]
File: environ

Comment 6 Ilia Gradina 2015-07-17 15:23:29 UTC
Created attachment 1053138 [details]
File: limits

Comment 7 Ilia Gradina 2015-07-17 15:23:31 UTC
Created attachment 1053139 [details]
File: maps

Comment 8 Ilia Gradina 2015-07-17 15:23:34 UTC
Created attachment 1053140 [details]
File: mountinfo

Comment 9 Ilia Gradina 2015-07-17 15:23:35 UTC
Created attachment 1053141 [details]
File: namespaces

Comment 10 Ilia Gradina 2015-07-17 15:23:36 UTC
Created attachment 1053142 [details]
File: open_fds

Comment 11 Ilia Gradina 2015-07-17 15:23:37 UTC
Created attachment 1053143 [details]
File: proc_pid_status

Comment 12 Jakub Filak 2015-07-22 19:03:01 UTC
I did some debugging and I found out that Python3 correctly gets a return value of XOpenDisplay() but passes the argument of XCloseDisplay() truncated to 4 Bytes because of a bug in Modules/_ctypes/callproc.c at line 1795 where a unsigned long rvalue is assigned to an int lvalue:

   pa->value.i = (long)PyLong_AsUnsignedLong(obj);

pa->value : struct param { ... union value; ... }  : union value { ... int i; long l; ...}

Comment 13 Adam Williamson 2015-07-28 19:14:15 UTC
Perhaps this should be reported upstream to python?

Comment 14 Jakub Filak 2015-07-29 11:43:14 UTC
Actually, there is one more problem in Python ctypes. The return type of all functions is 'c_int' and that leads to truncation of the return value too.

Lib/ctypes/__init__.py
  class CDLL(object):
     _func_restype_ = c_int

When I run a modified reproducer from bug #1020505 comment #2 I get this:

print(XLIB.XOpenDisplay._restype_._type_) : i

Breakpoint 1, XOpenDisplay (display=0x0) at OpenDis.c:66
66      {
(gdb) n
...
115             if ((dpy = Xcalloc(1, sizeof(Display))) == NULL) {
(gdb) 
119             if ((dpy->display_name = strdup(display_name)) == NULL) {
(gdb) p dpy
$1 = (Display *) 0x55555590e0d0
(gdb) c
Continuing.
print(type(DISPLAY)) : <class 'int'>
print(hex(DISPLAY))  : 0x5590e0d0

Program received signal SIGSEGV, Segmentation fault.
XCloseDisplay (dpy=0x5590e0d0) at ClDisplay.c:51
51              if (!(dpy->flags & XlibDisplayClosing))




If I change _func_restype_ to c_long and run the reproducere again I get this:

print(XLIB.XOpenDisplay._restype_._type_) : l

Breakpoint 1, XOpenDisplay (display=0x0) at OpenDis.c:66
66      {
(gdb) n
... 
115             if ((dpy = Xcalloc(1, sizeof(Display))) == NULL) {
(gdb) 
119             if ((dpy->display_name = strdup(display_name)) == NULL) {
(gdb) p dpy
$1 = (Display *) 0x55555590dbf0
(gdb) c
Continuing.
print(type(DISPLAY)) : <class 'int'>
print(hex(DISPLAY))  : 0x55555590dbf0

Program received signal SIGSEGV, Segmentation fault.
XCloseDisplay (dpy=0x5590dbf0) at ClDisplay.c:51
51              if (!(dpy->flags & XlibDisplayClosing))

Comment 15 Petr Viktorin (pviktori) 2015-07-29 11:45:17 UTC
I noticed the documentation says that Python ints are always assumed to C ints.
There is indeed a Python bug, but in validation: using Python int that fit into a C long but not a C long is quietly truncated. Passing a Python2 long, or Python3 int, that is larger than a C long will fail with an OverflowError.

To pass a C long, there are two alternatives:
- explicitly wrap the number in c_long [0]:
  dll.function(ctyles.c_long(param))

- use prototypes [1]:

  func = dll.function
  func.argtypes = [c_long]
  func(param)


[0]: https://docs.python.org/2/library/ctypes.html#fundamental-data-types
[1]: https://docs.python.org/2/library/ctypes.html#specifying-the-required-argument-types-function-prototypes

Comment 16 Jakub Filak 2015-07-29 12:05:24 UTC
D`oh, sorry for the noise!

Adding these lines to the reproducer fixes the crash: 

XOpenDisplay = XLIB.XOpenDisplay                                                 
XOpenDisplay.restype = c_void_p                                                  
                                                                                 
XCloseDisplay = XLIB.XCloseDisplay                                               
XCloseDisplay.argtypes = [c_void_p]

Comment 17 Petr Viktorin (pviktori) 2015-07-29 12:13:24 UTC
Validation error reported upstream as http://bugs.python.org/issue24747

I'll write a patch for it after vacation, if it's still open.

Comment 18 Jakub Filak 2015-07-29 13:36:39 UTC
I have opened a github pull request for the bug in fros:
https://github.com/mozeq/fros/pull/12


Note You need to log in before you can comment on or make changes to this bug.