From: "d12fk (Code Review)" Date: Fri, 7 Nov 2025 18:23:15 +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: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="NzVG3wc1iIk="; 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 , selvanair Cc: openvpn-devel --NzVG3wc1iIk= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: cron2, flichtenheld, plaisthos, selva= nair. Hello cron2, flichtenheld, plaisthos, selvanair, 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 (#6). The following approvals got outdated and were removed: Code-Review+2 by selvanair 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. 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/6 diff --git a/src/openvpnserv/validate.c b/src/openvpnserv/validate.c index ddaa381..2dcfe1a 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, _countof(config_path), workdir= , fname); } else { - config_file =3D fname; + res =3D PathCchCanonicalize(config_path, _countof(config_path), fn= ame); } - /* 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 && wcsncmp(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: 6 Gerrit-Owner: d12fk Gerrit-Reviewer: cron2 Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-Reviewer: selvanair Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: cron2 Gerrit-Attention: flichtenheld Gerrit-Attention: selvanair --NzVG3wc1iIk= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

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

d12fk uploaded patch set #6 to this change.

View Change

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

iservice: validate config path =
better

Instead of just rejecting any path that contains "..&quo= t; use some WIN32 API
functions to combine, canonicalize and then check = if the resulting
path is located under the config directory. Makes the c= ode prettier
and more correct.

Change-Id: I0e94068f467f2899daf133= b032a785d2d7fc05e4
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:=
29418/openvpn refs/changes/07/1307/6
diff --git a/src/openvpnserv/v=
alidate.c b/src/openvpnserv/validate.c
index ddaa381..2dcfe= 1a 100644
--- a/src/openvpnserv/validate.c
= +++ b/src/openvpnserv/validate.c
@@ -24,8 +24,8 @@
#include <lmaccess.h>
#in= clude <shlwapi.h>
-#include <lm.h>
#include <pathcch.h><= br>+#include <lm.h>

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

/*
- * Check workdir\fname is inside config_d= ir
- * The logic here i= s simple: we may reject some valid paths if ..\ is in any of the strings
+ * Check that config p= ath is inside config_dir
+ * The logic here is simple: if the path isn't prefixed with confi= g_dir it's rejected
*/
static BOOL
CheckConfigPath(const WCHAR *workdir, const WCHAR *fname, c= onst settings_t *s)
{
- WCHAR tmp[MAX_PATH];
- const WCHAR *config_file =3D NULL;
- WCHAR config_dir[MAX_PATH];=
+ HRESULT res;+ WCHAR config_path[MAX_PAT= H];

/* fname =3D stdin is special: d= o 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 PathCchCombi= ne(config_path, _countof(config_path), workdir, fname);
= }
else
{
- config_file =3D fname;
+ res =3D PathCchCanonical= ize(config_path, _countof(config_path), fname);

}

- /* c= anonicalize config_dir and add trailing slash before comparison */- HRESULT res =3D PathCchCan= onicalizeEx(config_dir, _countof(config_dir), s->config_dir,
<= span style=3D"color: hsl(0, 100%, 40%);">- = PATHCCH_ENSURE_TRAILING_SLASH);

-
- = if (res =3D=3D S_OK
- = && wcsncmp(config_dir, config_file, wcslen(config_dir)) =3D= =3D 0
- &&am= p; wcsstr(config_file + wcslen(config_dir), L"..") =3D=3D NULL)
- {
- return TRUE;
- }
-
- = return FALSE;
+ = return res =3D=3D S_OK && wcsncmp(config_path, s->config_dir, wc= slen(s->config_dir)) =3D=3D 0;
}



To view, visit change 1307. T= o unsubscribe, 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: 6
Gerrit-Owner: d12fk <heiko@...515...>
Gerrit-Reviewer: cron2 <gert@...1296...>=
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-Reviewer: selvanair <selva.nair@...1665...= 77...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
Gerrit-Attention: cron2 <gert@...1296...>= ;
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
Gerrit-Attention: selvanair <selva.nair@...493...= 277...>
= --NzVG3wc1iIk=--