Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

validate.c File Reference

#include "precomp.h"
#include <ntsdexts.h>
#include "wow.h"

Go to the source code of this file.

Defines

#define ClientSharedInfo()   (&gSharedInfo)
#define ServerInfo()   (gpsi)
#define INCCRITSECCOUNT
#define INCDEVICEINFOLISTCRITSECCOUNT
#define CheckDevLockOut()

Functions

NTSTATUS ValidateHwinsta (HWINSTA hwinsta, KPROCESSOR_MODE AccessMode, ACCESS_MASK amDesired, PWINDOWSTATION *ppwinsta)
NTSTATUS ValidateHdesk (HDESK hdesk, KPROCESSOR_MODE AccessMode, ACCESS_MASK amDesired, PDESKTOP *ppdesk)
HRGN UserValidateCopyRgn (HRGN hrgn)
PMENU ValidateHmenu (HMENU hmenu)
PMONITOR ValidateHmonitor (HMONITOR hmonitor)
BOOL IsHandleEntrySecure (HANDLE h, PHE phe)
BOOL ValidateHandleSecure (HANDLE h)
PWND FASTCALL ValidateHwnd (HWND hwnd)
VOID UserEnterUserCritSec (VOID)
VOID UserLeaveUserCritSec (VOID)
BOOL UserGetCurrentDesktopId (DWORD *pdwDesktopId)
BOOL UserIsUserCritSecIn ()
void EnterCrit (void)
void EnterSharedCrit (void)
void LeaveCrit (void)
VOID ChangeAcquireResourceType (VOID)

Variables

__int64 gCSTimeExclusiveWhenEntering


Define Documentation

 
#define CheckDevLockOut  ) 
 

Definition at line 795 of file validate.c.

Referenced by ChangeAcquireResourceType(), EnterCrit(), EnterSharedCrit(), and LeaveCrit().

 
#define ClientSharedInfo  )     (&gSharedInfo)
 

Definition at line 20 of file validate.c.

#define INCCRITSECCOUNT
 

Definition at line 768 of file validate.c.

Referenced by EnterCrit(), EnterSharedCrit(), and LeaveCrit().

#define INCDEVICEINFOLISTCRITSECCOUNT
 

Definition at line 769 of file validate.c.

 
#define ServerInfo  )     (gpsi)
 

Definition at line 21 of file validate.c.


Function Documentation

VOID ChangeAcquireResourceType VOID   ) 
 

Definition at line 887 of file validate.c.

References CheckDevLockOut, ExAcquireResourceExclusiveLite(), ExReleaseResource, gpresUser, gptiCurrent, ISATOMICCHECK, TRUE, and VOID().

Referenced by NtUserGetKeyState().

00889 { 00890 #if DBG 00891 FlushCallStack(); 00892 CheckDevLockOut(); 00893 UserAssert(!ISATOMICCHECK()); 00894 #endif // DBG 00895 ExReleaseResource(gpresUser); 00896 ExAcquireResourceExclusiveLite(gpresUser, TRUE); 00897 gptiCurrent = ((PTHREADINFO)(W32GetCurrentThread())); 00898 #if DBG 00899 GetCallStack(); 00900 #endif // DBG 00901 }

void EnterCrit void   ) 
 

Definition at line 798 of file validate.c.

References CheckCritOut, CheckDeviceInfoListCritOut, CheckDevLockOut, ExAcquireResourceExclusiveLite(), gCSTimeExclusiveWhenEntering, gpresUser, gptiCurrent, INCCRITSECCOUNT, ISATOMICCHECK, KeEnterCriticalRegion, KeQueryPerformanceCounter(), NULL, and TRUE.

00799 { 00800 CheckCritOut(); 00801 CheckDeviceInfoListCritOut(); 00802 KeEnterCriticalRegion(); 00803 ExAcquireResourceExclusiveLite(gpresUser, TRUE); 00804 CheckDevLockOut(); 00805 UserAssert(!ISATOMICCHECK()); 00806 UserAssert(gptiCurrent == NULL); 00807 gptiCurrent = ((PTHREADINFO)(W32GetCurrentThread())); 00808 INCCRITSECCOUNT; 00809 #if defined (USER_PERFORMANCE) 00810 { 00811 __int64 i64Frecv; 00812 *(LARGE_INTEGER*)(&gCSTimeExclusiveWhenEntering) = KeQueryPerformanceCounter((LARGE_INTEGER*)&i64Frecv); 00813 InterlockedIncrement(&gCSStatistics.cExclusive); 00814 } 00815 #endif // (USER_PERFORMANCE) 00816 00817 #if DBG 00818 GetCallStack(); 00819 #endif // DBG 00820 }

void EnterSharedCrit void   ) 
 

Definition at line 833 of file validate.c.

References CheckDevLockOut, ExAcquireResourceSharedLite(), gpresUser, INCCRITSECCOUNT, ISATOMICCHECK, KeEnterCriticalRegion, and TRUE.

Referenced by xxxUserFindHandleForObject().

00834 { 00835 KeEnterCriticalRegion(); 00836 ExAcquireResourceSharedLite(gpresUser, TRUE); 00837 CheckDevLockOut(); 00838 UserAssert(!ISATOMICCHECK()); 00839 #if defined (USER_PERFORMANCE) 00840 InterlockedIncrement(&gCSStatistics.cShared); 00841 #endif // (USER_PERFORMANCE) 00842 00843 INCCRITSECCOUNT; 00844 }

BOOL IsHandleEntrySecure HANDLE  h,
PHE  phe
 

Definition at line 232 of file validate.c.

References tagHANDLETYPEINFO::bObjectCreateFlags, BOOL, _HANDLEENTRY::bType, DWORD, FALSE, gahti, NULL, OCF_PROCESSOWNED, OCF_THREADOWNED, tagW32JOB::pgh, _HANDLEENTRY::pOwner, tagTHREADINFO::ppi, PpiCurrent, tagPROCESSINFO::pW32Job, TRUE, tagW32JOB::ughCrt, and tagW32JOB::ughMax.

Referenced by ValidateHandleSecure(), and ValidateHwnd().

00235 { 00236 DWORD bCreateFlags; 00237 PPROCESSINFO ppiOwner; 00238 PPROCESSINFO ppiCurrent; 00239 PW32JOB pW32Job; 00240 DWORD ind; 00241 PULONG_PTR pgh; 00242 00243 /* 00244 * get the current process 00245 */ 00246 ppiCurrent = PpiCurrent(); 00247 00248 if (ppiCurrent == NULL) 00249 return TRUE; 00250 00251 UserAssert(ppiCurrent->pW32Job != NULL); 00252 00253 UserAssert(ppiCurrent->W32PF_Flags & W32PF_RESTRICTED); 00254 00255 /* 00256 * get the process that owns the handle 00257 */ 00258 00259 bCreateFlags = gahti[phe->bType].bObjectCreateFlags; 00260 00261 ppiOwner = NULL; 00262 00263 if (bCreateFlags & OCF_PROCESSOWNED) { 00264 ppiOwner = (PPROCESSINFO)phe->pOwner; 00265 } else if (bCreateFlags & OCF_THREADOWNED) { 00266 00267 PTHREADINFO pti; 00268 00269 pti = (PTHREADINFO)phe->pOwner; 00270 00271 if (pti != NULL) { 00272 ppiOwner = pti->ppi; 00273 } 00274 } 00275 00276 /* 00277 * if the owner is NULL then consider the handle secure 00278 */ 00279 if (ppiOwner == NULL) 00280 return FALSE; 00281 00282 00283 /* 00284 * if the handle is owned by a process in the same job, then it's secure 00285 */ 00286 if (ppiOwner->pW32Job == ppiCurrent->pW32Job) 00287 return TRUE; 00288 00289 /* 00290 * the handle is not owned by the current process 00291 */ 00292 00293 pW32Job = ppiCurrent->pW32Job; 00294 00295 if (pW32Job->pgh == NULL) 00296 return FALSE; 00297 00298 pgh = pW32Job->pgh; 00299 00300 UserAssert(pW32Job->ughCrt <= pW32Job->ughMax); 00301 00302 for (ind = 0; ind < pW32Job->ughCrt; ind++) { 00303 if (*(pgh + ind) == (ULONG_PTR)h) { 00304 return TRUE; 00305 } 00306 } 00307 00308 return FALSE; 00309 }

void LeaveCrit void   ) 
 

Definition at line 846 of file validate.c.

References CheckCritOut, CheckDevLockOut, ExReleaseResource, gCSTimeExclusiveWhenEntering, gpresUser, gptiCurrent, INCCRITSECCOUNT, ISATOMICCHECK, IsWinEventNotifyDeferredOK, KeLeaveCriticalRegion, KeQueryPerformanceCounter(), and NULL.

00847 { 00848 INCCRITSECCOUNT; 00849 #if DBG 00850 UserAssert(!ISATOMICCHECK()); 00851 UserAssert(IsWinEventNotifyDeferredOK()); 00852 CheckDevLockOut(); 00853 FlushCallStack(); 00854 gptiCurrent = NULL; 00855 #endif // DBG 00856 00857 #if defined (USER_PERFORMANCE) 00858 /* 00859 * A non null gCSTimeExclusiveWhenEntering means the 00860 * critical section is owned exclusive 00861 */ 00862 if (gCSTimeExclusiveWhenEntering) { 00863 __int64 i64Temp, i64Frecv; 00864 00865 *(LARGE_INTEGER*)(&i64Temp) = KeQueryPerformanceCounter((LARGE_INTEGER*)&i64Frecv); 00866 gCSStatistics.i64TimeExclusive += i64Temp - gCSTimeExclusiveWhenEntering; 00867 gCSTimeExclusiveWhenEntering = 0; 00868 } 00869 #endif // (USER_PERFORMANCE) 00870 ExReleaseResource(gpresUser); 00871 KeLeaveCriticalRegion(); 00872 CheckCritOut(); 00873 }

VOID UserEnterUserCritSec VOID   ) 
 

Definition at line 472 of file validate.c.

References EnterCrit, and VOID().

00473 { 00474 EnterCrit(); 00475 }

BOOL UserGetCurrentDesktopId DWORD pdwDesktopId  ) 
 

Definition at line 494 of file validate.c.

References BOOL, CheckCritIn, tagDESKTOP::dwDesktopId, FALSE, grpdeskRitInput, PtiCurrent, and TRUE.

00495 { 00496 PDESKTOP pdesktop; 00497 00498 CheckCritIn(); 00499 00500 /* 00501 * PtiCurrent()->rpdesk can be NULL !!! (in the case of thread shutdown). 00502 */ 00503 00504 pdesktop = PtiCurrent()->rpdesk; 00505 00506 if (pdesktop != grpdeskRitInput) { 00507 RIPMSG0(RIP_WARNING, "UserGetCurrentDesktopId on wrong desktop pdesk\n"); 00508 return FALSE; 00509 } 00510 00511 *pdwDesktopId = pdesktop->dwDesktopId; 00512 00513 return TRUE; 00514 }

BOOL UserIsUserCritSecIn  ) 
 

Definition at line 773 of file validate.c.

References BOOL, ExIsResourceAcquiredExclusiveLite(), ExIsResourceAcquiredSharedLite(), gpresUser, NULL, and TRUE.

00774 { 00775 UserAssert(gpresUser != NULL); 00776 return( (ExIsResourceAcquiredExclusiveLite(gpresUser) == TRUE) || 00777 (ExIsResourceAcquiredSharedLite(gpresUser) == TRUE)); 00778 00779 return(TRUE); 00780 }

VOID UserLeaveUserCritSec VOID   ) 
 

Definition at line 477 of file validate.c.

References LeaveCrit, and VOID().

00478 { 00479 LeaveCrit(); 00480 }

HRGN UserValidateCopyRgn HRGN  hrgn  ) 
 

Definition at line 151 of file validate.c.

References CopyRgn, CreateEmptyRgn(), and NULL.

Referenced by xxxDWP_DoNCActivate(), and xxxSetWindowRgn().

00153 { 00154 HRGN hrgnCopy = NULL; 00155 00156 00157 if (hrgn && (GreValidateServerHandle(hrgn, RGN_TYPE))) { 00158 00159 hrgnCopy = CreateEmptyRgn(); 00160 00161 if (CopyRgn(hrgnCopy, hrgn) == ERROR) { 00162 00163 GreDeleteObject(hrgnCopy); 00164 00165 hrgnCopy = NULL; 00166 } 00167 } 00168 00169 return hrgnCopy; 00170 }

BOOL ValidateHandleSecure HANDLE  h  ) 
 

Definition at line 321 of file validate.c.

References BeginTypeValidateHandleMacro, BOOL, CheckCritInShared, EndTypeValidateHandleMacro, EndValidateHandleMacro, FALSE, IsHandleEntrySecure(), StartValidateHandleMacro, TRUE, and TYPE_GENERIC.

Referenced by NtUserValidateHandleSecure().

00323 { 00324 PVOID pobj; 00325 00326 CheckCritInShared(); 00327 00328 StartValidateHandleMacro(h) 00329 BeginTypeValidateHandleMacro(pobj, TYPE_GENERIC) 00330 00331 if (IsHandleEntrySecure(h, phe)) { 00332 return TRUE; 00333 } 00334 00335 EndTypeValidateHandleMacro 00336 EndValidateHandleMacro 00337 00338 return FALSE; 00339 }

NTSTATUS ValidateHdesk HDESK  hdesk,
KPROCESSOR_MODE  AccessMode,
ACCESS_MASK  amDesired,
PDESKTOP ppdesk
 

Definition at line 92 of file validate.c.

References DF_DESKWNDDESTROYED, DF_DESTROYED, DF_DYING, Error, ExDesktopObjectType, gSessionId, LogDesktop, NT_SUCCESS, NTSTATUS(), NULL, ObDereferenceObject, ObReferenceObjectByHandle(), PtiCurrent, Status, and TRUE.

Referenced by NtUserBuildHwndList(), NtUserSetThreadDesktop(), and NtUserSwitchDesktop().

00097 { 00098 NTSTATUS Status; 00099 00100 Status = ObReferenceObjectByHandle( 00101 hdesk, 00102 amDesired, 00103 *ExDesktopObjectType, 00104 AccessMode, 00105 ppdesk, 00106 NULL); 00107 00108 if (NT_SUCCESS(Status)) { 00109 00110 if ((*ppdesk)->dwSessionId != gSessionId) { 00111 00112 RIPNTERR3(STATUS_INVALID_HANDLE, RIP_WARNING, 00113 "SessionId %d. Wrong session id %d for pdesk %#p", 00114 gSessionId, (*ppdesk)->dwSessionId, *ppdesk); 00115 00116 goto Error; 00117 } 00118 00119 LogDesktop(*ppdesk, LDL_VALIDATE_HDESK, TRUE, (ULONG_PTR)PtiCurrent()); 00120 00121 if ((*ppdesk)->dwDTFlags & (DF_DESTROYED | DF_DESKWNDDESTROYED | DF_DYING)) { 00122 RIPNTERR1(STATUS_INVALID_HANDLE, RIP_ERROR, 00123 "ValidateHdesk: destroyed desktop %#p", 00124 *ppdesk); 00125 Error: 00126 ObDereferenceObject(*ppdesk); 00127 #if DBG 00128 *ppdesk = NULL; 00129 #endif // DBG 00130 00131 return STATUS_INVALID_HANDLE; 00132 } 00133 } else { 00134 RIPNTERR1(Status, RIP_VERBOSE, "ValidateHdesk failed for %#p", hdesk); 00135 } 00136 00137 return Status; 00138 }

PMENU ValidateHmenu HMENU  hmenu  ) 
 

Definition at line 181 of file validate.c.

References tagMENU::head, HMValidateHandle(), NULL, PtiCurrentShared, tagTHREADINFO::rpdesk, and TYPE_MENU.

Referenced by xxxMenuWindowProc(), xxxSetLPITEMInfo(), and xxxSetWindowData().

00183 { 00184 PTHREADINFO pti = PtiCurrentShared(); 00185 PMENU pmenuRet; 00186 00187 pmenuRet = (PMENU)HMValidateHandle(hmenu, TYPE_MENU); 00188 00189 if (pmenuRet != NULL && 00190 ((pti->rpdesk != NULL && // hack so console initialization works. 00191 pmenuRet->head.rpdesk != pti->rpdesk))) { 00192 RIPERR1(ERROR_INVALID_MENU_HANDLE, RIP_WARNING, "Invalid menu handle (%#p)", hmenu); 00193 return NULL; 00194 } 00195 00196 return pmenuRet; 00197 }

PMONITOR ValidateHmonitor HMONITOR  hmonitor  ) 
 

Definition at line 210 of file validate.c.

References HMValidateSharedHandle(), and TYPE_MONITOR.

Referenced by GetHDevName(), xxxCreateThreadInfo(), and xxxCreateWindowEx().

00212 { 00213 return (PMONITOR)HMValidateSharedHandle(hmonitor, TYPE_MONITOR); 00214 }

NTSTATUS ValidateHwinsta HWINSTA  hwinsta,
KPROCESSOR_MODE  AccessMode,
ACCESS_MASK  amDesired,
PWINDOWSTATION ppwinsta
 

Definition at line 46 of file validate.c.

References ExWindowStationObjectType, gSessionId, NT_SUCCESS, NTSTATUS(), NULL, ObDereferenceObject, ObReferenceObjectByHandle(), and Status.

Referenced by NtUserBuildNameList(), NtUserCloseWindowStation(), NtUserLockWindowStation(), NtUserSetWindowStationUser(), and NtUserUnlockWindowStation().

00051 { 00052 NTSTATUS Status; 00053 00054 Status = ObReferenceObjectByHandle( 00055 hwinsta, 00056 amDesired, 00057 *ExWindowStationObjectType, 00058 AccessMode, 00059 ppwinsta, 00060 NULL); 00061 00062 if (!NT_SUCCESS(Status)) { 00063 RIPNTERR1(Status, RIP_VERBOSE, "ValidateHwinsta failed for %#p", hwinsta); 00064 00065 } else if ((*ppwinsta)->dwSessionId != gSessionId) { 00066 00067 RIPNTERR3(STATUS_INVALID_HANDLE, RIP_WARNING, 00068 "SessionId %d. Wrong session id %d for pwinsta %#p", 00069 gSessionId, (*ppwinsta)->dwSessionId, *ppwinsta); 00070 00071 ObDereferenceObject(*ppwinsta); 00072 #if DBG 00073 *ppwinsta = NULL; 00074 #endif // DBG 00075 00076 return STATUS_INVALID_HANDLE; 00077 } 00078 00079 return Status; 00080 }

PWND FASTCALL ValidateHwnd HWND  hwnd  ) 
 

Definition at line 348 of file validate.c.

References _CLIENTINFO::CallbackWnd, EndValidateHandleMacro, FASTCALL, GetClientInfo, GetDesktopView(), GETPTI, HANDLEF_DESTROY, tagWND::head, HMValidateHandle(), _CALLBACKWND::hwnd, IS_THREAD_RESTRICTED, IsHandleEntrySecure(), NULL, tagTHREADINFO::ppi, PtiCurrentShared, _CALLBACKWND::pwnd, tagTHREADINFO::rpdesk, StartValidateHandleMacro, tagTHREADINFO::TIF_flags, TIF_SYSTEMTHREAD, and TYPE_WINDOW.

00350 { 00351 StartValidateHandleMacro(hwnd) 00352 00353 /* 00354 * Now make sure the app is 00355 * passing the right handle 00356 * type for this api. If the 00357 * handle is TYPE_FREE, this'll 00358 * catch it. 00359 */ 00360 if (phe->bType == TYPE_WINDOW) { 00361 00362 PTHREADINFO pti = PtiCurrentShared(); 00363 00364 /* 00365 * This is called from thunks for routines in the shared critsec. 00366 */ 00367 PWND pwndRet = (PWND)phe->phead; 00368 00369 /* 00370 * This test establishes that the window belongs to the current 00371 * 'desktop'.. The two exceptions are for the desktop-window of 00372 * the current desktop, which ends up belonging to another desktop, 00373 * and when pti->rpdesk is NULL. This last case happens for 00374 * initialization of TIF_SYSTEMTHREAD threads (ie. console windows). 00375 * IanJa doesn't know if we should be test TIF_CSRSSTHREAD here, but 00376 * JohnC thinks the whole test below is no longer required ??? LATER 00377 */ 00378 00379 if (pwndRet != NULL) { 00380 if (phe->bFlags & HANDLEF_DESTROY) { 00381 RIPERR2(ERROR_INVALID_WINDOW_HANDLE, 00382 RIP_WARNING,"ValidateHwnd, hwnd %#p, pwnd %#p already destroyed\n", 00383 hwnd, pwndRet); 00384 return NULL; 00385 } 00386 if (GETPTI(pwndRet) == pti || 00387 ( 00388 (pwndRet->head.rpdesk == pti->rpdesk || 00389 (pti->TIF_flags & TIF_SYSTEMTHREAD) || // | TIF_CSRSSTHREAD I think 00390 GetDesktopView(pti->ppi, pwndRet->head.rpdesk) != 00391 NULL))) { 00392 00393 if (IS_THREAD_RESTRICTED(pti, JOB_OBJECT_UILIMIT_HANDLES)) { 00394 00395 /* 00396 * make sure this window belongs to this process 00397 */ 00398 if (!IsHandleEntrySecure(hwnd, phe)) { 00399 RIPERR1(ERROR_INVALID_WINDOW_HANDLE, 00400 RIP_WARNING, 00401 "ValidateHwnd: Invalid hwnd (%#p) for restricted process\n", 00402 hwnd); 00403 pwndRet = NULL; 00404 } 00405 } 00406 return pwndRet; 00407 } 00408 } 00409 } 00410 00411 EndValidateHandleMacro 00412 00413 RIPERR1(ERROR_INVALID_WINDOW_HANDLE, 00414 RIP_WARNING, 00415 "ValidateHwnd: Invalid hwnd (%#p)", 00416 hwnd); 00417 return NULL; 00418 }


Variable Documentation

__int64 gCSTimeExclusiveWhenEntering
 

Definition at line 34 of file validate.c.

Referenced by EnterCrit(), and LeaveCrit().


Generated on Sat May 15 19:46:06 2004 for test by doxygen 1.3.7