# Access check

---

# Access check

_Peios Kernel / Internals / KACS / Access check_

> Find the Peios kernel articles about access check.

Use these articles to understand access check in the Peios kernel.

- [AccessCheck Overview](</kernel/internals/kacs/access-check/accesscheck-overview.md>)
- [The DACL Walk](</kernel/internals/kacs/access-check/the-dacl-walk.md>)
- [Mandatory Integrity Control](</kernel/internals/kacs/access-check/mandatory-integrity-control.md>)
- [Restricted Tokens](</kernel/internals/kacs/access-check/restricted-tokens.md>)
- [Object ACEs and Property-Level Access](</kernel/internals/kacs/access-check/object-aces-and-property-level-access.md>)
- [Application Confinement](</kernel/internals/kacs/access-check/application-confinement.md>)
- [PIP in AccessCheck](</kernel/internals/kacs/access-check/pip-in-accesscheck.md>)
- [Central Access and Auditing Policy](</kernel/internals/kacs/access-check/central-access-and-auditing-policy.md>)
- [Auditing in AccessCheck](</kernel/internals/kacs/access-check/auditing-in-accesscheck.md>)
- [The Algorithm](</kernel/internals/kacs/access-check/the-algorithm.md>)

---

# AccessCheck Overview

_Peios Kernel / Internals / KACS / Access check_

> The function that connects tokens to descriptors — its two API variants, and the three state values a right can hold during evaluation.

<a id="trm-3-8-1"></a>

AccessCheck is the function that connects tokens to security
descriptors. Given a token — who is asking — a descriptor — what the
rules are — and a desired access mask — what they want to do — it
returns a verdict: which of the requested rights are granted, and
whether the request as a whole succeeds.

It is a pipeline, evaluating several layers of policy in a fixed
order. Each layer can grant or constrain access and the layers
interact: integrity policy can block what the DACL would allow,
privileges can override what the DACL denied, and confinement can
revoke what privileges granted. The order is not incidental — it is
the specification.

<a id="trm-3-8-1-1"></a>

## Two API variants

**AccessCheck** is the common case. It returns the granted access
mask, whether the request succeeded, a continuous audit mask derived
from SACL alarm ACEs, and a CAAP staging mismatch flag. <a id="cite-check.accesscheck.returns"></a> When an object
type list is supplied, success requires every listed node to pass and
the returned mask is the intersection across them. The staging
mismatch flag is set when the staged scalar result differs from the
effective scalar result, when any per-node staged grant differs from
the effective per-node grant, or when staged auditing differs from
effective auditing. <a id="cite-check.staging-flag.accesscheck"></a>

**AccessCheckResultList** is the per-property variant and requires an
object type list. <a id="cite-check.result-list.requires-tree"></a> It returns a separate verdict for each node, so a
denial on one property fails that property alone rather than the whole
request. <a id="cite-check.result-list.returns"></a> It returns the same continuous audit mask and staging
mismatch flag, with the flag set when the staged scalar result differs
from the effective one, when any node's staged granted mask differs
from that node's effective granted mask, or when staged auditing
differs from effective auditing — the scalar comparison is not
mode-branched. <a id="cite-check.staging-flag.result-list"></a> Directory services use it,
because one operation there may touch several properties with
independent access rules. Privilege-use auditing in this variant takes
the same per-node view: a privilege counts as successfully used if its
contributed bits survive on *any* node's final granted mask.

Both variants share one evaluation pipeline. Only the collection of
results differs.

## A supplied subject without a token

The separate `kacs_access_check_subject` query evaluates caller-supplied SID,
group and typed-claim facts without creating, adopting or impersonating a
token. It reuses the DACL, conditional and object-ACE evaluators. Omitted
facts stay unknown; known-empty collections and explicit claim absences
are distinct. No access fact is inherited from the caller. Explicit integrity,
trust, scoped-policy and privilege requirements return missing execution
context rather than acquiring the caller's authority.

Syscall 1028 accepts a versioned request buffer and writes a granted, denied
or missing-context result. Missing context carries no provisional grant.
The kernel copies and validates one bounded buffer; internal offsets replace
nested userspace pointers. The UAPI access header specifies layout and limits.
Malformed or excessive inputs fail the entire query without truncating facts.

Matching SACL audit ACEs require enabled `SeAuditPrivilege` on the actual
caller. `KACS_SUBJECT_NO_AUDIT` suppresses this query's records; it does not bypass mandatory
SACL labels. Audit-only missing facts matter only while auditing is active.
Records use `kacs.audit.subject.checked`: `subject` is the real caller and
`source.supplied-subject.sid` is a hypothetical assertion. An optional generic `AuditContext`
labels the guarded object without influencing policy. Detected audit
preparation or submission errors fail the query. Records are submitted before
result writeback, so a bad output pointer cannot silence requested auditing.

<a id="trm-3-8-1-2"></a>

## The three state values

Every access check tracks three masks.

**`decided`** records which bits have been resolved. It enforces
first-writer-wins within the DACL walk: once a bit is decided, no
later ACE in the same walk changes its outcome. Pipeline layers that
operate on top of the DACL result — restricted token intersection,
confinement intersection, PIP revocation, CAAP intersection — may
still revoke granted bits. Those layers narrow the result; they do not
re-open decided bits for re-evaluation through the DACL. <a id="cite-check.state.narrow-not-reopen"></a>

**`granted`** records which bits resolved to yes. During the walk it
is a subset of `decided`. Afterwards the later layers may remove bits
from it, and the final value is what the caller receives.

**`privilege_granted`** records which bits in `granted` came from a
privilege rather than from the DACL. It exists for two reasons: audit
accuracy, so that privilege-granted access is distinguishable from
DACL-granted access, and the restricted token merge, where
privilege-granted bits are restored after the intersection so that
privileges bypass the restricted pass. PIP may revoke
privilege-granted bits.

With an object type list present, each node carries its own `decided`
and `granted` pair.

---

# The DACL Walk

_Peios Kernel / Internals / KACS / Access check_

> Walking the ACEs in order under first-writer-wins — SID matching, absent and empty DACLs, owner implicit rights and MAXIMUM_ALLOWED.

<a id="trm-3-8-2"></a>

The DACL is an ordered list of ACEs, walked from first to last,
comparing each ACE's SID against the calling token's identity. The
governing principle is **first-writer-wins**: once a bit has been
resolved, granted or denied, no later ACE changes the outcome for that
bit. <a id="cite-check.dacl.first-writer-wins"></a>

An **allow** ACE whose SID matches the token grants the rights it
carries that have not yet been decided, leaving already-decided bits
untouched. <a id="cite-check.dacl.allow-grants-undecided"></a> A **deny** ACE whose SID matches denies its
not-yet-decided rights — marking them decided but not granted — and
likewise leaves decided bits alone. <a id="cite-check.dacl.deny-marks-decided"></a>

<a id="trm-3-8-2-1"></a>

## SID matching

An ACE's SID matches the token when it equals the user SID or a group
SID on the token, subject to attribute filtering.

For **allow** ACEs, only groups that are enabled and not deny-only
match. <a id="cite-check.dacl.allow-enabled-groups-only"></a> For **deny** ACEs, both enabled groups and deny-only groups
match: a deny-only group always participates in deny matching whatever
its enabled state. <a id="cite-check.dacl.deny-matches-deny-only"></a> A group with neither `SE_GROUP_ENABLED` nor
`SE_GROUP_USE_FOR_DENY_ONLY` participates in no matching at all. <a id="cite-check.dacl.inert-group"></a>

The user SID follows the same rule — when `user_deny_only` is set on
the token, it matches deny ACEs and not allow ACEs. <a id="cite-check.dacl.user-deny-only"></a>

<a id="trm-3-8-2-2"></a>

## Skipping and mapping

ACEs carrying `INHERIT_ONLY` exist purely to propagate to child
objects and are skipped by the walk. <a id="cite-check.dacl.inherit-only-skipped"></a>

At the top of the walk each ACE's access mask is mapped through
`MapGenericBits` using the same GenericMapping applied to the caller's
request. <a id="cite-check.dacl.ace-mask-mapped"></a> The mapping works on a local copy — the ACE itself is never
mutated. Mapping ACE masks at evaluation time is a deliberate
departure from MS-DTYP, and it is what makes `GENERIC_ALL` work in
central access policy recovery ACEs ([Central Access and Auditing Policy](</kernel/internals/kacs/access-check/central-access-and-auditing-policy.md#trm-3-8-8>)).

Descriptors that KACS stores on its own objects reach the walk already
mapped. Every path that writes an object's descriptor — creation,
inheritance, the token's default DACL, and setting a descriptor on an
existing object — maps generic rights in the ACEs that apply to the
object, through that object type's GenericMapping. An ACE that applies
to the object and is also inherited is split, as at creation, into a
mapped ACE for the object and an inherit-only copy that keeps its
generic rights for the children it will reach. Inherit-only ACEs keep
theirs. <a id="cite-check.dacl.stored-descriptors-mapped"></a> A descriptor therefore reads back the same however it was
applied. The walk's own mapping remains for descriptors that never pass
through those paths, such as ones a caller hands to AccessCheck.

<a id="trm-3-8-2-3"></a>

## Absent and empty DACLs

If the descriptor has no DACL — `SE_DACL_PRESENT` unset — every valid
right not already decided by an earlier pipeline stage is granted. <a id="cite-check.dacl.absent-grants-valid-rights"></a> The
valid rights are bounded by `MapGenericBits(GENERIC_ALL, mapping)`
rather than by a raw `0xFFFFFFFF`. <a id="cite-check.dacl.absent-bounded-by-generic-all"></a>

If the DACL is present but holds zero ACEs, the walk grants nothing. <a id="cite-check.dacl.empty-grants-nothing"></a>
The only access an owner gets in that case comes from the implicit
rights mechanism below.

<a id="trm-3-8-2-4"></a>

## Owner implicit rights

By default the owner of an object receives `READ_CONTROL` and
`WRITE_DAC` whatever the DACL says. <a id="cite-check.dacl.owner-implicit-rights"></a> These are granted **before** the
walk begins, as the first action inside `EvaluateDACL`, and because
first-writer-wins governs the walk, no deny ACE encountered later can
override them. <a id="cite-check.dacl.owner-implicit-before-walk"></a>

`EvaluateDACL` takes a `skip_owner_implicit` parameter. The
confinement pass sets it, because confinement is an absolute
intersection with no owner bypass.

The grant is suppressed entirely if any non-inherit-only
access-control ACE in the DACL targets the `OWNER RIGHTS` SID
(`S-1-3-4`). <a id="cite-check.dacl.owner-rights-suppresses-implicit"></a> This is a pre-scan performed at the start of
`EvaluateDACL`, before the main loop, and it checks only for the SID's
presence — it does not evaluate any conditional expression on the ACE. <a id="cite-check.dacl.owner-rights-prescan-presence-only"></a>

During the walk proper, `S-1-3-4` is treated as an ordinary SID
matching the owner, at both allow and deny polarity. <a id="cite-check.dacl.owner-rights-ordinary-sid"></a> It obeys the same
rules as any other SID: an allow ACE matches only through an enabled,
non-deny-only group, and not through the user SID of a
`user_deny_only` token; a deny ACE matches through a group that is
enabled or deny-only, and through the user SID unconditionally.

Note that the *implicit* grant above is a separate rule and remains
presence-based. It is bounded by the pre-scan rather than by polarity.

The implicit grant is also bounded twice over: by the object type's
valid rights, and by what has already been decided. A pre-decision
from MIC, PIP or a privilege therefore suppresses it — a non-dominant
owner does not receive `WRITE_DAC` through this route. <a id="cite-check.dacl.owner-implicit-bounded-by-decided"></a>

<a id="trm-3-8-2-5"></a>

## MAXIMUM_ALLOWED

When the caller includes `MAXIMUM_ALLOWED` (bit 25), AccessCheck runs
the full pipeline and returns the complete set of rights that would be
granted. The bit is stripped from the desired mask before evaluation
begins. <a id="cite-check.dacl.max-allowed-stripped"></a>

Two things change. The walk runs to completion with no short-circuit,
and the returned mask is whatever the pipeline accumulated rather than
being filtered to the requested bits. <a id="cite-check.dacl.max-allowed-returns-accumulated"></a>

`MAXIMUM_ALLOWED` can be combined with specific rights:
`MAXIMUM_ALLOWED | READ_CONTROL` asks both "can I read the
descriptor?" as a success or failure and "what else could I get?" as a
mask. A pure `MAXIMUM_ALLOWED` request carrying no specific bits
always succeeds. <a id="cite-check.dacl.max-allowed-alone-succeeds"></a>

Otherwise — when the desired mask is fully decided — the walk may stop
early.

First-writer-wins applies to `MAXIMUM_ALLOWED` requests exactly as it
does to targeted ones. <a id="cite-check.dacl.max-allowed-first-writer-wins"></a> MS-DTYP treats the two differently; KACS does
not, which is what stops "what can I do?" and "can I do this?"
disagreeing on a DACL that is not in canonical order.

---

# Mandatory Integrity Control

_Peios Kernel / Internals / KACS / Access check_

> MIC restricts what the DACL is allowed to grant along a vertical trust hierarchy — the labels, the policy bits, and the algorithm.

<a id="trm-3-8-3"></a>

MIC is a mandatory constraint that restricts which rights the DACL is
allowed to grant, along a vertical trust hierarchy. It is evaluated
**before** the DACL walk, in the pre-SACL phase. <a id="cite-check.mic.before-dacl"></a>

Every token carries an integrity level, and every object may carry a
mandatory label — a `SYSTEM_MANDATORY_LABEL_ACE` in its SACL. MIC
compares the two: a caller below the object's level is blocked from
whole categories of access whatever the DACL says.

The default is **no-write-up**. A lower-integrity process can read and
execute a higher-integrity object but cannot write to it, and the
object's label may additionally block reads or execution for callers
beneath it. <a id="cite-check.mic.default-no-write-up"></a>

An object with no mandatory label ACE in its SACL — or no SACL at all
— is treated as Medium integrity with no-write-up, so Low and
Untrusted processes cannot write to unlabelled objects. <a id="cite-check.mic.unlabelled-is-medium"></a>

A caller whose level is greater than or equal to the object's label
**dominates** it, and MIC pre-decides nothing: the DACL handles
authorization normally. <a id="cite-check.mic.dominant-no-effect"></a>

<a id="trm-3-8-3-1"></a>

## What MIC does and does not touch

MIC constrains what the DACL can grant. It does not revoke what
privileges have already granted, because it mutates only `decided` and
never touches `granted` or `privilege_granted`. <a id="cite-check.mic.never-revokes-privileges"></a>

`ACCESS_SYSTEM_SECURITY` is outside its reach for a structural reason:
the bits MIC can decide are bounded by
`MapGenericBits(GENERIC_ALL, mapping)`, which does not include it. The
right is privilege-granted rather than DACL-granted, so MIC never
blocks it. <a id="cite-check.mic.access-system-security-untouched"></a> PIP is stricter and does revoke it for non-dominant callers
— explicitly ORing it into the set of bits it can take away — which is
the mechanism by which objects stay protected even from
administrators.

`SeRelabelPrivilege` has one specific interaction: it lets the DACL
grant `WRITE_OWNER` even when an integrity mismatch would otherwise
block it, so a privileged administrator can take ownership of a
higher-integrity object as the first step in modifying it. <a id="cite-check.mic.relabel-allows-write-owner"></a> The bit
granted this way is recorded under its own provenance and is
deliberately **not** part of `privilege_granted`, so it is not
restored after the restricted merge and is not preserved by the CAAP
error escape hatch. <a id="cite-check.mic.relabel-not-privilege-granted"></a>

Enforcement is gated on the token's `mandatory_policy`: with
`NO_WRITE_UP` set — the default — the rule applies, and with it clear
MIC is effectively disabled for that token. <a id="cite-check.mic.mandatory-policy-gate"></a> The field is fixed at
creation ([Token Structure](</kernel/internals/kacs/tokens/token-structure.md#trm-3-2-2>)), which is what makes MIC a boundary rather than a
suggestion.

<a id="trm-3-8-3-2"></a>

## Labels

An object's SACL may carry more than one mandatory label ACE. Only the
first non-inherit-only one is used; inherit-only labels do not apply
to the object carrying them. <a id="cite-check.mic.first-non-inherit-only-label"></a>

The SID in a mandatory label ACE has the Mandatory Label authority
(`S-1-16`) and exactly one sub-authority, and that sub-authority value
*is* the integrity level, compared as an unsigned integer. <a id="cite-check.mic.label-sid-shape"></a> Any
`S-1-16-X` is therefore valid.

| SID | Level | Name |
|---|---:|---|
| `S-1-16-0` | 0 | Untrusted |
| `S-1-16-4096` | 4096 | Low |
| `S-1-16-8192` | 8192 | Medium |
| `S-1-16-12288` | 12288 | High |
| `S-1-16-16384` | 16384 | System |

Peios tooling and authd use these five, but intermediate values such
as `S-1-16-2048` or `S-1-16-8448` are valid and compared numerically,
which is what allows Windows-originated descriptors carrying
non-standard levels to be evaluated without translation. <a id="cite-check.mic.nonstandard-levels-accepted"></a>

A label ACE whose SID falls outside the `S-1-16` authority — wrong
identifier authority, or the wrong sub-authority count — is
malformed, and so is one that is not a plain single-SID ACE. Either
causes AccessCheck to reject the whole descriptor with an error rather
than ignore the label. <a id="cite-check.mic.malformed-label-rejects-descriptor"></a>

<a id="trm-3-8-3-3"></a>

## Policy bits

| Bit | Value | Meaning |
|---|---|---|
| `SYSTEM_MANDATORY_LABEL_NO_READ_UP` | 0x00000001 | Non-dominant callers receive no read-mapped rights from the DACL. <a id="cite-check.mic.policy.no-read-up"></a> |
| `SYSTEM_MANDATORY_LABEL_NO_WRITE_UP` | 0x00000002 | Non-dominant callers receive no write-mapped rights from the DACL. <a id="cite-check.mic.policy.no-write-up"></a> |
| `SYSTEM_MANDATORY_LABEL_NO_EXECUTE_UP` | 0x00000004 | Non-dominant callers receive no execute-mapped rights from the DACL. <a id="cite-check.mic.policy.no-execute-up"></a> |

Unknown bits in a label mask are ignored. <a id="cite-check.mic.unknown-policy-bits-ignored"></a>

<a id="trm-3-8-3-4"></a>

## The algorithm <a id="cite-check.mic.algorithm"></a>

```
EnforceMIC(ace, token, mapping, &decided):

    if not (token.mandatory_policy & NO_WRITE_UP):
        return

    token_dominates = (token.integrity_level >= ace.integrity_level)

    if token_dominates:
        return

    // Non-dominant: start with read + execute, strip per label policy.
    allowed = MapGenericBits(GENERIC_READ, mapping)
            | MapGenericBits(GENERIC_EXECUTE, mapping)

    if ace.mask & SYSTEM_MANDATORY_LABEL_NO_READ_UP:
        allowed &= ~MapGenericBits(GENERIC_READ, mapping)
    if ace.mask & SYSTEM_MANDATORY_LABEL_NO_WRITE_UP:
        allowed &= ~MapGenericBits(GENERIC_WRITE, mapping)
    if ace.mask & SYSTEM_MANDATORY_LABEL_NO_EXECUTE_UP:
        allowed &= ~MapGenericBits(GENERIC_EXECUTE, mapping)

    // READ_CONTROL and SYNCHRONIZE are always allowed regardless of the
    // object type's GenericMapping and the label's up-strip policy — a
    // non-dominant caller can always read the descriptor and synchronize
    // on the object. Applied after the strips because a file GENERIC_READ
    // mapping folds these bits in, so NO_READ_UP would otherwise take them.
    allowed |= READ_CONTROL | SYNCHRONIZE

    // SeRelabelPrivilege: let WRITE_OWNER through MIC.
    if token.privilege_enabled(SeRelabelPrivilege):
        allowed |= WRITE_OWNER

    all_bits = MapGenericBits(GENERIC_ALL, mapping)
    decided |= all_bits & ~allowed
```

---

# Restricted Tokens

_Peios Kernel / Internals / KACS / Access check_

> The second pass a restricted token forces — when it runs, how privileges bypass it, and how owner rights and virtual groups behave in it.

<a id="trm-3-8-4"></a>

A restricted token carries a secondary SID list, the restricting SIDs.
The second pass runs whenever that list or the restricted device group
list is non-empty, and AccessCheck evaluates the DACL twice. <a id="cite-check.restricted.second-pass-trigger"></a>

The **normal pass** evaluates the DACL against the token's ordinary
identity — user SID and group SIDs — exactly as usual. The
**restricted pass** evaluates the same DACL again with SID matching
drawn only from the restricting SID list; the token's normal groups
are invisible to it. <a id="cite-check.restricted.only-restricting-sids-match"></a> Conditional membership operators — `Member_of`,
`Member_of_Any`, and their device variants — take the same restricted
view, seeing only the restricting SIDs plus any virtual groups
injected from that list. <a id="cite-check.restricted.conditional-membership-restricted"></a>

The restricting SID list is **presence-based**. A SID participates
whenever it appears in the list, and `SE_GROUP_ENABLED` and
`SE_GROUP_USE_FOR_DENY_ONLY` on those entries are ignored both for
restricted-pass SID matching and for restricted-pass non-device
conditional membership. <a id="cite-check.restricted.presence-based"></a> This matches Windows restricted-token
behaviour, where restricting SIDs are always enabled for access
checks.

Access is granted only for rights **both passes agree on** — the
intersection. <a id="cite-check.restricted.intersection"></a> The restricting list acts as a ceiling: the principal
can never receive more access than the restricting SIDs would
independently justify.

<a id="trm-3-8-4-1"></a>

## Write-restricted tokens <a id="cite-check.restricted.write-restricted"></a>

In the write-restricted variant the intersection applies only to
write-category bits, and read and execute access comes from the normal
pass alone. What counts as write is whatever the object type's
GenericMapping maps `GENERIC_WRITE` onto.

<a id="trm-3-8-4-2"></a>

## Privileges bypass the restricted pass <a id="cite-check.restricted.privileges-bypass"></a>

Rights granted by privileges are added back after the intersection.
Privileges are system-level grants from security policy rather than
from the object's DACL: token restriction reduces the identity-based
access surface, and privilege-based grants are orthogonal to it. The
bits restored are the post-PIP privilege-granted set together with the
take-ownership grant. <a id="cite-check.restricted.restored-set"></a>

<a id="trm-3-8-4-3"></a>

## Owner rights and virtual groups in the restricted pass

The restricted pass evaluates owner implicit rights independently. If
the object's owner SID appears in the restricting SID list, the pass
grants `READ_CONTROL` and `WRITE_DAC`, subject to the same `OWNER
RIGHTS` suppression pre-scan as the normal pass; if the owner SID is
not a restricting SID, no implicit rights are granted. <a id="cite-check.restricted.owner-implicit"></a>

Two virtual groups are injected on the same basis. `S-1-3-4` (`OWNER
RIGHTS`) is injected when the object's owner SID is among the
restricting SIDs, and `S-1-5-10` (`PRINCIPAL_SELF`) when `self_sid`
is. <a id="cite-check.restricted.virtual-groups"></a> This keeps the restricted pass consistent in its handling of these
well-known SIDs rather than letting them leak the unrestricted
identity.

Restricted device groups, when the token has them, are swapped in for
the restricted pass so that `Device_Member_of` and its relatives
evaluate against the restricted set rather than the unrestricted
device groups. <a id="cite-check.restricted.device-groups-swapped"></a>

## Choosing a restriction

Removing privileges without supplying restricting SIDs reduces privilege
presence without adding a restricted-SID intersection. Supplying restricting
SIDs adds another identity-based ceiling; it does not remove existing
privileges by itself. Review both choices when launching reduced-authority
work.

Write restriction limits the intersection to mapped write rights, but its
required `user_deny_only` state also changes ordinary user-SID matching.
Do not describe it as an unconditional promise that all previous reads
remain available. The user SID can match denies rather than grants.

A capability SID in a restricting list is still an ordinary SID in this
mechanism. It is not the dedicated confinement pass, which has separate
semantics and does not allow privileges to bypass its ceiling. Test the
complete intended token and object policy rather than treating either
restriction as a universal sandbox recipe.

---

# Object ACEs and Property-Level Access

_Peios Kernel / Internals / KACS / Access check_

> Per-property access control through GUID-scoped ACEs — object type lists, propagation, PRINCIPAL_SELF, and per-node results.

<a id="trm-3-8-5"></a>

An object ACE carries a GUID identifying the property or property set
its rule applies to, which is what enables per-property access control
on objects with internal structure — Active Directory objects, most
obviously. An object ACE with no GUID, meaning
`ACE_OBJECT_TYPE_PRESENT` is unset, behaves exactly like a basic ACE. <a id="cite-check.object-ace.no-guid-is-basic"></a>

<a id="trm-3-8-5-1"></a>

## Object type lists

To request property-level access the caller supplies an object type
list: a tree of GUIDs representing the properties being asked for.
Each node carries its own `decided` and `granted` pair and is resolved
independently. <a id="cite-check.object-ace.per-node-state"></a>

With no list supplied, object ACEs with GUIDs apply globally, as if
they were basic ACEs. <a id="cite-check.object-ace.no-list-applies-globally"></a> With a list supplied, every ACE that behaves
like a basic ACE — ordinary basic ACEs, and object ACEs without an
`ObjectType` GUID — applies to every node in the tree. <a id="cite-check.object-ace.basic-applies-to-all-nodes"></a> An object ACE
whose GUID does not appear anywhere in the supplied tree is silently
skipped. <a id="cite-check.object-ace.unmatched-guid-skipped"></a>

<a id="trm-3-8-5-2"></a>

## Propagation

Decisions move through the tree in four ways.

**Downward from grants.** A grant on a property set flows to every
attribute within it, each child node still applying first-writer-wins
for itself. <a id="cite-check.object-ace.grant-propagates-down"></a>

**Upward from grants.** When every attribute within a property set has
been granted the same right, that right propagates up to the set's
node. <a id="cite-check.object-ace.grant-propagates-up"></a> The propagation is a per-bit intersection, so a right reaches
the parent only if all siblings share it.

**Upward from denials.** A denial on an attribute propagates to every
ancestor regardless of what its siblings hold, and siblings are
themselves unaffected. <a id="cite-check.object-ace.denial-propagates-up"></a> Ancestors still apply first-writer-wins to the
propagated bits, so a denial cannot overturn something an ancestor had
already decided. <a id="cite-check.object-ace.denial-up-first-writer-wins"></a>

**Downward from denials.** A denial on a property set flows to every
attribute within it, again subject to first-writer-wins. <a id="cite-check.object-ace.denial-propagates-down"></a>

<a id="trm-3-8-5-3"></a>

## PRINCIPAL_SELF

`PRINCIPAL_SELF` (`S-1-5-10`) is a placeholder for the object's
associated principal. An ACE targeting it matches the caller when the
caller's token represents the same principal as the object, which the
caller establishes by passing the object's principal SID as the
`self_sid` parameter. <a id="cite-check.object-ace.principal-self-matches-self-sid"></a> With a null `self_sid`, `PRINCIPAL_SELF` ACEs
match nothing. <a id="cite-check.object-ace.principal-self-null-matches-nothing"></a>

It follows the ordinary deny-only rules: if the caller's matching SID
is deny-only, `PRINCIPAL_SELF` matches deny ACEs but not allow ACEs. <a id="cite-check.object-ace.principal-self-deny-only"></a>

<a id="trm-3-8-5-4"></a>

## Scalar and per-node results

`AccessCheck` requires every node to pass, so a denial on any one
property fails the whole request. <a id="cite-check.object-ace.scalar-requires-all-nodes"></a> `AccessCheckResultList` returns a
separate verdict per node.

The scalar result `AccessCheck` returns is the root node's granted
mask. <a id="cite-check.object-ace.scalar-is-root-mask"></a> That is equivalent to the intersection across all nodes, but by
construction rather than by computation: upward denial propagation
forces every descendant's denial into all of its ancestors' `decided`
sets, which guarantees the root's granted mask is a subset of every
node's.

<a id="trm-3-8-5-5"></a>

## Validation

Object type lists are validated strictly, at parse time.

- A supplied list is non-empty. <a id="cite-check.object-ace.list-non-empty"></a>
- Its first node is at level 0. <a id="cite-check.object-ace.list-first-node-level-zero"></a>
- There is exactly one level-0 node. <a id="cite-check.object-ace.list-one-root"></a>
- There are no level gaps, meaning no node at level N+2 following one
  at level N. <a id="cite-check.object-ace.list-no-level-gaps"></a>
- No GUID appears twice. <a id="cite-check.object-ace.list-no-duplicate-guid"></a>

These checks are stricter than MS-DTYP, which does not specify them.
They exist because a duplicate GUID makes node lookup return the wrong
node, and a level gap makes propagation undefined.

---

# Application Confinement

_Peios Kernel / Internals / KACS / Access check_

> An absolute boundary a confined token cannot cross whatever the DACL says — normal and strict confinement, and where it sits in the order.

<a id="trm-3-8-6"></a>

Confinement restricts a token's effective access to what is explicitly
granted to its confinement identity. Even where the normal DACL walk
grants access through the user SID or a group SID, the confinement
pass intersects that with what the confinement SIDs would receive on
their own, and revokes anything they cannot independently justify. <a id="cite-check.confinement.intersects-confinement-identity"></a>

A confined token carries `confinement_sid`, its confinement identity;
`confinement_capabilities`, the capability SIDs the application
declares; and `confinement_exempt`, an escape hatch that skips
confinement evaluation entirely. <a id="cite-check.confinement.exempt-skips-evaluation"></a>

The confinement SID set is `confinement_sid` together with every SID
in `confinement_capabilities`. <a id="cite-check.confinement.sid-set"></a> Capabilities are **presence-based**
identities rather than ordinary ACE-matching groups: a capability SID
participates whenever it is present, and disabling an entry or marking
it deny-only does not remove it from the confinement identity. <a id="cite-check.confinement.capabilities-presence-based"></a>

The pass also injects two confinement-scoped virtual groups.
`S-1-5-10` (`PRINCIPAL_SELF`) is injected only when `self_sid` equals
the confinement SID or one of the capability SIDs, and `S-1-3-4`
(`OWNER RIGHTS`) only when the object's owner SID does. <a id="cite-check.confinement.virtual-groups"></a> Both apply to
ACE SID matching during the confinement walk *and* to the conditional
membership operators — `Member_of`, `Member_of_Any`, and their device
and negated variants — evaluated during that pass. <a id="cite-check.confinement.virtual-groups-in-conditionals"></a>

<a id="trm-3-8-6-1"></a>

## An absolute boundary

Confinement is not overridable. Privileges do not bypass it: the
confinement merge takes no privilege-granted input at all, so backup,
restore, `SeTakeOwnershipPrivilege` and `SeSecurityPrivilege` are
alike unable to grant access the confinement check denies. <a id="cite-check.confinement.privileges-do-not-bypass"></a> Owner
implicit rights are skipped entirely, because the pass runs with
`skip_owner_implicit` set. <a id="cite-check.confinement.skips-owner-implicit"></a>

One thing does pass through: an object with a **null DACL** grants in
the confinement pass exactly as it does in the normal pass. <a id="cite-check.confinement.null-dacl-grants"></a> A null
DACL means "no discretionary restrictions", and the confinement pass
follows standard evaluation, granting all valid bits.

<a id="trm-3-8-6-2"></a>

## Strict confinement

A normal confined token carries both `ALL_APPLICATION_PACKAGES` and
`ALL_RESTRICTED_APPLICATION_PACKAGES` among its capabilities. Omitting
`ALL_APPLICATION_PACKAGES` gives strict confinement: far fewer system
objects grant to `ALL_RESTRICTED_APPLICATION_PACKAGES`, so the access
surface is much narrower. <a id="cite-check.confinement.strict-omits-all-app-packages"></a>

Strict confinement is not a separate kernel mode bit. It is derived
purely from the SID set supplied at token creation — if
`ALL_APPLICATION_PACKAGES` is absent, AccessCheck simply evaluates the
remaining confinement SIDs. The kernel never synthesises it, and never
rejects an otherwise valid confined token for carrying it. <a id="cite-check.confinement.strict-never-rejected"></a> Deciding
which capabilities a package token receives belongs to authd and
policy tooling.

<a id="trm-3-8-6-3"></a>

## Consequences worth stating

**SACL access is unreachable.** `ACCESS_SYSTEM_SECURITY` is only ever
privilege-granted, and privileges do not bypass confinement, so a
confined token cannot reach a SACL unless a confinement ACE grants the
right outright. <a id="cite-check.confinement.sacl-unreachable"></a>

**`OWNER RIGHTS` is confinement-scoped.** `S-1-3-4` matches in the
confinement pass only when the owner SID is part of the confinement
SID set.

**`PRINCIPAL_SELF` is isolated from user identity.** `S-1-5-10` is
injected only when `self_sid` matches a confinement SID — the package
SID or one of its capabilities — not when it matches the user.

**Conditional expressions still see the full token.** The confinement
pass isolates ordinary SID matching to the confinement identity, but
conditional expressions inside ACEs continue to evaluate against the
user's real groups and claims. <a id="cite-check.confinement.conditionals-see-full-token"></a> The two confinement-scoped virtual
groups are the only exception, and they follow the confinement rules
during conditional membership evaluation.

<a id="trm-3-8-6-4"></a>

## Ordering

Confinement runs **after** the restricted token merge and after its
privilege restoration. <a id="cite-check.confinement.after-restricted-merge"></a> The order is load-bearing: privileges bypass
the restricted pass but must not bypass confinement, and if
confinement ran first the privilege restoration would resurrect bits
that confinement had already blocked.

---

# PIP in AccessCheck

_Peios Kernel / Internals / KACS / Access check_

> How a trust label ACE is evaluated — the label SID, the privileges it revokes, the algorithm, and where the compared values come from.

<a id="trm-3-8-7"></a>

An object opts in to PIP protection by carrying a
`SYSTEM_PROCESS_TRUST_LABEL_ACE` in its SACL. <a id="cite-check.pip.opt-in-via-sacl-ace"></a> The ACE's SID encodes
the required type and trust, and its access mask names exactly the
rights a non-dominant caller may still have.

A caller that **dominates** — `pip_type` and `pip_trust` both greater
than or equal to the ACE's — is unrestricted by PIP. <a id="cite-check.pip.ace-dominance-test"></a> A caller that
does not dominate is limited to the ACE mask, and everything else is
denied. <a id="cite-check.pip.non-dominant-limited-to-ace-mask"></a>

Unlike MIC, PIP has **no default**. An object with no trust label is
unrestricted, reachable by any process whatever its PIP identity. <a id="cite-check.pip.no-default"></a>

<a id="trm-3-8-7-1"></a>

## The label SID

A trust label SID has the form `S-1-19-{type}-{trust}` — the Process
Trust authority, exactly two sub-authorities. <a id="cite-check.pip.label-sid-shape"></a> Both axes are compared
numerically. The conventional type values are 0 (None), 512
(Protected) and 1024 (Isolated), but they are labels rather than a
closed enum: any other numeric type is valid and compared by the same
dominance rule. <a id="cite-check.pip.nonstandard-type-accepted"></a>

A trust label SID of any other shape — wrong authority, wrong
sub-authority count — makes the descriptor malformed, and AccessCheck
rejects it outright rather than guessing. <a id="cite-check.pip.malformed-label-rejects-descriptor"></a>

Where a SACL carries more than one trust label ACE, only the first
non-inherit-only one is used; inherit-only labels do not apply to the
object carrying them. <a id="cite-check.pip.first-non-inherit-only-label"></a>

<a id="trm-3-8-7-2"></a>

## Privilege revocation

This is the critical difference from MIC. PIP does not merely
constrain what the DACL may grant — it **revokes rights privileges
already granted**. <a id="cite-check.pip.revokes-privilege-granted"></a> A non-dominant caller who used `SeBackupPrivilege`
to obtain read has those bits stripped; `SeTakeOwnershipPrivilege`'s
`WRITE_OWNER` is stripped; `SeSecurityPrivilege`'s
`ACCESS_SYSTEM_SECURITY` is stripped.

The last of those is the point. Without privilege revocation, a
non-dominant administrator holding `SeSecurityPrivilege` could read
the SACL of a PIP-protected object — and remove the trust label from
it. PIP would be self-defeating.

There is no escape hatch. PIP has no `SeRelabelPrivilege` equivalent,
and no privilege compensates for insufficient trust. It is an absolute
boundary, which is why the enforcement step explicitly ORs
`ACCESS_SYSTEM_SECURITY` into the set of bits it can take away —
that right is outside the generic mapping and would otherwise escape. <a id="cite-check.pip.revokes-access-system-security"></a>

<a id="trm-3-8-7-3"></a>

## The algorithm <a id="cite-check.pip.algorithm"></a>

```
EnforcePIP(ace, pip_type, pip_trust, mapping, &decided,
           &granted, &privilege_granted):

    // pip_type and pip_trust are the subject's process-trust context,
    // not a token field. See "Where the values come from" below.

    ace_type  = ace.sid.pip_type
    ace_trust = ace.sid.pip_trust

    caller_dominates = (pip_type  >= ace_type
                    and pip_trust >= ace_trust)

    if caller_dominates:
        return

    // Non-dominant: the ACE mask IS the allowed set.
    allowed = MapGenericBits(ace.mask, mapping)

    // Everything not explicitly allowed is denied, including
    // ACCESS_SYSTEM_SECURITY.
    all_bits = MapGenericBits(GENERIC_ALL, mapping)
             | ACCESS_SYSTEM_SECURITY
    pip_denied = all_bits & ~allowed

    decided |= pip_denied

    // Revoke privilege-granted rights.
    granted           &= ~pip_denied
    privilege_granted &= ~pip_denied
```

<a id="trm-3-8-7-4"></a>

## Where the values come from

`pip_type` and `pip_trust` are the subject's process trust context and
are never derived from a token field — the token structure has no PIP
field at all. They are passed into AccessCheck as explicit parameters
by whichever layer is enforcing. <a id="cite-check.pip.values-are-parameters"></a>

During enforcement — FACS file access, process boundaries — the values
are the subject process's PSB, set at exec from the binary's signature
([Binary Signature Verification](</kernel/internals/kacs/executable-trust/signature-verification.md#trm-3-6>), [Process Integrity Protection](</kernel/internals/kacs/executable-trust/process-integrity-protection.md#trm-3-7>)). <a id="cite-check.pip.enforcement-uses-psb"></a>

The `kacs_access_check` query may instead supply them through its
arguments, per axis: zero means "use the calling process's PSB value"
and a nonzero value evaluates against the supplied context. <a id="cite-check.pip.query-supplies-values-per-axis"></a> This lets
a userspace broker evaluate access under a client's trust level, in
the same way the query's token argument lets it evaluate a token other
than its own. The query is advisory and gates nothing in the kernel;
enforcement always uses the PSB. The same effective values are used
for the verdict and for the event the check emits, so an audit record
never disagrees with the decision it describes. <a id="cite-check.pip.same-values-for-verdict-and-event"></a>

The enforcement step also computes a record of which bits PIP decided.
Nothing currently consumes it — it is threaded through three
structures and exported, and no caller reads it.

---

# Central Access and Auditing Policy

_Peios Kernel / Internals / KACS / Access check_

> Policy defined once and referenced by objects — the policy structure, access and audit evaluation, the cache, and the recovery policy.

<a id="trm-3-8-8"></a>

CAAP separates policy definition from the objects it governs. A policy
is defined once, centrally; objects reference it by SID through a
`SYSTEM_SCOPED_POLICY_ID_ACE` in their SACL. <a id="cite-check.cap.reference-by-scoped-policy-ace"></a> When the policy changes,
every future AccessCheck against a referencing object uses the new
rules — already-open handles are unaffected, because the model is
check-at-open. <a id="cite-check.cap.check-at-open"></a>

It extends the Windows Central Access Policy model by adding an audit
component: each rule carries both an access restriction and an audit
requirement.

<a id="trm-3-8-8-1"></a>

## Policy structure

A policy is a named collection of rules identified by a policy SID.
Each rule carries:

An optional **applies-to condition**, a conditional expression
determining whether the rule governs this decision. It may reference
the `@Resource`, `@User`, `@Device` and `@Local` claim namespaces, but
it cannot inspect SID or device-group membership: `Member_of`,
`Member_of_Any`, `Device_Member_of`, `Device_Member_of_Any` and their
negated forms all evaluate to UNKNOWN inside `applies_to`. <a id="cite-check.cap.applies-to-membership-unknown"></a> A rule with
no condition applies to every object referencing the policy. <a id="cite-check.cap.no-condition-applies-always"></a>

A mandatory **effective DACL** — a real DACL evaluated through the
full pipeline. An optional **effective SACL**, whose audit ACEs merge
with the object's own during the audit walk. And optional **staged**
DACL and SACL, proposed replacements used for testing.

<a id="trm-3-8-8-2"></a>

## Access evaluation

The DACL result is ANDed with the normal evaluation. CAAP can only
restrict, never expand: if the object's DACL grants read and write but
the applicable rule's effective DACL grants only read, the result is
read. <a id="cite-check.cap.intersects-only"></a>

A SACL may carry several scoped policy ACEs, which makes policies
composable — and the AND semantics are what make composition safe,
since each additional policy can only narrow. <a id="cite-check.cap.multiple-scoped-policy-aces"></a> Inherit-only scoped
policy ACEs do not apply to the object carrying them and are ignored
during lookup. <a id="cite-check.cap.inherit-only-policy-ace-ignored"></a> MS-DTYP allows one scoped policy ACE per SACL; KACS
allows several.

For each scoped policy ACE, AccessCheck looks the policy up in the
kernel cache, then for every rule whose `applies_to` is TRUE or absent
evaluates the rule's effective DACL through the full pipeline —
privilege grants, MIC, PIP, the DACL walk, restricted tokens,
confinement — and intersects the result with the running total, which
starts at the normal evaluation's granted mask. <a id="cite-check.cap.rule-dacl-full-pipeline"></a>

A rule whose condition evaluates FALSE **or UNKNOWN** is skipped. <a id="cite-check.cap.unknown-condition-skips-rule"></a> That
is deliberately the opposite of the deny-ACE UNKNOWN rule: skipping is
the conservative choice here, because a rule's DACL can only narrow
what the normal DACL already granted.

If no rules apply — every condition false or unknown, or the policy
has no rules — CAAP has no effect and the normal result stands. <a id="cite-check.cap.no-applicable-rules-no-effect"></a>

The rule's DACL is evaluated with backup and restore intent **not**
passed: intent is a caller concern, not a policy concern. <a id="cite-check.cap.no-backup-restore-intent"></a> And CAAP
never recurses. A rule's synthetic descriptor has scoped policy ACEs
stripped before evaluation, so nested CAAP evaluation cannot occur
even when the original SACL carried more of them. <a id="cite-check.cap.no-recursion"></a> The synthetic
descriptor keeps the original owner and group, and preserves the MIC
and PIP labels, so a rule is evaluated against the same mandatory
constraints as the object itself. <a id="cite-check.cap.synthetic-preserves-labels"></a>

<a id="trm-3-8-8-3"></a>

## Audit evaluation

For each applicable rule carrying an effective SACL, the rule's audit
ACEs are evaluated alongside the object's own during the audit walk.
They are treated identically — if either says to audit an operation,
it is audited. <a id="cite-check.cap.sacl-merged-with-object"></a>

The SACL component is purely additive. A CAAP SACL can add audit
coverage and can never suppress auditing the object's own SACL asks
for. <a id="cite-check.cap.sacl-additive-only"></a>

<a id="trm-3-8-8-4"></a>

## The policy cache

The kernel keeps a map from policy SID to policy object, empty at
boot. Policies are pushed in through `kacs_set_caap`, which requires
`SeTcbPrivilege` — and marks it used. <a id="cite-check.cap.set-requires-tcb"></a> A non-null spec for an existing
SID replaces the policy; a null spec or zero length removes it. <a id="cite-check.cap.set-replaces-or-removes"></a>
Every call that passes the privilege gate writes a
`kacs.caap.policy.changed` record ([Audit Event Schemas](</kernel/internals/kacs/auditing/event-families-and-delivery.md#trm-3-c>)) naming the caller, the policy
SID as `caap.policy.sid`, and `operation.name` `set` or `remove`, with
`outcome.success` and, when the change did not apply, `outcome.errno`. <a id="cite-check.cap.set-recorded"></a> The
policy SID's length is bounded to 8–68 bytes before parsing begins,
and until the cache has been initialised both setting and evaluating
fail with `EACCES`. <a id="cite-check.cap.uninitialised-eacces"></a>

The wire format is:

```
[version:u8 = 0x01]
[rule_count:u32le]
per rule:
  [applies_to_len:u32le][applies_to_expr bytes]     (0 = no condition)
  [effective_dacl_len:u32le][effective_dacl bytes]  (MUST NOT be 0)
  [effective_sacl_len:u32le][effective_sacl bytes]  (0 = no audit rules)
  [staged_dacl_len:u32le][staged_dacl bytes]        (0 = no staged DACL)
  [staged_sacl_len:u32le][staged_sacl bytes]        (0 = no staged SACL)
```

All lengths are little-endian `u32`. ACLs use the standard binary
format, and every ACE type valid in a DACL or SACL is permitted inside
a policy ACL. <a id="cite-check.cap.any-ace-type-permitted"></a> The `applies_to` expression is conditional ACE bytecode,
carrying the same `artx` prefix as callback ACE application data. <a id="cite-check.cap.applies-to-artx-bytecode"></a>

The limits are a spec of at most 256 KB, at most 256 rules, an
`applies_to` of at most 64 KB, and an individual ACL of at most 64 KB. <a id="cite-check.cap.limits"></a>
The version byte has to be `0x01`. <a id="cite-check.cap.version-byte"></a> Trailing bytes after the declared
rules are rejected. <a id="cite-check.cap.trailing-bytes-rejected"></a>

Validation is strict and total. Malformed or truncated `applies_to`
bytecode fails the whole call with `EINVAL` at ingestion rather than
being admitted and later treated as a runtime UNKNOWN — the structural
check happens once, at the boundary. <a id="cite-check.cap.malformed-applies-to-einval"></a> A rule with a zero-length
effective DACL fails the same way, as do truncated fields, lengths
exceeding the buffer, and invalid ACL headers. <a id="cite-check.cap.zero-length-dacl-einval"></a> `SeTcbPrivilege` is
checked before any parsing begins. <a id="cite-check.cap.tcb-checked-before-parsing"></a>

The cache is a kernel mechanism. The maintained authd implementation does
not populate it from registry or directory policy. A deployment needs an
explicit privileged loader and distribution process; the existence of
`kacs_set_caap` does not establish that either is installed. Policies loaded
after services start do not retroactively affect already-open handles.

<a id="trm-3-8-8-5"></a>

## The recovery policy

When a scoped policy ACE names a SID that is not in the cache — the loader
did not install it or the policy was removed — a hardcoded recovery policy
is used instead: `GENERIC_ALL`
to BUILTIN\Administrators, to SYSTEM, and to `OWNER RIGHTS`. <a id="cite-check.cap.recovery-policy"></a>

Those masks are stored as the literal `GENERIC_ALL` bit rather than
pre-mapped object-specific bits, and are expanded through the caller's
GenericMapping at evaluation time, so the recovery policy works
correctly for every object type. <a id="cite-check.cap.recovery-generic-all-mapped"></a>

Because CAAP is an intersection, recovery does not widen access beyond
the object's own DACL: it limits missing-policy access to callers who
also satisfy the recovery DACL. This is a fail-closed recovery mode
with administrator, SYSTEM and owner escape hatches — not a no-effect
fallback.

<a id="trm-3-8-8-6"></a>

## Errors

A rule whose DACL evaluation errors denies everything except rights
granted by privileges — in the effective and the staged evaluation
alike, and in the scalar total exactly as on every node of a
result-list check. <a id="cite-check.cap.rule-error-denies-except-privileges"></a> Preserving those is the escape hatch: an
administrator with `SeSecurityPrivilege` keeps the ability to read and
modify the SACL and remove the offending scoped policy ACE.

The escape hatch is conditional, though, and the ordering is why. PIP
runs before CAAP and may already have stripped
`ACCESS_SYSTEM_SECURITY` from the privilege-granted set for a
non-dominant caller. The hatch therefore only works for callers who
are PIP-dominant, or where the object carries no trust label. <a id="cite-check.cap.error-hatch-requires-pip-dominance"></a>

Rule evaluation swallows every error kind, including allocation
failure, so an out-of-memory condition inside a rule is reported as
"this rule denied all except privileges" rather than as `ENOMEM`. <a id="cite-check.cap.rule-error-swallowed"></a>

A rule whose SACL evaluation errors has its audit contribution
skipped, and a diagnostic event is emitted. <a id="cite-check.cap.sacl-error-skipped-diagnostic"></a>

<a id="trm-3-8-8-7"></a>

## Staging

A rule may carry staged DACLs and SACLs alongside its effective ones,
and AccessCheck evaluates both in parallel. The staged result affects
neither access nor audit; where effective and staged differ, the
difference is reported through a staging mismatch flag returned to the
caller and a diagnostic event. <a id="cite-check.cap.staged-no-effect-reports-mismatch"></a>

A rule with no staged DACL contributes its effective result to both
running totals, and a rule with no staged SACL contributes its
effective SACL to both. <a id="cite-check.cap.no-staged-uses-effective"></a>

## Planning a staged rollout

Staging supplies comparison data, not an automatic rollout service. The
following procedure requires a deployment-specific loader and observation
path; authd does not provide that workflow.

1. Preserve the effective policy and its object references. Author proposed
   staged DACL/SACL fields without replacing the effective ones.
2. Load and verify the policy on each intended machine through the privileged
   kernel interface. Distribution and object-side scoped-policy ACEs are
   separate responsibilities.
3. Exercise representative access paths and collect mismatch evidence with
   subject, object, requested rights, and effective result. Check auditing
   and observation limits before treating silence as agreement.
4. Review unexpected differences. A mismatch is neither a denial caused by
   the staged policy nor a complete list of which ACEs differ.
5. When the change is approved, replace the effective fields and verify fresh
   opens. Remove or replace staging fields deliberately. Retain the prior
   effective policy for an explicit restoration if necessary.

Staging does not version policy or revoke existing handles. The cache starts
empty at boot; a restart requires loading the intended policy again. Removing
a cached policy while objects still reference its SID activates recovery
policy rather than removing all restriction. Recovery remains an intersection
with the preceding grant, not guaranteed administrator access to everything.
The actual recovery DACL, including Owner Rights matching, is evaluated by
the pipeline; it must not be inferred from a simplified audience label.

---

# Auditing in AccessCheck

_Peios Kernel / Internals / KACS / Access check_

> Auditing is purely observational and never changes a decision — access, continuous and privilege-use auditing, and per-token policy.

<a id="trm-3-8-9"></a>

Auditing is purely observational. No audit rule affects the access
decision, and audit ACEs are evaluated after the decision is final. <a id="cite-check.auditing.observational"></a>

Three mechanisms operate inside the pipeline, emitting two families of
KMES record: `kacs.audit.access.checked` for object-access events from the SACL
walk and from token audit-policy forcing, and `kacs.audit.privilege.used` for
privilege-use events. <a id="cite-check.auditing.event-families"></a> A third family is
emitted for the CAAP conditions of [Central Access and Auditing Policy](</kernel/internals/kacs/access-check/central-access-and-auditing-policy.md#trm-3-8-8>): `kacs.caap.sacl.skipped` for
a rule SACL that would not parse or evaluate, and
`kacs.caap.staging.diverged` for a staged-versus-effective mismatch. <a id="cite-check.auditing.caap-diagnostic-family"></a> The event type strings and
payload schemas are in [Audit Event Schemas](</kernel/internals/kacs/auditing/event-families-and-delivery.md#trm-3-c>).

Event delivery happens before any result is written back to the
caller, and a failure to deliver fails the call. <a id="cite-check.auditing.delivery-before-result"></a> An audit event cannot
be suppressed by handing the syscall a bad output pointer.

<a id="trm-3-8-9-1"></a>

## Access auditing

`SYSTEM_AUDIT` ACEs in the SACL define which attempts to log. Each
carries a SID, an access mask, and success and failure flags —
`SUCCESSFUL_ACCESS_ACE_FLAG` (0x40) and `FAILED_ACCESS_ACE_FLAG`
(0x80).

An event is emitted when the ACE's SID matches the caller, its mask
overlaps the requested access, and its flags match the outcome. <a id="cite-check.auditing.audit-ace-conditions"></a>

<a id="trm-3-8-9-1-1"></a>

### On the AccessCheck syscall

Through `kacs_access_check` and `kacs_access_check_list` the descriptor
is the caller's own, SACL included. So that no process can write
kernel-origin audit records at will by supplying a SACL that matches
itself, the records a SACL generates there are written only when the
calling process's effective token holds `SeAuditPrivilege`, enabled.
Without it the check runs and answers exactly as it would otherwise,
and its SACL records are withheld; the privilege is marked used when it
admits them. <a id="cite-check.auditing.syscall-sacl-needs-audit-privilege"></a> The
privilege is the caller's, not the subject's: a daemon checking a
client through `token_fd` needs it on its own token. This is Windows'
rule for `AccessCheckAndAuditAlarm`.

The records the checked token's own audit policy forces, and
privilege-use and CAAP records, are not gated: the policy belongs to
the token, not to the caller. <a id="cite-check.auditing.syscall-policy-records-ungated"></a>

Two details matter. The SID is matched with **deny polarity** — the
broadest identity view, in which deny-only groups are visible —
because auditing should capture the widest possible picture rather
than the narrowest. <a id="cite-check.auditing.deny-polarity-matching"></a> And the overlap is tested against the
generic-mapped **requested** mask, not the final granted mask, so a
failed request is still auditable for the rights it actually asked
for. <a id="cite-check.auditing.overlap-against-requested"></a>

Conditional audit ACEs gate the event on an expression, using the same
deny-side membership polarity. An expression evaluating to UNKNOWN
emits the event: when in doubt, audit. <a id="cite-check.auditing.unknown-condition-emits"></a>

<a id="trm-3-8-9-2"></a>

## Continuous auditing

Access auditing fires once, where AccessCheck runs. Continuous
auditing covers per-operation monitoring.

`SYSTEM_ALARM` ACEs configure it. When AccessCheck evaluates an alarm
ACE whose SID matches, the ACE's mask is accumulated into a
**continuous audit mask** returned to the caller, which stores it on
the open handle and enforces it per operation. <a id="cite-check.auditing.alarm-accumulates-mask"></a> Conditional alarm ACEs
use the same deny-side polarity as conditional audit ACEs. The alarm
branch deliberately performs no overlap test against the requested
mask — an alarm ACE contributes its mask on a SID match alone. <a id="cite-check.auditing.alarm-no-overlap-test"></a>

On each later operation the enforcement point emits a
`kacs.audit.handle.used` event when the operation's normalised
required-access mask overlaps the stored mask. <a id="cite-check.auditing.continuous-event-on-overlap"></a> For FACS handles that
is the same mask used by the use-time check ([Use-Time Semantics](</kernel/internals/kacs/file-security/use-time-semantics.md#trm-3-9-4>)). Where an
operation's authorization accepts any one of several rights — append
or write data, say — the required mask holds the accepted set and the
event records the subset that overlapped, as `access.matched`, beside
the whole stored mask as `access.audit-mask`. <a id="cite-check.auditing.continuous-records-overlapping-subset"></a>

Events are emitted after the per-operation decision is known, for
successful and denied attempts alike. <a id="cite-check.auditing.continuous-both-outcomes"></a> The subject and process recorded
are the **operation-time** effective token and current task, not
necessarily the ones that opened the handle. <a id="cite-check.auditing.continuous-operation-time-subject"></a> That keeps attribution
correct after a handle is passed between processes, while still using
the opener-computed mask to decide whether the handle is audited at
all.

An enforcement point that cannot construct a required continuous-audit
event fails closed. <a id="cite-check.auditing.continuous-fails-closed"></a> Transport buffering and drop accounting remain
KMES's concern ([Failure Modes](</kernel/internals/kmes/failure-modes.md#trm-2-7>)).

<a id="trm-3-8-9-3"></a>

## Privilege-use auditing

When a privilege is exercised to grant access the DACL would not have
granted independently, a privilege-use event may be emitted. This runs
after the complete pipeline — after integrity policy, confinement and
central access policy — so it reflects the final result rather than an
intermediate one. <a id="cite-check.auditing.privilege-use-after-pipeline"></a>

**Successful** privilege use means the privilege's contributed bits
survive into the final granted result. The privilege is marked used,
and an event is emitted when the token's `audit_policy` carries
`PRIVILEGE_USE_SUCCESS` (0x04). <a id="cite-check.auditing.privilege-use-success"></a> **Failed** privilege use means the
privilege contributed bits during evaluation that did not survive. The
privilege is *not* marked used, and an event is emitted under
`PRIVILEGE_USE_FAILURE` (0x08). <a id="cite-check.auditing.privilege-use-failure"></a> A privilege that contributed nothing
to the requested access produces no event either way. <a id="cite-check.auditing.privilege-use-no-contribution"></a>

With an object type list, the test is per-node: a privilege counts as
successfully used if its bits survive on *any* node's final mask. <a id="cite-check.auditing.privilege-use-per-node"></a>

A `MAXIMUM_ALLOWED` request short-circuits this stage entirely,
recording no used bits and emitting no privilege-use events at all. <a id="cite-check.auditing.max-allowed-skips-privilege-use"></a>

How counterfactual the accounting really is varies by privilege, as
[The Privilege Model](</kernel/internals/kacs/privileges/the-privilege-model.md#trm-3-4-1>) describes: `SeSecurityPrivilege` and `SeTakeOwnershipPrivilege`
contribute only where the DACL had not already granted the right,
while backup and restore seed their bits unconditionally and so also
report use for accesses the DACL alone would have permitted. <a id="cite-check.auditing.backup-restore-overreport"></a>

<a id="trm-3-8-9-4"></a>

## Per-token audit policy

A token's `audit_policy` can force events regardless of SACL content.
This runs after the SACL walk and before result computation: if the
access succeeded and the policy carries `OBJECT_ACCESS_SUCCESS`
(0x01), a success event is emitted; if it failed and the policy
carries `OBJECT_ACCESS_FAILURE` (0x02), a failure event is. <a id="cite-check.auditing.forced-events"></a>

Success here means every requested bit was granted, or that nothing
was requested at all. <a id="cite-check.auditing.forced-success-definition"></a>

These events are additive — they fire even when no SACL ACE matched —
and they carry the object identity from the audit context the caller
supplied, exactly as a SACL-triggered record does. <a id="cite-check.auditing.forced-additive"></a> The
policy is per-token, fixed at creation, and follows impersonation,
since it is read from the effective token. <a id="cite-check.auditing.policy-from-effective-token"></a>

<a id="trm-3-8-9-5"></a>

## Event contents

An event carries the **subject**, the calling token's identity —
`subject.token.sid`, `.groups` with their parallel `.group-attributes`,
`.integrity`, the token's own LUID as `.id`, its logon session as
`.auth-id`, `.type`, `.impersonation` and the projected `.uid` — and
the PIP state as `subject.pip.type` and `subject.pip.trust`; the
**object**, as `object.kind` and the fields beneath it; the **access**,
as `access.requested` and `access.granted`, with `outcome.success`;
the **trigger**, `trigger.kind` (`sacl` or `policy`) and, for `sacl`,
the matched ACE as `trigger.ace`, or for a privilege record the
`privilege.*` fields; and the **process**, as
`emitter.process.pid`, `.name` and `.executable`. <a id="cite-check.auditing.event-contents"></a>

An access record also says what the mandatory checks withheld, since
that is often the whole reason a check the DACL would allow was denied:
`access.denied-integrity` is the requested bits the object's mandatory
label denied, and `access.denied-trust` the requested bits its
process-trust label denied — every bit each denied, for a
`MAXIMUM_ALLOWED` request — and each is absent when it denied none. <a id="cite-check.auditing.mandatory-denials-recorded"></a>

The pipeline itself produces only the object-and-access half — the
matched ACE bytes, the requested and granted masks, the outcome,
whether the event was policy-forced, the privilege, and the audit
context. The subject and process halves are attached at emission time
from the resolved call context, which is also where the effective PIP
values used for the verdict are reused for attribution.

<a id="trm-3-8-9-5-1"></a>

### The object

Where the kernel makes the check itself it knows the kind of object
and writes `object.kind`: `file`, `process`, `token`, `socket` (which
covers port-reservation binds) or `ipc`. A token check also writes the
target's `object.token.id` and `object.token.guid`. Some identity is
not yet reachable where the record is built, and is absent rather than
invented: `object.file.path` on file checks, `object.process.pid` and
`object.process.guid` on process checks. A mount-namespace check writes
`object.kind` `mount-namespace` and nothing beneath it: a namespace has
no name or identifier to carry. <a id="cite-check.auditing.mount-namespace-object-kind"></a>

A check made through `kacs_access_check` names its object through the
**audit context** (`audit_context_ptr`, `audit_context_len`), the
PGSS [The event stream](</kernel/internals/ntfe/event-ring-and-delivery.md#trm-6-7>) map:

```text
{kind: "service", service: {name: "jellyfin"}}
```

The kernel validates it before running the check and fails the call
with `EINVAL` unless it is well-formed msgpack no deeper than KMES's
default nesting depth less one; its root is a map of one or two
entries with string keys; it has exactly one `kind`, a string matching
the PGSS [The snapshot](</kernel/internals/ntfe/the-snapshot.md#trm-6-3>) segment grammar `[a-z][a-z0-9]*(-[a-z0-9]+)*`; and its
only other entry is keyed by that kind and holds a non-empty map whose
keys match the same grammar. The kernel copies it into the record as
`object.kind` and `object.<kind>.*` — `object.service.name` above. A
call without an audit context writes no `object`: the kernel does not
know what was checked.

These values are the caller's claim, which the kernel copied but did
not observe. So is everything else on the syscall path: the descriptor,
and with it `trigger.ace`, is the caller's, as is any PIP type or trust
it passes. Every record of `kacs_access_check` and
`kacs_access_check_list` therefore carries `fields.attestation.userspace`
set to `true`, with or without an audit context, and a record of a check
the kernel makes itself never does. <a id="cite-check.auditing.syscall-records-asserted"></a>
A context that is anything other than this map, such as the free-form
strings earlier components passed, fails with `EINVAL`.

---

# The Algorithm

_Peios Kernel / Internals / KACS / Access check_

> How every layer composes — the definitive statement of the evaluation order, from EvaluateSecurityDescriptor down through AccessCheckCore.

<a id="trm-3-8-10"></a>

The preceding sections describe what each layer of AccessCheck does.
This one describes how they compose, and is the definitive statement
of the evaluation order.

<a id="trm-3-8-10-1"></a>

## Pipeline overview <a id="cite-check.algorithm.pipeline-order"></a>

Before the pipeline proper, two things are checked and can fail the
call outright.

- The token's own invariants are validated — a `write_restricted`
  token without `user_deny_only` is rejected as invalid. <a id="cite-check.algorithm.write-restricted-needs-deny-only"></a>
- In the orchestrator, a null descriptor is rejected and
  `AccessCheckResultList` is required to have been given an object
  type list. <a id="cite-check.algorithm.null-descriptor-rejected"></a>

A null descriptor presented by an Identification-level token
therefore fails as an invalid parameter rather than as access denied,
because the null check runs first. <a id="cite-check.algorithm.null-check-runs-first"></a>

The pipeline then runs in this order:

0. **Impersonation level gate.** An impersonation token at
   Identification level is denied immediately. <a id="cite-check.algorithm.identification-denied"></a> Anonymous tokens
   proceed through the full pipeline. <a id="cite-check.algorithm.anonymous-allowed"></a>
1. **Input validation.** Reject a descriptor with no owner. <a id="cite-check.algorithm.no-owner-rejected"></a> A null
   group SID is valid and has no direct effect on the decision. <a id="cite-check.algorithm.null-group-valid"></a>
2. **Generic mapping.** Map generic bits in the desired mask to
   object-specific bits; strip `MAXIMUM_ALLOWED`. <a id="cite-check.algorithm.desired-mask-mapped"></a>
3. **Effective privileges.** Clear the backup and restore bits when
   the corresponding intent flag is absent. <a id="cite-check.algorithm.intent-gates-backup-restore"></a> Callers of the
   userspace AccessCheck can give only these two intents.
4. **Privilege grants.** Resolve `ACCESS_SYSTEM_SECURITY`, backup and
   restore. Seed `decided`, `granted` and `privilege_granted`. <a id="cite-check.algorithm.privilege-seeding"></a>
5. **Pre-SACL walk.** Extract the mandatory integrity label, the PIP
   trust label, resource attributes and scoped policy SIDs from the
   SACL, then enforce MIC and PIP. <a id="cite-check.algorithm.pre-sacl-walk"></a>
6. **Virtual group resolution.** `S-1-3-4` and `S-1-5-10` become
   matchable where the caller is the owner or the object's principal.
7. **Tree initialisation.** Seed each node from the scalar state. <a id="cite-check.algorithm.tree-seeded-from-scalar"></a>
8. **Normal DACL evaluation.** Owner implicit rights, then the walk.
   Under the kernel-internal creator-grant intent, which only a file
   open that creates its object carries, the walk instead grants every
   right not already decided ([KACS-Native Open](</kernel/internals/kacs/file-security/kacs-native-open.md#trm-3-9-2-10>)). Every later step
   still applies. <a id="cite-check.algorithm.creator-grant"></a>
9. **Post-DACL WRITE_OWNER override.** `SeTakeOwnershipPrivilege`
   grants `WRITE_OWNER` if the DACL did not and no mandatory
   mechanism blocked it. <a id="cite-check.algorithm.take-ownership-override"></a>
10. **Restricted token pass**, with intersection and privilege
    restoration.
11. **Confinement pass**, with absolute intersection.
12. **CAAP.** Evaluate each applicable rule's DACL through the full
    per-descriptor pipeline and intersect; collect SACLs.
13. **Privilege-use auditing.**
14. **Audit emission**, over the object's SACL and any CAAP SACLs.
15. **Result computation.**

Object type lists are validated at parse time rather than at step 1 —
non-empty, one level-0 node first, no level gaps, no duplicate GUIDs —
so a malformed list never reaches the pipeline. <a id="cite-check.algorithm.list-validated-before-pipeline"></a> Step 1 re-checks only
emptiness.

Reserved access-mask bits (`0x0CE0_0000`) are rejected wherever a mask
is mapped. <a id="cite-check.algorithm.reserved-bits-rejected"></a> That applies to the caller's desired mask *and* to every
ACE mask, so a single ACE carrying a reserved bit aborts the entire
check rather than being skipped. <a id="cite-check.algorithm.reserved-bit-ace-aborts-check"></a>

<a id="trm-3-8-10-2"></a>

## EvaluateSecurityDescriptor

Steps 0–11, called once for the normal evaluation and once per CAAP
rule with a synthetic descriptor.

```
EvaluateSecurityDescriptor(
    sd, token, pip_type, pip_trust, desired, mapping,
    object_tree, self_sid, local_claims, privilege_intent
) -> (decided, granted, privilege_granted,
      max_allowed_mode, mapped_desired, resource_attributes,
      policy_sids) | error

    // Step 0: Impersonation level gate.
    if token.token_type == Impersonation
       and token.impersonation_level == Identification:
        return ERROR_ACCESS_DENIED

    // Step 1: Input validation.
    if sd.owner is null:
        return ERROR_INVALID_SECURITY_DESCR

    // Step 2: Generic mapping.
    desired = MapGenericBits(desired, mapping)
    max_allowed_mode = (desired & MAXIMUM_ALLOWED) != 0
    desired = desired & ~MAXIMUM_ALLOWED

    // Step 3: Effective privileges.
    effective_privileges = token.privileges_enabled
    if not (privilege_intent & BACKUP_INTENT):
        effective_privileges &= ~SeBackupPrivilege
    if not (privilege_intent & RESTORE_INTENT):
        effective_privileges &= ~SeRestorePrivilege

    // Step 4: Privilege-based grants.
    decided = 0; granted = 0; privilege_granted = 0

    // ACCESS_SYSTEM_SECURITY is always decided by privilege.
    decided |= ACCESS_SYSTEM_SECURITY
    if (effective_privileges & SeSecurityPrivilege):
        granted           |= ACCESS_SYSTEM_SECURITY
        privilege_granted |= ACCESS_SYSTEM_SECURITY

    if (effective_privileges & SeBackupPrivilege):
        backup_bits = MapGenericBits(GENERIC_READ, mapping)
        decided |= backup_bits; granted |= backup_bits
        privilege_granted |= backup_bits

    if (effective_privileges & SeRestorePrivilege):
        restore_bits = MapGenericBits(GENERIC_WRITE, mapping)
                     | WRITE_DAC | WRITE_OWNER | DELETE
                     | ACCESS_SYSTEM_SECURITY
        decided |= restore_bits; granted |= restore_bits
        privilege_granted |= restore_bits

    // Restore already includes WRITE_OWNER, so when it is active
    // step 9 has nothing left to do. Step 9 is the fallback for
    // when restore is inactive and the DACL did not grant it.

    // Step 5: Pre-SACL walk. mandatory_decided records bits decided
    // by MIC and PIP, so step 9 cannot override them.
    resource_attributes = {}; policy_sids = []; mandatory_decided = 0
    PreSACLWalk(sd, token, pip_type, pip_trust, mapping,
                &decided, &granted, &privilege_granted,
                &mandatory_decided, &resource_attributes,
                &policy_sids)

    // Steps 6-8: owner implicit rights are granted first, inside
    // EvaluateDACL, and the tree is seeded from the already
    // augmented scalar state. Virtual groups are resolved per
    // lookup rather than by building an enriched token.
    EvaluateDACL(sd, token, mapping, object_tree,
                 SidMatchesToken, desired, max_allowed_mode,
                 resource_attributes, local_claims,
                 skip_owner_implicit=false,
                 &decided, &granted)

    // Step 9: Post-DACL WRITE_OWNER override.
    if (desired & WRITE_OWNER) != 0 or max_allowed_mode:
        if (effective_privileges & SeTakeOwnershipPrivilege):
            if not (mandatory_decided & WRITE_OWNER)
               and not (granted & WRITE_OWNER):
                decided |= WRITE_OWNER
                granted |= WRITE_OWNER
                privilege_granted |= WRITE_OWNER
                for each node with WRITE_OWNER ungranted:
                    node.decided |= WRITE_OWNER
                    node.granted |= WRITE_OWNER

    // Step 10: Restricted token pass.
    if token.restricted_sids or token.restricted_device_groups:
        // Restricted identity view: only restricting SIDs, plus
        // S-1-3-4 if the owner is among them and S-1-5-10 if
        // self_sid is. Restricted device groups swap in.
        // Fresh tree, zeroed state.
        EvaluateDACL(sd, restricted_view, mapping, r_tree,
                     SidInRestrictingSids, desired,
                     max_allowed_mode, resource_attributes,
                     local_claims, skip_owner_implicit=false,
                     &r_decided, &r_granted)
        if token.write_restricted:
            write_bits = MapGenericBits(GENERIC_WRITE, mapping)
            granted = (granted & ~write_bits)
                    | (granted & r_granted & write_bits)
        else:
            granted = granted & r_granted
        granted |= privilege_granted        // privileges bypass
        // Same intersection and restoration per node.

    // Step 11: Confinement pass.
    if token.confinement_sid and not token.confinement_exempt:
        // Confinement SID set: confinement_sid plus every
        // capability, presence-based. S-1-3-4 and S-1-5-10 are
        // injected only if the owner or self_sid is in that set.
        EvaluateDACL(sd, token, mapping, c_tree,
                     SidInConfinementSids, desired,
                     max_allowed_mode, resource_attributes,
                     local_claims, skip_owner_implicit=true,
                     &c_decided, &c_granted)
        granted = granted & c_granted       // no privilege bypass
        // Same absolute intersection per node.

    return (decided, granted & root-consistent state,
            privilege_granted narrowed to what survived,
            max_allowed_mode, desired, resource_attributes,
            policy_sids)
```

The returned `privilege_granted` is **narrowed** by what actually
survived the pass — it is intersected with the root's granted mask on
return, and the orchestrator narrows it again against the CAAP result. <a id="cite-check.algorithm.privilege-granted-narrowed"></a>
A privilege-granted bit that the write-restricted merge or the
confinement intersection removed is therefore no longer part of it,
which matters in two places: the CAAP error escape hatch ([Central Access and Auditing Policy](</kernel/internals/kacs/access-check/central-access-and-auditing-policy.md#trm-3-8-8>)) has
fewer bits to preserve, and the audit provenance masks reflect the
narrowed set.

<a id="trm-3-8-10-3"></a>

## AccessCheckCore

The orchestrator runs steps 12 through 15.

**Step 12, CAAP.** For each scoped policy SID, look the policy up —
falling back to the recovery policy when it is absent — and for each
rule whose `applies_to` is TRUE or absent, evaluate the rule's
synthetic descriptor through `EvaluateSecurityDescriptor` and
intersect. A rule that errors denies everything except the (already
narrowed) privilege-granted bits. Staged DACLs are evaluated in
parallel into a separate running total; a rule with no staged DACL
contributes its effective result to both.

After all policies, the staged and effective totals are compared and
any difference sets the staging mismatch flag. In result-list mode a
per-node delta sets it too — and so does a scalar delta, since the
comparison is not mode-branched. <a id="cite-check.algorithm.scalar-delta-sets-flag"></a>

**Step 13, privilege-use auditing.** For each of the five provenance
masks — security, backup, restore, take-ownership and relabel:

```
success_bits = provenance & mapped_desired & granted
failure_bits = provenance & mapped_desired & ~granted
```

Nonzero `success_bits` means the privilege was load-bearing: mark it
used on the token, and emit a success event under
`PRIVILEGE_USE_SUCCESS`. Otherwise nonzero `failure_bits` means it was
exercised but did not survive: do **not** mark it used, and emit a
failure event under `PRIVILEGE_USE_FAILURE`. Both zero means no event.
In result-list mode the comparison folds across nodes — success if the
bits survive on any node, failure only if they survive on none. <a id="cite-check.algorithm.privilege-use-folds-across-nodes"></a>

The event is `kacs.audit.privilege.used`. Its `privilege.contributed`
is `provenance & mapped_desired`, its `privilege.surviving` is
`success_bits` (empty on a failure event), and its `access.requested`
and `access.granted` are the whole check's `mapped_desired` and final
`granted`, not this privilege's share of them.

The whole step is skipped in `MAXIMUM_ALLOWED` mode, so such a request
marks nothing used and emits nothing.

Note that `relabel_granted` is tracked as provenance but is
deliberately excluded from `privilege_granted` itself, so a
relabel-loosened `WRITE_OWNER` is neither restored after the
restricted merge nor preserved by the CAAP error hatch.

**Step 14, audit emission.** Walk the object's SACL, then each CAAP
effective SACL, accumulating audit events and ORing alarm masks into
the continuous audit mask. <a id="cite-check.algorithm.sacl-walk-order"></a> This is read-only with respect to
`granted`.

The staged comparison then walks the object's SACL again followed by
the staged SACLs. That second walk is driven by the **staged** granted
total rather than the effective one, so the success and failure
classification of staged audit events reflects the staged access
result — which is what makes the flag sensitive to descriptors whose
staged and effective grants differ. <a id="cite-check.algorithm.staged-audit-walk-uses-staged-grant"></a>

**Step 14b, forced auditing.** With
`success = (granted & mapped_desired) == mapped_desired or
mapped_desired == 0`, the token's `audit_policy` forces a success or
failure event additively, regardless of what the SACL matched.

**Step 15** returns the accumulated state.

<a id="trm-3-8-10-4"></a>

## The wrappers

`AccessCheck` takes the **root node's** granted mask when a tree is
present, then computes `allowed` as `mapped_desired == 0` or every
requested bit granted. <a id="cite-check.algorithm.allowed-computation"></a> The root's mask equals the intersection across
all nodes by construction rather than by computation: upward denial
propagation ([Object ACEs and Property-Level Access](</kernel/internals/kacs/access-check/object-aces-and-property-level-access.md#trm-3-8-5>)) forces every descendant's denial into all of its
ancestors, so the root can never grant what a descendant denies.

`AccessCheckResultList` requires a tree and returns a per-node granted
mask and status, each node judged against `mapped_desired`
independently.

Neither wrapper filters the returned `granted` to the requested mask. <a id="cite-check.algorithm.granted-not-filtered"></a>
Privilege seeding at step 4 ORs bits in regardless of what was asked
for, so a caller that requested only `READ_CONTROL` while holding
backup can see read bits it never requested. The file enforcement path
does filter its result; the generic query path does not. <a id="cite-check.algorithm.file-path-filters-result"></a>

<a id="trm-3-8-10-5"></a>

## Helpers

```
SidMatchesToken(sid, token, for_allow) -> bool
    if sid == token.user_sid:
        if for_allow and token.user_deny_only:
            return false
        return true
    for group in token.groups:
        if not group.enabled and not group.deny_only:
            continue
        if for_allow and group.deny_only:
            continue
        if sid == group.sid:
            return true
    return false
```

```
MapGenericBits(mask, mapping) -> ACCESS_MASK
    if mask & RESERVED_BITS: reject
    mapped = mask & ~(GENERIC_READ | GENERIC_WRITE
                    | GENERIC_EXECUTE | GENERIC_ALL)
    if mask & GENERIC_READ:    mapped |= mapping.read
    if mask & GENERIC_WRITE:   mapped |= mapping.write
    if mask & GENERIC_EXECUTE: mapped |= mapping.execute
    if mask & GENERIC_ALL:     mapped |= mapping.all
    return mapped
```

All four generic bits are cleared before any is expanded, so a mask
naming several generics maps every one of them. <a id="cite-check.algorithm.all-generics-expand"></a>

**Virtual group resolution.** There is no enrichment step producing a
modified token. `S-1-3-4` and `S-1-5-10` are resolved at each lookup
instead, in the DACL walk, the SACL walk and conditional membership
alike. <a id="cite-check.algorithm.virtual-groups-per-lookup"></a> `S-1-5-10` resolves through the ordinary polarity rules against
`self_sid`, and `S-1-3-4` through the ordinary polarity rules against
the object's owner SID. Both are computed once per walk — the owner is
fixed while the polarity is per ACE — so each carries its allow and
deny answers together.

**`EvaluateSACL`** walks in a fixed order per ACE: SID match with deny
polarity, then object-type scoping against the tree, then the
condition, then the mask overlap against `mapped_desired`. <a id="cite-check.algorithm.sacl-ace-check-order"></a> Audit ACEs
need all four; alarm ACEs deliberately skip the overlap test and
contribute their mask on a SID match alone. Inherit-only ACEs are
skipped throughout. <a id="cite-check.algorithm.sacl-inherit-only-skipped"></a>

**`synthetic_sd`** builds a CAAP rule's descriptor from the original's
owner and optional group with the rule's DACL substituted, and the
SACL copied with every scoped policy ACE stripped — which is what
prevents recursion. The MIC and PIP labels are preserved, so a rule is
evaluated under the same mandatory constraints as the object. The
control bits and the stripped SACL's revision are recomputed rather
than copied. <a id="cite-check.algorithm.synthetic-recomputes-control-bits"></a>

<a id="trm-3-8-10-6"></a>

## Provenance masks

| Variable | Set at | Meaning |
|---|---|---|
| `security_granted` | Step 4 | `SeSecurityPrivilege` granted `ACCESS_SYSTEM_SECURITY`. <a id="cite-check.algorithm.provenance.security"></a> |
| `backup_granted` | Step 4 | `SeBackupPrivilege` granted read bits. <a id="cite-check.algorithm.provenance.backup"></a> |
| `restore_granted` | Step 4 | `SeRestorePrivilege` granted write and metadata bits. <a id="cite-check.algorithm.provenance.restore"></a> |
| `take_ownership_granted` | Step 9 | `SeTakeOwnershipPrivilege` granted `WRITE_OWNER`. <a id="cite-check.algorithm.provenance.take-ownership"></a> |
| `relabel_granted` | Step 5 | `SeRelabelPrivilege` added `WRITE_OWNER` to the MIC allowed set. <a id="cite-check.algorithm.provenance.relabel"></a> |

Each records which bits that privilege contributed, and step 13
compares each against the requested mask and the final result.
