summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorNing Wu <nwu@vmware.com>2020-01-21 23:46:58 -0800
committerAlin Gabriel Serdean <aserdean@ovn.org>2020-01-24 16:51:34 +0200
commit929dc96d0bca21fe3dc134cf45c3e0718811536a (patch)
tree928b1688b05aec53287f9bf271c5e0c68f9d4f98 /lib
parentdbbd0cf64492426938c4ad3177cabb444b1e9163 (diff)
downloadopenvswitch-929dc96d0bca21fe3dc134cf45c3e0718811536a.tar.gz
lib/stream-windows.c: Grant Access Privilege of Named Pipe to Creator
Current implementation of ovs on windows only allows LocalSystem and Administrators to access the named pipe created with API of ovs. Thus any service that needs to invoke the API to create named pipe has to run as System account to interactive with ovs. It causes the system more vulnerable if one of those services was break into. The patch adds the creator owner account to allowed ACLs. Signed-off-by: Ning Wu <nwu@vmware.com> Acked-by: Alin Gabriel Serdean <aserdean@ovn.org> Acked-by: Anand Kumar <kumaranand@vmware.com> Signed-off-by: Alin Gabriel Serdean <aserdean@ovn.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/stream-windows.c33
1 files changed, 32 insertions, 1 deletions
diff --git a/lib/stream-windows.c b/lib/stream-windows.c
index 34bc610b6..5c4c55e5d 100644
--- a/lib/stream-windows.c
+++ b/lib/stream-windows.c
@@ -41,7 +41,7 @@ static void maybe_unlink_and_free(char *path);
#define LOCAL_PREFIX "\\\\.\\pipe\\"
/* Size of the allowed PSIDs for securing Named Pipe. */
-#define ALLOWED_PSIDS_SIZE 2
+#define ALLOWED_PSIDS_SIZE 3
/* This function has the purpose to remove all the slashes received in s. */
static char *
@@ -412,6 +412,9 @@ create_pnpipe(char *name)
PACL acl = NULL;
PSECURITY_DESCRIPTOR psd = NULL;
HANDLE npipe;
+ HANDLE hToken = NULL;
+ DWORD dwBufSize = 0;
+ PTOKEN_USER pTokenUsr = NULL;
/* Disable access over network. */
if (!AllocateAndInitializeSid(&sia, 1, SECURITY_NETWORK_RID,
@@ -438,6 +441,32 @@ create_pnpipe(char *name)
goto handle_error;
}
+ /* Open the access token of calling process */
+ if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken)) {
+ VLOG_ERR_RL(&rl, "Error opening access token of calling process.");
+ goto handle_error;
+ }
+
+ /* get the buffer size buffer needed for SID */
+ GetTokenInformation(hToken, TokenUser, NULL, 0, &dwBufSize);
+
+ pTokenUsr = xmalloc(dwBufSize);
+ memset(pTokenUsr, 0, dwBufSize);
+
+ /* Retrieve the token information in a TOKEN_USER structure. */
+ if (!GetTokenInformation(hToken, TokenUser, pTokenUsr, dwBufSize,
+ &dwBufSize)) {
+ VLOG_ERR_RL(&rl, "Error retrieving token information.");
+ goto handle_error;
+ }
+ CloseHandle(hToken);
+
+ if (!IsValidSid(pTokenUsr->User.Sid)) {
+ VLOG_ERR_RL(&rl, "Invalid SID.");
+ goto handle_error;
+ }
+ allowedPsid[2] = pTokenUsr->User.Sid;
+
for (int i = 0; i < ALLOWED_PSIDS_SIZE; i++) {
aclSize += sizeof(ACCESS_ALLOWED_ACE) +
GetLengthSid(allowedPsid[i]) -
@@ -490,11 +519,13 @@ create_pnpipe(char *name)
npipe = CreateNamedPipe(name, PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED,
PIPE_TYPE_MESSAGE | PIPE_READMODE_BYTE | PIPE_WAIT,
64, BUFSIZE, BUFSIZE, 0, &sa);
+ free(pTokenUsr);
free(acl);
free(psd);
return npipe;
handle_error:
+ free(pTokenUsr);
free(acl);
free(psd);
return INVALID_HANDLE_VALUE;