Skip to content

Commit 878c2f4

Browse files
committed
[WIN32K:NTUSER] Implement security infrastructure for NTUSER component
Implement a base security infrastructure with code that sets up a security descriptor for the service that we're going to connect through it. Such service is based upon a desktop and a window station. === DOCUMENTATION REMARKS === The authenticated user, represented by an access token that describes its security context, is the main holder and has ultimate power against the default created desktop and window station objects in USER. The authenticated user in question is the actual logged in user, this is the case when the server is impersonating a client. Administrators on the other hand have some share of power against default desktop but their power in question is extremely limited against the default window station as admins can only just enumerate the available and valid handle stations within a desktop.
1 parent bee9b2f commit 878c2f4

File tree

10 files changed

+617
-56
lines changed

10 files changed

+617
-56
lines changed

win32ss/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ list(APPEND SOURCE
144144
user/ntuser/prop.c
145145
user/ntuser/scrollbar.c
146146
user/ntuser/scrollex.c
147+
user/ntuser/security.c
147148
user/ntuser/session.c
148149
user/ntuser/shutdown.c
149150
user/ntuser/simplecall.c

win32ss/gdi/ntgdi/gdidbg.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ DBG_CHANNEL DbgChannels[DbgChCount] = {
8787
{L"UserProcess", DbgChUserProcess},
8888
{L"UserProp", DbgChUserProp},
8989
{L"UserScrollbar", DbgChUserScrollbar},
90+
{L"UserSecurity", DbgChUserSecurity},
9091
{L"UserShutdown", DbgChUserShutdown},
9192
{L"UserSysparams", DbgChUserSysparams},
9293
{L"UserTimer", DbgChUserTimer},

win32ss/pch.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <ndk/mmfuncs.h>
2626
#include <ndk/obfuncs.h>
2727
#include <ndk/psfuncs.h>
28+
#include <ndk/sefuncs.h>
2829
#include <ndk/rtlfuncs.h>
2930
#include <ntstrsafe.h>
3031
#include <ntintsafe.h>

win32ss/user/ntuser/desktop.c

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,7 @@ IntResolveDesktop(
555555
LUID ProcessLuid;
556556
USHORT StrSize;
557557
SIZE_T MemSize;
558+
PSECURITY_DESCRIPTOR ServiceSD = NULL;
558559
POBJECT_ATTRIBUTES ObjectAttributes = NULL;
559560
PUNICODE_STRING ObjectName;
560561
UNICODE_STRING WinStaName, DesktopName;
@@ -1012,16 +1013,29 @@ IntResolveDesktop(
10121013
}
10131014
ObjectName->Length = (USHORT)(wcslen(ObjectName->Buffer) * sizeof(WCHAR));
10141015

1016+
/*
1017+
* Set up a security descriptor for the service.
1018+
* A service is generally based upon a desktop
1019+
* and a window station. The newly created window
1020+
* station and desktop will get this security descriptor
1021+
* if such objects weren't created before.
1022+
*/
1023+
Status = IntCreateServiceSecurity(&ServiceSD);
1024+
if (!NT_SUCCESS(Status))
1025+
{
1026+
ERR("Failed to create a security descriptor for default window station, Status 0x%08lx\n", Status);
1027+
goto Quit;
1028+
}
1029+
10151030
/*
10161031
* Create or open the non-interactive window station.
10171032
* NOTE: The non-interactive window station handle is never inheritable.
10181033
*/
1019-
// FIXME: Set security!
10201034
InitializeObjectAttributes(ObjectAttributes,
10211035
ObjectName,
10221036
OBJ_CASE_INSENSITIVE | OBJ_OPENIF,
10231037
NULL,
1024-
NULL);
1038+
ServiceSD);
10251039

10261040
Status = IntCreateWindowStation(&hWinSta,
10271041
ObjectAttributes,
@@ -1054,8 +1068,11 @@ IntResolveDesktop(
10541068
}
10551069
ObjectName->Length = (USHORT)(wcslen(ObjectName->Buffer) * sizeof(WCHAR));
10561070

1057-
/* NOTE: The non-interactive desktop handle is never inheritable. */
1058-
// FIXME: Set security!
1071+
/*
1072+
* NOTE: The non-interactive desktop handle is never inheritable.
1073+
* The security descriptor is inherited from the newly created
1074+
* window station for the desktop.
1075+
*/
10591076
InitializeObjectAttributes(ObjectAttributes,
10601077
ObjectName,
10611078
OBJ_CASE_INSENSITIVE | OBJ_OPENIF,
@@ -1175,6 +1192,8 @@ IntResolveDesktop(
11751192
{
11761193
*phWinSta = hWinSta;
11771194
*phDesktop = hDesktop;
1195+
1196+
IntFreeSecurityBuffer(ServiceSD);
11781197
return STATUS_SUCCESS;
11791198
}
11801199
else
@@ -1191,6 +1210,9 @@ IntResolveDesktop(
11911210
if (hWinSta)
11921211
ObCloseHandle(hWinSta, UserMode);
11931212

1213+
if (ServiceSD)
1214+
IntFreeSecurityBuffer(ServiceSD);
1215+
11941216
SetLastNtError(Status);
11951217
return Status;
11961218
}

win32ss/user/ntuser/desktop.h

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -55,32 +55,6 @@ typedef struct _DESKTOP
5555
#define DT_GWL_PROCESSID 0
5656
#define DT_GWL_THREADID 4
5757

58-
#define DESKTOP_READ STANDARD_RIGHTS_READ | \
59-
DESKTOP_ENUMERATE | \
60-
DESKTOP_READOBJECTS
61-
62-
#define DESKTOP_WRITE STANDARD_RIGHTS_WRITE | \
63-
DESKTOP_CREATEMENU | \
64-
DESKTOP_CREATEWINDOW | \
65-
DESKTOP_HOOKCONTROL | \
66-
DESKTOP_JOURNALPLAYBACK | \
67-
DESKTOP_JOURNALRECORD | \
68-
DESKTOP_WRITEOBJECTS
69-
70-
#define DESKTOP_EXECUTE STANDARD_RIGHTS_EXECUTE | \
71-
DESKTOP_SWITCHDESKTOP
72-
73-
#define DESKTOP_ALL_ACCESS STANDARD_RIGHTS_REQUIRED | \
74-
DESKTOP_CREATEMENU | \
75-
DESKTOP_CREATEWINDOW | \
76-
DESKTOP_ENUMERATE | \
77-
DESKTOP_HOOKCONTROL | \
78-
DESKTOP_JOURNALPLAYBACK | \
79-
DESKTOP_JOURNALRECORD | \
80-
DESKTOP_READOBJECTS | \
81-
DESKTOP_SWITCHDESKTOP | \
82-
DESKTOP_WRITEOBJECTS
83-
8458
extern PDESKTOP gpdeskInputDesktop;
8559
extern PCLS DesktopWindowClass;
8660
extern HDC ScreenDeviceContext;

0 commit comments

Comments
 (0)