From: "cron2 (Code Review)" Date: Fri, 19 Sep 2025 07:41:04 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641..., lstipakov@...277... Message-ID: <83f420ab3546517261831259128728ceef93e737-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="4izd/KSAFR4="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[release/2.6]: Validate DNS domain name before powershell invocation List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: stipa , plaisthos , flichtenheld Cc: openvpn-devel --4izd/KSAFR4= 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/+/1198?usp=3Demail ) The following approvals got outdated and were removed: Code-Review+2 by cron2 Change subject: Validate DNS domain name before powershell invocation ...................................................................... Validate DNS domain name before powershell invocation Starting from commit d383d6e ("win: replace wmic invocation with powershell") we pass --dhcp-option DOMAIN value to a powershell command to set DNS domain. Without validation this opens the door to a command injection atack. This only allows domain names with characters: [A-Za-z0-9.-_\x80-\0xff] Change-Id: I7a57d7b4e84aa2b9c9e71e30520ed468b0e3c278 Signed-off-by: Lev Stipakov Acked-by: Gert Doering Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1198 Message-Id: <20250918173447.32466-1-gert@...1296...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg33= 071.html Signed-off-by: Gert Doering --- A src/openvpn/domain_helper.h M src/openvpn/tun.c M src/openvpnserv/interactive.c 3 files changed, 59 insertions(+), 0 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/98/1198/2 diff --git a/src/openvpn/domain_helper.h b/src/openvpn/domain_helper.h new file mode 100644 index 0000000..f1ecf86 --- /dev/null +++ b/src/openvpn/domain_helper.h @@ -0,0 +1,45 @@ +/* + * OpenVPN -- An application to securely tunnel IP networks + * over a single UDP port, with support for SSL/TLS-based + * session authentication and key exchange, + * packet encryption, packet authentication, and + * packet compression. + * + * Copyright (C) 2025 Lev Stipakov + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +static inline bool +is_allowed_domain_ascii(unsigned char c) +{ + return (c >=3D 'A' && c <=3D 'Z') + || (c >=3D 'a' && c <=3D 'z') + || (c >=3D '0' && c <=3D '9') + || c =3D=3D '.' || c =3D=3D '-' || c =3D=3D '_' || c >=3D 0x80; +} + +static inline bool +validate_domain(const char *domain) +{ + for (const char *ch =3D domain; *ch; ++ch) + { + if (!is_allowed_domain_ascii((unsigned char)*ch)) + { + return false; + } + } + + return true; +} diff --git a/src/openvpn/tun.c b/src/openvpn/tun.c index 99dc490..2784941 100644 --- a/src/openvpn/tun.c +++ b/src/openvpn/tun.c @@ -46,6 +46,7 @@ #include "win32.h" #include "block_dns.h" #include "networking.h" +#include "domain_helper.h" #include "memdbg.h" @@ -390,6 +391,12 @@ return; } + if (add && !validate_domain(tt->options.domain)) + { + msg(M_WARN, "Failed to set DNS domain '%s' because it contains inv= alid characters", tt->options.domain); + return; + } + struct argv argv =3D argv_new(); argv_printf(&argv, "%s%s -NoProfile -NonInteractive -Command Set-DnsClient -I= nterfaceIndex %lu -ConnectionSpecificSuffix '%s'", diff --git a/src/openvpnserv/interactive.c b/src/openvpnserv/interactive.c index ca58596..c12d34f 100644 --- a/src/openvpnserv/interactive.c +++ b/src/openvpnserv/interactive.c @@ -40,6 +40,7 @@ #include "validate.h" #include "block_dns.h" #include "ring_buffer.h" +#include "domain_helper.h" #define IO_TIMEOUT 2000 /*ms*/ @@ -1216,6 +1217,12 @@ { NET_IFINDEX if_index; + if (!validate_domain(domain)) + { + MsgToEventLog(MSG_FLAGS_ERROR, TEXT("Failed to set DNS domain '%hs= ' because it contains invalid characters"), domain); + return ERROR_INVALID_DATA; + } + DWORD err =3D ConvertInterfaceNameToIndex(if_name, &if_index); if (err !=3D ERROR_SUCCESS) { -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1198?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: I7a57d7b4e84aa2b9c9e71e30520ed468b0e3c278 Gerrit-Change-Number: 1198 Gerrit-PatchSet: 2 Gerrit-Owner: stipa Gerrit-Reviewer: cron2 Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-MessageType: newpatchset --4izd/KSAFR4= 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 an= d were removed: Code-Review+2 by cron2

Validate DNS domain name before powershell invocatio=
n

Starting from commit

d383d6e ("win: replace wmic inv= ocation with powershell")

we pass --dhcp-option DOMAIN value to= a powershell command
to set DNS domain. Without validation this opens t= he door
to a command injection atack.

This only allows domain nam= es with characters:

[A-Za-z0-9.-_\x80-\0xff]

Change-Id: I7a= 57d7b4e84aa2b9c9e71e30520ed468b0e3c278
Signed-off-by: Lev Stipakov <l= ev@...515...>
Acked-by: Gert Doering <gert@...1296...>
Gerri= t URL: https://gerrit.openvpn.net/c/openvpn/+/1198
Message-Id: <20250= 918173447.32466-1-gert@...1296...>
URL: https://www.mail-archive.com/= openvpn-devel@lists.sourceforge.net/msg33071.html
Signed-off-by: Gert Do= ering <gert@...1296...>
---
A src/openvpn/domain_helper.h
M = src/openvpn/tun.c
M src/openvpnserv/interactive.c
3 files changed, 59= insertions(+), 0 deletions(-)

git pull ssh://gerrit.openvpn.net:=
29418/openvpn refs/changes/98/1198/2
diff --git a/src/openvpn/domai=
n_helper.h b/src/openvpn/domain_helper.h
new file mode 1006= 44
index 0000000..f1ecf86
--- /dev/null
+++ b/src/openvpn/domain_helper.h
@@ -0,0 +1,4= 5 @@
+/*
+ * OpenVPN -- An application to= securely tunnel IP networks

+ * over a single UDP port, with support for SSL/TLS-ba= sed
+ * s= ession authentication and key exchange,
+ * packet encryption, packet authentication= , and
+ * = packet compression.
= + *
+ * Copyright (C= ) 2025 Lev Stipakov <lev@...515...>
+ *
+ * This program is free software; you can redistribute it and/or modi= fy
+ * it under the = terms of the GNU General Public License version 2
+ * as published by the Free Software Foundat= ion.
+ *
+ * This program is distributed = in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warr= anty of
+ * MERCHANT= ABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more d= etails.
+ *+ * You should have received = a copy of the GNU General Public License along
+ * with this program; if not, write to the Free= Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+static inline bool
+is_allowed_domain_ascii(unsigned char c)
+{
+ return (c >=3D 'A' && c <=3D &= #39;Z')
+ = || (c >=3D 'a' && c <=3D 'z')
+ || (c >=3D '0&= #39; && c <=3D '9')

+ || c =3D=3D '.' || c =3D=3D '-= 9; || c =3D=3D '_' || c >=3D 0x80;
+}
+
+static inli= ne bool
+validate_dom= ain(const char *domain)
+{
+ for (const= char *ch =3D domain; *ch; ++ch)
+ {
+ = if (!is_allowed_domain_ascii((unsigned char)*ch))
+ {
+ return false;
+ }
+ }
+
+ retur= n true;
+}
= diff --git a/src/openvpn/tun.c b/src/openvpn/tun.c
in= dex 99dc490..2784941 100644
--- a/src/openvpn/tun.c<= br>+++ b/src/openvpn/tun.c
@@ -46,6 +46,7 @@ #include "win32.h"
#include "block= _dns.h"
#include "networking.h"
<= span style=3D"color: hsl(120, 100%, 40%);">+#include "domain_helper.h&= quot;

#include "memdbg.h"

@@ -390,6 +391,12 @@
= return;
}

+ if (add && !validate_domain(tt-&g= t;options.domain))
+ = {
+ msg(M_W= ARN, "Failed to set DNS domain '%s' because it contains invali= d characters", tt->options.domain);
+ return;
+ }
+
struct argv argv =3D argv_new();
argv_printf(&argv,

"%s%s -= NoProfile -NonInteractive -Command Set-DnsClient -InterfaceIndex %lu -Conne= ctionSpecificSuffix '%s'",
diff --git a/src/op= envpnserv/interactive.c b/src/openvpnserv/interactive.c
ind= ex ca58596..c12d34f 100644
--- a/src/openvpnserv/interactiv= e.c
+++ b/src/openvpnserv/interactive.c
@@ = -40,6 +40,7 @@
#include "validate.h"
<= span> #include "block_dns.h"
#include "ring= _buffer.h"
+#inc= lude "domain_helper.h"

#define= IO_TIMEOUT 2000 /*ms*/

@@ -1216,6 +1217= ,12 @@
{
NET_IFINDEX if_index;=

+ if (= !validate_domain(domain))
+ {
+ = MsgToEventLog(MSG_FLAGS_ERROR, TEXT("Failed to set DNS domain '%hs= ' because it contains invalid characters"), domain);
+ return ERROR_INVALID_DATA= ;
+ }
+
DWORD err = =3D ConvertInterfaceNameToIndex(if_name, &if_index);
= if (err !=3D ERROR_SUCCESS)
{

To view, visit change 1198. To unsubscribe, or for help writing= mail filters, visit setting= s.

Gerrit-Project: openvpn
Gerrit-Branch: release/2.6
Gerrit-Change-Id: I7a57d7b4e84aa2b9c9e71e30520= ed468b0e3c278
Gerrit-Change-Number: 1198
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
--4izd/KSAFR4=--