itkach / ovpn-py

Automatically exported from code.google.com/p/ovpn-py
0 stars 0 forks source link

openvpn server with ovpn-py plugin crashes #3

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Install openvpn 2.2.1
2. Build ovpn-py.c
3. Write plugin in Python
4. Create openvpn configuration that uses the Python plugin
5. Start openvpn  

What is the expected output?
openvpn runs forever

What do you see instead?
openvpn crashes after several hours of normal operation with the following 
trace:

Core was generated by `/usr/sbin/openvpn --daemon --writepid 
/var/run/openvpn/vpn-udp.pid --config vpn'. 
Program terminated with signal 6, Aborted. 
#0 0x00bd6402 in __kernel_vsyscall () 
(gdb) where 
#0 0x00bd6402 in __kernel_vsyscall () 
#1 0x003dfdf0 in raise () from /lib/libc.so.6 
#2 0x003e1701 in abort () from /lib/libc.so.6 
#3 0x003d926b in __assert_fail () from /lib/libc.so.6 
#4 0x00652f8d in visit_decref (op=0xb7c6bbdc, data=0x0) at 
Modules/gcmodule.c:277 
#5 0x005b8c7c in frame_traverse (f=0x90e195c, visit=0x652ee0 <visit_decref>, 
arg=0x0) at Objects/frameobject.c:461 
#6 0x006535d8 in subtract_refs (generation=2) at Modules/gcmodule.c:296 
#7 collect (generation=2) at Modules/gcmodule.c:817 
#8 0x00653fa8 in collect_generations (basicsize=12) at Modules/gcmodule.c:924 
#9 _PyObject_GC_Malloc (basicsize=12) at Modules/gcmodule.c:1363 
#10 0x00654035 in _PyObject_GC_New (tp=0x6b50c0) at Modules/gcmodule.c:1373 
#11 0x0059f31b in PyCell_New (obj=0x6b2c30) at Objects/cellobject.c:10 
#12 0x00629e91 in PyEval_EvalCodeEx (co=0x8f11410, globals=0x8e291c4, 
locals=0x0, args=0x90f0fd4, argcount=2, kws=0x90f0fdc, kwcount=1, 
    defs=0x8f84e98, defcount=1, closure=0x0) at Python/ceval.c:2962 
#13 0x00628338 in call_function (f=0x90f0e5c, throwflag=0) at 
Python/ceval.c:3846 
#14 PyEval_EvalFrameEx (f=0x90f0e5c, throwflag=0) at Python/ceval.c:2412 
#15 0x0062a3f1 in PyEval_EvalCodeEx (co=0x8f11848, globals=0x8e291c4, 
locals=0x0, args=0x90ef40c, argcount=1, kws=0x90ef410, kwcount=0, 
    defs=0x8f84ef8, defcount=1, closure=0x0) at Python/ceval.c:3000 
#16 0x00628338 in call_function (f=0x90ef27c, throwflag=0) at 
Python/ceval.c:3846 
#17 PyEval_EvalFrameEx (f=0x90ef27c, throwflag=0) at Python/ceval.c:2412 
#18 0x0062a3f1 in PyEval_EvalCodeEx (co=0x8f8a0f8, globals=0x8f8668c, 
locals=0x0, args=0x90e2a28, argcount=15, kws=0x90e2a64, kwcount=0, 
    defs=0x8f8a3e0, defcount=12, closure=0x0) at Python/ceval.c:3000 
#19 0x00628338 in call_function (f=0x90e28b4, throwflag=0) at 
Python/ceval.c:3846 
#20 PyEval_EvalFrameEx (f=0x90e28b4, throwflag=0) at Python/ceval.c:2412 
#21 0x0062a3f1 in PyEval_EvalCodeEx (co=0x8f119f8, globals=0x8f862d4, 
locals=0x0, args=0x8f84498, argcount=2, kws=0x90244d0, kwcount=1, 
    defs=0x8f1bce0, defcount=12, closure=0x0) at Python/ceval.c:3000 
#22 0x005bb0a9 in function_call (func=0x8f82f0c, arg=0x8f8448c, kw=0xa6570b4) 
at Objects/funcobject.c:524 
#23 0x0058f58c in PyObject_Call (func=0x8f82f0c, arg=0x8f8448c, kw=0xa6570b4) 
at Objects/abstract.c:2492 
#24 0x00624adf in ext_do_call (f=0x90e274c, throwflag=0) at Python/ceval.c:4063 
#25 PyEval_EvalFrameEx (f=0x90e274c, throwflag=0) at Python/ceval.c:2452 
#26 0x0062a3f1 in PyEval_EvalCodeEx (co=0x8f16920, globals=0x8f862d4, 
locals=0x0, args=0x90e1ab0, argcount=1, kws=0x90e1ab4, kwcount=0, 
    defs=0x0, defcount=0, closure=0x0) at Python/ceval.c:3000 
#27 0x00628338 in call_function (f=0x90e195c, throwflag=0) at 
Python/ceval.c:3846 
#28 PyEval_EvalFrameEx (f=0x90e195c, throwflag=0) at Python/ceval.c:2412 
---Type <return> to continue, or q <return> to quit--- 
#29 0x0062a3f1 in PyEval_EvalCodeEx (co=0xb7ecd260, globals=0xb7c6bbdc, 
locals=0x0, args=0xb7c68858, argcount=1, kws=0x0, kwcount=0, defs=0x0, 
    defcount=0, closure=0x0) at Python/ceval.c:3000 
#30 0x005bafba in function_call (func=0x8fa217c, arg=0xb7c6884c, kw=0x0) at 
Objects/funcobject.c:524 
#31 0x0058f58c in PyObject_Call (func=0x8fa217c, arg=0xb7c6884c, kw=0x0) at 
Objects/abstract.c:2492 
#32 0x00622f74 in PyEval_CallObjectWithKeywords (func=0x8fa217c, 
arg=0xb7c6884c, kw=0x0) at Python/ceval.c:3619 
#33 0x0058ffcc in PyObject_CallObject (o=0x8fa217c, a=0xb7c6884c) at 
Objects/abstract.c:2480 
#34 0x0094edcb in openvpn_plugin_func_v1 (handle=0x8d3d4a0, type=5, 
argv=0x90600c8, envp=0x952c4c8) at ovpn-py.c:179 
#35 0x0808c4b4 in plugin_call () 
#36 0x080a2abc in key_method_2_read () 
#37 0x080a45ff in tls_process () 
#38 0x080a55fc in tls_multi_process () 
#39 0x08055b07 in check_tls_dowork () 
#40 0x08057c32 in pre_select () 
#41 0x08071889 in multi_process_post () 
#42 0x08073893 in multi_process_incoming_link () 
#43 0x0806ec12 in tunnel_server_udp () 
#44 0x08077430 in main () 

What version of the product are you using? On what operating system?
openvpn 2.2.1, 32-bit CentOS 5.6

Please provide any additional information below.
The call trace above is for openvpn server using UDP, TCP server crashes too 
with exact same call trace. 

Original issue reported on code.google.com by itk...@gmail.com on 24 Nov 2011 at 4:08

GoogleCodeExporter commented 8 years ago
Slightly different trace from another run:

Core was generated by `/usr/sbin/openvpn --daemon --writepid 
/var/run/openvpn/vpn-tcp.pid --config vpn'.
Program terminated with signal 6, Aborted.
#0  0x00e8c402 in __kernel_vsyscall ()
(gdb) where
#0  0x00e8c402 in __kernel_vsyscall ()
#1  0x00b8edf0 in raise () from /lib/libc.so.6
#2  0x00b90701 in abort () from /lib/libc.so.6
#3  0x00b8826b in __assert_fail () from /lib/libc.so.6
#4  0x00652f8d in visit_decref (op=0xb7cf2bdc, data=0x0) at 
Modules/gcmodule.c:277
#5  0x005b8c7c in frame_traverse (f=0xa19b02c, visit=0x652ee0 <visit_decref>, 
arg=0x0) at Objects/frameobject.c:461
#6  0x006535d8 in subtract_refs (generation=2) at Modules/gcmodule.c:296
#7  collect (generation=2) at Modules/gcmodule.c:817
#8  0x00653fa8 in collect_generations (basicsize=20) at Modules/gcmodule.c:924
#9  _PyObject_GC_Malloc (basicsize=20) at Modules/gcmodule.c:1363
#10 0x00654035 in _PyObject_GC_New (tp=0x6bda60) at Modules/gcmodule.c:1373
#11 0x005c1e75 in PyList_New (size=0) at Objects/listobject.c:142
#12 0x006260bd in PyEval_EvalFrameEx (f=0xa24f364, throwflag=0) at 
Python/ceval.c:2050
#13 0x00629aea in call_function (f=0xa24ea4c, throwflag=0) at 
Python/ceval.c:3836
#14 PyEval_EvalFrameEx (f=0xa24ea4c, throwflag=0) at Python/ceval.c:2412
#15 0x0062a3f1 in PyEval_EvalCodeEx (co=0x9ed5800, globals=0x9ed0714, 
locals=0x0, args=0x9f5bcc8, argcount=5, kws=0x0, kwcount=0, defs=0x0, 
defcount=0, closure=0x0) at Python/ceval.c:3000
#16 0x005bafba in function_call (func=0x9ee048c, arg=0x9f5bcbc, kw=0x0) at 
Objects/funcobject.c:524
#17 0x0058f58c in PyObject_Call (func=0x9ee048c, arg=0x9f5bcbc, kw=0x0) at 
Objects/abstract.c:2492
#18 0x00624adf in ext_do_call (f=0xa24e75c, throwflag=0) at Python/ceval.c:4063
#19 PyEval_EvalFrameEx (f=0xa24e75c, throwflag=0) at Python/ceval.c:2452
#20 0x00629aea in call_function (f=0xa1a75dc, throwflag=0) at 
Python/ceval.c:3836
#21 PyEval_EvalFrameEx (f=0xa1a75dc, throwflag=0) at Python/ceval.c:2412
#22 0x0062a3f1 in PyEval_EvalCodeEx (co=0x9ed5848, globals=0x9ded1c4, 
locals=0x0, args=0xa1a5b8c, argcount=1, kws=0xa1a5b90, kwcount=0, 
defs=0x9f48ef8, defcount=1, closure=0x0) at Python/ceval.c:3000
#23 0x00628338 in call_function (f=0xa1a59fc, throwflag=0) at 
Python/ceval.c:3846
#24 PyEval_EvalFrameEx (f=0xa1a59fc, throwflag=0) at Python/ceval.c:2412
#25 0x0062a3f1 in PyEval_EvalCodeEx (co=0x9f4e0f8, globals=0x9f4a68c, 
locals=0x0, args=0xa105180, argcount=15, kws=0xa1051bc, kwcount=0, 
defs=0x9f4e3e0, defcount=12, closure=0x0) at Python/ceval.c:3000
#26 0x00628338 in call_function (f=0xa10500c, throwflag=0) at 
Python/ceval.c:3846
#27 PyEval_EvalFrameEx (f=0xa10500c, throwflag=0) at Python/ceval.c:2412
#28 0x0062a3f1 in PyEval_EvalCodeEx (co=0x9ed59f8, globals=0x9f4a2d4, 
locals=0x0, args=0x9f48498, argcount=2, kws=0xaab33b0, kwcount=1, 
defs=0x9edfce0, defcount=12, closure=0x0) at Python/ceval.c:3000
#29 0x005bb0a9 in function_call (func=0x9f46f0c, arg=0x9f4848c, kw=0xa29ddfc) 
at Objects/funcobject.c:524
#30 0x0058f58c in PyObject_Call (func=0x9f46f0c, arg=0x9f4848c, kw=0xa29ddfc) 
at Objects/abstract.c:2492
#31 0x00624adf in ext_do_call (f=0xa199ac4, throwflag=0) at Python/ceval.c:4063
#32 PyEval_EvalFrameEx (f=0xa199ac4, throwflag=0) at Python/ceval.c:2452
#33 0x0062a3f1 in PyEval_EvalCodeEx (co=0x9ee9650, globals=0x9f4a2d4, 
locals=0x0, args=0xa19b198, argcount=1, kws=0xa19b19c, kwcount=1, 
defs=0x9ed1f58, defcount=1, closure=0x0) at Python/ceval.c:3000
#34 0x00628338 in call_function (f=0xa19b02c, throwflag=0) at 
Python/ceval.c:3846
#35 PyEval_EvalFrameEx (f=0xa19b02c, throwflag=0) at Python/ceval.c:2412
#36 0x0062a3f1 in PyEval_EvalCodeEx (co=0xb7f54650, globals=0xb7cf2bdc, 
locals=0x0, args=0xb7cef858, argcount=1, kws=0x0, kwcount=0, defs=0x0, 
defcount=0, closure=0x0) at Python/ceval.c:3000
#37 0x005bafba in function_call (func=0x9f661b4, arg=0xb7cef84c, kw=0x0) at 
Objects/funcobject.c:524
#38 0x0058f58c in PyObject_Call (func=0x9f661b4, arg=0xb7cef84c, kw=0x0) at 
Objects/abstract.c:2492
#39 0x00622f74 in PyEval_CallObjectWithKeywords (func=0x9f661b4, 
arg=0xb7cef84c, kw=0x0) at Python/ceval.c:3619
#40 0x0058ffcc in PyObject_CallObject (o=0x9f661b4, a=0xb7cef84c) at 
Objects/abstract.c:2480
#41 0x00940e1f in openvpn_plugin_func_v1 (handle=0x9d01970, type=9, 
argv=0xa6c10b0, envp=0xa183fd0) at ovpn-py.c:183
#42 0x0808c4b4 in plugin_call ()
#43 0x08071e22 in multi_process_post ()
#44 0x08073893 in multi_process_incoming_link ()
#45 0x0806d195 in multi_tcp_action ()
#46 0x0806db69 in tunnel_server_tcp ()
#47 0x08077430 in main ()

Original comment by itk...@gmail.com on 28 Nov 2011 at 2:53

GoogleCodeExporter commented 8 years ago
Python plugin implements plugin_up, plugin_down, auth_user_pass_verify, 
client_connect and client_disconnect.

Original comment by itk...@gmail.com on 28 Nov 2011 at 2:56

GoogleCodeExporter commented 8 years ago
Note lines 

    http://code.google.com/p/ovpn-py/source/browse/ovpn-py.c#158 

and 

    http://code.google.com/p/ovpn-py/source/browse/ovpn-py.c#202 

According to http://docs.python.org/c-api/intro.html#reference-count-details, 
"Few functions steal references; the two notable exceptions are 
PyList_SetItem() and PyTuple_SetItem(), which steal a reference to the item 
(but not to the tuple or list into which the item is put!)." 

env being added to tuple doesn't need Py_DECREF.

Another error is at 
http://code.google.com/p/ovpn-py/source/browse/ovpn-py.c#155 

Unlike PyTuple_SetItem, PyDict_SetItemString does not steal reference, so 
caller is responsible for calling Py_DECREF. 

Finally (and this is what appears to cause the crashes), there's a Py_DECREF at 
http://code.google.com/p/ovpn-py/source/browse/ovpn-py.c#134 on a borrowed 
references (returned by PyModule_GetDict at 
http://code.google.com/p/ovpn-py/source/browse/ovpn-py.c#77).

Attached patch fixes all these issues. With this patch applied I have openvpn 
running   for almost three days now without crashes, although memory usage 
seems to have climbed a bit too high, so there still may be memory leaks.

Original comment by itk...@gmail.com on 4 Dec 2011 at 4:08

Attachments: