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
#if defined(ALLOC_PRAGMA) && defined(NTOS_KERNEL_RUNTIME)
00024
00025
#pragma alloc_text(PAGE,NtSetSecurityObject)
00026
#pragma alloc_text(PAGE,NtQuerySecurityObject)
00027
#pragma alloc_text(PAGE,ObAssignObjectSecurityDescriptor)
00028
#pragma alloc_text(PAGE,ObAssignSecurity)
00029
#pragma alloc_text(PAGE,ObCheckCreateObjectAccess)
00030
#pragma alloc_text(PAGE,ObCheckObjectAccess)
00031
#pragma alloc_text(PAGE,ObCheckObjectReference)
00032
#pragma alloc_text(PAGE,ObpCheckTraverseAccess)
00033
#pragma alloc_text(PAGE,ObGetObjectSecurity)
00034
#pragma alloc_text(PAGE,ObSetSecurityDescriptorInfo)
00035
#pragma alloc_text(PAGE,ObQuerySecurityDescriptorInfo)
00036
#pragma alloc_text(PAGE,ObReleaseObjectSecurity)
00037
#pragma alloc_text(PAGE,ObSetSecurityQuotaCharged)
00038
#pragma alloc_text(PAGE,ObValidateSecurityQuota)
00039
#pragma alloc_text(PAGE,ObpValidateAccessMask)
00040
#pragma alloc_text(PAGE,ObSetSecurityObjectByPointer)
00041
00042
#endif
00043
00044
00045
NTSTATUS
00046 NtSetSecurityObject (
00047 IN HANDLE Handle,
00048 IN SECURITY_INFORMATION SecurityInformation,
00049 IN PSECURITY_DESCRIPTOR SecurityDescriptor
00050 )
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075 {
00076
NTSTATUS Status;
00077 PVOID Object;
00078 ACCESS_MASK DesiredAccess;
00079
OBJECT_HANDLE_INFORMATION HandleInformation;
00080
KPROCESSOR_MODE RequestorMode;
00081 SECURITY_DESCRIPTOR_RELATIVE *CapturedDescriptor;
00082
00083
PAGED_CODE();
00084
00085
00086
00087
00088
00089
00090
00091
if (!ARGUMENT_PRESENT( SecurityDescriptor )) {
00092
00093
return( STATUS_ACCESS_VIOLATION );
00094 }
00095
00096
00097
00098
00099
00100
00101
SeSetSecurityAccessMask( SecurityInformation, &DesiredAccess );
00102
00103
Status =
ObReferenceObjectByHandle(
Handle,
00104 DesiredAccess,
00105
NULL,
00106 RequestorMode = KeGetPreviousMode(),
00107 &Object,
00108 &HandleInformation );
00109
00110
if (
NT_SUCCESS(
Status )) {
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
Status =
SeCaptureSecurityDescriptor( SecurityDescriptor,
00121 RequestorMode,
00122
PagedPool,
00123
TRUE,
00124 (PSECURITY_DESCRIPTOR *)&CapturedDescriptor );
00125
00126
if (
NT_SUCCESS(
Status )) {
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
ASSERT(CapturedDescriptor->Control & SE_SELF_RELATIVE);
00137
00138
if (((SecurityInformation & OWNER_SECURITY_INFORMATION) &&
00139 (CapturedDescriptor->Owner == 0))
00140
00141 ||
00142
00143 ((SecurityInformation & GROUP_SECURITY_INFORMATION) &&
00144 (CapturedDescriptor->Group == 0))) {
00145
00146
SeReleaseSecurityDescriptor( (PSECURITY_DESCRIPTOR)CapturedDescriptor,
00147 RequestorMode,
00148
TRUE );
00149
00150
ObDereferenceObject( Object );
00151
00152
ASSERT(
FALSE);
00153
return( STATUS_INVALID_SECURITY_DESCR );
00154 }
00155
00156
Status =
ObSetSecurityObjectByPointer( Object,
00157 SecurityInformation,
00158 CapturedDescriptor );
00159
00160
SeReleaseSecurityDescriptor( (PSECURITY_DESCRIPTOR)CapturedDescriptor,
00161 RequestorMode,
00162
TRUE );
00163 }
00164
00165
ObDereferenceObject( Object );
00166
00167 }
00168
00169
return(
Status );
00170 }
00171
00172
00173
NTSTATUS
00174 ObSetSecurityObjectByPointer (
00175 IN PVOID Object,
00176 IN SECURITY_INFORMATION SecurityInformation,
00177 IN PSECURITY_DESCRIPTOR SecurityDescriptor
00178 )
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206 {
00207
NTSTATUS Status;
00208
POBJECT_HEADER ObjectHeader;
00209
POBJECT_TYPE ObjectType;
00210
00211
PAGED_CODE();
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222 ObjectHeader =
OBJECT_TO_OBJECT_HEADER( Object );
00223 ObjectType = ObjectHeader->
Type;
00224
00225
00226
00227
00228
00229
ASSERT(ARGUMENT_PRESENT( SecurityDescriptor ));
00230
00231
00232
00233
00234
00235
00236
Status = (ObjectType->
TypeInfo.
SecurityProcedure)
00237 ( Object,
00238
SetSecurityDescriptor,
00239 &SecurityInformation,
00240 SecurityDescriptor,
00241
NULL,
00242 &ObjectHeader->
SecurityDescriptor,
00243 ObjectType->
TypeInfo.
PoolType,
00244 &ObjectType->
TypeInfo.
GenericMapping );
00245
00246
00247
00248
00249
00250
return(
Status );
00251 }
00252
00253
00254
NTSTATUS
00255 NtQuerySecurityObject (
00256 IN HANDLE Handle,
00257 IN SECURITY_INFORMATION SecurityInformation,
00258 OUT PSECURITY_DESCRIPTOR SecurityDescriptor,
00259 IN ULONG Length,
00260 OUT PULONG LengthNeeded
00261 )
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291 {
00292
NTSTATUS Status;
00293 PVOID Object;
00294 ACCESS_MASK DesiredAccess;
00295
OBJECT_HANDLE_INFORMATION HandleInformation;
00296
KPROCESSOR_MODE RequestorMode;
00297
POBJECT_HEADER ObjectHeader;
00298
POBJECT_TYPE ObjectType;
00299
00300
PAGED_CODE();
00301
00302
00303
00304
00305
00306 RequestorMode = KeGetPreviousMode();
00307
00308
if (RequestorMode !=
KernelMode) {
00309
00310
try {
00311
00312
ProbeForWriteUlong( LengthNeeded );
00313
00314
ProbeForWrite( SecurityDescriptor, Length,
sizeof(ULONG) );
00315
00316 } except(
EXCEPTION_EXECUTE_HANDLER) {
00317
00318
return GetExceptionCode();
00319 }
00320 }
00321
00322
00323
00324
00325
00326
00327
SeQuerySecurityAccessMask( SecurityInformation, &DesiredAccess );
00328
00329
Status =
ObReferenceObjectByHandle(
Handle,
00330 DesiredAccess,
00331
NULL,
00332 RequestorMode,
00333 &Object,
00334 &HandleInformation );
00335
00336
if (!
NT_SUCCESS(
Status )) {
00337
00338
return(
Status );
00339 }
00340
00341
00342
00343
00344
00345
00346 ObjectHeader =
OBJECT_TO_OBJECT_HEADER( Object );
00347 ObjectType = ObjectHeader->
Type;
00348
00349
00350
00351
00352
00353
00354
00355
Status = (ObjectType->
TypeInfo.
SecurityProcedure)( Object,
00356
QuerySecurityDescriptor,
00357 &SecurityInformation,
00358 SecurityDescriptor,
00359 &Length,
00360 &ObjectHeader->
SecurityDescriptor,
00361 ObjectType->
TypeInfo.
PoolType,
00362 &ObjectType->
TypeInfo.
GenericMapping );
00363
00364
00365
00366
00367
00368
00369
00370
try {
00371
00372 *LengthNeeded = Length;
00373
00374 } except(
EXCEPTION_EXECUTE_HANDLER) {
00375
00376
ObDereferenceObject( Object );
00377
00378
return(GetExceptionCode());
00379 }
00380
00381
00382
00383
00384
00385
ObDereferenceObject( Object );
00386
00387
return(
Status );
00388 }
00389
00390
00391 BOOLEAN
00392 ObCheckObjectAccess (
00393 IN PVOID Object,
00394 IN OUT
PACCESS_STATE AccessState,
00395 IN BOOLEAN TypeMutexLocked,
00396 IN KPROCESSOR_MODE AccessMode,
00397 OUT PNTSTATUS AccessStatus
00398 )
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438 {
00439 ACCESS_MASK GrantedAccess = 0;
00440 BOOLEAN AccessAllowed;
00441 BOOLEAN MemoryAllocated;
00442
NTSTATUS Status;
00443 PSECURITY_DESCRIPTOR SecurityDescriptor =
NULL;
00444
POBJECT_HEADER ObjectHeader;
00445
POBJECT_TYPE ObjectType;
00446 PPRIVILEGE_SET Privileges =
NULL;
00447
00448
PAGED_CODE();
00449
00450
00451
00452
00453
00454
00455 ObjectHeader =
OBJECT_TO_OBJECT_HEADER( Object );
00456 ObjectType = ObjectHeader->
Type;
00457
00458
00459
00460
00461
00462
00463
if (!TypeMutexLocked) {
00464
00465
ObpEnterObjectTypeMutex( ObjectType );
00466 }
00467
00468
00469
00470
00471
00472
Status =
ObGetObjectSecurity( Object,
00473 &SecurityDescriptor,
00474 &MemoryAllocated );
00475
00476
00477
00478
00479
00480
00481
00482
if (!
NT_SUCCESS(
Status )) {
00483
00484
if (!TypeMutexLocked) {
00485
00486
ObpLeaveObjectTypeMutex( ObjectType );
00487 }
00488
00489 *AccessStatus =
Status;
00490
00491
return(
FALSE );
00492
00493 }
else {
00494
00495
00496
00497
00498
00499
00500
if (SecurityDescriptor ==
NULL) {
00501
00502
if (!TypeMutexLocked) {
00503
00504
ObpLeaveObjectTypeMutex( ObjectType );
00505 }
00506
00507 *AccessStatus =
Status;
00508
00509
return(
TRUE);
00510 }
00511 }
00512
00513
00514
00515
00516
00517
00518
00519
SeLockSubjectContext( &AccessState->SubjectSecurityContext );
00520
00521
00522
00523
00524
00525
00526 AccessAllowed =
SeAccessCheck( SecurityDescriptor,
00527 &AccessState->SubjectSecurityContext,
00528
TRUE,
00529 AccessState->RemainingDesiredAccess,
00530 AccessState->PreviouslyGrantedAccess,
00531 &Privileges,
00532 &ObjectType->
TypeInfo.
GenericMapping,
00533 AccessMode,
00534 &GrantedAccess,
00535 AccessStatus );
00536
00537
if (Privileges !=
NULL) {
00538
00539
Status =
SeAppendPrivileges( AccessState,
00540 Privileges );
00541
00542
SeFreePrivileges( Privileges );
00543 }
00544
00545
00546
00547
00548
00549
00550
00551
if (AccessAllowed) {
00552
00553 AccessState->PreviouslyGrantedAccess |= GrantedAccess;
00554 AccessState->RemainingDesiredAccess &= ~(GrantedAccess | MAXIMUM_ALLOWED);
00555 }
00556
00557
00558
00559
00560
00561
00562
00563
00564
if ( SecurityDescriptor !=
NULL ) {
00565
00566
SeOpenObjectAuditAlarm( &ObjectType->
Name,
00567 Object,
00568
NULL,
00569 SecurityDescriptor,
00570 AccessState,
00571
FALSE,
00572 AccessAllowed,
00573 AccessMode,
00574 &AccessState->GenerateOnClose );
00575 }
00576
00577
SeUnlockSubjectContext( &AccessState->SubjectSecurityContext );
00578
00579
00580
00581
00582
00583
00584
if (!TypeMutexLocked) {
00585
00586
ObpLeaveObjectTypeMutex( ObjectType );
00587 }
00588
00589
00590
00591
00592
00593
00594
ObReleaseObjectSecurity( SecurityDescriptor,
00595 MemoryAllocated );
00596
00597
return( AccessAllowed );
00598 }
00599
00600
00601 BOOLEAN
00602 ObpCheckObjectReference (
00603 IN PVOID Object,
00604 IN OUT
PACCESS_STATE AccessState,
00605 IN BOOLEAN TypeMutexLocked,
00606 IN KPROCESSOR_MODE AccessMode,
00607 OUT PNTSTATUS AccessStatus
00608 )
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651 {
00652 BOOLEAN AccessAllowed;
00653 ACCESS_MASK GrantedAccess = 0;
00654 BOOLEAN MemoryAllocated;
00655 PSECURITY_DESCRIPTOR SecurityDescriptor;
00656
NTSTATUS Status;
00657
POBJECT_HEADER ObjectHeader;
00658
POBJECT_TYPE ObjectType;
00659 PPRIVILEGE_SET Privileges =
NULL;
00660
00661
PAGED_CODE();
00662
00663
00664
00665
00666
00667
00668 ObjectHeader =
OBJECT_TO_OBJECT_HEADER( Object );
00669 ObjectType = ObjectHeader->
Type;
00670
00671
00672
00673
00674
00675
00676
if (!TypeMutexLocked) {
00677
00678
ObpEnterObjectTypeMutex( ObjectType );
00679 }
00680
00681
00682
00683
00684
00685
Status =
ObGetObjectSecurity( Object,
00686 &SecurityDescriptor,
00687 &MemoryAllocated );
00688
00689
00690
00691
00692
00693
00694
00695
if (!
NT_SUCCESS(
Status )) {
00696
00697
if (!TypeMutexLocked) {
00698
00699
ObpLeaveObjectTypeMutex( ObjectType );
00700 }
00701
00702 *AccessStatus =
Status;
00703
00704
return(
FALSE );
00705 }
00706
00707
00708
00709
00710
00711
00712
SeLockSubjectContext( &AccessState->SubjectSecurityContext );
00713
00714
00715
00716
00717
00718
00719 AccessAllowed =
SeAccessCheck( SecurityDescriptor,
00720 &AccessState->SubjectSecurityContext,
00721
TRUE,
00722 AccessState->RemainingDesiredAccess,
00723 AccessState->PreviouslyGrantedAccess,
00724 &Privileges,
00725 &ObjectType->
TypeInfo.
GenericMapping,
00726 AccessMode,
00727 &GrantedAccess,
00728 AccessStatus );
00729
00730
if (AccessAllowed) {
00731
00732 AccessState->PreviouslyGrantedAccess |= GrantedAccess;
00733 AccessState->RemainingDesiredAccess &= ~GrantedAccess;
00734 }
00735
00736
00737
00738
00739
00740
00741
if ( SecurityDescriptor !=
NULL ) {
00742
00743
SeObjectReferenceAuditAlarm( &AccessState->OperationID,
00744 Object,
00745 SecurityDescriptor,
00746 &AccessState->SubjectSecurityContext,
00747 AccessState->RemainingDesiredAccess | AccessState->PreviouslyGrantedAccess,
00748 ((
PAUX_ACCESS_DATA)(AccessState->AuxData))->PrivilegesUsed,
00749 AccessAllowed,
00750 AccessMode );
00751 }
00752
00753
SeUnlockSubjectContext( &AccessState->SubjectSecurityContext );
00754
00755
00756
00757
00758
00759
00760
if (!TypeMutexLocked) {
00761
00762
ObpLeaveObjectTypeMutex( ObjectType );
00763 }
00764
00765
00766
00767
00768
00769
00770
ObReleaseObjectSecurity( SecurityDescriptor,
00771 MemoryAllocated );
00772
00773
return( AccessAllowed );
00774 }
00775
00776
00777 BOOLEAN
00778 ObpCheckTraverseAccess (
00779 IN PVOID DirectoryObject,
00780 IN ACCESS_MASK TraverseAccess,
00781 IN
PACCESS_STATE AccessState OPTIONAL,
00782 IN BOOLEAN TypeMutexLocked,
00783 IN KPROCESSOR_MODE PreviousMode,
00784 OUT PNTSTATUS AccessStatus
00785 )
00786
00787
00788
00789
00790
00791
00792
00793
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813
00814
00815
00816
00817
00818
00819
00820
00821
00822
00823
00824
00825
00826
00827
00828
00829
00830
00831 {
00832 BOOLEAN AccessAllowed;
00833 ACCESS_MASK GrantedAccess = 0;
00834 PSECURITY_DESCRIPTOR SecurityDescriptor;
00835 BOOLEAN MemoryAllocated;
00836
NTSTATUS Status;
00837
POBJECT_HEADER ObjectHeader;
00838
POBJECT_TYPE ObjectType;
00839 BOOLEAN SubjectContextLocked =
FALSE;
00840 PPRIVILEGE_SET Privileges =
NULL;
00841
00842
PAGED_CODE();
00843
00844
00845
00846
00847
00848
00849 ObjectHeader =
OBJECT_TO_OBJECT_HEADER( DirectoryObject );
00850 ObjectType = ObjectHeader->
Type;
00851
00852
00853
00854
00855
00856
00857
if (!TypeMutexLocked) {
00858
00859
ObpEnterObjectTypeMutex( ObjectType );
00860 }
00861
00862
00863
00864
00865
00866
00867
Status =
ObGetObjectSecurity( DirectoryObject,
00868 &SecurityDescriptor,
00869 &MemoryAllocated );
00870
00871
if (!
NT_SUCCESS(
Status )) {
00872
00873
if (!TypeMutexLocked) {
00874
00875
ObpLeaveObjectTypeMutex( ObjectType );
00876 }
00877
00878 *AccessStatus =
Status;
00879
00880
return(
FALSE );
00881 }
00882
00883
00884
00885
00886
00887
00888
00889
if (((AccessState->Flags &
TOKEN_IS_RESTRICTED) != 0)
00890
00891 ||
00892
00893 (!
SeFastTraverseCheck( SecurityDescriptor,
00894 DIRECTORY_TRAVERSE,
00895 PreviousMode ))) {
00896
00897
00898
00899
00900
00901
00902
00903
00904
00905
if (ARGUMENT_PRESENT( AccessState )) {
00906
00907
00908
00909
00910
00911
00912
00913
00914
00915
SeLockSubjectContext( &AccessState->SubjectSecurityContext );
00916
00917 SubjectContextLocked =
TRUE;
00918
00919 AccessAllowed =
SeAccessCheck( SecurityDescriptor,
00920 &AccessState->SubjectSecurityContext,
00921
TRUE,
00922 TraverseAccess,
00923 0,
00924 &Privileges,
00925 &ObjectType->
TypeInfo.
GenericMapping,
00926 PreviousMode,
00927 &GrantedAccess,
00928 AccessStatus );
00929
00930
if (Privileges !=
NULL) {
00931
00932
Status =
SeAppendPrivileges( AccessState,
00933 Privileges );
00934
00935
SeFreePrivileges( Privileges );
00936 }
00937 }
00938
00939 }
else {
00940
00941
00942
00943
00944
00945 AccessAllowed =
TRUE;
00946 }
00947
00948
00949
00950
00951
00952
00953
00954
00955
if ( SubjectContextLocked ) {
00956
00957
SeUnlockSubjectContext( &AccessState->SubjectSecurityContext );
00958 }
00959
00960
00961
00962
00963
00964
00965
if (!TypeMutexLocked) {
00966
00967
ObpLeaveObjectTypeMutex( ObjectType );
00968 }
00969
00970
00971
00972
00973
00974
00975
ObReleaseObjectSecurity( SecurityDescriptor,
00976 MemoryAllocated );
00977
00978
return( AccessAllowed );
00979 }
00980
00981
00982 BOOLEAN
00983 ObCheckCreateObjectAccess (
00984 IN PVOID DirectoryObject,
00985 IN ACCESS_MASK CreateAccess,
00986 IN
PACCESS_STATE AccessState,
00987 IN PUNICODE_STRING ComponentName,
00988 IN BOOLEAN TypeMutexLocked,
00989 IN KPROCESSOR_MODE PreviousMode,
00990 OUT PNTSTATUS AccessStatus
00991 )
00992
00993
00994
00995
00996
00997
00998
00999
01000
01001
01002
01003
01004
01005
01006
01007
01008
01009
01010
01011
01012
01013
01014
01015
01016
01017
01018
01019
01020
01021
01022
01023
01024
01025
01026
01027
01028
01029
01030
01031
01032
01033
01034 {
01035 BOOLEAN AccessAllowed;
01036 ACCESS_MASK GrantedAccess = 0;
01037 PSECURITY_DESCRIPTOR SecurityDescriptor;
01038 BOOLEAN MemoryAllocated;
01039
NTSTATUS Status;
01040
POBJECT_HEADER ObjectHeader;
01041
POBJECT_TYPE ObjectType;
01042 PPRIVILEGE_SET Privileges =
NULL;
01043 BOOLEAN AuditPerformed =
FALSE;
01044
01045
PAGED_CODE();
01046
01047
01048
01049
01050
01051
01052 ObjectHeader =
OBJECT_TO_OBJECT_HEADER( DirectoryObject );
01053 ObjectType = ObjectHeader->
Type;
01054
01055
01056
01057
01058
01059
01060
if (!TypeMutexLocked) {
01061
01062
ObpEnterObjectTypeMutex( ObjectType );
01063 }
01064
01065
01066
01067
01068
01069
01070
Status =
ObGetObjectSecurity( DirectoryObject,
01071 &SecurityDescriptor,
01072 &MemoryAllocated );
01073
01074
if (!
NT_SUCCESS(
Status )) {
01075
01076
if (!TypeMutexLocked) {
01077
01078
ObpLeaveObjectTypeMutex( ObjectType );
01079 }
01080
01081 *AccessStatus =
Status;
01082
01083
return(
FALSE );
01084 }
01085
01086
01087
01088
01089
01090
01091
SeLockSubjectContext( &AccessState->SubjectSecurityContext );
01092
01093
01094
01095
01096
01097
01098
01099
if (SecurityDescriptor !=
NULL) {
01100
01101 AccessAllowed =
SeAccessCheck( SecurityDescriptor,
01102 &AccessState->SubjectSecurityContext,
01103
TRUE,
01104 CreateAccess,
01105 0,
01106 &Privileges,
01107 &ObjectType->
TypeInfo.
GenericMapping,
01108 PreviousMode,
01109 &GrantedAccess,
01110 AccessStatus );
01111
01112
if (Privileges !=
NULL) {
01113
01114
Status =
SeAppendPrivileges( AccessState,
01115 Privileges );
01116
01117
SeFreePrivileges( Privileges );
01118 }
01119
01120
01121
01122
01123
01124
01125
01126
01127
01128
01129
01130
#if 0
01131
SeCreateObjectAuditAlarm( &AccessState->OperationID,
01132 DirectoryObject,
01133 ComponentName,
01134 SecurityDescriptor,
01135 &AccessState->SubjectSecurityContext,
01136 CreateAccess,
01137 AccessState->PrivilegesUsed,
01138 AccessAllowed,
01139 &AuditPerformed,
01140 PreviousMode );
01141
01142
if ( AuditPerformed ) {
01143
01144 AccessState->AuditHandleCreation =
TRUE;
01145 }
01146
#endif
01147
01148 }
else {
01149
01150
01151
01152
01153
01154
01155 AccessAllowed =
TRUE;
01156 }
01157
01158
01159
01160
01161
01162
01163
SeUnlockSubjectContext( &AccessState->SubjectSecurityContext );
01164
01165
if (!TypeMutexLocked) {
01166
01167
ObpLeaveObjectTypeMutex( ObjectType );
01168 }
01169
01170
01171
01172
01173
01174
01175
ObReleaseObjectSecurity( SecurityDescriptor,
01176 MemoryAllocated );
01177
01178
return( AccessAllowed );
01179 }
01180
01181
01182
NTSTATUS
01183 ObAssignObjectSecurityDescriptor (
01184 IN PVOID Object,
01185 IN PSECURITY_DESCRIPTOR SecurityDescriptor OPTIONAL,
01186 IN POOL_TYPE PoolType
01187 )
01188
01189
01190
01191
01192
01193
01194
01195
01196
01197
01198
01199
01200
01201
01202
01203
01204
01205
01206
01207
01208
01209
01210
01211
01212
01213 {
01214
NTSTATUS Status;
01215 PSECURITY_DESCRIPTOR OutputSecurityDescriptor;
01216
01217
PAGED_CODE();
01218
01219
01220
01221
01222
01223
01224
01225
if (!ARGUMENT_PRESENT(SecurityDescriptor)) {
01226
01227
OBJECT_TO_OBJECT_HEADER( Object )->SecurityDescriptor =
NULL;
01228
01229
return( STATUS_SUCCESS );
01230 }
01231
01232
01233
01234
01235
01236
01237
Status =
ObpLogSecurityDescriptor( SecurityDescriptor, &OutputSecurityDescriptor );
01238
01239
01240
01241
01242
01243
01244
if (
NT_SUCCESS(
Status)) {
01245
01246
OBJECT_TO_OBJECT_HEADER( Object )->SecurityDescriptor = OutputSecurityDescriptor;
01247 }
01248
01249
01250
01251
01252
01253
return(
Status );
01254 }
01255
01256
01257
NTSTATUS
01258 ObGetObjectSecurity (
01259 IN PVOID Object,
01260 OUT PSECURITY_DESCRIPTOR *SecurityDescriptor,
01261 OUT PBOOLEAN MemoryAllocated
01262 )
01263
01264
01265
01266
01267
01268
01269
01270
01271
01272
01273
01274
01275
01276
01277
01278
01279
01280
01281
01282
01283
01284
01285
01286
01287
01288
01289
01290
01291
01292
01293
01294
01295
01296
01297
01298 {
01299 SECURITY_INFORMATION SecurityInformation;
01300 ULONG Length = 0;
01301
NTSTATUS Status;
01302
POBJECT_TYPE ObjectType;
01303
POBJECT_HEADER ObjectHeader;
01304 KIRQL SaveIrql;
01305
01306
PAGED_CODE();
01307
01308
01309
01310
01311
01312
01313 ObjectHeader =
OBJECT_TO_OBJECT_HEADER( Object );
01314 ObjectType = ObjectHeader->
Type;
01315
01316
01317
01318
01319
01320
01321
01322
01323
01324
if (
ObpCentralizedSecurity(ObjectType)) {
01325
01326 *SecurityDescriptor =
ObpReferenceSecurityDescriptor( Object );
01327
01328 *MemoryAllocated =
FALSE;
01329
01330
return( STATUS_SUCCESS );
01331 }
01332
01333
01334
01335
01336
01337 SecurityInformation = OWNER_SECURITY_INFORMATION |
01338 GROUP_SECURITY_INFORMATION |
01339 DACL_SECURITY_INFORMATION |
01340 SACL_SECURITY_INFORMATION;
01341
01342
01343
01344
01345
01346
01347
01348
01349
01350
01351
01352
01353
01354
ObpBeginTypeSpecificCallOut( SaveIrql );
01355
01356
Status = (*ObjectType->
TypeInfo.
SecurityProcedure)( Object,
01357
QuerySecurityDescriptor,
01358 &SecurityInformation,
01359 *SecurityDescriptor,
01360 &Length,
01361 &ObjectHeader->
SecurityDescriptor,
01362 ObjectType->
TypeInfo.
PoolType,
01363 &ObjectType->
TypeInfo.
GenericMapping );
01364
01365
ObpEndTypeSpecificCallOut( SaveIrql,
"Security", ObjectType, Object );
01366
01367
if (
Status != STATUS_BUFFER_TOO_SMALL) {
01368
01369
return(
Status );
01370 }
01371
01372
01373
01374
01375
01376
01377 *SecurityDescriptor =
ExAllocatePoolWithTag(
PagedPool, Length, 'qSbO' );
01378
01379
if (*SecurityDescriptor ==
NULL) {
01380
01381
return( STATUS_INSUFFICIENT_RESOURCES );
01382 }
01383
01384 *MemoryAllocated =
TRUE;
01385
01386
01387
01388
01389
01390
01391
01392
01393
ObpBeginTypeSpecificCallOut( SaveIrql );
01394
01395
Status = (*ObjectType->
TypeInfo.
SecurityProcedure)( Object,
01396
QuerySecurityDescriptor,
01397 &SecurityInformation,
01398 *SecurityDescriptor,
01399 &Length,
01400 &ObjectHeader->
SecurityDescriptor,
01401 ObjectType->
TypeInfo.
PoolType,
01402 &ObjectType->
TypeInfo.
GenericMapping );
01403
01404
ObpEndTypeSpecificCallOut( SaveIrql,
"Security", ObjectType, Object );
01405
01406
if (!
NT_SUCCESS(
Status )) {
01407
01408
ExFreePool( *SecurityDescriptor );
01409
01410 *MemoryAllocated =
FALSE;
01411 }
01412
01413
return(
Status );
01414 }
01415
01416
01417
VOID
01418 ObReleaseObjectSecurity (
01419 IN PSECURITY_DESCRIPTOR SecurityDescriptor,
01420 IN BOOLEAN MemoryAllocated
01421 )
01422
01423
01424
01425
01426
01427
01428
01429
01430
01431
01432
01433
01434
01435
01436
01437
01438
01439
01440
01441
01442
01443
01444 {
01445
PAGED_CODE();
01446
01447
01448
01449
01450
01451
if ( SecurityDescriptor !=
NULL ) {
01452
01453
01454
01455
01456
01457
01458
01459
01460
if (MemoryAllocated) {
01461
01462
ExFreePool( SecurityDescriptor );
01463
01464 }
else {
01465
01466
ObpDereferenceSecurityDescriptor( SecurityDescriptor );
01467 }
01468 }
01469 }
01470
01471
01472
NTSTATUS
01473 ObValidateSecurityQuota (
01474 IN PVOID Object,
01475 IN ULONG NewSize
01476 )
01477
01478
01479
01480
01481
01482
01483
01484
01485
01486
01487
01488
01489
01490
01491
01492
01493
01494
01495
01496
01497
01498
01499
01500
01501
01502 {
01503
POBJECT_HEADER ObjectHeader;
01504
POBJECT_HEADER_QUOTA_INFO QuotaInfo;
01505
01506
PAGED_CODE();
01507
01508
01509
01510
01511
01512
01513 ObjectHeader =
OBJECT_TO_OBJECT_HEADER( Object );
01514 QuotaInfo =
OBJECT_HEADER_TO_QUOTA_INFO( ObjectHeader );
01515
01516
01517
01518
01519
01520
01521
01522
01523
if ((QuotaInfo ==
NULL) && (NewSize >
SE_DEFAULT_SECURITY_QUOTA)) {
01524
01525
if (!(ObjectHeader->
Flags &
OB_FLAG_DEFAULT_SECURITY_QUOTA)) {
01526
01527
01528
01529
01530
01531
return( STATUS_SUCCESS );
01532 }
01533
01534
return( STATUS_QUOTA_EXCEEDED );
01535
01536
01537
01538
01539
01540
01541
01542
01543
01544 }
else if ((QuotaInfo !=
NULL) && (NewSize > QuotaInfo->
SecurityDescriptorCharge)) {
01545
01546
if (QuotaInfo->
SecurityDescriptorCharge == 0) {
01547
01548
01549
01550
01551
01552
01553
01554
return( STATUS_SUCCESS );
01555 }
01556
01557
return( STATUS_QUOTA_EXCEEDED );
01558
01559
01560
01561
01562
01563
01564
01565
01566 }
else {
01567
01568
return( STATUS_SUCCESS );
01569 }
01570 }
01571
01572
01573
NTSTATUS
01574 ObAssignSecurity (
01575 IN
PACCESS_STATE AccessState,
01576 IN PSECURITY_DESCRIPTOR ParentDescriptor OPTIONAL,
01577 IN PVOID Object,
01578 IN
POBJECT_TYPE ObjectType
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 PSECURITY_DESCRIPTOR NewDescriptor =
NULL;
01618
NTSTATUS Status;
01619 KIRQL SaveIrql;
01620
01621
PAGED_CODE();
01622
01623
01624
01625
01626
01627
01628
Status =
SeAssignSecurity( ParentDescriptor,
01629 AccessState->SecurityDescriptor,
01630 &NewDescriptor,
01631 (BOOLEAN)(ObjectType ==
ObpDirectoryObjectType),
01632 &AccessState->SubjectSecurityContext,
01633 &ObjectType->TypeInfo.GenericMapping,
01634
PagedPool );
01635
01636
if (!
NT_SUCCESS(
Status )) {
01637
01638
return(
Status );
01639 }
01640
01641
ObpBeginTypeSpecificCallOut( SaveIrql );
01642
01643
01644
01645
01646
01647
01648
Status = (*ObjectType->TypeInfo.SecurityProcedure)( Object,
01649
AssignSecurityDescriptor,
01650
NULL,
01651 NewDescriptor,
01652
NULL,
01653
NULL,
01654
PagedPool,
01655 &ObjectType->TypeInfo.GenericMapping );
01656
01657
ObpEndTypeSpecificCallOut( SaveIrql,
"Security", ObjectType, Object );
01658
01659
if (!
NT_SUCCESS(
Status )) {
01660
01661
01662
01663
01664
01665
01666
SeDeassignSecurity( &NewDescriptor );
01667 }
01668
01669
01670
01671
01672
01673
return(
Status );
01674 }
01675
01676
01677
01678
NTSTATUS
01679 ObQuerySecurityDescriptorInfo(
01680 IN PSECURITY_INFORMATION SecurityInformation,
01681 OUT PSECURITY_DESCRIPTOR SecurityDescriptor,
01682 IN OUT PULONG Length,
01683 IN PSECURITY_DESCRIPTOR *ObjectsSecurityDescriptor
01684 )
01685
01686
01687
01688
01689
01690
01691
01692
01693
01694
01695
01696
01697
01698
01699
01700
01701
01702
01703
01704
01705
01706
01707
01708
01709
01710
01711
01712
01713
01714
01715
01716
01717
01718
01719
01720
01721
01722 {
01723
NTSTATUS Status;
01724
01725
PAGED_CODE();
01726
01727
01728
01729
01730
01731
01732
01733
ObpAcquireDescriptorCacheReadLock();
01734
01735
Status =
SeQuerySecurityDescriptorInfo( SecurityInformation,
01736 SecurityDescriptor,
01737 Length,
01738 ObjectsSecurityDescriptor
01739 );
01740
ObpReleaseDescriptorCacheLock();
01741
01742
return(
Status );
01743 }
01744
01745
01746
01747
NTSTATUS
01748 ObSetSecurityDescriptorInfo (
01749 IN PVOID Object,
01750 IN PSECURITY_INFORMATION SecurityInformation,
01751 IN OUT PSECURITY_DESCRIPTOR SecurityDescriptor,
01752 IN OUT PSECURITY_DESCRIPTOR *ObjectsSecurityDescriptor,
01753 IN POOL_TYPE PoolType,
01754 IN PGENERIC_MAPPING GenericMapping
01755 )
01756
01757
01758
01759
01760
01761
01762
01763
01764
01765
01766
01767
01768
01769
01770
01771
01772
01773
01774
01775
01776
01777
01778
01779
01780
01781
01782
01783
01784 {
01785 PSECURITY_DESCRIPTOR OldDescriptor;
01786 PSECURITY_DESCRIPTOR NewDescriptor;
01787
NTSTATUS Status;
01788
01789
PAGED_CODE();
01790
01791
01792
01793
01794
01795
01796
01797
ObpAcquireDescriptorCacheWriteLock();
01798
01799 OldDescriptor = *ObjectsSecurityDescriptor;
01800 NewDescriptor = OldDescriptor;
01801
01802
Status =
SeSetSecurityDescriptorInfo( Object,
01803 SecurityInformation,
01804 SecurityDescriptor,
01805 &NewDescriptor,
01806 PoolType,
01807 GenericMapping );
01808
01809
01810
01811
01812
01813
01814
01815
01816
01817
if (
NT_SUCCESS(
Status )
01818
01819 &&
01820
01821 (
OBJECT_TO_OBJECT_HEADER( Object )->Type ==
ObpDirectoryObjectType)
01822
01823 &&
01824
01825 (((
POBJECT_DIRECTORY)Object)->SymbolicLinkUsageCount != 0)
01826
01827 &&
01828
01829 !
SeFastTraverseCheck( NewDescriptor, DIRECTORY_TRAVERSE,
UserMode )) {
01830
01831 KdPrint((
"OB: Failing attempt the remove world traverse access from object directory\n" ));
01832
01833
ExFreePool( NewDescriptor );
01834
01835
Status = STATUS_INVALID_PARAMETER;
01836 }
01837
01838
01839
01840
01841
01842
01843
01844
if (
NT_SUCCESS(
Status )) {
01845
01846
Status =
ObpLogSecurityDescriptor( NewDescriptor,
01847 ObjectsSecurityDescriptor );
01848
01849
ObpReleaseDescriptorCacheLock();
01850
01851
if (
NT_SUCCESS(
Status )) {
01852
01853
01854
01855
01856
01857
ObpDereferenceSecurityDescriptor( OldDescriptor );
01858
01859 }
else {
01860
01861
01862
01863
01864
01865
01866
ExFreePool( NewDescriptor );
01867 }
01868 }
else {
01869
01870
01871
01872
01873
01874
ObpReleaseDescriptorCacheLock();
01875 }
01876
01877
01878
01879
01880
01881
return(
Status );
01882 }
01883
01884
01885
NTSTATUS
01886 ObpValidateAccessMask (
01887
PACCESS_STATE AccessState
01888 )
01889
01890
01891
01892
01893
01894
01895
01896
01897
01898
01899
01900
01901
01902
01903
01904
01905
01906
01907 {
01908 SECURITY_DESCRIPTOR *SecurityDescriptor = AccessState->
SecurityDescriptor;
01909
01910
PAGED_CODE();
01911
01912
01913
01914
01915
01916
01917
01918
01919
if (SecurityDescriptor !=
NULL) {
01920
01921
if ( SecurityDescriptor->Control & SE_SACL_PRESENT ) {
01922
01923
if ( !(AccessState->
PreviouslyGrantedAccess & ACCESS_SYSTEM_SECURITY)) {
01924
01925 AccessState->
RemainingDesiredAccess |= ACCESS_SYSTEM_SECURITY;
01926 }
01927 }
01928 }
01929
01930
return( STATUS_SUCCESS );
01931 }
01932