Skip to contentSkip to conversation

Openvpn 2.3.2 potential memory-leak after 24hours (addendum2)

Openvpn-devel [email protected]... 2 participants 8 messages Oct 17, 2013 – Oct 23, 2013

lore
Share & tools
lore
#0 lore raw

Dear all,

unfortunately, the potential memory leak, first reported "Brad Zhang", Sept. 27 2013, proves to be a real memory leak:

pls. see earlier parts of my story in attached eMails below, thank you.

We now have enlarged the time-window for the renegotiation process " reneg-sec 86400" -> 172800 and additionally added "reneg-bytes 1024000" to randomize the renegotiation phase of individual O-VPN clients and to prevent the situation, all connected clients to start to renegotiate within a time window of 5 minutes.

We still recongized the memory consumption of the openvpn process to start

to steadily increase, until the memory limit per process has become reached and openvpn crashed as following:

Oct 15 12:13:15 ip-10-56-61-152 openvpn[21742]: openvpn_execve: unable to 
fork: Cannot allocate memory (errno=12)
Oct 15 12:13:16 ip-10-56-61-152 openvpn[21742]: openvpn_execve: unable to 

fork: Cannot allocate memory (errno=12)
Oct 15 12:13:16 ip-10-56-61-152 openvpn[21742]: Exiting due to fatal error
Unfortunately, we never recognized, reserved memory for openvpn to start to decreased, which is another sign for a memory leak.

Pls. can anyone provide me with a response, whether this mailing list is the right place to deal with this kind of problem?
Thank you very much

freundlich grüsst,
kind regards,

_________________________
_________________________
_________________________
_________________________
_________________________
________________

Arno Odermatt
Phone +41414454053
[email protected]...

Schindler Elevator Ltd. | Corporate Research & Development | CRD/CO-BAT Zugerstr. 13 | CH-6030 Ebikon, Switzerland
http://www.schindler.com
_________________________
_________________________
_________________________
_________________________
_________________________
________________

Please consider your environment.

Schindler supports sustainable urban development with safe, reliable and ecologically sound mobility solutions.

----- Forwarded by Arno Odermatt/R&D/SCH/SCHINDLER on 17.10.2013 14:50
-----

From:   Arno Odermatt/R&D/SCH/SCHINDLER
To:     [email protected], 
Date:   10.10.2013 11:11
Subject:        Openvpn 2.3.2 potential memory-leak after 24hours 

(addendum1)

Dear all,

we found our certificate renegotiating timer to be set to 86400secs = 24h. Therefore, we strongly assume, potentially a memory leak occurs in the renegotiating phase of the keys (passwords) as already earlier described in the mailing-list by "Brad Zhang" (Sept. 27. 2013) and treated/discussed by David Sommerseth.

http://sourceforge.net/mailarchive/forum.php?thread_name=52456F61.3000104%40topphemmelig.net&forum_name=openvpn-devel

our server side config-file:
reneg-sec 86400

more /etc/openvpn/server.cnf

;log /var/log/openvpn_cgwvpn.log

# Set server mode
mode server
float
management tunnel 7505
port 443
proto tcp-server
max-clients 5000

# Use Ethernet tunnel
dev tap

# The IPv4 addresses are used to establish the tunnel # All traffic is routed using IPv6 addresses ifconfig 172.16.0.1 255.255.128.0 ifconfig-pool 172.16.1.1 172.16.127.254 255.255.128.0

# Server certificate settings
tls-server
dh /etc/openvpn/servervpn/keys/dh1024.pem
ca /etc/openvpn/servervpn/keys/ca.crt
cert /etc/openvpn/servervpn/keys/CLTVpnSrv.crt
key /etc/openvpn/servervpn/keys/CLTVpnSrv.key

# Keep tunnel open
persist-tun
persist-key

# keep-alive ping
# -> keepalive 10 60
# will also be pushed to the client
# if mode server:
#   ping 10
#   ping-restart 120
#   push "ping 10"
#   push "ping-restart 60"
# else
#   ping 10
#   ping-restart 60
keepalive 240 600

# Renegotiate data channel key once per day
reneg-sec 86400

# optimize timout of slow GPRS connections
tcp-queue-limit 256
tcp-nodelay
tls-timeout 60
hand-window 120
sndbuf 262144
txqueuelen 400
bcast-buffers 4096
# enable LZO compression
comp-lzo
# moderate verbosity
verb 0
mute 10

#Execute scripts
script-security 2 system
up /etc/openvpn/servervpn/vpn-up.sh
down /etc/openvpn/servervpn/vpn-down.sh client-connect /etc/openvpn/servervpn/client-connect.sh client-disconnect /etc/openvpn/servervpn/client-disconnect.sh tmp-dir /var/tmp
[[email protected]... ~]

Any reply on this and idea for a soonest fix would be appreciated

thx and regards,

AO

From:   [email protected]...
To:     [email protected], 
Date:   09.10.2013 19:19
Subject:        [Openvpn-devel] Openvpn 2.3.2 potential memory-leak after 

24hours

All,

we are running Openvpn 2.3.2 on Fedora17/64Bit with 8GByte RAM total (EoL,

yes we are aware) and seem to run into a memory leak situation, as following:

- around 2955 Openvpn session running OK for 23'58"
- memory allocated 3247mByte, memory reserved 2.5gByte, CPU utilization ~1% (see "status-prior-o-vpnrestart-131009.rtf")
- script-security 2 (in openvpn.conf)

After exactly 24hours, allocated and reserved memory of the openvpn-process start to increase in 1-2Mbyte steps, without seeing an increase in the amount of Openvpn sessions and steps up to around 3970mByte for the allocated and 3.2gByte for the reserved memory. Then Openvpn crashes! (see bottom "status-prior-o-vpnrestart-131009.rtf")

The behavior of this symptom has been recognized in Openvpn 2.2.2-7 and 2.3.2 as following:

Quoted 1 line

Openvpn 2.2.2-7: keeps reporting "external program fork failed"

2.2.2-7 endlessly keeps reporting a fork failed, when the client-connect
script should be executed, no new openvpn sessions can be established but the process stays alive.

WARNING: Failed running command (--client-connect): external program fork failed
WARNING: Failed running command (--client-connect): external program fork failed
WARNING: Failed running command (--client-connect): external program fork failed

Quoted 1 line

Openvpn 2.3.2: exiting due to fatal error (openvpn is killed)

When a certain memory stage from a perspective of allocated and reserved memory is reached, following scenario happens:

Oct  9 15:40:29 ip-10-56-61-152 openvpn[25964]: openvpn_execve: unable to 
fork: Cannot allocate memory (errno=12) 
Oct  9 15:40:29 ip-10-56-61-152 openvpn[25964]: Exiting due to fatal error 

Please, can you analyze the issue and send us a feedback about the possible root cause and mitigation?

snip log:
------------------------------

Oct  9 15:40:29 ip-10-56-61-152 openvpn[25964]: openvpn_execve: unable to 
fork: Cannot allocate memory (errno=12) 
Oct  9 15:40:29 ip-10-56-61-152 openvpn[25964]: Exiting due to fatal error 
Oct  9 15:40:29 ip-10-56-61-152 openvpn[25964]: Closing TUN/TAP interface 
Oct  9 15:40:29 ip-10-56-61-152 openvpn[25964]: /usr/sbin/ip addr del dev 
tap1 172.16.0.1/17 
Oct  9 15:40:29 ip-10-56-61-152 openvpn[25964]: openvpn_execve: unable to 
fork: Cannot allocate memory (errno=12) 
Oct  9 15:40:29 ip-10-56-61-152 openvpn[25964]: Exiting due to fatal error 

^C[[email protected]... ~]$
[[email protected]... ~]$ sudo tail -f /var/log/messages

Oct  9 15:40:27 ip-10-56-61-152 openvpn[25964]: 
NL-200000134777/109.37.153.117:41299 NOTE: --mute triggered... 
Oct  9 15:40:29 ip-10-56-61-152 openvpn[25964]: 
DE-2024460/139.7.160.82:42187 40 variation(s) on previous 10 message(s) 
suppressed by --mute 
Oct  9 15:40:29 ip-10-56-61-152 openvpn[25964]: 
DE-2024460/139.7.160.82:42187 Connection reset, restarting [0] 
Oct  9 15:40:29 ip-10-56-61-152 openvpn[25964]: 
DE-2024460/139.7.160.82:42187 SIGUSR1[soft,connection-reset] received, 
client-instance restarting 
Oct  9 15:40:29 ip-10-56-61-152 openvpn[25964]: openvpn_execve: unable to 
fork: Cannot allocate memory (errno=12) 
Oct  9 15:40:29 ip-10-56-61-152 openvpn[25964]: Exiting due to fatal error 
Oct  9 15:40:29 ip-10-56-61-152 openvpn[25964]: Closing TUN/TAP interface 
Oct  9 15:40:29 ip-10-56-61-152 openvpn[25964]: /usr/sbin/ip addr del dev 
tap1 172.16.0.1/17 
Oct  9 15:40:29 ip-10-56-61-152 openvpn[25964]: openvpn_execve: unable to 
fork: Cannot allocate memory (errno=12) 
Oct  9 15:40:29 ip-10-56-61-152 openvpn[25964]: Exiting due to fatal error

thx and regards,

AO

_________________________
_________________________
_________________________
_________________________
_________________________
________________

******************************************************
Notice: The information contained in this message is intended only for use

of the individual(s) named above and may contain confidential, proprietary

or legally privileged information. No confidentiality or privilege is waived or lost by any mistransmission. If you are not the intended recipient of this message you are hereby notified that you must not use, disseminate , copy it in any form or take any action in reliance of it. If

you have received this message in error please delete it and any copies of

it and notify the sender immediately. *******************************************************[attachment "status-prior-o-vpnrestart-131009.rtf" deleted by Arno Odermatt/R&D/SCH/SCHINDLER]
------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance. Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60134071&iu=/4140/ostg.clktrk
_________________________
______________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

******************************************************
Notice: The information contained in this message is intended only for use of the individual(s) named above and may contain confidential, proprietary or legally privileged information. No confidentiality or privilege is waived or lost by any mistransmission. If you are not the intended recipient of this message you are hereby notified that you must not use, disseminate , copy it in any form or take any action in reliance of it. If you have received this message in error please delete it and any copies of it and notify the sender immediately.
*******************************************************

#1 lore raw

Hi,

Quoted 2 lines · On Thu, Oct 17, 2013 at 03:47:44PM +0200, [email protected]... wrote:

Pls. can anyone provide me with a response, whether this mailing list is the right place to deal with this kind of problem?

It is the right place to deal with this kind of problems.

The problem is that nobody seems to have time to start debugging this into more detail yet. What I'd try (if I had time) is to compile OpenVPN with valgrind (a memory leak searching tool), run it through a few client key renegotiations, and then check the output to see whether it shows anything "obvious".

In any case, thanks for tracing this so far and making it clear to us that we have an issue there. Even if it looks like nobody is caring.

gert

Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
                                                           //www.muc.de/~gert/
Gert Doering - Munich, Germany                             [email protected]...
fax: +49-89-35655025                        [email protected]...
#2 lore raw

[Openvpn-devel] Openvpn 2.3.2 potential memory-leak after 24hours (addendum3)

Good Morning,

thank you for replying.
Do you see any time window, you potentially could have time for this?

Meanwhile, we have been able to rise the memory limits of the system be adding to /etc/sysctl.conf:
"vm.overcommit_ratio = 80"
"vm.overcommit_memory = 2"

and by adding "virtual memory" by increasing the amount of swap space.

Using this setup, we now were able to successfully walk through the first re-negotiation cycle, which really seems to double memory consumption, which never is being freed, after the re-neg process is completed.

regards,

Arno

From:   Gert Doering <[email protected]...>
To:     [email protected]..., 
Date:   17.10.2013 16:19
Subject:        Re: [Openvpn-devel] Openvpn 2.3.2 potential memory-leak 

after 24hours (addendum2)

Hi,

Quoted 3 lines · On Thu, Oct 17, 2013 at 03:47:44PM +0200, [email protected]... wrote:

Pls. can anyone provide me with a response, whether this mailing list is

the right place to deal with this kind of problem?

It is the right place to deal with this kind of problems.

The problem is that nobody seems to have time to start debugging this into more detail yet. What I'd try (if I had time) is to compile OpenVPN with valgrind (a memory leak searching tool), run it through a few client key renegotiations, and then check the output to see whether it shows anything "obvious".

In any case, thanks for tracing this so far and making it clear to us that we have an issue there. Even if it looks like nobody is caring.

gert

Signature · 10 lines
USENET is *not* the non-clickable part of WWW!
 //www.muc.de/~gert/
Gert Doering - Munich, Germany [email protected]...
fax: +49-89-35655025 [email protected]...



******************************************************
Notice: The information contained in this message is intended only for use of the individual(s) named above and may contain confidential, proprietary or legally privileged information. No confidentiality or privilege is waived or lost by any mistransmission. If you are not the intended recipient of this message you are hereby notified that you must not use, disseminate , copy it in any form or take any action in reliance of it. If you have received this message in error please delete it and any copies of it and notify the sender immediately.
*******************************************************
#3 lore raw

Re: [Openvpn-devel] Openvpn 2.3.2 potential memory-leak after 24hours (addendum3)

Hi,

Quoted 2 lines · On Mon, Oct 21, 2013 at 10:34:27AM +0200, [email protected]... wrote:

thank you for replying.
Do you see any time window, you potentially could have time for this?

I just gave it an initial try (using the "master" branch but that code should have the same issues, if any, as no (known) fixes have been commited).

Valgrind isn't telling me about any clear mem-leaks yet...

==1953== HEAP SUMMARY:
==1953== in use at exit: 2,560 bytes in 52 blocks
==1953== total heap usage: 52,139 allocs, 52,087 frees, 15,723,723 bytes allocated

... but I could see memory go up in "while sleep 1; do ps wwup 1953 ; done" listings at exactly the point in time where renegotiation was taking place, with two clients connected to it.

I could use some ideas on how to debug this further - if valgrind isn't complaining, normally our memory management should be OK, but why is VSZ/RSZ still growing, then...?

gert

Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
                                                           //www.muc.de/~gert/
Gert Doering - Munich, Germany                             [email protected]...
fax: +49-89-35655025                        [email protected]...
#4 lore raw

Re: [Openvpn-devel] Openvpn 2.3.2 potential memory-leak after 24hours (addendum3)

Hi,

Quoted 3 lines · Gert Doering

I could use some ideas on how to debug this further - if valgrind isn't complaining, normally our memory management should be OK, but why is VSZ/RSZ still growing, then...?

Arne brought up a good point. If we "lose" the memory inside the gc_* functions (as in: use the same gc block for a very long time, like "while OpenVPN runs", but *do* free it at the end), valgrind might not be able to see it - after all, we nicely cleaned up later - but we'll still grow out of bounds at runtime.

Now, since 2.1 is supposedly not doing this, but 2.2.2 *is*, and the difference between those versions is not all that big, I really wonder where and how this got introduced. Maybe time to do some git bisect...

gert

Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
                                                           //www.muc.de/~gert/
Gert Doering - Munich, Germany                             [email protected]...
fax: +49-89-35655025                        [email protected]...
#5 lore raw

Re: [Openvpn-devel] Openvpn 2.3.2 potential memory-leak after 24hours (addendum3)

Hi,

Quoted 1 line · Gert Doering

On Tue, Oct 22, 2013 at 01:40:18PM +0200, Gert Doering wrote:

(I seem to be talking to myself a lot, lately...)

Quoted 9 lines
Quoted 3 lines

I could use some ideas on how to debug this further - if valgrind isn't complaining, normally our memory management should be OK, but why is VSZ/RSZ still growing, then...?

Arne brought up a good point. If we "lose" the memory inside the gc_* functions (as in: use the same gc block for a very long time, like "while OpenVPN runs", but *do* free it at the end), valgrind might not be able to see it - after all, we nicely cleaned up later - but we'll still grow out of bounds at runtime.

... and *that* seems to be the issue here. I've instrumented the gc_arena to have a creation time (time_t) and a use_count, and the only one that shows up at renegotiation time is the gc inside the "environment set", with this call chain... (included for those that are curious :-) ).

#3 0x080714e8 in add_env_item (str=0x811287c "untrusted_ip6=::ffff:127.0.0.1", do_alloc=true, list=0x80fc500,

    gc=0x810a65c) at ../../../openvpn-testing/src/openvpn/misc.c:553
#4  0x0807156a in env_set_add_nolock (es=0x80fc4fc, str=0x811287c "untrusted_ip6=::ffff:127.0.0.1")
    at ../../../openvpn-testing/src/openvpn/misc.c:568
#5  0x080716b2 in env_set_add (es=0x80fc4fc, str=0x811287c "untrusted_ip6=::ffff:127.0.0.1")
    at ../../../openvpn-testing/src/openvpn/misc.c:613
#6  0x08071b96 in setenv_str_ex (es=0x80fc4fc, name=0xbfffd430 "untrusted_ip6", 
    value=0xbfffd3b0 "::ffff:127.0.0.1", name_include=32772, name_exclude=0, name_replace=0 '\000', 
    value_include=128, value_exclude=0, value_replace=0 '\000') at ../../../openvpn-testing/src/openvpn/misc.c:784
#7  0x080719d6 in setenv_str (es=0x80fc4fc, name=0xbfffd430 "untrusted_ip6", value=0xbfffd3b0 "::ffff:127.0.0.1")
    at ../../../openvpn-testing/src/openvpn/misc.c:735
#8  0x080b1a7a in setenv_sockaddr (es=0x80fc4fc, name_prefix=0x80e2139 "untrusted", addr=0x810b20c, flags=1)
    at ../../../openvpn-testing/src/openvpn/socket.c:2396
#9  0x080b1b7e in setenv_link_socket_actual (es=0x80fc4fc, name_prefix=0x80e2139 "untrusted", act=0x810b20c, 
    flags=1) at ../../../openvpn-testing/src/openvpn/socket.c:2426
#10 0x080bde24 in setenv_untrusted (session=0x810b19c) at ../../../openvpn-testing/src/openvpn/ssl_verify.c:74
#11 0x080bf07a in verify_cert (session=0x810b19c, cert=0x812fa50, cert_depth=0)
    at ../../../openvpn-testing/src/openvpn/ssl_verify.c:667
#12 0x080c050e in verify_callback (preverify_ok=1, ctx=0xbfffd748)
    at ../../../openvpn-testing/src/openvpn/ssl_verify_openssl.c:84

Preliminary analysis: the problematic code seems to be

env_set_add_nolock (struct env_set *es, const char *str) {
remove_env_item (str, es->gc == NULL, &es->list); add_env_item ((char *)str, true, &es->list, es->gc);
}

... because add_env_item() will (have to) do...

add_env_item (char *str, const bool do_alloc, struct env_item **list, struct gc_arena *gc) {
...
ALLOC_OBJ_GC (item, struct env_item, gc);
item->string = do_alloc ? string_alloc (str, gc): str;
item->next = *list;
*list = item;
...
}

so while the environment list itself is not growing out of bounds, the gc_arena used for storing the local copy of the string is (because these are only ever cleaned up if gc_free() is destroying the whole arena, which for *this* one is only happening at program end).

OTOH, the whole thing looks like it would work perfectly if es->gc were just NULL (string_alloc() would then call malloc() instead, and remove_env_item() would call free()). So maybe this can be solved fairly easily without rewriting all of this...

(Doing this in a train which will arrive soon -> digging deeper on my way back)

gert

Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
                                                           //www.muc.de/~gert/
Gert Doering - Munich, Germany                             [email protected]...
fax: +49-89-35655025                        [email protected]...
#6 lore raw

Re: [Openvpn-devel] Openvpn 2.3.2 potential memory-leak after 24hours (addendum3)

In reply to Gert Doering

Dear Gert,

thank you so much.
Meanwhile, we can define the substantial memory growth for the phase of the first renegotiation cycle.
Memory is growing by almost double.
Surely, if one had only 50 to 100 concurrent sessions, it is not quit hurting anything. But driving the amount of concurrent session as we got it in our scenario, memory treatment seems to become key.

kind regards,

_____________________________________________________________________________________________________________________________________________

Arno

From:   Gert Doering <[email protected]...>
To:     [email protected]..., 
Cc:     Gert Doering <[email protected]...>, 
[email protected]
Date:   22.10.2013 13:43
Subject:        Re: Openvpn 2.3.2 potential memory-leak after 24hours 

(addendum3)

Hi,

Quoted 2 lines · On Mon, Oct 21, 2013 at 10:34:27AM +0200, [email protected]... wrote:

thank you for replying.
Do you see any time window, you potentially could have time for this?

I just gave it an initial try (using the "master" branch but that code should have the same issues, if any, as no (known) fixes have been commited).

Valgrind isn't telling me about any clear mem-leaks yet...

==1953== HEAP SUMMARY:
==1953== in use at exit: 2,560 bytes in 52 blocks
==1953== total heap usage: 52,139 allocs, 52,087 frees, 15,723,723 bytes
allocated

... but I could see memory go up in "while sleep 1; do ps wwup 1953 ; done"
listings at exactly the point in time where renegotiation was taking place,
with two clients connected to it.

I could use some ideas on how to debug this further - if valgrind isn't complaining, normally our memory management should be OK, but why is VSZ/RSZ still growing, then...?

gert

Signature · 10 lines
USENET is *not* the non-clickable part of WWW!
 //www.muc.de/~gert/
Gert Doering - Munich, Germany [email protected]...
fax: +49-89-35655025 [email protected]...
[attachment "attmxcg3.dat" deleted by Arno Odermatt/R&D/SCH/SCHINDLER] 


******************************************************
Notice: The information contained in this message is intended only for use of the individual(s) named above and may contain confidential, proprietary or legally privileged information. No confidentiality or privilege is waived or lost by any mistransmission. If you are not the intended recipient of this message you are hereby notified that you must not use, disseminate , copy it in any form or take any action in reliance of it. If you have received this message in error please delete it and any copies of it and notify the sender immediately.
*******************************************************
#7 lore raw

Re: [Openvpn-devel] Openvpn 2.3.2 potential memory-leak after 24hours (addendum3)

Hi,

Quoted 7 lines · On Tue, Oct 22, 2013 at 03:16:30PM +0200, [email protected]... wrote:

thank you so much.
Meanwhile, we can define the substantial memory growth for the phase of the first renegotiation cycle.
Memory is growing by almost double.
Surely, if one had only 50 to 100 concurrent sessions, it is not quit hurting anything. But driving the amount of concurrent session as we got it in our scenario, memory treatment seems to become key.

I'm not sure I found everything yet, but what I've seen to far will definitely raise memory consumption for long-term connected clients (as in: for every renegotiation, memory goes up). This particular gc is cleared upon client disconnection, thogh - so maybe that is why it wasn't noticed earlier.

About your user base: is this more dynamic clients (like "mobile users"), or are these very persistent long-term sessions (like "1000s of sensors that come online upon reboot, and stay online for weeks at a time")?

I'd like to understand your usage scenaro better to see whether what I'm tracking can be relevant at all, or not.

(As an extra question: if I find something and have tested it enough to say "this should fix things for you", can you run a test version in your environment? Or is this all production and needs to come in form of a binary distribution, etc.?)

gert

Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
                                                           //www.muc.de/~gert/
Gert Doering - Munich, Germany                             [email protected]...
fax: +49-89-35655025                        [email protected]...