From: "cron2 (Code Review)" Date: Wed, 2 Apr 2025 14:33:34 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641..., lstipakov@...277... Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="OmZTUqKfYyY="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[release/2.6]: dco-win: Ensure correct OVERLAPPED scope List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: stipa , plaisthos , flichtenheld Cc: openvpn-devel --OmZTUqKfYyY= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has uploaded a new patch set (#2) to the change originally created by= stipa. ( http://gerrit.openvpn.net/c/openvpn/+/933?usp=3Demail ) The following approvals got outdated and were removed: Code-Review+2 by cron2 Change subject: dco-win: Ensure correct OVERLAPPED scope ...................................................................... dco-win: Ensure correct OVERLAPPED scope This is a backport of the master commit f60a493 ("dco-win: Fix crash when cancelling pending operation") Although I am unable to reproduce this issue on release branch, the code is clearly wrong and has to be fixed. The OVERLAPPED structure must remain valid for the entire duration of an asynchronous operation. Previously, when a TCP connection was pending inside the NEW_PEER call, the OVERLAPPED structure was defined as a local variable within dco_p2p_new_peer(). When CancelIo() was called later from close_tun_handle(), the OVERLAPPED structure was already out of scope, resulting in undefined behavior and stack corruption. This fix moves the OVERLAPPED structure to the tuntap struct, ensuring it remains valid throughout the operation's lifetime. Change-Id: I44a73f06c0672c1d288bf46e9424dc0dc2abe054 Signed-off-by: Lev Stipakov Acked-by: Gert Doering Message-Id: <20250402113016.14980-1-gert@...1296...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg31= 316.html Signed-off-by: Gert Doering --- M src/openvpn/dco_win.c M src/openvpn/dco_win.h M src/openvpn/socket.c M src/openvpn/tun.h 4 files changed, 9 insertions(+), 6 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/33/933/2 diff --git a/src/openvpn/dco_win.c b/src/openvpn/dco_win.c index 3ec946f..0b8f831 100644 --- a/src/openvpn/dco_win.c +++ b/src/openvpn/dco_win.c @@ -156,7 +156,8 @@ } void -dco_create_socket(HANDLE handle, struct addrinfo *remoteaddr, bool bind_lo= cal, +dco_create_socket(HANDLE handle, OVERLAPPED *ov, + struct addrinfo *remoteaddr, bool bind_local, struct addrinfo *bind, int timeout, struct signal_info *sig_info) { @@ -229,8 +230,8 @@ ASSERT(0); } - OVERLAPPED ov =3D { 0 }; - if (!DeviceIoControl(handle, OVPN_IOCTL_NEW_PEER, &peer, sizeof(peer),= NULL, 0, NULL, &ov)) + CLEAR(*ov); + if (!DeviceIoControl(handle, OVPN_IOCTL_NEW_PEER, &peer, sizeof(peer),= NULL, 0, NULL, ov)) { DWORD err =3D GetLastError(); if (err !=3D ERROR_IO_PENDING) @@ -239,7 +240,7 @@ } else { - dco_connect_wait(handle, &ov, timeout, sig_info); + dco_connect_wait(handle, ov, timeout, sig_info); } } } diff --git a/src/openvpn/dco_win.h b/src/openvpn/dco_win.h index 4883629..dcf480e 100644 --- a/src/openvpn/dco_win.h +++ b/src/openvpn/dco_win.h @@ -41,7 +41,8 @@ create_dco_handle(const char *devname, struct gc_arena *gc); void -dco_create_socket(HANDLE handle, struct addrinfo *remoteaddr, bool bind_lo= cal, +dco_create_socket(HANDLE handle, OVERLAPPED *ov, + struct addrinfo *remoteaddr, bool bind_local, struct addrinfo *bind, int timeout, struct signal_info *sig_info); diff --git a/src/openvpn/socket.c b/src/openvpn/socket.c index e070688..2eb2e74 100644 --- a/src/openvpn/socket.c +++ b/src/openvpn/socket.c @@ -2148,7 +2148,7 @@ c->c1.tuntap =3D tt; } - dco_create_socket(c->c1.tuntap->hand, + dco_create_socket(c->c1.tuntap->hand, &c->c1.tuntap->dco_new_peer_ov, sock->info.lsa->current_remote, sock->bind_local, sock->info.lsa->bind_local, get_server_poll_remaining_time(sock->server_poll_tim= eout), diff --git a/src/openvpn/tun.h b/src/openvpn/tun.h index 33b9552..91dbeef 100644 --- a/src/openvpn/tun.h +++ b/src/openvpn/tun.h @@ -196,6 +196,7 @@ #ifdef _WIN32 HANDLE hand; + OVERLAPPED dco_new_peer_ov; /* used for async NEW_PEER dco call, which= might wait for TCP connect */ struct overlapped_io reads; struct overlapped_io writes; struct rw_handle rw_handle; -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/933?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: release/2.6 Gerrit-Change-Id: I44a73f06c0672c1d288bf46e9424dc0dc2abe054 Gerrit-Change-Number: 933 Gerrit-PatchSet: 2 Gerrit-Owner: stipa Gerrit-Reviewer: cron2 Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-MessageType: newpatchset --OmZTUqKfYyY= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 uploaded patch set #2 to the change originally cr= eated by stipa.

View Change

The following approvals got outdated and= were removed: Code-Review+2 by cron2

dco-win: Ensure correct OVERLAPPED scope

This= is a backport of the master commit

f60a493 ("dco-win: Fix c= rash when cancelling pending operation")

Although I am unable t= o reproduce this issue on release branch,
the code is clearly wrong and = has to be fixed.

The OVERLAPPED structure must remain valid for the = entire duration of an
asynchronous operation. Previously, when a TCP con= nection was pending
inside the NEW_PEER call, the OVERLAPPED structure w= as defined as a
local variable within dco_p2p_new_peer().

When Ca= ncelIo() was called later from close_tun_handle(), the OVERLAPPED
struct= ure was already out of scope, resulting in undefined behavior and
stack = corruption.

This fix moves the OVERLAPPED structure to the tuntap st= ruct, ensuring
it remains valid throughout the operation's lifetime.=

Change-Id: I44a73f06c0672c1d288bf46e9424dc0dc2abe054
Signed-off-= by: Lev Stipakov <lev@...515...>
Acked-by: Gert Doering <gert@...220...= ..1296...>
Message-Id: <20250402113016.14980-1-gert@...1296...>=
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/m= sg31316.html
Signed-off-by: Gert Doering <gert@...1296...>
---<= br>M src/openvpn/dco_win.c
M src/openvpn/dco_win.h
M src/openvpn/sock= et.c
M src/openvpn/tun.h
4 files changed, 9 insertions(+), 6 deletion= s(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes=
/33/933/2
diff --git a/src/openvpn/dco_win.c b/src/openvpn/dco_win.=
c
index 3ec946f..0b8f831 100644
--- a/src/o= penvpn/dco_win.c
+++ b/src/openvpn/dco_win.c
@@ -156,7 +156,8 @@
}

= void
-dco_create_socke= t(HANDLE handle, struct addrinfo *remoteaddr, bool bind_local,
+dco_create_socket(HANDLE handle,= OVERLAPPED *ov,
+ = struct addrinfo *remoteaddr, bool bind_local,
struct addrinfo *bind, int timeout,
= struct signal_info *sig_info)
{@@ -229,8 +230,8 @@
ASSERT(0);
}

- OVERLAPPED ov =3D { 0 };
- if (!DeviceIoControl(handle, OVPN_IOCTL_NEW_PEER, &pe= er, sizeof(peer), NULL, 0, NULL, &ov))
+ CLEAR(*ov);
+ if (!DeviceIoControl(handle, OVPN_IOCTL_NEW_PEER, &a= mp;peer, sizeof(peer), NULL, 0, NULL, ov))
{ DWORD err =3D GetLastError();
if (= err !=3D ERROR_IO_PENDING)
@@ -239,7 +240,7 @@
}
else
{
- dco_connect_w= ait(handle, &ov, timeout, sig_info);
+ dco_connect_wait(handle, ov, timeout, sig_= info);
}
}
}=
diff --git a/src/openvpn/dco_win.h b/src/openvpn/dco_win.h=
index 4883629..dcf480e 100644
--- a/src/op= envpn/dco_win.h
+++ b/src/openvpn/dco_win.h
@@ -41,7 +41,8 @@

create_dco_handle(const char *devname, = struct gc_arena *gc);

void
-dco_create_socket(HANDLE handle, st= ruct addrinfo *remoteaddr, bool bind_local,
+dco_create_socket(HANDLE handle, OVERLAPPED *ov,

+ stru= ct addrinfo *remoteaddr, bool bind_local,
= struct addrinfo *bind, int timeout,
st= ruct signal_info *sig_info);

diff --git a= /src/openvpn/socket.c b/src/openvpn/socket.c
index e070688.= .2eb2e74 100644
--- a/src/openvpn/socket.c
= +++ b/src/openvpn/socket.c
@@ -2148,7 +2148,7 @@
= c->c1.tuntap =3D tt;
}

- dco_create_so= cket(c->c1.tuntap->hand,
+ dco_create_socket(c->c1.tuntap->hand, &c->c1.tu= ntap->dco_new_peer_ov,
sock->i= nfo.lsa->current_remote,
sock->= ;bind_local, sock->info.lsa->bind_local,
= get_server_poll_remaining_time(sock->server_poll_timeout),

diff --git a/src/openvpn/tun.h b/src/openvpn/tun.h
= index 33b9552..91dbeef 100644
--- a/src/openvpn/tun.h=
+++ b/src/openvpn/tun.h
@@ -196,6 +196,7 @= @

#ifdef _WIN32
HAN= DLE hand;
+ OVERLA= PPED dco_new_peer_ov; /* used for async NEW_PEER dco call, which might wait= for TCP connect */
struct overlapped_io reads;=
struct overlapped_io writes;
struct rw_= handle rw_handle;

To view, visit change 933.= To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: release/2.6
Gerrit-Change-Id: I44a73f06c0672c1d288bf46e942= 4dc0dc2abe054
Gerrit-Change-Number: 933
Gerrit-PatchSet: 2
Gerrit-Owner: stipa <lstipakov@...277...>= ;
Gerrit-Reviewer: cron2 <gert@...1296...>=
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-MessageType: newpatchset
--OmZTUqKfYyY=--