From: "d12fk (Code Review)" Date: Thu, 6 Nov 2025 20:59:21 +0000 In-Reply-To: References: Reply-To: heiko@...515..., arne-openvpn@...1227..., selva.nair@...277..., openvpn-devel@lists.sourceforge.net, frank@...2641..., gert@...1296... Message-ID: <60ec790e2fad39199a368d1131847f16c9554686-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="APhNsAG0aQ0="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: iservice: validate config path better List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos , flichtenheld Cc: openvpn-devel , selvanair --APhNsAG0aQ0= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: cron2, d12fk, flichtenheld, plaisthos. Hello cron2, flichtenheld, plaisthos, I'd like you to reexamine a change. Please visit http://gerrit.openvpn.net/c/openvpn/+/1307?usp=3Demail to look at the new patch set (#4). Change subject: iservice: validate config path better ...................................................................... iservice: validate config path better Instead of just rejecting any path that contains ".." use some WIN32 API functions to combine, canonicalize and then check if the resulting path is located under the config directory. Makes the code prettier and more correct. Also compare case insensitive, since Windows filesystems do not make a difference here. Change-Id: I0e94068f467f2899daf133b032a785d2d7fc05e4 Signed-off-by: Heiko Hund --- M src/openvpnserv/validate.c 1 file changed, 9 insertions(+), 22 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/07/1307/4 diff --git a/src/openvpnserv/validate.c b/src/openvpnserv/validate.c index ddaa381..4eb3141 100644 --- a/src/openvpnserv/validate.c +++ b/src/openvpnserv/validate.c @@ -24,8 +24,8 @@ #include #include -#include #include +#include #ifndef HAVE_PATHCCH_ENSURE_TRAILING_SLASH #define PATHCCH_ENSURE_TRAILING_SLASH 0x20 @@ -58,44 +58,31 @@ static PTOKEN_GROUPS GetTokenGroups(const HANDLE token); /* - * Check workdir\fname is inside config_dir - * The logic here is simple: we may reject some valid paths if ..\ is in a= ny of the strings + * Check that config path is inside config_dir + * The logic here is simple: if the path isn't prefixed with config_dir it= 's rejected */ static BOOL CheckConfigPath(const WCHAR *workdir, const WCHAR *fname, const settings_t= *s) { - WCHAR tmp[MAX_PATH]; - const WCHAR *config_file =3D NULL; - WCHAR config_dir[MAX_PATH]; + HRESULT res; + WCHAR config_path[MAX_PATH]; /* fname =3D stdin is special: do not treat it as a relative path */ if (wcscmp(fname, L"stdin") =3D=3D 0) { return FALSE; } - /* convert fname to full path */ + /* convert fname to full canonical path */ if (PathIsRelativeW(fname)) { - swprintf(tmp, _countof(tmp), L"%ls\\%ls", workdir, fname); - config_file =3D tmp; + res =3D PathCchCombine(config_path, sizeof(config_path), workdir, = fname); } else { - config_file =3D fname; + res =3D PathCchCanonicalize(config_path, sizeof(config_path), fnam= e); } - /* canonicalize config_dir and add trailing slash before comparison */ - HRESULT res =3D PathCchCanonicalizeEx(config_dir, _countof(config_dir)= , s->config_dir, - PATHCCH_ENSURE_TRAILING_SLASH); - - if (res =3D=3D S_OK - && wcsncmp(config_dir, config_file, wcslen(config_dir)) =3D=3D 0 - && wcsstr(config_file + wcslen(config_dir), L"..") =3D=3D NULL) - { - return TRUE; - } - - return FALSE; + return res =3D=3D S_OK && wcsnicmp(config_path, s->config_dir, wcslen(= s->config_dir)) =3D=3D 0; } -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1307?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: I0e94068f467f2899daf133b032a785d2d7fc05e4 Gerrit-Change-Number: 1307 Gerrit-PatchSet: 4 Gerrit-Owner: d12fk Gerrit-Reviewer: cron2 Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-CC: selvanair Gerrit-Attention: plaisthos Gerrit-Attention: cron2 Gerrit-Attention: flichtenheld Gerrit-Attention: d12fk --APhNsAG0aQ0= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

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

d12fk uploaded patch set #4 to this change.

View Change

iservice: validate config path better

Instead of= just rejecting any path that contains ".." use some WIN32 APIfunctions to combine, canonicalize and then check if the resulting
path= is located under the config directory. Makes the code prettier
and more= correct.

Also compare case insensitive, since Windows filesystems d= o not make a
difference here.

Change-Id: I0e94068f467f2899daf133b= 032a785d2d7fc05e4
Signed-off-by: Heiko Hund <heiko@...2662...>
= ---
M src/openvpnserv/validate.c
1 file changed, 9 insertions(+), 22 = deletions(-)

git pull ssh://gerrit.openvpn.net:2=
9418/openvpn refs/changes/07/1307/4
diff --git a/src/openvpnserv/va=
lidate.c b/src/openvpnserv/validate.c
index ddaa381..4eb314= 1 100644
--- a/src/openvpnserv/validate.c
+= ++ b/src/openvpnserv/validate.c
@@ -24,8 +24,8 @@
#include <lmaccess.h>
#inc= lude <shlwapi.h>
= -#include <lm.h>
#include <pathcch.h>+#include <lm.h>=

#ifndef HAVE_PATHCCH_ENSURE_TRAILING_SLASH
#define PATHCCH_ENSURE_TRAILING_SLASH 0x20
@@= -58,44 +58,31 @@
static PTOKEN_GROUPS GetTokenGroups(cons= t HANDLE token);

/*
- * Check workdir\fname is inside config_di= r
- * The logic here is= simple: we may reject some valid paths if ..\ is in any of the strings
+ * Check that config pa= th is inside config_dir
+ * The logic here is simple: if the path isn't prefixed with config= _dir it's rejected
*/
static BOOL
CheckConfigPath(const WCHAR *workdir, const WCHAR *fname, co= nst settings_t *s)
{
- WCHAR tmp[MAX_PATH];
- const WCHAR *config_file =3D NULL;
- WCHAR config_dir[MAX_PATH];<= br>+ HRESULT res;
= + WCHAR config_path[MAX_PATH= ];

/* fname =3D stdin is special: do= not treat it as a relative path */
if (wcscmp(fname, = L"stdin") =3D=3D 0)
{
= return FALSE;
}
- /* convert fname to full path */
+ /* convert fname to full canonical p= ath */
if (PathIsRelativeW(fname))
= {
- swprintf(t= mp, _countof(tmp), L"%ls\\%ls", workdir, fname);
- config_file =3D tmp;+ res =3D PathCchCombin= e(config_path, sizeof(config_path), workdir, fname);
}=
else
{
- config_file =3D fname;
+ res =3D PathCchCanonicalize(= config_path, sizeof(config_path), fname);
}
=
- /* canonic= alize config_dir and add trailing slash before comparison */
- HRESULT res =3D PathCchCanonical= izeEx(config_dir, _countof(config_dir), s->config_dir,

- = PATHCCH_ENSURE_TRAILING_SLASH);
-
- if (re= s =3D=3D S_OK
- = && wcsncmp(config_dir, config_file, wcslen(config_dir)) =3D=3D 0
- && wcsst= r(config_file + wcslen(config_dir), L"..") =3D=3D NULL)- {
- return TRUE;
- }
-
- return= FALSE;
+ return r= es =3D=3D S_OK && wcsnicmp(config_path, s->config_dir, wcslen(s-= >config_dir)) =3D=3D 0;
}

<= span>


To view, visit change 1307. To unsub= scribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I0e94068f467f2899daf133b032a= 785d2d7fc05e4
Gerrit-Change-Number: 1307
Gerrit-PatchSet: 4
Gerrit-Owner: d12fk <heiko@...515...>
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-CC: selvanair <selva.nair@...277...&= gt;
Gerrit-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
Gerrit-Attention: cron2 <gert@...1296...>= ;
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
Gerrit-Attention: d12fk <heiko@...515...>= ;
= --APhNsAG0aQ0=--