From: Timo Kreuzer Date: Tue, 4 Nov 2014 20:41:10 +0000 (+0000) Subject: [NTOSKRNL] X-Git-Tag: backups/tcpip_revolution@71025~94 X-Git-Url: https://git.reactos.org/?p=reactos.git;a=commitdiff_plain;h=afc42dae68d1c4de3a9c9b928b3098b984e9b582 [NTOSKRNL] Merge r62304 and r65253 from kernel-fun branch: Fix logic in ObSetSecurityDescriptorInfo. To understand the change: it is not only style change! The old code modified SecurityDescriptor, which must always stay the same in the loop! svn path=/trunk/; revision=65254 --- diff --git a/reactos/ntoskrnl/ob/obsecure.c b/reactos/ntoskrnl/ob/obsecure.c index 15395b7d9ae..3009c448967 100644 --- a/reactos/ntoskrnl/ob/obsecure.c +++ b/reactos/ntoskrnl/ob/obsecure.c @@ -144,61 +144,54 @@ ObSetSecurityDescriptorInfo(IN PVOID Object, &NewDescriptor, PoolType, GenericMapping); - if (NT_SUCCESS(Status)) + if (!NT_SUCCESS(Status)) { - /* Now add this to the cache */ - Status = ObLogSecurityDescriptor(NewDescriptor, - &CachedDescriptor, - MAX_FAST_REFS + 1); - - /* Let go of our uncached copy */ - ExFreePool(NewDescriptor); - - /* Check for success */ - if (NT_SUCCESS(Status)) - { - /* Do the swap */ - FastRef = (PEX_FAST_REF)OutputSecurityDescriptor; - OldValue = ExCompareSwapFastReference(FastRef, - CachedDescriptor, - OldDescriptor); - - /* Get the security descriptor */ - SecurityDescriptor = ExGetObjectFastReference(OldValue); - Count = ExGetCountFastReference(OldValue); - - /* Make sure the swap worked */ - if (SecurityDescriptor == OldDescriptor) - { - /* Flush waiters */ - ObpAcquireObjectLock(ObjectHeader); - ObpReleaseObjectLock(ObjectHeader); - - /* And dereference the old one */ - ObDereferenceSecurityDescriptor(OldDescriptor, Count + 2); - break; - } - else - { - /* Someone changed it behind our back -- try again */ - ObDereferenceSecurityDescriptor(OldDescriptor, 1); - ObDereferenceSecurityDescriptor(CachedDescriptor, - MAX_FAST_REFS + 1); - } - } - else - { - /* We failed, dereference the old one */ - ObDereferenceSecurityDescriptor(OldDescriptor, 1); - break; - } + /* We failed, dereference the old one */ + if (OldDescriptor) ObDereferenceSecurityDescriptor(OldDescriptor, 1); + break; } - else + + /* Now add this to the cache */ + Status = ObLogSecurityDescriptor(NewDescriptor, + &CachedDescriptor, + MAX_FAST_REFS + 1); + + /* Let go of our uncached copy */ + ExFreePool(NewDescriptor); + + /* Check for success */ + if (!NT_SUCCESS(Status)) { /* We failed, dereference the old one */ - if (OldDescriptor) ObDereferenceSecurityDescriptor(OldDescriptor, 1); + ObDereferenceSecurityDescriptor(OldDescriptor, 1); break; } + + /* Do the swap */ + FastRef = (PEX_FAST_REF)OutputSecurityDescriptor; + OldValue = ExCompareSwapFastReference(FastRef, + CachedDescriptor, + OldDescriptor); + + /* Make sure the swap worked */ + if (ExGetObjectFastReference(OldValue) == OldDescriptor) + { + /* Flush waiters */ + ObpAcquireObjectLock(ObjectHeader); + ObpReleaseObjectLock(ObjectHeader); + + /* And dereference the old one */ + Count = ExGetCountFastReference(OldValue); + ObDereferenceSecurityDescriptor(OldDescriptor, Count + 2); + break; + } + else + { + /* Someone changed it behind our back -- try again */ + ObDereferenceSecurityDescriptor(OldDescriptor, 1); + ObDereferenceSecurityDescriptor(CachedDescriptor, + MAX_FAST_REFS + 1); + } } /* Return status */