Attention is currently required from: Arne Schwabe.

Hello Arne Schwabe,

I'd like you to do a code review.
Please visit

    https://gerrit.openvpn.net/c/openvpn/+/2204?usp=email

to review the following change.


Change subject: dco: don't access tls_multi in dco_get_peer_stats() during a 
restart
......................................................................

dco: don't access tls_multi in dco_get_peer_stats() during a restart

On a restart init_instance() registers the management callbacks before
the restart pause, while c2.tls_multi is still NULL: close_instance()
freed it and do_init_crypto_tls() has not created the new one yet.
A management "status" command during the pause therefore calls
dco_get_peer_stats() without a tls_multi.

With --persist-tun the DCO interface survives the restart, so the Linux
and Windows implementations get past their interface checks and
dereference the NULL tls_multi; FreeBSD hits ASSERT(c->c2.tls_multi)
even without --persist-tun. Either way openvpn dies.

Return an error when there is no tls_multi, as when there is no DCO
interface.

Reproduced on Linux with a DCO client using --persist-tun:

  (echo 'signal SIGUSR1'; sleep 0.5; echo status; sleep 3) | nc 127.0.0.1 7505

segfaults in dco_get_peer_stats() during the restart pause.

Gerrit change 2201 makes print_status() answer even when
dco_get_peer_stats() fails; together with this change, "status" gets
a reply during a reconnect instead of hanging or crashing.

Related: https://gerrit.openvpn.net/c/openvpn/+/2201
Change-Id: I2088345f10a630241fbddde68336ea7c1f7b449d
Signed-off-by: Antonio Quartulli <[email protected]>
---
M src/openvpn/dco_freebsd.c
M src/openvpn/dco_linux.c
M src/openvpn/dco_win.c
3 files changed, 9 insertions(+), 3 deletions(-)



  git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/04/2204/1

diff --git a/src/openvpn/dco_freebsd.c b/src/openvpn/dco_freebsd.c
index 11b8dff..6701d21 100644
--- a/src/openvpn/dco_freebsd.c
+++ b/src/openvpn/dco_freebsd.c
@@ -916,7 +916,11 @@
 int
 dco_get_peer_stats(struct context *c, const bool raise_sigusr1_on_err)
 {
-    ASSERT(c->c2.tls_multi);
+    /* tls_multi is NULL during a restart */
+    if (!c->c2.tls_multi)
+    {
+        return -EINVAL;
+    }
     msg(D_DCO_DEBUG, "%s: peer-id %d", __func__, c->c2.tls_multi->dco_peer_id);

     if (c->c2.tls_multi->dco_peer_id < 0)
diff --git a/src/openvpn/dco_linux.c b/src/openvpn/dco_linux.c
index 3a55b6e..befad61 100644
--- a/src/openvpn/dco_linux.c
+++ b/src/openvpn/dco_linux.c
@@ -1280,7 +1280,8 @@
 int
 dco_get_peer_stats(struct context *c, const bool raise_sigusr1_on_err)
 {
-    if (!c->c1.tuntap || c->c1.tuntap->dco.ifindex == 0)
+    /* tls_multi is NULL during a restart, while a persisted tun is still 
around */
+    if (!c->c1.tuntap || c->c1.tuntap->dco.ifindex == 0 || !c->c2.tls_multi)
     {
         return -1;
     }
diff --git a/src/openvpn/dco_win.c b/src/openvpn/dco_win.c
index a854045..eff4d33 100644
--- a/src/openvpn/dco_win.c
+++ b/src/openvpn/dco_win.c
@@ -898,7 +898,8 @@
 {
     const struct tuntap *tt = c->c1.tuntap;

-    if (!tuntap_defined(tt))
+    /* tls_multi is NULL during a restart, while a persisted tun is still 
around */
+    if (!tuntap_defined(tt) || !c->c2.tls_multi)
     {
         return -1;
     }

--
To view, visit https://gerrit.openvpn.net/c/openvpn/+/2204?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I2088345f10a630241fbddde68336ea7c1f7b449d
Gerrit-Change-Number: 2204
Gerrit-PatchSet: 1
Gerrit-Owner: Antonio Quartulli <[email protected]>
Gerrit-Reviewer: Arne Schwabe <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: Arne Schwabe <[email protected]>
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel
  • [Openvpn-devel] [S] Chan... Antonio Quartulli (Code Review) via Openvpn-devel

Reply via email to