00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
#include "obp.h"
00022
00023
00024
00025
00026
00027 GENERIC_MAPPING
ObpTypeMapping = {
00028 STANDARD_RIGHTS_READ,
00029 STANDARD_RIGHTS_WRITE,
00030 STANDARD_RIGHTS_EXECUTE,
00031 OBJECT_TYPE_ALL_ACCESS
00032 };
00033
00034 GENERIC_MAPPING
ObpDirectoryMapping = {
00035 STANDARD_RIGHTS_READ |
00036 DIRECTORY_QUERY |
00037 DIRECTORY_TRAVERSE,
00038 STANDARD_RIGHTS_WRITE |
00039 DIRECTORY_CREATE_OBJECT |
00040 DIRECTORY_CREATE_SUBDIRECTORY,
00041 STANDARD_RIGHTS_EXECUTE |
00042 DIRECTORY_QUERY |
00043 DIRECTORY_TRAVERSE,
00044 DIRECTORY_ALL_ACCESS
00045 };
00046
00047 GENERIC_MAPPING
ObpSymbolicLinkMapping = {
00048 STANDARD_RIGHTS_READ |
00049 SYMBOLIC_LINK_QUERY,
00050 STANDARD_RIGHTS_WRITE,
00051 STANDARD_RIGHTS_EXECUTE |
00052 SYMBOLIC_LINK_QUERY,
00053 SYMBOLIC_LINK_ALL_ACCESS
00054 };
00055
00056
00057
00058
00059
00060
NTSTATUS
00061
ObpCreateDosDevicesDirectory (
00062 VOID
00063 );
00064
00065
NTSTATUS
00066
ObpGetDosDevicesProtection (
00067 PSECURITY_DESCRIPTOR SecurityDescriptor
00068 );
00069
00070
VOID
00071
ObpFreeDosDevicesProtection (
00072 PSECURITY_DESCRIPTOR SecurityDescriptor
00073 );
00074
00075
00076
#ifdef ALLOC_PRAGMA
00077
#pragma alloc_text(INIT,ObInitSystem)
00078
#pragma alloc_text(INIT,ObpCreateDosDevicesDirectory)
00079
#pragma alloc_text(INIT,ObpGetDosDevicesProtection)
00080
#pragma alloc_text(INIT,ObpFreeDosDevicesProtection)
00081
#pragma alloc_text(PAGE,ObKillProcess)
00082
#endif
00083
00084
00085
00086
00087
00088 extern EPROCESS_QUOTA_BLOCK PspDefaultQuotaBlock;
00089
00090
00091
00092
00093
00094
00095 KMUTANT ObpInitKillMutant;
00096
00097
00098
00099
00100
00101
00102 ULONG
ObpProtectionMode;
00103 ULONG
ObpAuditBaseDirectories;
00104 ULONG
ObpAuditBaseObjects;
00105
00106
00107
00108
00109
00110 UNICODE_STRING
ObpDosDevicesShortName;
00111 ULARGE_INTEGER
ObpDosDevicesShortNamePrefix;
00112 ULARGE_INTEGER
ObpDosDevicesShortNameRoot;
00113 PDEVICE_MAP ObSystemDeviceMap;
00114
00115
00116 BOOLEAN
00117 ObInitSystem (
00118 VOID
00119 )
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145 {
00146
USHORT CreateInfoMaxDepth;
00147
USHORT NameBufferMaxDepth;
00148 ULONG RegionSegmentSize;
00149
OBJECT_TYPE_INITIALIZER ObjectTypeInitializer;
00150 UNICODE_STRING TypeTypeName;
00151 UNICODE_STRING SymbolicLinkTypeName;
00152 UNICODE_STRING DosDevicesDirectoryName;
00153 UNICODE_STRING DirectoryTypeName;
00154 UNICODE_STRING RootDirectoryName;
00155 UNICODE_STRING TypeDirectoryName;
00156
NTSTATUS Status;
00157 OBJECT_ATTRIBUTES
ObjectAttributes;
00158 HANDLE RootDirectoryHandle;
00159 HANDLE TypeDirectoryHandle;
00160 PLIST_ENTRY Next, Head;
00161
POBJECT_HEADER ObjectTypeHeader;
00162
POBJECT_HEADER_CREATOR_INFO CreatorInfo;
00163
POBJECT_HEADER_NAME_INFO NameInfo;
00164
MM_SYSTEMSIZE SystemSize;
00165 SECURITY_DESCRIPTOR AuditSd;
00166 PSECURITY_DESCRIPTOR EffectiveSd;
00167 PACL AuditAllAcl;
00168 UCHAR AuditAllBuffer[250];
00169 ULONG AuditAllLength;
00170 PACE_HEADER Ace;
00171
PNPAGED_LOOKASIDE_LIST Lookaside;
00172 ULONG
Index;
00173 PKPRCB Prcb;
00174
00175
00176
00177
00178
00179
00180 SystemSize =
MmQuerySystemSize();
00181
00182
if (SystemSize ==
MmLargeSystem) {
00183
00184
if (
MmIsThisAnNtAsSystem()) {
00185
00186 CreateInfoMaxDepth = 64;
00187 NameBufferMaxDepth = 32;
00188
00189 }
else {
00190
00191 CreateInfoMaxDepth = 32;
00192 NameBufferMaxDepth = 16;
00193 }
00194
00195 }
else {
00196
00197 CreateInfoMaxDepth = 3;
00198 NameBufferMaxDepth = 3;
00199 }
00200
00201
00202
00203
00204
00205
if (
InitializationPhase == 0) {
00206
00207
00208
00209
00210
00211
ExInitializeNPagedLookasideList( &
ObpCreateInfoLookasideList,
00212
NULL,
00213
NULL,
00214 0,
00215
sizeof(
OBJECT_CREATE_INFORMATION),
00216 'iCbO',
00217 CreateInfoMaxDepth );
00218
00219
00220
00221
00222
00223
ExInitializeNPagedLookasideList( &
ObpNameBufferLookasideList,
00224
NULL,
00225
NULL,
00226 0,
00227
OBJECT_NAME_BUFFER_SIZE,
00228 'mNbO',
00229 NameBufferMaxDepth );
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242 Prcb =
KeGetCurrentPrcb();
00243 Prcb->PPLookasideList[
LookasideCreateInfoList].L = &
ObpCreateInfoLookasideList;
00244 Prcb->PPLookasideList[
LookasideCreateInfoList].P = &
ObpCreateInfoLookasideList;
00245 Prcb->PPLookasideList[
LookasideNameBufferList].
L = &
ObpNameBufferLookasideList;
00246 Prcb->PPLookasideList[
LookasideNameBufferList].P = &
ObpNameBufferLookasideList;
00247
00248
00249
00250
00251
00252
ObpRemoveObjectQueue =
NULL;
00253
00254
00255
00256
00257
00258
ObpInitSecurityDescriptorCache();
00259
00260
KeInitializeMutant( &
ObpInitKillMutant,
FALSE );
00261
KeInitializeEvent( &
ObpDefaultObject, NotificationEvent,
TRUE );
00262
KeInitializeSpinLock( &
ObpLock );
00263
PsGetCurrentProcess()->GrantedAccess = PROCESS_ALL_ACCESS;
00264
PsGetCurrentThread()->GrantedAccess = THREAD_ALL_ACCESS;
00265
00266
KeInitializeSpinLock( &
ObpDeviceMapLock );
00267
00268
00269
00270
00271
00272
00273
KeInitializeSpinLock(&
PspDefaultQuotaBlock.
QuotaLock);
00274
PspDefaultQuotaBlock.
ReferenceCount = 1;
00275
PspDefaultQuotaBlock.
QuotaPoolLimit[
PagedPool] = (ULONG)-1;
00276
PspDefaultQuotaBlock.
QuotaPoolLimit[
NonPagedPool] = (ULONG)-1;
00277
PspDefaultQuotaBlock.
PagefileLimit = (ULONG)-1;
00278
00279
PsGetCurrentProcess()->QuotaBlock = &
PspDefaultQuotaBlock;
00280
00281
00282
00283
00284
00285
00286
PsGetCurrentProcess()->ObjectTable =
ExCreateHandleTable(
NULL );
00287
ObpKernelHandleTable =
ExCreateHandleTable(
NULL );
00288
00289
00290
00291
00292
00293
00294 RtlZeroMemory( &ObjectTypeInitializer,
sizeof( ObjectTypeInitializer ) );
00295 ObjectTypeInitializer.Length =
sizeof( ObjectTypeInitializer );
00296 ObjectTypeInitializer.InvalidAttributes = OBJ_OPENLINK;
00297 ObjectTypeInitializer.PoolType =
NonPagedPool;
00298
00299
RtlInitUnicodeString( &TypeTypeName,
L"Type" );
00300 ObjectTypeInitializer.ValidAccessMask = OBJECT_TYPE_ALL_ACCESS;
00301 ObjectTypeInitializer.GenericMapping =
ObpTypeMapping;
00302 ObjectTypeInitializer.DefaultNonPagedPoolCharge =
sizeof(
OBJECT_TYPE );
00303 ObjectTypeInitializer.MaintainTypeList =
TRUE;
00304 ObjectTypeInitializer.UseDefaultObject =
TRUE;
00305
ObCreateObjectType( &TypeTypeName,
00306 &ObjectTypeInitializer,
00307 (PSECURITY_DESCRIPTOR)
NULL,
00308 &
ObpTypeObjectType );
00309
00310
00311
00312
00313
00314
RtlInitUnicodeString( &DirectoryTypeName,
L"Directory" );
00315 ObjectTypeInitializer.DefaultNonPagedPoolCharge =
sizeof(
OBJECT_DIRECTORY );
00316 ObjectTypeInitializer.ValidAccessMask = DIRECTORY_ALL_ACCESS;
00317 ObjectTypeInitializer.GenericMapping =
ObpDirectoryMapping;
00318 ObjectTypeInitializer.UseDefaultObject =
FALSE;
00319 ObjectTypeInitializer.MaintainTypeList =
FALSE;
00320
ObCreateObjectType( &DirectoryTypeName,
00321 &ObjectTypeInitializer,
00322 (PSECURITY_DESCRIPTOR)
NULL,
00323 &
ObpDirectoryObjectType );
00324
00325
00326
00327
00328
00329
RtlInitUnicodeString( &SymbolicLinkTypeName,
L"SymbolicLink" );
00330 ObjectTypeInitializer.DefaultNonPagedPoolCharge =
sizeof(
OBJECT_SYMBOLIC_LINK );
00331 ObjectTypeInitializer.ValidAccessMask = SYMBOLIC_LINK_ALL_ACCESS;
00332 ObjectTypeInitializer.GenericMapping =
ObpSymbolicLinkMapping;
00333 ObjectTypeInitializer.DeleteProcedure =
ObpDeleteSymbolicLink;
00334 ObjectTypeInitializer.ParseProcedure =
ObpParseSymbolicLink;
00335
ObCreateObjectType( &SymbolicLinkTypeName,
00336 &ObjectTypeInitializer,
00337 (PSECURITY_DESCRIPTOR)
NULL,
00338 &
ObpSymbolicLinkObjectType );
00339
00340
00341
00342
00343
00344
ExInitializeResourceLite( &
ObpRootDirectoryMutex );
00345
00346
#if i386 && !FPO
00347
00348
00349
00350
00351
00352
00353 ObpCurCachedGrantedAccessIndex = 0;
00354 ObpMaxCachedGrantedAccessIndex =
PAGE_SIZE /
sizeof( ACCESS_MASK );
00355 ObpCachedGrantedAccesses =
ExAllocatePoolWithTag(
NonPagedPool,
PAGE_SIZE, 'gAbO' );
00356
00357
#endif // i386 && !FPO
00358
00359 }
00360
00361
00362
00363
00364
00365
00366
if (
InitializationPhase == 1) {
00367
00368
00369
00370
00371
00372
for (
Index = 0;
Index < (ULONG)
KeNumberProcessors;
Index += 1) {
00373 Prcb =
KiProcessorBlock[
Index];
00374
00375
00376
00377
00378
00379 Prcb->PPLookasideList[
LookasideCreateInfoList].L = &
ObpCreateInfoLookasideList;
00380 Lookaside = (
PNPAGED_LOOKASIDE_LIST)
ExAllocatePoolWithTag(
NonPagedPool,
00381
sizeof(
NPAGED_LOOKASIDE_LIST),
00382 'ICbO');
00383
00384
if (Lookaside !=
NULL) {
00385
ExInitializeNPagedLookasideList( Lookaside,
00386
NULL,
00387
NULL,
00388 0,
00389
sizeof(
OBJECT_CREATE_INFORMATION),
00390 'ICbO',
00391 CreateInfoMaxDepth );
00392
00393 }
else {
00394 Lookaside = &
ObpCreateInfoLookasideList;
00395 }
00396
00397 Prcb->PPLookasideList[
LookasideCreateInfoList].P = Lookaside;
00398
00399
00400
00401
00402
00403 Prcb->PPLookasideList[
LookasideNameBufferList].
L = &
ObpNameBufferLookasideList;
00404 Lookaside = (
PNPAGED_LOOKASIDE_LIST)
ExAllocatePoolWithTag(
NonPagedPool,
00405
sizeof(
NPAGED_LOOKASIDE_LIST),
00406 'MNbO');
00407
00408
if (Lookaside !=
NULL) {
00409
ExInitializeNPagedLookasideList( Lookaside,
00410
NULL,
00411
NULL,
00412 0,
00413
OBJECT_NAME_BUFFER_SIZE,
00414 'MNbO',
00415 NameBufferMaxDepth);
00416
00417 }
else {
00418 Lookaside = &
ObpNameBufferLookasideList;
00419 }
00420
00421 Prcb->PPLookasideList[
LookasideNameBufferList].P = Lookaside;
00422 }
00423
00424 EffectiveSd =
SePublicDefaultUnrestrictedSd;
00425
00426
00427
00428
00429
00430
if ((
ObpAuditBaseDirectories != 0) || (
ObpAuditBaseObjects != 0)) {
00431
00432
00433
00434
00435
00436 AuditAllAcl = (PACL)AuditAllBuffer;
00437 AuditAllLength = (ULONG)
sizeof(ACL) +
00438 ((ULONG)
sizeof(SYSTEM_AUDIT_ACE)) +
00439
SeLengthSid(
SeWorldSid);
00440
00441
ASSERT(
sizeof(AuditAllBuffer) > AuditAllLength );
00442
00443
Status =
RtlCreateAcl( AuditAllAcl, AuditAllLength, ACL_REVISION2);
00444
00445
ASSERT(
NT_SUCCESS(
Status) );
00446
00447
Status =
RtlAddAuditAccessAce ( AuditAllAcl,
00448 ACL_REVISION2,
00449 GENERIC_ALL,
00450
SeWorldSid,
00451
TRUE,
TRUE );
00452
ASSERT(
NT_SUCCESS(
Status) );
00453
00454
Status =
RtlGetAce( AuditAllAcl, 0, (PVOID)&Ace );
00455
00456
ASSERT(
NT_SUCCESS(
Status) );
00457
00458
if (
ObpAuditBaseDirectories != 0) {
00459
00460 Ace->AceFlags |= (CONTAINER_INHERIT_ACE | INHERIT_ONLY_ACE);
00461 }
00462
00463
if (
ObpAuditBaseObjects != 0) {
00464
00465 Ace->AceFlags |= (OBJECT_INHERIT_ACE |
00466 CONTAINER_INHERIT_ACE |
00467 INHERIT_ONLY_ACE);
00468 }
00469
00470
00471
00472
00473
00474
00475 EffectiveSd = (PSECURITY_DESCRIPTOR)&AuditSd;
00476
Status =
RtlCreateSecurityDescriptor( EffectiveSd,
00477 SECURITY_DESCRIPTOR_REVISION1 );
00478
00479
ASSERT(
NT_SUCCESS(
Status) );
00480
00481
Status =
RtlSetDaclSecurityDescriptor( EffectiveSd,
00482
TRUE,
00483
SePublicDefaultUnrestrictedDacl,
00484
FALSE );
00485
00486
ASSERT(
NT_SUCCESS(
Status) );
00487
00488
Status =
RtlSetSaclSecurityDescriptor( EffectiveSd,
00489
TRUE,
00490 AuditAllAcl,
00491
FALSE );
00492
00493
ASSERT(
NT_SUCCESS(
Status) );
00494 }
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
RtlInitUnicodeString( &RootDirectoryName,
L"\\" );
00506
00507 InitializeObjectAttributes( &
ObjectAttributes,
00508 &RootDirectoryName,
00509 OBJ_CASE_INSENSITIVE |
00510 OBJ_PERMANENT,
00511
NULL,
00512 EffectiveSd );
00513
00514
Status =
NtCreateDirectoryObject( &RootDirectoryHandle,
00515 DIRECTORY_ALL_ACCESS,
00516 &
ObjectAttributes );
00517
00518
if (!
NT_SUCCESS(
Status )) {
00519
00520
return(
FALSE );
00521 }
00522
00523
Status =
ObReferenceObjectByHandle( RootDirectoryHandle,
00524 0,
00525
ObpDirectoryObjectType,
00526
KernelMode,
00527 (PVOID *)&
ObpRootDirectoryObject,
00528
NULL );
00529
00530
if (!
NT_SUCCESS(
Status )) {
00531
00532
return(
FALSE );
00533 }
00534
00535
Status =
NtClose( RootDirectoryHandle );
00536
00537
if (!
NT_SUCCESS(
Status )) {
00538
00539
return(
FALSE );
00540 }
00541
00542
00543
00544
00545
00546
RtlInitUnicodeString( &TypeDirectoryName,
L"\\ObjectTypes" );
00547
00548 InitializeObjectAttributes( &
ObjectAttributes,
00549 &TypeDirectoryName,
00550 OBJ_CASE_INSENSITIVE |
00551 OBJ_PERMANENT,
00552
NULL,
00553
NULL );
00554
00555
Status =
NtCreateDirectoryObject( &TypeDirectoryHandle,
00556 DIRECTORY_ALL_ACCESS,
00557 &
ObjectAttributes );
00558
00559
if (!
NT_SUCCESS(
Status )) {
00560
00561
return(
FALSE );
00562 }
00563
00564
Status =
ObReferenceObjectByHandle( TypeDirectoryHandle,
00565 0,
00566
ObpDirectoryObjectType,
00567
KernelMode,
00568 (PVOID *)&
ObpTypeDirectoryObject,
00569
NULL );
00570
00571
if (!
NT_SUCCESS(
Status )) {
00572
00573
return(
FALSE );
00574 }
00575
00576
Status =
NtClose( TypeDirectoryHandle );
00577
00578
if (!
NT_SUCCESS(
Status )) {
00579
00580
return(
FALSE );
00581 }
00582
00583
00584
00585
00586
00587
ObpEnterRootDirectoryMutex();
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598 Head = &
ObpTypeObjectType->
TypeList;
00599 Next = Head->Flink;
00600
00601
while (Next != Head) {
00602
00603
00604
00605
00606
00607
00608 CreatorInfo = CONTAINING_RECORD( Next,
00609
OBJECT_HEADER_CREATOR_INFO,
00610 TypeList );
00611
00612 ObjectTypeHeader = (
POBJECT_HEADER)(CreatorInfo+1);
00613
00614 NameInfo =
OBJECT_HEADER_TO_NAME_INFO( ObjectTypeHeader );
00615
00616
00617
00618
00619
00620
00621
if ((NameInfo !=
NULL) && (NameInfo->
Directory ==
NULL)) {
00622
00623
if (!
ObpLookupDirectoryEntry(
ObpTypeDirectoryObject,
00624 &NameInfo->
Name,
00625 OBJ_CASE_INSENSITIVE )) {
00626
00627
ObpInsertDirectoryEntry(
ObpTypeDirectoryObject,
00628 &ObjectTypeHeader->
Body );
00629 }
00630 }
00631
00632 Next = Next->Flink;
00633 }
00634
00635
00636
00637
00638
00639
ObpLeaveRootDirectoryMutex();
00640
00641
00642
00643
00644
00645
Status =
ObpCreateDosDevicesDirectory();
00646
00647
if (!
NT_SUCCESS(
Status )) {
00648
00649
return FALSE;
00650 }
00651 }
00652
00653
return TRUE;
00654 }
00655
00656
00657 BOOLEAN
00658 ObDupHandleProcedure (
00659
PEPROCESS Process,
00660
PHANDLE_TABLE_ENTRY ObjectTableEntry
00661 )
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684 {
00685
NTSTATUS Status;
00686
POBJECT_HEADER ObjectHeader;
00687 PVOID Object;
00688
ACCESS_STATE AccessState;
00689
00690
00691
00692
00693
00694
if (!(ObjectTableEntry->
ObAttributes & OBJ_INHERIT)) {
00695
00696
return(
FALSE );
00697 }
00698
00699
00700
00701
00702
00703 ObjectHeader = (
POBJECT_HEADER)(((ULONG_PTR)(ObjectTableEntry->
Object)) & ~
OBJ_HANDLE_ATTRIBUTES);
00704
00705 Object = &ObjectHeader->
Body;
00706
00707
00708
00709
00710
00711
00712
00713
#if i386 && !FPO
00714
00715
if (
NtGlobalFlag & FLG_KERNEL_STACK_TRACE_DB) {
00716
00717 AccessState.
PreviouslyGrantedAccess = ObpTranslateGrantedAccessIndex( ObjectTableEntry->
GrantedAccessIndex );
00718
00719 }
else {
00720
00721 AccessState.
PreviouslyGrantedAccess = ObjectTableEntry->
GrantedAccess;
00722 }
00723
00724
#else
00725
00726 AccessState.
PreviouslyGrantedAccess = ObjectTableEntry->
GrantedAccess;
00727
00728
#endif // i386 && !FPO
00729
00730
00731
00732
00733
00734
00735
Status =
ObpIncrementHandleCount(
ObInheritHandle,
00736 Process,
00737 Object,
00738 ObjectHeader->
Type,
00739 &AccessState,
00740
KernelMode,
00741 0 );
00742
00743
if (!
NT_SUCCESS(
Status )) {
00744
00745
return(
FALSE );
00746 }
00747
00748
00749
00750
00751
00752
ObpIncrPointerCount( ObjectHeader );
00753
00754
return(
TRUE );
00755 }
00756
00757
00758 BOOLEAN
00759 ObAuditInheritedHandleProcedure (
00760 IN
PHANDLE_TABLE_ENTRY ObjectTableEntry,
00761 IN HANDLE HandleId,
00762 IN PVOID EnumParameter
00763 )
00764
00765
00766
00767
00768
00769
00770
00771
00772
00773
00774
00775
00776
00777
00778
00779
00780
00781
00782
00783
00784
00785
00786
00787
00788 {
00789
PSE_PROCESS_AUDIT_INFO ProcessAuditInfo = EnumParameter;
00790
00791
00792
00793
00794
00795
if (!(ObjectTableEntry->ObAttributes &
OBJ_AUDIT_OBJECT_CLOSE)) {
00796
00797
return(
FALSE );
00798 }
00799
00800
00801
00802
00803
00804
SeAuditHandleDuplication( HandleId,
00805 HandleId,
00806 ProcessAuditInfo->
Parent,
00807 ProcessAuditInfo->
Process );
00808
00809
return(
FALSE );
00810 }
00811
00812
00813
00814
NTSTATUS
00815 ObInitProcess (
00816
PEPROCESS ParentProcess OPTIONAL,
00817
PEPROCESS NewProcess
00818 )
00819
00820
00821
00822
00823
00824
00825
00826
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836
00837
00838
00839
00840
00841
00842
00843
00844
00845
00846
00847
00848 {
00849
PHANDLE_TABLE OldObjectTable;
00850
PHANDLE_TABLE NewObjectTable;
00851 ULONG PoolCharges[
MaxPoolType ];
00852
SE_PROCESS_AUDIT_INFO ProcessAuditInfo;
00853
00854 RtlZeroMemory( PoolCharges,
sizeof( PoolCharges ) );
00855
00856
00857
00858
00859
00860
00861
00862
00863
if (ARGUMENT_PRESENT( ParentProcess )) {
00864
00865
KeEnterCriticalRegion();
00866
KeWaitForSingleObject( &
ObpInitKillMutant,
00867
Executive,
00868
KernelMode,
00869
FALSE,
00870
NULL );
00871
00872 OldObjectTable = ParentProcess->ObjectTable;
00873
00874
if ( !OldObjectTable ) {
00875
00876
KeReleaseMutant( &
ObpInitKillMutant, 0,
FALSE,
FALSE );
00877
KeLeaveCriticalRegion();
00878
00879
return STATUS_PROCESS_IS_TERMINATING;
00880 }
00881
00882 NewObjectTable =
ExDupHandleTable( NewProcess,
00883 OldObjectTable,
00884
ObDupHandleProcedure );
00885
00886 }
else {
00887
00888 OldObjectTable =
NULL;
00889 NewObjectTable =
ExCreateHandleTable( NewProcess );
00890 }
00891
00892
00893
00894
00895
00896
00897
if (NewObjectTable) {
00898
00899
00900
00901
00902
00903
00904
00905 NewProcess->
ObjectTable = NewObjectTable;
00906
00907
if (
SeDetailedAuditing ) {
00908
00909 ProcessAuditInfo.
Process = NewProcess;
00910 ProcessAuditInfo.
Parent = ParentProcess;
00911
00912
ExEnumHandleTable( NewObjectTable,
00913
ObAuditInheritedHandleProcedure,
00914 (PVOID)&ProcessAuditInfo,
00915 (PHANDLE)
NULL );
00916 }
00917
00918
00919
00920
00921
00922
00923
if ( OldObjectTable ) {
00924
00925
KeReleaseMutant( &
ObpInitKillMutant, 0,
FALSE,
FALSE );
00926
KeLeaveCriticalRegion();
00927 }
00928
00929
return( STATUS_SUCCESS );
00930
00931 }
else {
00932
00933
00934
00935
00936
00937
00938
00939 NewProcess->
ObjectTable =
NULL;
00940
00941
if ( OldObjectTable ) {
00942
00943
KeReleaseMutant( &
ObpInitKillMutant, 0,
FALSE,
FALSE );
00944
KeLeaveCriticalRegion();
00945 }
00946
00947
return( STATUS_INSUFFICIENT_RESOURCES );
00948 }
00949 }
00950
00951
00952
VOID
00953 ObInitProcess2 (
00954
PEPROCESS NewProcess
00955 )
00956
00957
00958
00959
00960
00961
00962
00963
00964
00965
00966
00967
00968
00969
00970
00971
00972
00973
00974
00975
00976 {
00977
00978
00979
00980
00981
if (NewProcess->
ObjectTable) {
00982
00983
ExSetHandleTableOrder( NewProcess->
ObjectTable, (BOOLEAN)(NewProcess->
SubSystemVersion <= 0x332) );
00984 }
00985
00986
return;
00987 }
00988
00989
00990
VOID
00991 ObDestroyHandleProcedure (
00992 IN HANDLE HandleIndex
00993 )
00994
00995
00996
00997
00998
00999
01000
01001
01002
01003
01004
01005
01006
01007
01008
01009
01010
01011
01012
01013
01014 {
01015 ZwClose( HandleIndex );
01016
01017
return;
01018 }
01019
01020
01021
VOID
01022 ObKillProcess (
01023 BOOLEAN AcquireLock,
01024
PEPROCESS Process
01025 )
01026
01027
01028
01029
01030
01031
01032
01033
01034
01035
01036
01037
01038
01039
01040
01041
01042
01043
01044
01045
01046
01047
01048 {
01049 PVOID ObjectTable;
01050 BOOLEAN PreviousIOHardError;
01051
01052
PAGED_CODE();
01053
01054
ObpValidateIrql(
"ObKillProcess" );
01055
01056
01057
01058
01059
01060
if (AcquireLock) {
01061
01062
KeEnterCriticalRegion();
01063
01064
KeWaitForSingleObject( &
ObpInitKillMutant,
01065
Executive,
01066
KernelMode,
01067
FALSE,
01068
NULL );
01069 }
01070
01071
01072
01073
01074
01075 ObjectTable = Process->
ObjectTable;
01076
01077
if (ObjectTable !=
NULL) {
01078
01079 PreviousIOHardError =
IoSetThreadHardErrorMode(
FALSE);
01080
01081
01082
01083
01084
01085
01086
ExDestroyHandleTable( ObjectTable,
ObDestroyHandleProcedure );
01087
01088 Process->
ObjectTable =
NULL;
01089
01090
IoSetThreadHardErrorMode( PreviousIOHardError );
01091 }
01092
01093
01094
01095
01096
01097
if (AcquireLock) {
01098
01099
KeReleaseMutant( &
ObpInitKillMutant, 0,
FALSE,
FALSE );
01100
01101
KeLeaveCriticalRegion();
01102 }
01103
01104
01105
01106
01107
01108
return;
01109 }
01110
01111
01112
01113
01114
01115
01116
01117
01118 typedef struct _OBP_FIND_HANDLE_DATA {
01119
01120 POBJECT_HEADER ObjectHeader;
01121 POBJECT_TYPE ObjectType;
01122 POBJECT_HANDLE_INFORMATION HandleInformation;
01123
01124 }
OBP_FIND_HANDLE_DATA, *
POBP_FIND_HANDLE_DATA;
01125
01126 BOOLEAN
01127 ObpEnumFindHandleProcedure (
01128
PHANDLE_TABLE_ENTRY ObjectTableEntry,
01129 HANDLE HandleId,
01130 PVOID EnumParameter
01131 )
01132
01133
01134
01135
01136
01137
01138
01139
01140
01141
01142
01143
01144
01145
01146
01147
01148
01149
01150
01151
01152
01153
01154
01155
01156 {
01157
POBJECT_HEADER ObjectHeader;
01158 ACCESS_MASK GrantedAccess;
01159 ULONG HandleAttributes;
01160
POBP_FIND_HANDLE_DATA MatchCriteria = EnumParameter;
01161
01162
01163
01164
01165
01166
01167 ObjectHeader = (
POBJECT_HEADER)((ULONG_PTR)ObjectTableEntry->
Object & ~
OBJ_HANDLE_ATTRIBUTES);
01168
01169
if ((MatchCriteria->
ObjectHeader !=
NULL) &&
01170 (MatchCriteria->
ObjectHeader != ObjectHeader)) {
01171
01172
return FALSE;
01173 }
01174
01175
if ((MatchCriteria->
ObjectType !=
NULL) &&
01176 (MatchCriteria->
ObjectType != ObjectHeader->
Type)) {
01177
01178
return FALSE;
01179 }
01180
01181
01182
01183
01184
01185
if (ARGUMENT_PRESENT( MatchCriteria->
HandleInformation )) {
01186
01187
01188
01189
01190
01191
01192
01193
#if i386 && !FPO
01194
01195
if (
NtGlobalFlag & FLG_KERNEL_STACK_TRACE_DB) {
01196
01197 GrantedAccess = ObpTranslateGrantedAccessIndex( ObjectTableEntry->
GrantedAccessIndex );
01198
01199 }
else {
01200
01201 GrantedAccess = ObjectTableEntry->
GrantedAccess;
01202 }
01203
#else
01204
01205 GrantedAccess = ObjectTableEntry->
GrantedAccess;
01206
01207
#endif // i386 && !FPO
01208
01209
01210
01211
01212
01213
01214
01215 HandleAttributes = (ULONG)((ULONG_PTR)ObjectTableEntry->
Object &
OBJ_HANDLE_ATTRIBUTES);
01216
01217
if (MatchCriteria->
HandleInformation->
HandleAttributes != HandleAttributes ||
01218 MatchCriteria->
HandleInformation->
GrantedAccess != GrantedAccess ) {
01219
01220
return FALSE;
01221 }
01222 }
01223
01224
01225
01226
01227
01228
01229
return TRUE;
01230 }
01231
01232
01233 BOOLEAN
01234 ObFindHandleForObject (
01235 IN
PEPROCESS Process,
01236 IN PVOID Object OPTIONAL,
01237 IN
POBJECT_TYPE ObjectType OPTIONAL,
01238 IN
POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL,
01239 OUT PHANDLE Handle
01240 )
01241
01242
01243
01244
01245
01246
01247
01248
01249
01250
01251
01252
01253
01254
01255
01256
01257
01258
01259
01260
01261
01262
01263
01264
01265
01266
01267
01268
01269
01270
01271
01272
01273
01274 {
01275
HANDLE_TABLE_ENTRY ObjectTableEntry;
01276
OBP_FIND_HANDLE_DATA EnumParameter;
01277 BOOLEAN Result;
01278
01279 Result =
FALSE;
01280
01281
01282
01283
01284
01285
KeEnterCriticalRegion();
01286
01287
KeWaitForSingleObject( &
ObpInitKillMutant,
01288
Executive,
01289
KernelMode,
01290
FALSE,
01291
NULL );
01292
01293
01294
01295
01296
01297
01298
if (Process->ObjectTable !=
NULL) {
01299
01300
01301
01302
01303
01304
if (ARGUMENT_PRESENT( Object )) {
01305
01306 EnumParameter.
ObjectHeader =
OBJECT_TO_OBJECT_HEADER( Object );
01307
01308 }
else {
01309
01310 EnumParameter.
ObjectHeader =
NULL;
01311 }
01312
01313 EnumParameter.
ObjectType = ObjectType;
01314 EnumParameter.
HandleInformation = HandleInformation;
01315
01316
01317
01318
01319
01320
01321
01322
01323
if (
ExEnumHandleTable( Process->ObjectTable,
01324
ObpEnumFindHandleProcedure,
01325 &EnumParameter,
01326
Handle )) {
01327
01328 Result =
TRUE;
01329 }
01330 }
01331
01332
01333
01334
01335
01336
KeReleaseMutant( &
ObpInitKillMutant, 0,
FALSE,
FALSE );
01337
01338
KeLeaveCriticalRegion();
01339
01340
return Result;
01341 }
01342
01343
01344
01345
01346
01347
01348
NTSTATUS
01349 ObpCreateDosDevicesDirectory (
01350 VOID
01351 )
01352
01353
01354
01355
01356
01357
01358
01359
01360
01361
01362
01363
01364
01365
01366
01367
01368
01369
01370 {
01371
NTSTATUS Status;
01372 UNICODE_STRING NameString;
01373 UNICODE_STRING LinkNameString;
01374 UNICODE_STRING TargetString;
01375 OBJECT_ATTRIBUTES
ObjectAttributes;
01376 HANDLE
DirectoryHandle;
01377 HANDLE SymbolicLinkHandle;
01378 SECURITY_DESCRIPTOR DosDevicesSD;
01379
01380
01381
01382
01383
01384
Status =
ObpGetDosDevicesProtection( &DosDevicesSD );
01385
01386
if (!
NT_SUCCESS(
Status )) {
01387
01388
return Status;
01389 }
01390
01391
01392
01393
01394
01395
RtlInitUnicodeString( &NameString,
L"\\??" );
01396
01397 InitializeObjectAttributes( &
ObjectAttributes,
01398 &NameString,
01399 OBJ_PERMANENT,
01400 (HANDLE)
NULL,
01401 &DosDevicesSD );
01402
01403
Status =
NtCreateDirectoryObject( &
DirectoryHandle,
01404 DIRECTORY_ALL_ACCESS,
01405 &
ObjectAttributes );
01406
01407
if (!
NT_SUCCESS(
Status )) {
01408
01409
return Status;
01410 }
01411
01412
01413
01414
01415
01416
01417
01418
Status =
ObSetDeviceMap(
NULL,
DirectoryHandle );
01419
01420
01421
01422
01423
01424
01425
01426
01427
01428
01429
01430
RtlInitUnicodeString( &LinkNameString,
L"GLOBALROOT" );
01431
RtlInitUnicodeString( &TargetString,
L"" );
01432
01433 InitializeObjectAttributes( &
ObjectAttributes,
01434 &LinkNameString,
01435 OBJ_PERMANENT,
01436
DirectoryHandle,
01437 &DosDevicesSD );
01438
01439
Status =
NtCreateSymbolicLinkObject( &SymbolicLinkHandle,
01440 SYMBOLIC_LINK_ALL_ACCESS,
01441 &
ObjectAttributes,
01442 &TargetString );
01443
01444
if (
NT_SUCCESS(
Status )) {
01445
01446
NtClose( SymbolicLinkHandle );
01447 }
01448
01449
01450
01451
01452
01453
01454
01455
01456
01457
01458
RtlInitUnicodeString( &LinkNameString,
L"Global" );
01459
RtlInitUnicodeString( &TargetString,
L"\\??" );
01460
01461 InitializeObjectAttributes( &
ObjectAttributes,
01462 &LinkNameString,
01463 OBJ_PERMANENT,
01464
DirectoryHandle,
01465 &DosDevicesSD );
01466
01467
Status =
NtCreateSymbolicLinkObject( &SymbolicLinkHandle,
01468 SYMBOLIC_LINK_ALL_ACCESS,
01469 &
ObjectAttributes,
01470 &TargetString );
01471
01472
if (
NT_SUCCESS(
Status )) {
01473
01474
NtClose( SymbolicLinkHandle );
01475 }
01476
01477
01478
NtClose(
DirectoryHandle );
01479
01480
if (!
NT_SUCCESS(
Status )) {
01481
01482
return Status;
01483 }
01484
01485
01486
01487
01488
01489
01490
ObpDosDevicesShortName.Buffer = (PWSTR)&
ObpDosDevicesShortNamePrefix.QuadPart;
01491
ObpDosDevicesShortName.Length = 0;
01492
ObpDosDevicesShortName.MaximumLength =
sizeof(
ObpDosDevicesShortNamePrefix );
01493
01494
RtlCopyUnicodeString( &
ObpDosDevicesShortName, &NameString );
01495
01496
ObpDosDevicesShortName.Buffer[ 3 ] = UNICODE_NULL;
01497
ObpDosDevicesShortNameRoot.QuadPart =
ObpDosDevicesShortNamePrefix.QuadPart;
01498
01499
01500
01501
01502
01503
01504
01505
RtlCreateUnicodeString( &NameString,
L"\\DosDevices" );
01506
01507 InitializeObjectAttributes( &
ObjectAttributes,
01508 &NameString,
01509 OBJ_PERMANENT,
01510 (HANDLE)
NULL,
01511 &DosDevicesSD );
01512
01513
Status =
NtCreateSymbolicLinkObject( &SymbolicLinkHandle,
01514 SYMBOLIC_LINK_ALL_ACCESS,
01515 &
ObjectAttributes,
01516 &
ObpDosDevicesShortName );
01517
01518
if (
NT_SUCCESS(
Status )) {
01519
01520
NtClose( SymbolicLinkHandle );
01521 }
01522
01523
01524
01525
01526
01527
ObpDosDevicesShortName.Buffer[ 3 ] = OBJ_NAME_PATH_SEPARATOR;
01528
ObpDosDevicesShortName.Length +=
sizeof( OBJ_NAME_PATH_SEPARATOR );
01529
01530
01531
01532
01533
01534
ObpFreeDosDevicesProtection( &DosDevicesSD );
01535
01536
return STATUS_SUCCESS;
01537 }
01538
01539
01540
01541
01542
01543
01544
NTSTATUS
01545 ObpGetDosDevicesProtection (
01546 PSECURITY_DESCRIPTOR SecurityDescriptor
01547 )
01548
01549
01550
01551
01552
01553
01554
01555
01556
01557
01558
01559
01560
01561
01562
01563
01564
01565
01566
01567
01568
01569
01570
01571
01572
01573
01574
01575
01576
01577
01578
01579
01580
01581
01582
01583
01584
01585
01586
01587
01588
01589
01590
01591
01592
01593
01594
01595
01596
01597
01598
01599
01600
01601
01602
01603
01604
01605
01606
01607
01608
01609
01610
01611
01612
01613
01614
01615
01616
01617
01618
01619
01620
01621
01622
01623
01624 {
01625
NTSTATUS Status;
01626 ULONG aceIndex, aclLength;
01627 PACL dacl;
01628 PACE_HEADER ace;
01629 ACCESS_MASK accessMask;
01630
01631 UCHAR inheritOnlyFlags = (OBJECT_INHERIT_ACE |
01632 CONTAINER_INHERIT_ACE |
01633 INHERIT_ONLY_ACE
01634 );
01635
01636
01637
01638
01639
01640
Status =
RtlCreateSecurityDescriptor( SecurityDescriptor, SECURITY_DESCRIPTOR_REVISION );
01641
01642
ASSERT(
NT_SUCCESS(
Status ) );
01643
01644
if (
ObpProtectionMode & 0x00000001) {
01645
01646
01647
01648
01649
01650
01651
01652
01653
01654
01655
01656 aclLength =
sizeof( ACL ) +
01657 6 *
sizeof( ACCESS_ALLOWED_ACE ) +
01658 (2*
RtlLengthSid(
SeWorldSid )) +
01659 (2*
RtlLengthSid(
SeLocalSystemSid )) +
01660
RtlLengthSid(
SeAliasAdminsSid ) +
01661
RtlLengthSid(
SeCreatorOwnerSid );
01662
01663 dacl = (PACL)
ExAllocatePool(
PagedPool, aclLength );
01664
01665
if (dacl ==
NULL) {
01666
01667
return STATUS_NO_MEMORY;
01668 }
01669
01670
Status =
RtlCreateAcl( dacl, aclLength, ACL_REVISION2);
01671
ASSERT(
NT_SUCCESS(
Status ) );
01672
01673
01674
01675
01676
01677
01678
01679 aceIndex = 0;
01680 accessMask = (GENERIC_READ | GENERIC_EXECUTE);
01681
Status =
RtlAddAccessAllowedAce ( dacl, ACL_REVISION2, accessMask,
SeWorldSid );
01682
ASSERT(
NT_SUCCESS(
Status ) );
01683 aceIndex++;
01684 accessMask = (GENERIC_ALL);
01685
Status =
RtlAddAccessAllowedAce ( dacl, ACL_REVISION2, accessMask,
SeLocalSystemSid );
01686
ASSERT(
NT_SUCCESS(
Status ) );
01687
01688
01689
01690
01691
01692
01693
01694
01695
01696 aceIndex++;
01697 accessMask = (GENERIC_EXECUTE);
01698
Status =
RtlAddAccessAllowedAce ( dacl, ACL_REVISION2, accessMask,
SeWorldSid );
01699
ASSERT(
NT_SUCCESS(
Status ) );
01700
Status =
RtlGetAce( dacl, aceIndex, (PVOID)&ace );
01701
ASSERT(
NT_SUCCESS(
Status ) );
01702 ace->AceFlags |= inheritOnlyFlags;
01703
01704 aceIndex++;
01705 accessMask = (GENERIC_ALL);
01706
Status =
RtlAddAccessAllowedAce ( dacl, ACL_REVISION2, accessMask,
SeAliasAdminsSid );
01707
ASSERT(
NT_SUCCESS(
Status ) );
01708
Status =
RtlGetAce( dacl, aceIndex, (PVOID)&ace );
01709
ASSERT(
NT_SUCCESS(
Status ) );
01710 ace->AceFlags |= inheritOnlyFlags;
01711
01712 aceIndex++;
01713 accessMask = (GENERIC_ALL);
01714
Status =
RtlAddAccessAllowedAce ( dacl, ACL_REVISION2, accessMask,
SeLocalSystemSid );
01715
ASSERT(
NT_SUCCESS(
Status ) );
01716
Status =
RtlGetAce( dacl, aceIndex, (PVOID)&ace );
01717
ASSERT(
NT_SUCCESS(
Status ) );
01718 ace->AceFlags |= inheritOnlyFlags;
01719
01720 aceIndex++;
01721 accessMask = (GENERIC_ALL);
01722
Status =
RtlAddAccessAllowedAce ( dacl, ACL_REVISION2, accessMask,
SeCreatorOwnerSid );
01723
ASSERT(
NT_SUCCESS(
Status ) );
01724
Status =
RtlGetAce( dacl, aceIndex, (PVOID)&ace );
01725
ASSERT(
NT_SUCCESS(
Status ) );
01726 ace->AceFlags |= inheritOnlyFlags;
01727
01728
Status =
RtlSetDaclSecurityDescriptor( SecurityDescriptor,
01729
TRUE,
01730 dacl,
01731
FALSE );
01732
01733
ASSERT(
NT_SUCCESS(
Status ) );
01734
01735 }
else {
01736
01737
01738
01739
01740
01741
01742
01743
01744 aclLength =
sizeof( ACL ) +
01745 3 *
sizeof( ACCESS_ALLOWED_ACE ) +
01746 (2*
RtlLengthSid(
SeWorldSid )) +
01747
RtlLengthSid(
SeLocalSystemSid );
01748
01749 dacl = (PACL)
ExAllocatePool(
PagedPool, aclLength );
01750
01751
if (dacl ==
NULL) {
01752
01753
return STATUS_NO_MEMORY;
01754 }
01755
01756
Status =
RtlCreateAcl( dacl, aclLength, ACL_REVISION2);
01757
ASSERT(
NT_SUCCESS(
Status ) );
01758
01759
01760
01761
01762
01763
01764
01765 aceIndex = 0;
01766 accessMask = (GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE);
01767
Status =
RtlAddAccessAllowedAce ( dacl, ACL_REVISION2, accessMask,
SeWorldSid );
01768
ASSERT(
NT_SUCCESS(
Status ) );
01769
01770 aceIndex++;
01771 accessMask = (GENERIC_ALL);
01772
Status =
RtlAddAccessAllowedAce ( dacl, ACL_REVISION2, accessMask,
SeLocalSystemSid );
01773
ASSERT(
NT_SUCCESS(
Status ) );
01774
01775
01776
01777
01778
01779
01780 aceIndex++;
01781 accessMask = (GENERIC_ALL);
01782
Status =
RtlAddAccessAllowedAce ( dacl, ACL_REVISION2, accessMask,
SeWorldSid );
01783
ASSERT(
NT_SUCCESS(
Status ) );
01784
Status =
RtlGetAce( dacl, aceIndex, (PVOID)&ace );
01785
ASSERT(
NT_SUCCESS(
Status ) );
01786 ace->AceFlags |= inheritOnlyFlags;
01787
01788
Status =
RtlSetDaclSecurityDescriptor( SecurityDescriptor,
01789
TRUE,
01790 dacl,
01791
FALSE );
01792
01793
ASSERT(
NT_SUCCESS(
Status ) );
01794 }
01795
01796
return STATUS_SUCCESS;
01797 }
01798
01799
01800
01801
01802
01803
01804
VOID
01805 ObpFreeDosDevicesProtection (
01806 PSECURITY_DESCRIPTOR SecurityDescriptor
01807 )
01808
01809
01810
01811
01812
01813
01814
01815
01816
01817
01818
01819
01820
01821
01822
01823
01824
01825
01826 {
01827
NTSTATUS Status;
01828 PACL
Dacl;
01829 BOOLEAN DaclPresent, Defaulted;
01830
01831
Status =
RtlGetDaclSecurityDescriptor ( SecurityDescriptor,
01832 &DaclPresent,
01833 &
Dacl,
01834 &Defaulted );
01835
01836
ASSERT(
NT_SUCCESS(
Status ) );
01837
ASSERT( DaclPresent );
01838
ASSERT(
Dacl !=
NULL );
01839
01840
ExFreePool( (PVOID)
Dacl );
01841
01842
return;
01843 }