From: "stipa (Code Review)" Date: Thu, 30 Oct 2025 14:11:24 +0000 References: Reply-To: lstipakov@...277..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <919c933c21b99b20d9b61fc9d6787b8ecbf0cf21-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="Z1PNA5aKr6E="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: openvpnserv: validate opevnvpn-gui process path List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos , flichtenheld Cc: openvpn-devel --Z1PNA5aKr6E= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: flichtenheld, plaisthos. Hello plaisthos, flichtenheld, I'd like you to do a code review. Please visit http://gerrit.openvpn.net/c/openvpn/+/1333?usp=3Demail to review the following change. Change subject: openvpnserv: validate opevnvpn-gui process path ...................................................................... openvpnserv: validate opevnvpn-gui process path Ensure that the service pipe client process (which is openvpn-gui) is from openvpn binary directory, defined in registry. This limits unauthorized connections to the service pipe. Reported-by: Abdul Mhanni Change-Id: Ie990f4dd10094810d6632f8dedfa261727ebfbcb Signed-off-by: Lev Stipakov --- M src/openvpnserv/interactive.c M src/openvpnserv/validate.c M src/openvpnserv/validate.h 3 files changed, 55 insertions(+), 0 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/33/1333/1 diff --git a/src/openvpnserv/interactive.c b/src/openvpnserv/interactive.c index ce0d4dd..f4b3311 100644 --- a/src/openvpnserv/interactive.c +++ b/src/openvpnserv/interactive.c @@ -3275,6 +3275,12 @@ ZeroMemory(&undo_lists, sizeof(undo_lists)); ZeroMemory(&proc_info, sizeof(proc_info)); + if (!ValidateServicePipeClient(pipe, &settings)) + { + ReturnError(pipe, ERROR_ACCESS_DENIED, L"ValidateServicePipeClient= ", 1, &exit_event); + goto out; + } + if (!GetStartupData(pipe, &sud)) { goto out; diff --git a/src/openvpnserv/validate.c b/src/openvpnserv/validate.c index 2187fb5..c5688d2 100644 --- a/src/openvpnserv/validate.c +++ b/src/openvpnserv/validate.c @@ -342,3 +342,48 @@ return TRUE; } + +BOOL +ValidateServicePipeClient(HANDLE pipe, const settings_t *s) +{ + ULONG clientPID =3D 0; + if (!GetNamedPipeClientProcessId(pipe, &clientPID)) + { + MsgToEventLog(M_SYSERR, L"GetNamedPipeClientProcessId() failed"); + return FALSE; + } + + HANDLE hProc =3D OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE,= clientPID); + if (hProc =3D=3D NULL) + { + MsgToEventLog(M_SYSERR, L"OpenProcess() failed"); + return FALSE; + } + + wchar_t path[MAX_PATH] =3D { 0 }; + DWORD size =3D _countof(path); + BOOL res =3D FALSE; + if (QueryFullProcessImageNameW(hProc, 0, path, &size)) + { + WCHAR bin_dir[MAX_PATH]; + + /* canonicalize bin_dir and add trailing slash before comparison */ + HRESULT hr =3D PathCchCanonicalizeEx(bin_dir, _countof(bin_dir), s= ->bin_dir, + PATHCCH_ENSURE_TRAILING_SLASH); + if ((hr =3D=3D S_OK) && wcsncmp(bin_dir, path, wcslen(bin_dir)) = =3D=3D 0) + { + res =3D TRUE; + } + else + { + MsgToEventLog(M_ERR, L"Reject client from untrusted path %ls",= path); + } + } + else + { + MsgToEventLog(M_SYSERR, L"QueryFullProcessImageNameW() failed"); + } + CloseHandle(hProc); + + return res; +} diff --git a/src/openvpnserv/validate.h b/src/openvpnserv/validate.h index 6f3bf09..495902d 100644 --- a/src/openvpnserv/validate.h +++ b/src/openvpnserv/validate.h @@ -49,4 +49,8 @@ return (wcsncmp(o, L"--", 2) =3D=3D 0); } +/* Ensures that the service pipe client (openvpn-gui process) + * is from OpenVPN binary directory */ +BOOL ValidateServicePipeClient(HANDLE pipe, const settings_t *s); + #endif /* ifndef VALIDATE_H */ -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1333?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings?usp=3Demail Gerrit-MessageType: newchange Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: Ie990f4dd10094810d6632f8dedfa261727ebfbcb Gerrit-Change-Number: 1333 Gerrit-PatchSet: 1 Gerrit-Owner: stipa Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: flichtenheld --Z1PNA5aKr6E= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

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

stipa would like plaisthos and flichtenheld to review t= his change.

V= iew Change

openvpnserv: validate opevnvpn-gui process =
path

Ensure that the service pipe client process (which is openvpn-g= ui)
is from openvpn binary directory, defined in registry. This limitsunauthorized connections to the service pipe.

Reported-by: Abdul M= hanni <abdul.mhanni@...2951...>

Change-Id: Ie990f4dd10094810d6= 632f8dedfa261727ebfbcb
Signed-off-by: Lev Stipakov <lev@...515...>=
---
M src/openvpnserv/interactive.c
M src/openvpnserv/validate.c<= br>M src/openvpnserv/validate.h
3 files changed, 55 insertions(+), 0 del= etions(-)

git pull ssh://gerrit.openvpn.net:2941=
8/openvpn refs/changes/33/1333/1
diff --git a/src/openvpnserv/inter=
active.c b/src/openvpnserv/interactive.c
index ce0d4dd..f4b= 3311 100644
--- a/src/openvpnserv/interactive.c
<= span>+++ b/src/openvpnserv/interactive.c
@@ -3275,6 +3275,1= 2 @@
ZeroMemory(&undo_lists, sizeof(undo_lists));<= /span>
ZeroMemory(&proc_info, sizeof(proc_info));<= br>
+ if (!= ValidateServicePipeClient(pipe, &settings))
+ {
+ ReturnError(pipe, ERROR_ACCESS_DENIED, L"Validat= eServicePipeClient", 1, &exit_event);
+ goto out;
+ }
+
if (!GetStartupData(pipe, &sud))
{
goto out;
diff -= -git a/src/openvpnserv/validate.c b/src/openvpnserv/validate.c
index 2187fb5..c5688d2 100644

--- a/src/openvpnserv/val= idate.c
+++ b/src/openvpnserv/validate.c
@@= -342,3 +342,48 @@

return TRUE;
}
+
+BOOL
+ValidateServicePipeClient(HANDLE pipe, = const settings_t *s)
= +{
+ ULONG clientP= ID =3D 0;
+ if (!G= etNamedPipeClientProcessId(pipe, &clientPID))
+ {
+ MsgToEventLog(M_SYSERR, L"GetNamedPipeClientPr= ocessId() failed");
+ return FALSE;
+ }
+=
+ HANDLE hProc =3D OpenP= rocess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, clientPID);
+ if (hProc =3D=3D NULL)
<= br>+ {
+ MsgToEventLog(M_SYSERR, L"Op= enProcess() failed");
+ return FALSE;
+ }
+
+ wchar_t path[MAX_PAT= H] =3D { 0 };
+ DW= ORD size =3D _countof(path);
+ BOOL res =3D FALSE;
+ if (QueryFullProcessImageNameW(hProc, 0, path, &size))=
+ {
+ WCHAR bin_dir[MAX_PATH];<= /span>
+
+ /* canonicalize bin_dir and add= trailing slash before comparison */
+ HRESULT hr =3D PathCchCanonicalizeEx(bin_dir, _cou= ntof(bin_dir), s->bin_dir,
+ PATHCCH_ENSURE_TRAILIN= G_SLASH);
+ if= ((hr =3D=3D S_OK) && wcsncmp(bin_dir, path, wcslen(bin_dir)) =3D= =3D 0)
+ {

+ res =3D TRU= E;
+ }<= br>+ else
+ {

+ MsgToEventLog(M_ERR, L"Reje= ct client from untrusted path %ls", path);
+ }
+ }
+ else
+ {
+ MsgToEventLog= (M_SYSERR, L"QueryFullProcessImageNameW() failed");
+ }

+ CloseHandle(hProc);
+
+ return res;
+}
diff --git a/src/openvpnserv/validate.h b/src/= openvpnserv/validate.h
index 6f3bf09..495902d 100644=
--- a/src/openvpnserv/validate.h
+++ b/src/openvp= nserv/validate.h
@@ -49,4 +49,8 @@
ret= urn (wcsncmp(o, L"--", 2) =3D=3D 0);
}
+/* Ensures = that the service pipe client (openvpn-gui process)
+ * is from OpenVPN binary directory */
+BOOL ValidateServicePipeC= lient(HANDLE pipe, const settings_t *s);
+
#endif /* ifndef VALIDATE_H */

To view, visit change 1333. To unsubscribe, or f= or help writing mail filters, visit settings.

Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ie990f4dd10094810d6632f8dedf= a261727ebfbcb
Gerrit-Change-Number: 1333
Gerrit-PatchSet: 1
Gerrit-Owner: stipa <lstipakov@...277...>= ;
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...>
= --Z1PNA5aKr6E=--