From: "stipa (Code Review)" Date: Fri, 31 Oct 2025 11:33:26 +0000 In-Reply-To: References: Reply-To: lstipakov@...277..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641..., gert@...1296... Message-ID: <5ec8380da1a7082d3cbadb602c0701248746efd2-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="O2BOPlzUIfQ="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: win32: ensure plugin dir has the trailing slash List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos , flichtenheld Cc: openvpn-devel --O2BOPlzUIfQ= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: flichtenheld, plaisthos, stipa. Hello cron2, flichtenheld, plaisthos, I'd like you to reexamine a change. Please visit http://gerrit.openvpn.net/c/openvpn/+/1332?usp=3Demail to look at the new patch set (#2). Change subject: win32: ensure plugin dir has the trailing slash ...................................................................... win32: ensure plugin dir has the trailing slash This prevents loading plugins from the directories which share initial characters with the trusted path. Reported-by: Joshua Rogers Found-by: ZeroPath (https://zeropath.com/) Change-Id: I5ea90594493ab5cb858f7495f773e080b379e8e8 Signed-off-by: Lev Stipakov --- M CMakeLists.txt M src/openvpn/Makefile.am M src/openvpn/win32.c 3 files changed, 30 insertions(+), 12 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/32/1332/2 diff --git a/CMakeLists.txt b/CMakeLists.txt index c9301e6..6888de3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -245,6 +245,9 @@ check_symbol_exists(chsize io.h HAVE_CHSIZE) check_symbol_exists(getrlimit sys/resource.h HAVE_GETRLIMIT) +# Some old versions of mingw does not have PATHCCH_OPTIONS enums -- add a = check +check_symbol_exists(PATHCCH_ENSURE_TRAILING_SLASH pathcch.h HAVE_PATHCCH_E= NSURE_TRAILING_SLASH) + # Some OS (e.g. FreeBSD) need some basic headers to allow # including network headers set(NETEXTRA sys/types.h) @@ -338,7 +341,7 @@ if (WIN32) target_link_libraries(${target} PUBLIC ws2_32.lib crypt32.lib fwpuclnt.lib iphlpapi.lib - wininet.lib setupapi.lib rpcrt4.lib wtsapi32.lib ncrypt.li= b bcrypt.lib) + wininet.lib setupapi.lib rpcrt4.lib wtsapi32.lib ncrypt.li= b bcrypt.lib pathcch.lib) endif () endif () diff --git a/src/openvpn/Makefile.am b/src/openvpn/Makefile.am index db87dfc..a2b5e92 100644 --- a/src/openvpn/Makefile.am +++ b/src/openvpn/Makefile.am @@ -166,5 +166,5 @@ $(OPTIONAL_INOTIFY_LIBS) if WIN32 openvpn_SOURCES +=3D openvpn_win32_resources.rc wfp_block.c wfp_block.h -openvpn_LDADD +=3D -lgdi32 -lws2_32 -lwininet -lcrypt32 -liphlpapi -lwinmm= -lfwpuclnt -lrpcrt4 -lncrypt -lsetupapi -lbcrypt +openvpn_LDADD +=3D -lgdi32 -lws2_32 -lwininet -lcrypt32 -liphlpapi -lwinmm= -lfwpuclnt -lrpcrt4 -lncrypt -lsetupapi -lbcrypt -lpathcch endif diff --git a/src/openvpn/win32.c b/src/openvpn/win32.c index df29dd7..3ed28f6 100644 --- a/src/openvpn/win32.c +++ b/src/openvpn/win32.c @@ -51,6 +51,12 @@ #include "wfp_block.h" +#include + +#ifndef HAVE_PATHCCH_ENSURE_TRAILING_SLASH +#define PATHCCH_ENSURE_TRAILING_SLASH 0x20 +#endif + /* * WFP handle */ @@ -1553,12 +1559,12 @@ return false; } - WCHAR plugin_dir[MAX_PATH] =3D { 0 }; + WCHAR plugin_dir_reg[MAX_PATH] =3D { 0 }; /* Attempt to retrieve the trusted plugin directory path from the regi= stry, * using installation path as a fallback */ - if (!get_openvpn_reg_value(L"plugin_dir", plugin_dir, _countof(plugin_= dir)) - && !get_openvpn_reg_value(NULL, plugin_dir, _countof(plugin_dir))) + if (!get_openvpn_reg_value(L"plugin_dir", plugin_dir_reg, _countof(plu= gin_dir_reg)) + && !get_openvpn_reg_value(NULL, plugin_dir_reg, _countof(plugin_di= r_reg))) { msg(M_WARN, "Installation path could not be determined."); } @@ -1570,26 +1576,35 @@ msg(M_NONFATAL | M_ERRNO, "Failed to get system directory."); } - if ((wcslen(plugin_dir) =3D=3D 0) && (wcslen(system_dir) =3D=3D 0)) + if ((wcslen(plugin_dir_reg) =3D=3D 0) && (wcslen(system_dir) =3D=3D 0)) { return false; } - WCHAR normalized_plugin_dir[MAX_PATH] =3D { 0 }; + WCHAR plugin_dir[MAX_PATH] =3D { 0 }; - /* Normalize the plugin dir */ - if (wcslen(plugin_dir) > 0) + /* normalize and canonicalize the plugin dir and add trailing slash */ + if (wcslen(plugin_dir_reg) > 0) { - if (!GetFullPathNameW(plugin_dir, MAX_PATH, normalized_plugin_dir,= NULL)) + WCHAR normalized_plugin_dir[MAX_PATH] =3D { 0 }; + if (!GetFullPathNameW(plugin_dir_reg, MAX_PATH, normalized_plugin_= dir, NULL)) { msg(M_NONFATAL | M_ERRNO, "Failed to normalize plugin dir."); + } + + HRESULT res =3D PathCchCanonicalizeEx(plugin_dir, _countof(plugin_= dir), normalized_plugin_dir, + PATHCCH_ENSURE_TRAILING_SLASH); + if (res !=3D S_OK) + { + /* doc says we cannot rely on GetLastError() */ + msg(M_NONFATAL, "Failed to canonicalize plugin dir."); return false; } } /* Check if the plugin path resides within the plugin/install director= y */ - if ((wcslen(normalized_plugin_dir) > 0) - && (wcsnicmp(normalized_plugin_dir, plugin_path, wcslen(normalized= _plugin_dir)) =3D=3D 0)) + if ((wcslen(plugin_dir) > 0) + && (wcsnicmp(plugin_dir, plugin_path, wcslen(plugin_dir)) =3D=3D 0= )) { return true; } -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1332?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings?usp=3Demail Gerrit-MessageType: newpatchset Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I5ea90594493ab5cb858f7495f773e080b379e8e8 Gerrit-Change-Number: 1332 Gerrit-PatchSet: 2 Gerrit-Owner: stipa Gerrit-Reviewer: cron2 Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: flichtenheld Gerrit-Attention: stipa --O2BOPlzUIfQ= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is cur= rently required from: flichtenheld, plaisthos, stipa.

stipa uploaded patch set #2 to this change.

View Change

win32: ensure plugin dir has the trailing slash

= This prevents loading plugins from the directories
which share initial c= haracters with the trusted path.

Reported-by: Joshua Rogers <cont= act@...2949...>
Found-by: ZeroPath (https://zeropath.com/)

Cha= nge-Id: I5ea90594493ab5cb858f7495f773e080b379e8e8
Signed-off-by: Lev Sti= pakov <lev@...515...>
---
M CMakeLists.txt
M src/openvpn/Mak= efile.am
M src/openvpn/win32.c
3 files changed, 30 insertions(+), 12 = deletions(-)

git pull ssh://gerrit.openvpn.net:2=
9418/openvpn refs/changes/32/1332/2
diff --git a/CMakeLists.txt b/C=
MakeLists.txt
index c9301e6..6888de3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
= @@ -245,6 +245,9 @@
check_symbol_exists(chsize io.h HAVE_C= HSIZE)
check_symbol_exists(getrlimit sys/resource.h HAVE_G= ETRLIMIT)

+# Some old versions of mingw does not have PATHCCH_OPTIONS enums --= add a check
+check_s= ymbol_exists(PATHCCH_ENSURE_TRAILING_SLASH pathcch.h HAVE_PATHCCH_ENSURE_TR= AILING_SLASH)
+

# Some OS (e.g. FreeBSD) need some basic headers to allow
# including network headers
set(NETEXTRA sys/t= ypes.h)
@@ -338,7 +341,7 @@
if (WI= N32)
target_link_libraries(${target} PUBLIC
ws2_32.lib crypt32.lib fwpuclnt.lib iphlpapi= .lib
- w= ininet.lib setupapi.lib rpcrt4.lib wtsapi32.lib ncrypt.lib bcrypt.lib)
+ wininet.= lib setupapi.lib rpcrt4.lib wtsapi32.lib ncrypt.lib bcrypt.lib pathcch.lib)=
endif ()

e= ndif ()
diff --git a/src/openvpn/Makefile.am b/src/openvpn/= Makefile.am
index db87dfc..a2b5e92 100644
-= -- a/src/openvpn/Makefile.am
+++ b/src/openvpn/Makefile.am<= /span>
@@ -166,5 +166,5 @@
$(OPTIONAL_INOTIFY_LI= BS)
if WIN32
openvpn_SOURCES +=3D openvpn= _win32_resources.rc wfp_block.c wfp_block.h
-openvpn_LDADD +=3D -lgdi32 -lws2_32 -lwininet -lcrypt= 32 -liphlpapi -lwinmm -lfwpuclnt -lrpcrt4 -lncrypt -lsetupapi -lbcrypt
+openvpn_LDADD +=3D -lgdi= 32 -lws2_32 -lwininet -lcrypt32 -liphlpapi -lwinmm -lfwpuclnt -lrpcrt4 -lnc= rypt -lsetupapi -lbcrypt -lpathcch
endif
d= iff --git a/src/openvpn/win32.c b/src/openvpn/win32.c
index= df29dd7..3ed28f6 100644
--- a/src/openvpn/win32.c+++ b/src/openvpn/win32.c
@@ -51,6 +51,12 @@=

#include "wfp_block.h"

+#include <pa= thcch.h>
+<= br>+#ifndef HAVE_PATHCCH_ENSURE= _TRAILING_SLASH
+#def= ine PATHCCH_ENSURE_TRAILING_SLASH 0x20
+#endif
+
/*
* WFP handle
= */
@@ -1553,12 +1559,12 @@
return= false;
}

- WCHAR plugin_dir[MAX_PATH] =3D { 0 };=
+ WCHAR plugin_dir_reg[M= AX_PATH] =3D { 0 };

/* Attempt to re= trieve the trusted plugin directory path from the registry,
* using installation path as a fallback */

- if (!get_openvpn_reg_value(L"plugin_di= r", plugin_dir, _countof(plugin_dir))
- && !get_openvpn_reg_value(NULL, plugin= _dir, _countof(plugin_dir)))
+ if (!get_openvpn_reg_value(L"plugin_dir", plugin_dir= _reg, _countof(plugin_dir_reg))
+ && !get_openvpn_reg_value(NULL, plugin_dir_reg,= _countof(plugin_dir_reg)))
{
= msg(M_WARN, "Installation path could not be determined.");
}
@@ -1570,26 +1576,35 @@
= msg(M_NONFATAL | M_ERRNO, "Failed to get system directory.&quo= t;);
}

- if ((wcslen(plugin_dir) =3D=3D 0) && (w= cslen(system_dir) =3D=3D 0))
+ if ((wcslen(plugin_dir_reg) =3D=3D 0) && (wcslen(syste= m_dir) =3D=3D 0))
{
return fa= lse;
}

- WCHAR normalized_plugin_dir[MAX_PATH] =3D { 0 }= ;
+ WCHAR plugin_d= ir[MAX_PATH] =3D { 0 };

- /* Normalize the plugin dir */
- if (wcslen(plugin_dir) > 0)<= br>+ /* normalize and canoni= calize the plugin dir and add trailing slash */
+ if (wcslen(plugin_dir_reg) > 0) {
- = if (!GetFullPathNameW(plugin_dir, MAX_PATH, normalized_plugin_dir, NULL))<= /span>
+ WCHAR normal= ized_plugin_dir[MAX_PATH] =3D { 0 };
+ if (!GetFullPathNameW(plugin_dir_reg, MAX_PATH, no= rmalized_plugin_dir, NULL))
{
= msg(M_NONFATAL | M_ERRNO, "Failed to normalize plugin dir.&qu= ot;);
+ }
+
+ HRESULT res =3D PathCchCanonicali= zeEx(plugin_dir, _countof(plugin_dir), normalized_plugin_dir,
+ = PATHCCH_ENSURE_TRAILING_SLASH);

+ if (res !=3D S_OK)
+ {
+ /* doc says we cannot rely on GetLastError(= ) */
+ msg= (M_NONFATAL, "Failed to canonicalize plugin dir.");
return false;

}
= }

/* Check if the plugin path res= ides within the plugin/install directory */
- if ((wcslen(normalized_plugin_dir) > 0)=
- && (wcsnicmp= (normalized_plugin_dir, plugin_path, wcslen(normalized_plugin_dir)) =3D=3D = 0))
+ if ((wcslen(= plugin_dir) > 0)
+= && (wcsnicmp(plugin_dir, plugin_path, wcslen(plugin_dir)) = =3D=3D 0))
{
return true;
}

To view, visit change 1332<= /a>. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I5ea90594493ab5cb858f7495f77= 3e080b379e8e8
Gerrit-Change-Number: 1332
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-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
Gerrit-Attention: stipa <lstipakov@...1663...= .>
= --O2BOPlzUIfQ=--