From: "stipa (Code Review)" Date: Thu, 30 Oct 2025 14:11:43 +0000 In-Reply-To: References: Reply-To: lstipakov@...277..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <28143412a9658f544a35b30e574cd3cfd98b08f7-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="FiSGQ7ww0e8="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: openvpnserv: validate openvpn-gui process path List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos , flichtenheld Cc: openvpn-devel --FiSGQ7ww0e8= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: flichtenheld, plaisthos. Hello flichtenheld, plaisthos, I'd like you to reexamine a change. Please visit http://gerrit.openvpn.net/c/openvpn/+/1333?usp=3Demail to look at the new patch set (#2). Change subject: openvpnserv: validate openvpn-gui process path ...................................................................... openvpnserv: validate openvpn-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/2 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: newpatchset Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: Ie990f4dd10094810d6632f8dedfa261727ebfbcb Gerrit-Change-Number: 1333 Gerrit-PatchSet: 2 Gerrit-Owner: stipa Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: flichtenheld --FiSGQ7ww0e8= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

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

stipa uploaded patch set #2 to this change.

View Change

openvpnserv: validate openvpn-gui process path

E= nsure that the service pipe client process (which is openvpn-gui)
is fro= m openvpn binary directory, defined in registry. This limits
unauthorize= d connections to the service pipe.

Reported-by: Abdul Mhanni <abd= ul.mhanni@...2951...>

Change-Id: Ie990f4dd10094810d6632f8dedfa261= 727ebfbcb
Signed-off-by: Lev Stipakov <lev@...515...>
---
M = src/openvpnserv/interactive.c
M src/openvpnserv/validate.c
M src/open= vpnserv/validate.h
3 files changed, 55 insertions(+), 0 deletions(-)
=
git pull ssh://gerrit.openvpn.net:29418/openvpn ref=
s/changes/33/1333/2
diff --git a/src/openvpnserv/interactive.c b/sr=
c/openvpnserv/interactive.c
index ce0d4dd..f4b3311 100644
--- a/src/openvpnserv/interactive.c
+++ b/sr= c/openvpnserv/interactive.c
@@ -3275,6 +3275,12 @@ ZeroMemory(&undo_lists, sizeof(undo_lists));
ZeroMemory(&proc_info, sizeof(proc_info));


+ if (!ValidateServi= cePipeClient(pipe, &settings))
+ {
= + ReturnError(pipe, ERROR_ACCESS_DENIED, L"ValidateServicePipeC= lient", 1, &exit_event);
+ goto out;
+ }
+
if (!GetStartupData(pipe, &sud))
= {
goto out;
diff --git a/src/op= envpnserv/validate.c b/src/openvpnserv/validate.c
index 218= 7fb5..c5688d2 100644
--- a/src/openvpnserv/validate.c
+++ b/src/openvpnserv/validate.c
@@ -342,3 +342,= 48 @@

return TRUE;
= }
+
+BOOL
+ValidateServicePipeClient(HANDLE pipe, const setting= s_t *s)
+{
= + ULONG clientPID =3D 0;
+ if (!GetNamedPipeCl= ientProcessId(pipe, &clientPID))
+ {
+ = return FALSE;
+ }<= /span>
+
+ HANDLE hProc =3D OpenProcess(PROCES= S_QUERY_LIMITED_INFORMATION, FALSE, clientPID);
+ if (hProc =3D=3D NULL)
+ {
+ MsgToEventLog(M_SYSERR, L"OpenProcess() f= ailed");
+ = 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 sla= sh 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&q= uot;QueryFullProcessImageNameW() failed");

+ }
+ CloseHandle(hProc);
+
+ = return res;
+}
diff --git a/src/openvpnserv/validate.h b/src/openvpnserv/vali= date.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);
}
<= br>+/* Ensures that the service= pipe client (openvpn-gui process)
+ * is from OpenVPN binary directory */
+BOOL ValidateServicePipeClient(HANDLE pip= e, const settings_t *s);
+
#endif /* ifndef VALIDATE_H */

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

=
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ie990f4dd10094810d6632f8dedf= a261727ebfbcb
Gerrit-Change-Number: 1333
Gerrit-PatchSet: 2
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...>
= --FiSGQ7ww0e8=--