runtime icon indicating copy to clipboard operation
runtime copied to clipboard

DirectoryObjectSecurity.GetAccessRules throws NullReferenceException when SetSecurityDescriptorBinaryForm is used to initialize the object

Open tquerec opened this issue 7 years ago • 8 comments

  • @dsgouda who committed the initial version of these files.

During .NET core a new private field ( _securityDescriptor) was added to DirectoryObjectSecurity. This field obscures the _securityDescriptor field in the base class (ObjectSecurity). ObjectSecurity exposes a public method, SetSecurityDescriptorBinaryForm which is expected to populate the object with a user supplied descriptor. If SetSecurityDescriptorBinaryForm is called on a DirectoryObjectSecurity class only ObjectSecurity._securityDescriptor is populated. DirectoryObjectSecurity._securityDescriptor is still null. When DirectoryObjectSecurity.GetAccessRules is called, it accesses DirectoryObjectSecurity._securityDescriptor which is null. It appears DirectoryObjectSecurity._securityDescriptor was added when the code was ported .NET core as the current full framework versions do not have the new private field. The issue was identified using the ActiveDirectoryPowershell module in PSH core as it uses these objects to inspect the permissions on a principal.

To repro

Open PSH core on Windows 1809 or later Run Get-ADUser administrator -prop *

cmd will fail with NullReferenceException

PS C:\Users\administrator.TQDFT5D> get-aduser administrator -prop *
get-aduser : Object reference not set to an instance of an object.
At line:1 char:1
+ get-aduser administrator -prop *
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (administrator:ADUser) [Get-ADUser], NullReferenceException
+ FullyQualifiedErrorId : ActiveDirectoryCmdlet:System.NullReferenceException,Microsoft.ActiveDirectory.Management.Commands.GetADUser

Stack Trace

PS C:\Users\administrator.TQDFT5D> $error[0].Exception.StackTrace

   at System.Security.AccessControl.DirectoryObjectSecurity.GetRules(Boolean access, Boolean includeExplicit, Boolean includeInherited, Type targetType)
   at System.Security.AccessControl.DirectoryObjectSecurity.GetAccessRules(Boolean includeExplicit, Boolean includeInherited, Type targetType)
   at Microsoft.ActiveDirectory.Management.Commands.ADAccountFactory`1.ScanACLForChangePasswordRight(ActiveDirectorySecurity adsSecurity, Boolean& denySelfFound, Boolean& denyWorldFound, Boolean& allowSelfFound, Boolean& allowWorldFound)
   at Microsoft.ActiveDirectory.Management.Commands.ADAccountFactory`1.ToExtendedCannotChangePassword(String extendedAttribute, String[] directoryAttributes, ADEntity userObj, ADEntity directoryObj, CmdletSessionInfo cmdletSessionInfo)
   at Microsoft.ActiveDirectory.Management.Commands.AttributeConverterEntry.InvokeToExtendedConverter(ADEntity userObj, ADEntity directoryObj, CmdletSessionInfo cmdletSessionInfo)
   at Microsoft.ActiveDirectory.Management.Commands.ADFactory`1.Construct(ADEntity directoryObj, AttributeSetRequest requestedAttributes)
   at Microsoft.ActiveDirectory.Management.Commands.ADPrincipalFactory`1.Construct(ADEntity directoryObj, AttributeSetRequest requestedAttributes)
   at Microsoft.ActiveDirectory.Management.Commands.ADFactory`1.GetExtendedObjectFromIdentity(T identityObj, String identityQueryPath, ICollection`1 propertiesToFetch, Boolean showDeleted, Boolean showLinkTtl)
   at Microsoft.ActiveDirectory.Management.Commands.ADFactory`1.GetExtendedObjectFromIdentity(T identityObj, String identityQueryPath, ICollection`1 propertiesToFetch, Boolean showDeleted)
   at Microsoft.ActiveDirectory.Management.Commands.ADGetCmdletBase`3.ADGetCmdletBaseProcessCSRoutine()
   at Microsoft.ActiveDirectory.Management.CmdletSubroutinePipeline.Invoke()
   at Microsoft.ActiveDirectory.Management.Commands.ADCmdletBase`1.ProcessRecord()

tquerec avatar Dec 18 '18 23:12 tquerec

@joshfree can you help find the right person to take a look into this?

dsgouda avatar Dec 18 '18 23:12 dsgouda

@JeremyKuhne can you please help here? It seems like we might want to add protected getter for ObjectSecurity._securityDescriptor for inhereted classes. It seems to me that DirectoryObjectSecurity._securityDescriptor is trying to work around that limitation (intercepting it in constructor), but cannot easily intercept ObjectSecurity.SetSecurityDescriptorBinaryForm calls on parent.

@dsgouda is there any special priority for this bug?

karelz avatar Dec 19 '18 19:12 karelz

@karelz I haven't worked on this library, not sure how I ended up being assigned.

dsgouda avatar Dec 19 '18 19:12 dsgouda

Although @dsgouda did port this https://github.com/dotnet/corefx/pull/4946 it was a copy of internal ProjectK sources

TFS change that introduced it was #1386807 in 2014 by someone who seems to have left. Possibly some kind of copy paste error?

danmoseley avatar Jan 02 '19 23:01 danmoseley

As @karelz mentions, this is an issue of internal visibility. On desktop ObjectSecurity and DirectoryObjectSecurity are both in mscorlib, now they are in different files. Opened an api proposal to fix this.

JeremyKuhne avatar Mar 12 '19 18:03 JeremyKuhne

@JeremyKuhne only 1 area label please.

karelz avatar Apr 24 '19 20:04 karelz

@JeremyKuhne it does not seem like the API proposal has been approved. Is a fix still feasible for 3.0 here?

danmoseley avatar Jun 05 '19 16:06 danmoseley

it does not seem like the API proposal has been approved

I'll kick the internal alias for approval as it is simple.

JeremyKuhne avatar Jun 05 '19 16:06 JeremyKuhne