Windows permissions basics
SIDs, access tokens, security descriptors: the basics of permissions in Windows that I’ve had to learn to troubleshoot problems
Security identifier (SID)
Security identifiers (SIDs) identify whom we are talking about. A SID is
serialized to a string that starts with S-1- (presumably S for SID and
1 for “version 1”, and there was only ever a version 1), followed by a
sequence of dash separated numbers. For example the Built-in Administrators
group SID is S-1-5-32-544. There is nothing secret about a SID value.
The most straightforward usage is to identify a user that might log-in, and the
processes that run as that user, e.g. Bob. A SID is immutable: the SID stays
the same even if the user name changes. Some processes run as part of the
operating system, e.g. SYSTEM, with the SID S-1-5-18, is such a non human
user. Then, to refer collectively to users, there are user groups, such as the
Built-Administrators group I already mentioned.
Then there are all sort of synthetics SIDs, for example Creator Owner, with
the SID S-1-3-0, is a placeholder to be replaced with the actual SID of the
user that creates an object (like a file or folder). Another example are logon
session SIDs that have the form S-1-5-5- X-Y where X and Y are unique
numeric values during a boot cycle.
Access token
The access token contains information about the party that initiates access, in Windows these are practically processes.
When a process starts it receives an access token. The access token contains:
- the SID of the user the process runs as
- a list of group SIDs for all the groups that the user is member of
- a list of privileges
- and many more
A thread within the process can use a different token temporarily until the
thread token is dismissed using RevertToSelf by:
- creating a copy of the process token using
ImpersonateSelfand further change it - impersonating a client from the other side of a communication channel
A common change to the thread token is to enable privileges. Privileges restrict access to/behaviour of system-related tasks/APIs, they are not directly linked to an object (i.e. file, folder) security This is done per thread so that we don’t impact the behaviour of APIs in the other threads. To enable a privilege, it must be present in the token, but disabled.
For example, in a thread of a process running as an administrator one can
enable the SeTakeOwnershipPrivilege to allow the thread to change the
ownership of a file or folder.
The privileges like SeTakeOwnershipPrivilege are actually strings. A C macro,
e.g. SE_TAKE_OWNERSHIP_NAME is used to refer to that string. At runtime the
privilege is referred by a corresponding binary value that can obtained via
LookupPrivilegeValue.
The security of the system constraints a process in the ability to arbitrarily
manipulate its own token. For example it should not be able to arbitrarily add
the known Built-in Administrators group SID to its own token. That ability is
reserved to specific system processes such as those that handle user logs in.
Also it should not be able to arbitrarily add privileges, it can only enable
assigned ones.
Security descriptor
The security descriptor is the information describing security constraints for accessing an object such as a file, folder, Windows pipe, registry key, Windows event, Active Directory object.
The security descriptor contains:
- the SID of the owner
- the SID of the primary group
- a DACL
- a SACL
- a set of bits
The DACL controls who can access the object. DACL means discretionary ACL. ACL means access control list. The ACL contains ACEs. An ACE is an access control entry. An ACE contains:
- the type of ACE aka.
ACCESS_MODE(e.g. allow or deny) - a SID
- an access mask
- a set of bit flags (e.g. with regards to inheritance)
To start with, an ACE specifies if access is allowed or denied, to the SID identifying a user or a group, and with the access mask identifying the access type (e.g. read, write etc.)
The access mask is a 32 bit number of which:
- the first low-order 16 bits are for object-specific rights, i.e. the usage
depends on the object type. E.g. the first bit
0x0001isFILE_READ_DATAfor files,FILE_LIST_DIRECTORYfor folders,KEY_QUERY_VALUEfor registry keys etc. - the next 8 bits are for standard access rights, i.e. that might apply to
multiple object types. E.g.
0x00010000LisDELETEand means the right to delete the object,0x00020000LisREAD_CONTROLand means the right to read information in the security descriptor - some are reserved (or used in more specific scenarios)
- the high-order 4 bits are for generic read, write, execute and all. They are
pseudo values, i.e. not set on an object, but instead used to specify the
desired access, and then first mapped to the actual bits (standard and
specific) before actually checking access. Also note that
GENERIC_ALLis0x10000000L, which is not a combination of the other three generic flags, but a flag of its own.
It turns out that the terminology ACL/ACE is overloaded. In different contexts it means slightly different things:
- We’ve seen the usage for DACLs above.
- The ACL is reused for SACL. SACL means system access control list. It refers
to configuring auditing for access to objects, not access itself. In that
context the valid values for
ACCESS_MODEareSET_AUDIT_SUCCESSandSET_AUDIT_FAILURE. - When manipulating an ACL in a DACL there are pairs of
ACCESS_MODE.GRANT_ACCESSmeans to combine the provided access with the existing one, whileSET_ACCESSmeans to allow the provided access for the SID, overwriting the existing access. SimilarlyDENY_ACCESScombines, whileREVOKE_ACCESSremoves by overriding.
When manipulating programmatically security descriptors, bear in mind that they
contain pointers to the components such as DACL. When the security descriptor
is in absolute format, it is the programmer’s responsibility to
free/release/destroy the components. When the security descriptor is in the
relative format, the components use the same buffer as the security
descriptor, therefore freeing only the security descriptor is sufficient.
Functions like ConvertStringSecurityDescriptorToSecurityDescriptor are
useful for building security descriptors in relative format.
Security descriptors of Active Directory (AD) objects has additional complexity that I’m not covering here, due generally to the fact that AD wants to be more granular for it’s many object types rather than just two for file systems (files and folders).
Putting it all together
When a process accesses a file with CreateFile (yes, CreateFile can also
just open the file, not necessarily create it), it specifies the file name as
lpFileName, and the desired access as dwDesiredAccess. The generic bits in
the desired access are mapped to standard and specific bits, using mapping for
files (the mapping is object type dependent). This results in the actual
desired access mask.
The access token is selected. If there is a thread token it is used, else it falls back to the process token.
Privileges in the token are checked (in particular it might check
SeBackupPrivilege which gives read permissions regardless of the actual ones
specified for the file).
Then the security descriptor of the file is read. The DACL provides a list of ACEs for which the access is allowed or denied. The SID from an ACE is matched against the list of SIDs (i.e. user and groups) from the access token for the required access. The DACL list is sorted based on the depth from which the entries were inherited, started with the entries set explicitly set on this object, then parent, grandparent and so on, and within each level the denied entries are ahead of the allow entries. As the DACL is traversed we stop at the first matching denied or when all the required access is met by allow entries. This ordering means that explicit permissions (or closer ones) take precedence over parent ones (or more distant ones) e.g. an explicit allow overrides a parent deny.
If it reaches the end and access is still not met, then access is denied.
A common area of mistakes is caused by the fact that a missing DACL (usually a
NULL) usually gives access to all while an empty DACL denies all accesses.
There are a number of relatively obscure scenarios where a process needs to enable privileges:
- to be able to kill processes
SeDebugPrivilegemight be required - to unload drivers
SeLoadDriverPrivilegeis required - to access/remove files/folders/registry
SeBackupPrivilege,SeRestorePrivilege,SeTakeOwnershipPrivilegeetc. might be required
Security descriptor definition language (SDDL)
SDDL is a serialization to/from string for security descriptors. The conversion
is done via APIs like ConvertSecurityDescriptorToStringSecurityDescriptor and
ConvertStringSecurityDescriptorToSecurityDescriptor. When referring to a SID,
it can be either a serialized SID value e.g. S-1-5-18, or a known SID e.g.
SY for SYSTEM.
Here is a simple example: O:SYG:BAD:(A;;GA;;;SY)(A;;GA;;;BA)(A;;GR;;;BU)
O:SY-Oowner isSYforSYSTEMG:BA-Gprimary group isBAforBuilt-in AdministratorsD:DACL follows with 3 ACEs(A;;GA;;;SY)-Aaccess,GAgeneric all,SYforSYSTEM(A;;GA;;;BA)-Aaccess,GAgeneric all,BAforBuilt-in Administrators(A;;GR;;;BU)-Aaccess,GRgeneric read,BUforBuilt-in Users
- there is no SACL, because there is no
S:
Confusingly, in SDDS the colon : follows the O,G,D or S instead of
acting as a separator.
ACE inheritance introduction
Inheritance controls how ACEs on a container apply to its children. In a file
system, a folder is a container and its children can be containers (subfolders)
or not (files). Inheritance of ACLs does not apply to some objects like say a
Windows synchronization event object (created with CreateEvent).
When a child is created, inheritable ACEs are copied into the child’s DACL. This is so that when permissions are checked, the check can be done locally without having to check the parent (also due to links there could be multiple parents). In the case of registry, registry keys are containers, registry values are non-container children, but, unlike files, the registry values do not have their own security descriptor.
When you change ACEs for a container and propagate that to its children, how is it preserving the explicit changes done on the children? Concretely, when propagating, if the child has an ACE that allows access to a group, but the access was removed in the parent, should the child access be removed because it was present due to inheritance or should it be removed because it was an explicit override? Before Windows 2000 the solution to this problem was not great. When the Microsoft documentation in 2026 says that the inheritance rules “have been enhanced with the following features”, without specifying a timeline of the change, they refer to improvements done in Windows 2000, which have been carried in the following versions, and that’s the scheme I describe here.
ACE inheritance flags
Flags on an ACE control how they apply in an inheritance context (named in the
format «Flag name string used in the second field in ACE SDDL
serialization»/«programming constant for value in AceFlags in
ACE_HEADER»):
OI/OBJECT_INHERIT_ACE: ACE is to be inherited by child non-container objects (files)CI/CONTAINER_INHERIT_ACE: ACE is to be inherited by child containers (subfolder)IO/INHERIT_ONLY_ACE: This ACE doesn’t apply to this container object, present only to be inherited by its childrenNP/NO_PROPAGATE_INHERIT_ACE: To be inherited by immediate children only, not grandchildren
The flags above create the following viable options shown in the permissions dialog box for a container like a file system folder that effectively creates a ACE with regards to where the ACE applies:
- “This folder only” - none of the above flags, empty string
- “This folder, subfolders and files” -
OICI(orCIOI, concatenation order does not matter) - “This folder and subfolders” -
CI - “This folder and files” -
OI - “Subfolders and files only” -
OICIIO - “Subfolders only” -
CIIO - “Files only” -
OIIO
In the same dialog the option - “Only apply these permissions to objects and/or
containers within the container” adds NP (except for “This folder only” where
the string stays empty).
The same logic applies to registry keys, except that in the case of registry the registry values do not have a security descriptor, so the options involving “files” go away leaving us with just:
- “This key only” - empty string
- “This key and subkeys” -
CI - “Subkeys only” -
CIIO
When the parent’s inheritable ACEs are applied to a child (such as when the child is created), each inherited also gets the following flag:
ID/INHERITED_ACE: This ACE is here because it was inherited The contents of the ACE do not specify from which parent it was inherited.
For example the following ACE (A;CIID;KR;;;BU) means:
AallowCIIDto this key and subkeys, inherited (not set explicitly on this key)KR- key readBU- forBuilt-in Users
ACE inheritance propagation
As I said, when a child is created, e.g. a file using CreateFile when the
file does not already exist, inheritable ACEs are copied into the child’s DACL
from its parent. Another case is when the permissions of some parent are
reapplied, e.g. due to the parent’s permissions changing; APIs like
SetSecurityInfo (and SetNamedSecurityInfo) do that, while pre-Windows 2000
APIs like SetFileSecurity (which is marked obsolete) and RegSetKeySecurity
don’t.
A object can be configured to block this inheritance by having
SE_DACL_PROTECTED and/or SE_SACL_PROTECTED set on the control flags of its
security descriptor to block inheritance for the DACL ACEs or SACL ACEs
respectively. To set them via SetSecurityInfo you use
PROTECTED_DACL_SECURITY_INFORMATION and/or
PROTECTED_SACL_SECURITY_INFORMATION. Protection stops receiving ACEs from
above, but by default children still get the ACEs. When enabling protection in
the permissions dialog via “Disable inheritance”, the GUI asks what do do with
the existing ACEs that have the ID flag: remove them or keep them, but with
the ID flag removed.
When a ACE is transferred to a child due to inheritance, the ACE inheritance
flags are altered to preserve the propagation semantics. Here are some
examples. For a child that is a container, if the NP flag was set the
semantic is to propagate here, but not further, so then OI, CI, IO, NP
are cleared. For a child that is not a container (e.g. a file), OI, CI,
IO, NP are cleared. In both cases the ID flag is set so that it’s clear
that the ACE was received via inheritance. See ACE Inheritance
Rules
for further specific rules.
Role of the creator owner
ACEs for Creator Owner do not have any effect on the object they are set in
terms of granted or denied access as the access tokens don’t have that
synthetic SID in their SID list. The point of the ACEs for Creator Owner to
ensure that when children get created they also get additional ACEs for the
creator/owner of the child if they are not already covered by the other ACEs.
When the ACE for Creator Owner is to be inherited two things happen. The ACE
is inherited as per the inheritance rules (again with no effect on this child).
But then the creator (or owner) SID is replaced in the ACE and then if then by
inheriting this changes access, then the new ACE with permissions is added to
the child.
ACL related flags in the security descriptor
These are flags related to ACLs (DACL and/or SACL), stored at the security descriptor level, different from the ACE flags I’ve covered above.
For DACL:
PfollowingD:in SDDL/SE_DACL_PROTECTEDas discussed before it blocks inheritance from parents applying to this object, but not from applying from this object to its childrenAIorARfollowingD:in SDDL/SE_DACL_AUTO_INHERITEDorSE_DACL_AUTO_INHERIT_REQrespectively are flags related to “have the ACEs been migrated post Windows 2000 changes?”. In practice you’ll seeAIset for files/folders/registry, but not for cases where the inheritance does not apply such as Windows synchronization events. TheARis used to request this migration to happen.
For SACL things are similar: P, AI, AR follow the S: in SDDL and flag
names constants in C replace DACL with SACL.
Example of the oddities
Say for example you check the registry security descriptors for HKLM\SOFTWARE
and a subkey of.
I’m going to ignore the permissions for:
AC: a well known SID string forAll App Packages- and
S-1-15-3-1024-1065365936-1281604716-3511738428-1654721687-432734479-3232135806-4053264122-3456934681: a capability SID forregistryReadfor AppContainer processes
Ignoring them you’ll get for HLKM\SOFTWARE something like:
O:SYG:SYD:PAI(A;CI;KA;;;SY)(A;CI;KA;;;BA)(A;CI;KR;;;BU)(A;CI;KA;;;CO)
That kind of makes sense because it means that SYSTEM and Built-in
Administrators get full permissions, the Creator Owner also gets full
permissions (just in case), while Built-in Users get just read.
But if you look at (A;CI;KA;;;CO) this gives full permissions for the
Creator Owner for CI which means “This key and subkeys”. The correct value
should have been CIIO meaning “Subkeys only”, as the Creator Owner ACE has
no effect on the object, it only applies to children.
For a subkey of HKLM\SOFTWARE created by an administrator user you’ll get
something like this:
O:BAG:<<admin's user SID>>D:AI(A;CIID;KR;;;BU)(A;CIID;KA;;;BA)(A;CIID;KA;;;SY)(A;CIIOID;KA;;;CO)
It has no P after D: so the ACEs where inherited and it makes sense that
all ACEs have ID as well to indicate that they were inherited. The Creator
only entry was corrected from CI to CIIO.
No additional entry was created due to parent’s entry of full access for
Creator owner because the owner is BA (Built-in Administrators) and the
parent already had full access for BA.
But it’s weird that the owner is a group (BA) and the primary group
(following G:) is a user SID. Wait what’s the primary group for? Well as far
I can see not for much. It seems to have been created to help support the POSIX
subsystem which had a different permission model for the user, group and all.
But it helps with forensics, one can then see which user created the key.
Conclusion
Is this all? No, but it’s a basis that I use to troubleshoot problems with the permissions.
Reference
MSDN documentation about authorization in Windows.
MSDN documentation on the security descriptor definition language
MSDN documentation on ACE inheritance
Raymond Chen: Why doesn’t RegSetKeySecurity propagate inheritable ACEs, but
SetSecurityInfo
does?
In this article “The old code used the SetSecurityInfo function […] heir
revised version used RegSetKeySecurity, and they observed that that function
does not propagate inheritable ACEs to child keys.” is to be read that the old
code used the new function and the revised version switched to an older
function that precedes the Window 2000 changes to ACE inheritance and kept some
of the legacy behaviour.