Browse Source

win-capture: Always use minimal access rights within hook

This prevents issues with opening handles to objects within UWP
programs, which have increased security limitations.
jp9000 9 years ago
parent
commit
746061fb3a

+ 3 - 1
plugins/win-capture/graphics-hook-info.h

@@ -101,6 +101,8 @@ struct hook_info {
 
 #pragma pack(pop)
 
+#define GC_MAPPING_FLAGS (FILE_MAP_READ | FILE_MAP_WRITE)
+
 static inline HANDLE get_hook_info(DWORD id)
 {
 	HANDLE handle;
@@ -111,7 +113,7 @@ static inline HANDLE get_hook_info(DWORD id)
 			PAGE_READWRITE, 0, sizeof(struct hook_info), new_name);
 
 	if (!handle && GetLastError() == ERROR_ALREADY_EXISTS) {
-		handle = OpenFileMappingA(FILE_MAP_ALL_ACCESS, false,
+		handle = OpenFileMappingA(GC_MAPPING_FLAGS, false,
 				new_name);
 	}
 

+ 1 - 1
plugins/win-capture/graphics-hook/graphics-hook.c

@@ -88,7 +88,7 @@ static HANDLE init_mutex(const char *name, DWORD pid)
 
 	sprintf(new_name, "%s%lu", name, pid);
 
-	handle = OpenMutexA(MUTEX_ALL_ACCESS, false, new_name);
+	handle = OpenMutexA(SYNCHRONIZE, false, new_name);
 	if (!handle)
 		hlog("Failed to open mutex '%s': %lu", name, GetLastError());
 	return handle;

+ 1 - 1
plugins/win-capture/graphics-hook/graphics-hook.h

@@ -143,7 +143,7 @@ static inline HMODULE load_system_library(const char *name)
 
 static inline bool capture_alive(void)
 {
-	HANDLE event = OpenEventA(EVENT_ALL_ACCESS, false, keepalive_name);
+	HANDLE event = OpenEventA(GC_EVENT_FLAGS, false, keepalive_name);
 	if (event) {
 		CloseHandle(event);
 		return true;

+ 5 - 2
plugins/win-capture/hook-helpers.h

@@ -4,11 +4,14 @@
 #define inline __inline
 #endif
 
+#define GC_EVENT_FLAGS (EVENT_MODIFY_STATE | SYNCHRONIZE)
+#define GC_MUTEX_FLAGS (SYNCHRONIZE)
+
 static inline HANDLE get_event(const char *name)
 {
 	HANDLE event = CreateEventA(NULL, false, false, name);
 	if (!event)
-		event = OpenEventA(EVENT_ALL_ACCESS, false, name);
+		event = OpenEventA(GC_EVENT_FLAGS, false, name);
 
 	return event;
 }
@@ -17,7 +20,7 @@ static inline HANDLE get_mutex(const char *name)
 {
 	HANDLE event = CreateMutexA(NULL, false, name);
 	if (!event)
-		event = OpenMutexA(MUTEX_ALL_ACCESS, false, name);
+		event = OpenMutexA(GC_MUTEX_FLAGS, false, name);
 
 	return event;
 }