[Openvpn-devel,v1] dco: don't access tls_multi in dco_get_peer_stats() during a restart
Commit Message
From: Antonio Quartulli <antonio@mandelbit.com>
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 <antonio@mandelbit.com>
Acked-by: Lev Stipakov <lstipakov@gmail.com>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2204
---
This change was reviewed on Gerrit and approved by at least one
developer. I request to merge it to master.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2204
This mail reflects revision 1 of this Change.
Acked-by according to Gerrit (reflected above):
Lev Stipakov <lstipakov@gmail.com>
@@ -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)
@@ -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;
}
@@ -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;
}