Crash on duplicate PUSH_CONTROL message
Hello,
I fear we may have to delay the final release. While debugging a problem with a user of my app I found a nasty bug which causes OpenVPN to crash if two PUSH_CONTROL messages are received.
from push.c:
if (!c->c2.did_pre_pull_restore)
{
pre_pull_restore (&c->options);
md5_state_init (&c->c2.pulled_options_state);
c->c2.did_pre_pull_restore = true;
}This is executed on the first push message and initializes the md5 state. On further push messages (continuation or new) this is not executed again.
if (apply_push_options (&c->options,
&buf,
permission_mask,
option_types_found,
c->c2.es))
switch (c->options.push_continuation)
{
case 0:
case 1:
md5_state_update (&c->c2.pulled_options_state, BPTR(&buf_orig),
BLEN(&buf_orig));
md5_state_final (&c->c2.pulled_options_state,
&c->c2.pulled_options_digest);
ret = PUSH_MSG_REPLY;This finalizes the md5 state. leaving pulled_options_state in a uninitialized or at least undefined state. If a second push message after a final message is received md5_state_update will use this undefined context
break;
case 2:
md5_state_update (&c->c2.pulled_options_state, BPTR(&buf_orig),
BLEN(&buf_orig));
ret = PUSH_MSG_CONTINUATION;
break;
}To trigger this issue there have multiple things.
* A OpenVPN 2.3 server (commit 5d4f5435a421299ed047485d8d99bdf9a0d22fd1 allows duplicate sending of this message), you can also simply duplicate the send_push_something method call to trigger this bug on clients
* A bit flaky connection. The GSM/UMTS networks are great for this. They sometimes wait a very long time to deliver the packet (like 30s) without dropping packets
I think the bug also exists in 2.2 clients but I have not done extensive checks. Since push_control messages have no sequence number or such it is difficult to determine how to only apply the push messages only once.
A quick&dirty hack is to simply md5_state_init the state after the md5_state_final.
Arne
----- Original Message -----
Quoted 5 lines
From: "Arne Schwabe" <[email protected]...>
To: [email protected]
Sent: Sunday, 23 December, 2012 1:11:22 PM
Subject: [Openvpn-devel] Crash on duplicatePUSH_CONTROLmessage
Quoted 7 lines
Hello,
I fear we may have to delay the final release. While debugging a problem
with a user of my app I found a nasty bug which causes OpenVPN to crash
if twoPUSH_CONTROLmessages are received.
This is not good news :( Well, I agree, we need to sort this one out. We can't release with this bug. Having that said, I'm not sure if the commit 5d4f5435a421299ed047485d8d99bdf9a0d22fd1 is the core issue to this bug, or if it just flushes out another corner case. That commit was added to solve an issue introduced in commit ff65da3a230b658b2c1d52dc1a48612e80a2eb42, but James pointed me at some other things to check out as well. But I've never had enough time to dig deeper on that topic. Without commit 5d4f5435a421299ed047485d8d99bdf9a0d22fd1, the client will never be able to re-connect to the server before its SSL context expires and is re-created. Which leads me to think that we're having a new corner case.
Anyhow, we need to fix this ... and I'm going offline now until after new year, so I have no chance digging into this topic now, unfortunately. But I would prefer to solve both commit 5d4f5435a421299ed047485d8d99bdf9a0d22fd1 and this new issue in a better way then.
kind regards,
David Sommerseth
Quoted 67 lines
from
push.c:if (!c->c2.did_pre_pull_restore) { pre_pull_restore (&c->options); md5_state_init (&c->c2.pulled_options_state); c->c2.did_pre_pull_restore = true; }This is executed on the first push message and initializes the md5 state. On further push messages (continuation or new) this is not executed again.
if (apply_push_options (&c->options, &buf, permission_mask, option_types_found, c->c2.es)) switch (c->options.push_continuation) { case 0: case 1: md5_state_update (&c->c2.pulled_options_state, BPTR(&buf_orig), BLEN(&buf_orig)); md5_state_final (&c->c2.pulled_options_state, &c->c2.pulled_options_digest); ret = PUSH_MSG_REPLY;This finalizes the md5 state. leaving
pulled_options_statein a uninitialized or at least undefined state. If a second push message after a final message is receivedmd5_state_updatewill use this undefined contextbreak; case 2: md5_state_update (&c->c2.pulled_options_state, BPTR(&buf_orig), BLEN(&buf_orig)); ret = PUSH_MSG_CONTINUATION; break; }To trigger this issue there have multiple things.
* A OpenVPN 2.3 server (commit
5d4f5435a421299ed047485d8d99bdf9a0d22fd1
allows duplicate sending of this message), you can also simply duplicate
thesend_push_somethingmethod call to trigger this bug on clients
* A bit flaky connection. The GSM/UMTS networks are great for this. They
sometimes wait a very long time to deliver the packet (like 30s) without
dropping packetsI think the bug also exists in 2.2 clients but I have not done extensive
checks. Sincepush_controlmessages have no sequence number or such it
is difficult to determine how to only apply the push messages only once.A quick&dirty hack is to simply
md5_state_initthe state after themd5_state_final.Arne
Hi,
Quoted 13 lines · Arne Schwabe
I fear we may have to delay the final release. While debugging a problem with a user of my app I found a nasty bug which causes OpenVPN to crash if two
PUSH_CONTROLmessages are received.from
push.c:if (!c->c2.did_pre_pull_restore) { pre_pull_restore (&c->options); md5_state_init (&c->c2.pulled_options_state); c->c2.did_pre_pull_restore = true; }
Quoted 3 lines
This is executed on the first push message and initializes the md5 state. On further push messages (continuation or new) this is not executed again.
Indeed, this is coupling two things - "pre-pull options saving" (to restore to the state before pulling, which only ever needs to be executed once), and "md5 state init", which needs to be executed for every round of PUSH_REPLY...
Assuming there is only one PUSH_REPLY ever, this is no problem, but with the new server side code plus mobile networks, this can indeed be triggered.
I'd propose to fix this by adding "bool c->c2.pulled_options_md5_init", using that for md5_state_init() *and resetting it* after md5_state_final().
For a single PUSH_REPLY, this should not make a difference (except for a few bytes of code), and for multiple PUSH_REPLY messages this will re-init the md5_state properly.
(I'll send a patch as soon as I can test this - Arne, could you send me login credentials + config for your "will crash client!" server, please?)
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]...Hi,
Quoted 3 lines · Arne Schwabe
I fear we may have to delay the final release. While debugging a problem with a user of my app I found a nasty bug which causes OpenVPN to crash if two
PUSH_CONTROLmessages are received.
The appended patch fixes this for me (Client on Linux/i386, but that should be OS and architecture agnostic).
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]...From f38ff2ee809f85b6a7c1dc08bb8cf9bfc350070f Mon Sep 17 00:00:00 2001
From: Gert Doering <[email protected]...>
Date: Tue, 25 Dec 2012 13:41:50 +0100
Subject: [PATCH] Fix client crash on double PUSH_REPLY.
Introduce an extra bool variable c2.pulled_options_md5_init_done to keep track of md5_init state of pulled_options_state - avoid accessing uninitialized state when a second PUSH_REPLY comes in (which only happens under very particular circumstances).
Bug tracked down by Arne Schwabe <[email protected]...>.
--- src/openvpn/openvpn.h | 1 + src/openvpn/push.c | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletions(-)
src/openvpn/openvpn.h +1 -0
@@ -474,6 +474,7 @@ struct context_2bool did_pre_pull_restore;/* hash of pulled options, so we can compare when options change */ +bool pulled_options_md5_init_done;struct md5_state pulled_options_state;struct md5_digest pulled_options_digest;
src/openvpn/push.c +6 -1
@@ -446,10 +446,14 @@ process_incoming_push_msg (struct context *c,if (ch ==',' ) {struct buffer buf_orig = buf; +if (!c->c2.pulled_options_md5_init_done) + { +md5_state_init (&c->c2.pulled_options_state); + c->c2.pulled_options_md5_init_done = true; + }if (!c->c2.did_pre_pull_restore) {pre_pull_restore (&c->options); -md5_state_init (&c->c2.pulled_options_state); c->c2.did_pre_pull_restore = true; } if (apply_push_options (&c->options,
@@ -463,6 +467,7 @@ process_incoming_push_msg (struct context *c,case 1 :md5_state_update (&c->c2.pulled_options_state,BPTR (&buf_orig),BLEN (&buf_orig));md5_state_final (&c->c2.pulled_options_state, &c->c2.pulled_options_digest); + c->c2.pulled_options_md5_init_done = false; ret =PUSH_MSG_REPLY ;break ;case 2 :
Signature · 1 line
1.7.8.6
Am 25.12.12 13:48, schrieb Gert Doering:
Quoted 9 lines
Hi,
Quoted 3 lines · Arne Schwabe
I fear we may have to delay the final release. While debugging a problem with a user of my app I found a nasty bug which causes OpenVPN to crash if two
PUSH_CONTROLmessages are received.The appended patch fixes this for me (Client on Linux/i386, but that should be OS and architecture agnostic).
ACK. Also works on Android/ARMv7a.
Arne
Quoted 9 lines · Gert Doering
Hi,
Quoted 3 lines · Arne Schwabe
I fear we may have to delay the final release. While debugging a problem with a user of my app I found a nasty bug which causes OpenVPN to crash if two
PUSH_CONTROLmessages are received.The appended patch fixes this for me (Client on Linux/i386, but that should be OS and architecture agnostic).
Applied to master and beta/2.3
commit 1978db4b9657f0db134f1deaeb1e8400bf6a033e (master) commit 2e3b853dd1070435d60a1f11ff4364631c83d6a9 (beta/2.3)
Author: Gert Doering <[email protected]...> Date: Tue Dec 25 13:41:50 2012 +0100
Fix client crash on double PUSH_REPLY.
Introduce an extra bool variable c2.pulled_options_md5_init_done to keep track of md5_init state of pulled_options_state - avoid accessing uninitialized state when a second PUSH_REPLY comes in (which only happens under very particular circumstances).
Bug tracked down by Arne Schwabe <[email protected]...>.
Message-Id: [email protected]...
URL: http://article.gmane.org/gmane.network.openvpn.devel/7216
Signature · 3 lines
kind regards, David Sommerseth