# Security

---

# Security

_Peios Kernel / Internals / LCS / Security_

> Find the Peios kernel articles about security.

Use these articles to understand security in the Peios kernel.

- [The Access Flow](</kernel/internals/lcs/security/the-access-flow.md>)
- [Access Rights](</kernel/internals/lcs/security/access-rights.md>)
- [Inheritance and Hive Roots](</kernel/internals/lcs/security/inheritance-and-hive-roots.md>)
- [Audit](</kernel/internals/lcs/security/audit.md>)

---

# The Access Flow

_Peios Kernel / Internals / LCS / Security_

> The registry's security model is KACS applied to keys — no traverse checking, symlink handling, and why an fd is a capability.

<a id="trm-5-4-1"></a>

The registry's security model is KACS applied to keys. LCS defines no
access control mechanism of its own: the same AccessCheck, the same
Security Descriptors, the same tokens and SIDs that every other Peios
subsystem uses. What this section describes is how those primitives
attach to registry operations.

Every open follows the same five steps.

1. **Token capture.** LCS takes the calling thread's effective token —
   the impersonation token if one is set, otherwise the process primary
   token. This is the same capture KACS performs for every syscall. <a id="cite-access-flow.effective-token-capture"></a>

2. **Path resolution.** LCS walks the path through the layer stack,
   following symlinks. **No access check happens during the walk.**
   Intermediate keys are not evaluated; only the final key matters. <a id="cite-access-flow.no-check-during-walk"></a>

3. **AccessCheck.** LCS calls KACS AccessCheck with the captured token,
   the final key's Security Descriptor as returned by the source, and
   the desired access mask. Every requested right must be granted or
   the open fails with `EACCES`. There is no partial grant: the caller
   gets what it asked for or nothing. <a id="cite-access-flow.all-or-nothing-or-eacces"></a>

   `MAXIMUM_ALLOWED` is the exception, and the only way to ask for
   whatever is available. AccessCheck computes the full allowed set and
   that becomes the granted mask. <a id="cite-access-flow.maximum-allowed-grants-what-is-available"></a>

4. **The granted mask is stored on the fd.** It never changes. <a id="cite-access-flow.granted-mask-fixed-at-open"></a>

5. **Per-ioctl checks are bitmask tests.** Each ioctl has a required
   right; LCS tests the fd's granted mask against it and returns
   `EACCES` without contacting the source if it is absent. The
   Security Descriptor is not re-read and AccessCheck is not
   re-evaluated. <a id="cite-access-flow.per-ioctl-bitmask-test"></a>

<a id="trm-5-4-1-1"></a>

## No traverse checking

LCS checks nothing on the way down. A process can open
`Machine\System\Services\Jellyfin` without holding any access to
`Machine\System\Services` or `Machine\System`.

This matches the Windows registry and is a deliberate difference from
filesystem path semantics, where every directory in a path is checked
for traverse. It means a key's Security Descriptor is the whole story
about who can reach it, and that an ancestor's descriptor confers no
protection on its descendants.

<a id="trm-5-4-1-2"></a>

## Symlinks

Opening a symlink follows it, and AccessCheck runs on the **target**
key, not the link. `REG_OPEN_LINK` opens the link itself instead — but
only for the final path component. A symlink encountered part-way
through a path is followed regardless.

Creating a symlink is privileged: `KEY_CREATE_SUB_KEY` and
`KEY_CREATE_LINK` on the parent, plus either `SeTcbPrivilege` or
membership of Administrators ([Symlinks](</kernel/internals/lcs/data-model/symlinks.md#trm-5-2-4>)).

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

## Fds are capabilities

A key fd can be passed over a Unix socket with `SCM_RIGHTS`, and it
carries its granted mask with it. The recipient gets the access the
original opener was granted, whether or not its own token would have
passed AccessCheck. <a id="cite-access-flow.fd-passing-carries-granted-mask"></a>

This is explicit delegation and it is consistent with how fds work
everywhere else in Peios. Passing a `KEY_WRITE` fd hands over write
access.

Opening relative to a parent fd skips path parsing and AccessCheck for
the parent portion — the caller already proved its access when it
obtained the parent fd. This is the ordinary way to traverse a subtree. <a id="cite-access-flow.parent-fd-skips-check"></a>

<a id="trm-5-4-1-4"></a>

## Changing a descriptor does not revoke a handle

A Security Descriptor change takes effect for future opens. An fd that
already exists keeps the mask it was granted at open, because that is
what semantic rule 5 says ([Overview](</kernel/internals/lcs/start-here/overview.md#trm-5-1>)). <a id="cite-access-flow.descriptor-change-does-not-revoke-fd"></a> The recourse for genuinely revoking
access is to restart the process holding the fd.

Descriptor changes are also not layer-qualified. They are direct
mutations on the key object, and deleting a layer does not undo one
([Overview](</kernel/internals/lcs/start-here/overview.md#trm-5-1>), rule 4).

<a id="trm-5-4-1-5"></a>

## The second check nobody expects

Every layer-qualified mutation runs a **second** AccessCheck, against a
different object: the metadata key of the layer being written to. That
check is for `KEY_SET_VALUE` and it is in addition to the fd's granted
mask on the target key. Both must pass. [Writing Into a Layer](</kernel/internals/lcs/layers/writing-into-a-layer.md#trm-5-3-4>) covers it.

---

# Access Rights

_Peios Kernel / Internals / LCS / Security_

> Registry rights at their Windows bit positions — the convenience masks, generic mapping, and validation of what a caller asks and a source returns.

<a id="trm-5-4-2"></a>

Registry rights occupy the Windows bit positions, so a Security
Descriptor carrying registry ACEs is binary-compatible with one written
by Windows tooling. <a id="cite-right.windows-bit-positions"></a> That is a `registry.pol` and Samba requirement, not
an aesthetic choice.

The values are in [LCS ABI Reference](</kernel/userspace/native/lcs/generated-syscall-and-common-abi.md#trm-5-a>). In summary: six specific rights in bits 0–5
(`KEY_QUERY_VALUE`, `KEY_SET_VALUE`, `KEY_CREATE_SUB_KEY`,
`KEY_ENUMERATE_SUB_KEYS`, `KEY_NOTIFY`, `KEY_CREATE_LINK`), the four
standard rights `DELETE`, `READ_CONTROL`, `WRITE_DAC` and
`WRITE_OWNER`, and `ACCESS_SYSTEM_SECURITY` for the SACL, which is
itself gated by `SeSecurityPrivilege`.

There is no execute right on a key. <a id="cite-right.no-execute-right"></a>

<a id="trm-5-4-2-1"></a>

## Convenience masks and generic mapping

`KEY_READ`, `KEY_WRITE` and `KEY_ALL_ACCESS` are concrete masks, not
generic bits — they are unions of the rights above and are usable
directly. <a id="cite-right.convenience-masks-are-concrete"></a>

Separately, LCS accepts the raw KACS generic bits `GENERIC_READ`,
`GENERIC_WRITE`, `GENERIC_EXECUTE` and `GENERIC_ALL` in a caller's
`desired_access` and in ACE masks in a Security Descriptor. Those are
mapped through the registry generic mapping before AccessCheck sees
them. <a id="cite-right.generic-bits-accepted-and-mapped"></a>

`GENERIC_READ` maps to `KEY_READ`, `GENERIC_WRITE` to
`KEY_WRITE`, `GENERIC_ALL` to `KEY_ALL_ACCESS`, and **`GENERIC_EXECUTE`
maps to zero**, because there is nothing to execute. <a id="cite-right.generic-mapping"></a>

<a id="trm-5-4-2-2"></a>

## Validating what a caller asks for

`desired_access` is validated before path resolution or AccessCheck. <a id="cite-right.desired-access-validated-first"></a>

- Zero is `EINVAL`. A caller must ask for something. <a id="cite-right.zero-desired-access-is-einval"></a>
- Any bit outside the valid caller mask is `EINVAL`. <a id="cite-right.unknown-desired-access-bit-is-einval"></a>
- `MAXIMUM_ALLOWED` may appear alone or combined with anything else. <a id="cite-right.maximum-allowed-may-combine"></a>
- `SYNCHRONIZE` (`0x00100000`) is not a registry right, so it is an
  unknown bit and fails `EINVAL`. <a id="cite-right.synchronize-is-not-a-registry-right"></a>

The valid caller mask is a single constant, `REG_VALID_DESIRED_ACCESS_MASK`
([LCS ABI Reference](</kernel/userspace/native/lcs/generated-syscall-and-common-abi.md#trm-5-a>)): the six specific rights, the four standard rights,
`ACCESS_SYSTEM_SECURITY`, `MAXIMUM_ALLOWED` and the four generic bits. <a id="cite-right.valid-desired-access-mask-contents"></a>

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

## Validating what a source returns

Source-supplied Security Descriptors are validated too, because a
source is trusted for its data but not for its arithmetic ([Validation](</kernel/internals/lcs/sources/validation.md#trm-5-8-4>)).

An ACE mask may contain concrete registry rights and raw generic bits.
It **may not** contain `MAXIMUM_ALLOWED` — that is a request, not a
grant, and it is meaningless in an ACE. <a id="cite-right.ace-mask-rejects-maximum-allowed"></a>

After generic mapping, an ACE
mask must be a subset of the concrete registry rights plus
`ACCESS_SYSTEM_SECURITY`. <a id="cite-right.ace-mask-subset-after-mapping"></a>

A descriptor that breaks either rule is malformed source data: the
operation fails closed with `EIO` and an
`lcs.source.response.rejected` audit event is emitted ([Audit](</kernel/internals/lcs/security/audit.md#trm-5-4-4>)). <a id="cite-right.malformed-descriptor-is-eio"></a>

Two further constants, `REG_VALID_MAPPED_ACCESS_MASK` and
`REG_VALID_ACE_ACCESS_MASK`, express those two bounds.

<a id="trm-5-4-2-4"></a>

## Which right each operation needs

| Operation | Required |
|---|---|
| `REG_IOC_QUERY_VALUE`, `QUERY_VALUES_BATCH`, `ENUM_VALUES` | `KEY_QUERY_VALUE` <a id="cite-right.query-value"></a> |
| `REG_IOC_SET_VALUE`, `DELETE_VALUE`, `BLANKET_TOMBSTONE`, `FLUSH` | `KEY_SET_VALUE` <a id="cite-right.set-value"></a> |
| `REG_IOC_ENUM_SUBKEYS` | `KEY_ENUMERATE_SUB_KEYS` <a id="cite-right.enum-subkeys"></a> |
| `REG_IOC_QUERY_KEY_INFO` | `READ_CONTROL` <a id="cite-right.query-key-info"></a> |
| `REG_IOC_DELETE_KEY`, `HIDE_KEY` | `DELETE` <a id="cite-right.delete-key"></a> |
| `REG_IOC_NOTIFY` | `KEY_NOTIFY` <a id="cite-right.notify"></a> |
| `REG_IOC_GET_SECURITY` | `READ_CONTROL` for owner, group, DACL and label; `ACCESS_SYSTEM_SECURITY` for the SACL <a id="cite-right.get-security"></a> |
| `REG_IOC_SET_SECURITY` | `WRITE_OWNER` for owner, group or label; `WRITE_DAC` for the DACL; `ACCESS_SYSTEM_SECURITY` for the SACL; raising a label above the caller additionally requires enabled `SeRelabelPrivilege` <a id="cite-right.set-security"></a> |
| `REG_IOC_BACKUP` | `SeBackupPrivilege`, no per-key check |
| `REG_IOC_RESTORE` | `SeRestorePrivilege`, no per-key check |
| creating a key | `KEY_CREATE_SUB_KEY` on the parent <a id="cite-right.create-key"></a> |
| creating a symlink key | `KEY_CREATE_SUB_KEY` and `KEY_CREATE_LINK` on the parent, plus `SeTcbPrivilege` or Administrators |

Where a `REG_IOC_SET_SECURITY` or `GET_SECURITY` request names several
components, every right those components imply must be present before
the source is contacted. <a id="cite-right.security-info-needs-every-implied-right"></a>

`REG_IOC_FLUSH` requires `KEY_SET_VALUE` because a flush is only
meaningful to a caller that wrote something and wants it durable.
Requiring a write right stops an unprivileged reader using flush as a
disk-I/O amplifier.

<a id="trm-5-4-2-5"></a>

## Enumeration exposes names, not contents

`REG_IOC_ENUM_SUBKEYS` performs no per-child access check. Every
visible child is returned, whatever the caller's access to it. The
caller learns names, and must open each child separately — with a real
AccessCheck — to read anything. <a id="cite-right.enum-subkeys-no-per-child-check"></a>

Subtree watches work the same way: a watcher is told a descendant was
created without a check on that descendant. <a id="cite-right.subtree-watch-no-per-descendant-check"></a> Structure visibility is
deliberately weaker than content visibility, matching
`RegNotifyChangeKeyValue` and `RegEnumKeyEx`.

---

# Inheritance and Hive Roots

_Peios Kernel / Internals / LCS / Security_

> A new key's descriptor is computed from its parent by the KACS inheritance algorithm — plus hive roots and reading or writing a descriptor.

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

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

## Inheritance at creation

When `reg_create_key` creates a key, its initial Security Descriptor is
computed from the parent's by the KACS inheritance algorithm. LCS
supplies the parent descriptor, the creating token, the registry
generic mapping and the valid-mask bound, and hands the result to the
source to persist. It implements no inheritance logic of its own. <a id="cite-inherit.kacs-computes-lcs-persists"></a>

Three things about registry inheritance are worth stating.

**It is static.** The computation happens once, at creation. A later
change to the parent's descriptor does not propagate to children that
already exist. <a id="cite-inherit.static-no-repropagation"></a> Re-propagating is an explicit administrative action — a
client-side tree walk — not a kernel operation, and there is no code
anywhere in LCS that walks a tree to re-propagate.

**Only `CONTAINER_INHERIT_ACE` matters.** Every registry object is a
container: keys hold subkeys and values. Values are not independent
security objects and have no descriptors of their own; they inherit
their key's access control. <a id="cite-inherit.values-have-no-descriptor-of-their-own"></a>

`OBJECT_INHERIT_ACE` is never used to
select an ACE for inheritance. <a id="cite-inherit.object-inherit-ace-never-selects"></a> The child copy clears `OBJECT_INHERIT_ACE`,
`CONTAINER_INHERIT_ACE` and `NO_PROPAGATE_INHERIT_ACE` when
`NO_PROPAGATE_INHERIT_ACE` applies. <a id="cite-inherit.no-propagate-clears-object-inherit"></a>

**A parent with no inheritable ACEs falls back to the creating token's
default DACL.** <a id="cite-inherit.no-inheritable-aces-uses-token-default-dacl"></a>

That fallback covers the DACL only; there is no default
SACL. <a id="cite-inherit.no-default-sacl"></a>

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

### Creator SIDs and generic rights survive to the next generation

An inheritable ACE naming `CREATOR OWNER` or `CREATOR GROUP`, or carrying
generic rights, is resolved for each new key. When it also propagates to
further subkeys, the child receives two ACEs:

- An effective copy with the child's owner/group substituted and generic
  rights mapped to registry rights. It has `INHERITED_ACE` and no propagation
  flags.
- An inherit-only copy retaining the original SID and generic mask, with
  `INHERITED_ACE` and its propagation flags. This copy resolves afresh when
  the next subkey is created.

This applies to both DACL and SACL entries. An ordinary concrete ACE remains
one copy. `NO_PROPAGATE_INHERIT_ACE` ends the rule at the immediate child,
so it receives only the effective copy. Existing stored descriptors are not
rewritten by upgrading the kernel; an explicit propagation operation is
needed to repair an already-created subtree.

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

## Hive roots

A hive root has no parent, so it is the top of every inheritance chain
below it and cannot inherit anything itself. <a id="cite-inherit.hive-root-inherits-nothing"></a> Its descriptor is created
by the **source**, on first boot, and LCS enforces whatever the source
stored. <a id="cite-inherit.hive-root-descriptor-comes-from-the-source"></a>

LCS holds no template. There are no hardcoded SIDs, no default hive
root descriptors, and no code that would construct one — searching for
them finds nothing. The defaults that follow are what loregd writes;
they are conventions of the source, not properties of the kernel.

**`Machine\`:** <a id="cite-inherit.machine-root-default-descriptor"></a>

| Principal | Rights | Inheritance |
|---|---|---|
| SYSTEM | `KEY_ALL_ACCESS` | Container-inherit |
| Administrators | `KEY_ALL_ACCESS` | Container-inherit |
| Authenticated Users | `KEY_READ` | Container-inherit |

**`Users\<SID>\`:** <a id="cite-inherit.user-root-default-descriptor"></a>

| Principal | Rights | Inheritance |
|---|---|---|
| the user's SID | `KEY_ALL_ACCESS` | Container-inherit |
| SYSTEM | `KEY_ALL_ACCESS` | Container-inherit |
| Administrators | `KEY_ALL_ACCESS` | Container-inherit |

These mirror Windows HKLM and HKU. A subsystem needing something
tighter — `Machine\Security\`, say — sets an explicit descriptor on its
own subtree root at creation, overriding what it inherited.

Because there is no traverse checking ([The Access Flow](</kernel/internals/lcs/security/the-access-flow.md#trm-5-4-1>)), a restrictive
descriptor high in the tree protects only the key it is on. Protection
of a subtree comes from the descriptors its keys inherited at creation,
which is exactly why an administrator changing a parent's descriptor
and expecting the subtree to follow will be disappointed.

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

## Reading and writing descriptors

`REG_IOC_GET_SECURITY` and `REG_IOC_SET_SECURITY` take a
`security_info` bitmask naming which components to act on: owner,
group, DACL, SACL, or mandatory integrity label (`LABEL_SECURITY_INFORMATION`). <a id="cite-inherit.security-info-selects-components"></a>

Zero is `EINVAL`, and so is any unknown flag; both
are rejected before the source is contacted, before transaction
enlistment and before any mutation. <a id="cite-inherit.security-info-zero-or-unknown-is-einval"></a>

The rights required are computed from every component named. Reading
owner, group, the DACL or the label needs `READ_CONTROL`; reading the SACL needs
`ACCESS_SYSTEM_SECURITY`. Setting owner **or group** needs
`WRITE_OWNER`, as does setting the label; setting the DACL needs `WRITE_DAC`; setting the SACL
needs `ACCESS_SYSTEM_SECURITY`. A request naming several components
must hold all the corresponding rights.

A set is a merge, not a replacement. LCS reads only the components
`security_info` names from the supplied self-relative descriptor and
preserves the existing ones. <a id="cite-inherit.set-security-is-a-merge"></a>

Component selection includes its control flags even when the component
has no bytes. A null ACL remains `PRESENT` clear, but its defaulted,
inheritance and protection flags survive a query or an update to another
component. Replacing a selected DACL or SACL takes that ACL's flags from
the input descriptor, including for a null ACL; unselected component
flags are preserved. An empty ACL remains present with zero ACEs and is
not converted to null. The same preservation rule applies to a defaulted
null group. <a id="cite-inherit.null-acl-control-flags"></a>

`LABEL_SECURITY_INFORMATION` reads only the first effective mandatory-label
ACE from the SACL, omitting inherit-only labels and every non-label ACE.
If there is no effective label, the returned subset has no SACL. Reading
this subset needs `READ_CONTROL`; writing it needs `WRITE_OWNER`. Neither
operation needs `ACCESS_SYSTEM_SECURITY` or `SeSecurityPrivilege`.
<a id="cite-inherit.label-access-and-projection"></a>

A label update removes the existing mandatory-label ACEs and inserts the
supplied label before the remaining SACL entries. An input descriptor
with no SACL clears the explicit label. Non-label SACL entries, SACL
inheritance and protection flags, and all unselected descriptor components
are preserved, including flags on a null DACL. Clearing the last SACL
entry clears `SE_SACL_PRESENT` while retaining the other SACL flags.
<a id="cite-inherit.label-merge-preserves-other-security"></a>

For a label-only subset, a supplied SACL must contain exactly one
mandatory-label ACE with an `S-1-16-<level>` SID and without
`INHERIT_ONLY_ACE`; an empty ACL, an audit ACE, or multiple labels is
`EINVAL`. `SACL_SECURITY_INFORMATION` and `LABEL_SECURITY_INFORMATION`
cannot be combined. These input errors are rejected before source contact
or transaction enlistment. <a id="cite-inherit.label-input-validation"></a>

An explicit label above the current caller's integrity level requires
enabled `SeRelabelPrivilege`, checked before source contact or transaction
enlistment; otherwise the update fails with `EACCES`. Labels at or below
the caller's level do not require that privilege. The same rule applies
to an explicit label inside a whole-SACL write: `SeSecurityPrivilege`
does not substitute for `SeRelabelPrivilege`. Existing fd rights remain
cached, but this privilege check uses the caller performing the update.
<a id="cite-inherit.label-level-constraint"></a>

The result must still have an owner; a
merge that would leave the descriptor ownerless is `EINVAL`. <a id="cite-inherit.merge-must-leave-an-owner"></a>

A null
group SID stays valid. <a id="cite-inherit.null-group-sid-is-valid"></a>

Enlisting a descriptor change in a transaction gives it atomicity with
the rest of the transaction's operations. It does not make it
layer-qualified: the change is still a direct mutation on the key, is
still not reverted by deleting a layer, and is simply not applied at
all if the transaction aborts. <a id="cite-inherit.descriptor-change-in-a-transaction"></a>

---

# Audit

_Peios Kernel / Internals / LCS / Security_

> The fifteen audit events LCS emits, which are unconditional, how registry writes are audited through a key handle's alarm mask, and what happens when emission itself fails.

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

LCS emits audit events through KMES. Fifteen events exist. <a id="cite-lcs-audit.events-through-kmes"></a>

| Event | Emitted when |
|---|---|
| `lcs.audit.key.opened` | A key open matched a SACL audit ACE. <a id="cite-lcs-audit.key-open.on-sacl-match"></a> |
| `lcs.audit.value.set` | A value write through a handle whose audit mask covers `KEY_SET_VALUE`. |
| `lcs.audit.value.deleted` | A value delete through a handle whose audit mask covers `KEY_SET_VALUE`. |
| `lcs.audit.key.tombstoned` | A blanket tombstone set or cleared through a handle whose audit mask covers `KEY_SET_VALUE`. |
| `lcs.audit.key.deleted` | A key deleted through a handle whose audit mask covers `DELETE`. |
| `lcs.audit.key.hidden` | A key hidden through a handle whose audit mask covers `DELETE`. |
| `lcs.audit.key.created` | A key create that made a key matched a SACL audit ACE on the parent. |
| `lcs.audit.key.descriptor.changed` | A descriptor change included the SACL, or its right is covered by the handle's audit mask. |
| `lcs.audit.transaction.committed` | A transaction that staged an audited write ended. |
| `lcs.audit.backup.started` | After admission checks and before `REG_IOC_BACKUP` requests its read-only snapshot or reads any subtree data. <a id="cite-lcs-audit.backup-start.before-any-read"></a> |
| `lcs.audit.backup.ended` | After a backup completes or fails after starting. <a id="cite-lcs-audit.backup-complete.after-finish-or-failure"></a> |
| `lcs.audit.restore.started` | Before `REG_IOC_RESTORE` modifies any source state. <a id="cite-lcs-audit.restore-start.before-any-mutation"></a> |
| `lcs.audit.restore.ended` | After a restore completes or fails after starting. <a id="cite-lcs-audit.restore-complete.after-finish-or-failure"></a> |
| `lcs.source.response.rejected` | LCS rejected malformed source data. <a id="cite-lcs-audit.validation-failure.on-malformed-source-data"></a> |
| `lcs.config.value.rejected` | LCS rejected an invalid self-configuration value. <a id="cite-lcs-audit.self-config-invalid.on-invalid-value"></a> |

A registry open that a privilege contributed to is also recorded, as KACS's
`kacs.audit.privilege.used`; see [Privilege use on opens](#privilege-use-on-opens).

Backup and restore are audited **unconditionally**, whatever the SACL
on the target key says. <a id="cite-lcs-audit.backup-and-restore-unconditional"></a> They are privilege-gated bulk operations that
bypass per-key access checks entirely, so the audit trail is the only
record that they happened.

Every payload is a single MessagePack map with string keys. <a id="cite-lcs-audit.payload-is-a-msgpack-map"></a>
Each field path is written as nested maps, one per segment, so
`object.key.guid` is `{object: {key: {guid: …}}}`. A value LCS does not
have is left out rather than written as nil, and every map counts only
the keys actually written (PGSS [Evaluation](</kernel/internals/ntfe/evaluation.md#trm-6-4>)).

The key GUID, `object.key.guid`, is a 16-byte binary value, and the
caller's SID is a binary KACS encoding. The token and process GUIDs
are not payload fields at all: they ride in the KMES event header, so
the payload never repeats them. <a id="cite-lcs-audit.payload-guid-and-sid-encoding"></a>

<a id="trm-5-4-4-1"></a>

## The caller summary

Every event except `lcs.source.response.rejected` and
`lcs.config.value.rejected` describes the effective token used for the
operation under `subject.token`. It has six fields and no more: `sid`,
`integrity`, `id` (the token's LUID), `auth-id` (its logon session's
LUID), `type` (`primary` or `impersonation`) and `impersonation`, the
impersonation level. <a id="cite-lcs-audit.caller-summary-nine-fields"></a>

The bound is deliberate. Group lists, privilege arrays, claims and
default DACLs are unbounded and are never included. The summary carries
enough to correlate an event with a caller, and nothing that could make
one event arbitrarily large. `lcs.source.response.rejected` and
`lcs.config.value.rejected` carry no caller: neither is a principal
acting.

A primary token reports an impersonation
level of 0. <a id="cite-lcs-audit.primary-token-impersonation-level-zero"></a> An Anonymous impersonation token also
reports 0, which is why `subject.token.type` is recorded beside it.

<a id="trm-5-4-4-2"></a>

## Key opens

`lcs.audit.key.opened` carries the caller summary, then
`object.kind` (always `key`, which names the table the masks decode
against), `object.key.guid`, the requested and granted masks as
`access.requested` and `access.granted`, `outcome.success` (`true`
when the open was allowed), and `trigger.sacl-match` — bit 0 for a
success-audit match, bit 1 for a failure-audit match, no other
bits. <a id="cite-lcs-audit.key-open.payload-fields"></a>

`access.granted` is forced to zero on a denial, and that is enforced
rather than merely intended: a denied event carrying a non-zero granted
mask is rejected as a malformed payload. <a id="cite-lcs-audit.key-open.denied-event-has-zero-granted"></a>

`access.requested` is the mask
after registry generic mapping, with `MAXIMUM_ALLOWED` re-added if the
caller asked for it. <a id="cite-lcs-audit.key-open.requested-access-is-post-mapping"></a>

SACL evaluation follows the KACS AccessCheck algorithm — the SACL is
evaluated alongside the DACL, not separately. <a id="cite-lcs-audit.sacl-evaluated-with-the-dacl"></a>

Reading or modifying a
SACL requires `ACCESS_SYSTEM_SECURITY`, which is itself gated by
`SeSecurityPrivilege`. <a id="cite-lcs-audit.sacl-access-gated-by-sesecurityprivilege"></a>

A request of `MAXIMUM_ALLOWED` **alone** maps to a desired mask of zero,
so AccessCheck's SACL walk matches each audit ACE against the *granted*
mask instead. <a id="cite-lcs-audit.key-open.maximum-allowed-matches-granted-mask"></a> An audit ACE says "audit when someone gets this right",
and with `MAXIMUM_ALLOWED` they did get it.

Such an open therefore
always audits as a success, which is correct: `MAXIMUM_ALLOWED` returns
whatever is available and never fails, so a failure ACE has nothing to
record. <a id="cite-lcs-audit.key-open.maximum-allowed-always-audits-success"></a>

An ACE naming a right the caller did not receive still does not
match. <a id="cite-lcs-audit.key-open.ace-for-ungranted-right-does-not-match"></a>

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

## Registry writes

Writes are audited through the key handle, as file operations are
through a file handle. When a key is opened, the access check evaluates
the key's `SYSTEM_ALARM*` ACEs against the caller, and the union of the
masks of the ones that match becomes the handle's **continuous-audit
mask**. <a id="cite-lcs-audit.write.alarm-mask-cached-at-open"></a> Success and failure
`SYSTEM_AUDIT` ACEs do not contribute; they govern the open itself. This
is the continuous auditing of [Auditing in AccessCheck](</kernel/internals/kacs/access-check/auditing-in-accesscheck.md#trm-3-8-9>) with LCS as the enforcement point,
except in two respects: LCS writes records named for the operation
rather than `kacs.audit.handle.used`, and a record it cannot write does
not fail the operation (see below).

The mask is fixed for the life of the handle. A later change to the
key's SACL neither adds to it nor takes from it, so a handle that removes
the alarm ACE is still audited for the change it makes, and handles
opened before an alarm ACE was added are not. <a id="cite-lcs-audit.write.mask-fixed-for-handle-life"></a>

A write through the handle is recorded when the right it needs overlaps
the mask, and not otherwise. <a id="cite-lcs-audit.write.recorded-when-right-overlaps-mask"></a>
The right is the one the handle's own gate checks:

| Event | Operation | Right |
|---|---|---|
| `lcs.audit.value.set` | `REG_IOC_SET_VALUE` | `KEY_SET_VALUE` |
| `lcs.audit.value.deleted` | `REG_IOC_DELETE_VALUE` | `KEY_SET_VALUE` |
| `lcs.audit.key.tombstoned` | `REG_IOC_BLANKET_TOMBSTONE` | `KEY_SET_VALUE` |
| `lcs.audit.key.deleted` | `REG_IOC_DELETE_KEY` | `DELETE` |
| `lcs.audit.key.hidden` | `REG_IOC_HIDE_KEY` | `DELETE` |

<a id="cite-lcs-audit.write.rights-per-event"></a>

A write that fails is recorded too, with `outcome.success` false and
`outcome.errno` the negative errno the caller received. That includes a
write the handle's own gate refuses because the handle lacks the right:
the mask comes from the SACL, not the grant, so it can cover rights the
handle was not given. <a id="cite-lcs-audit.write.failures-recorded"></a>

Every write record carries the caller summary; `object.kind` (`key`),
`object.key.guid` and `object.key.path`, the handle's key and its
resolved path; `object.key.layer.name`, the layer written; the masks
`access.requested` (the right above), `access.granted` (the handle's
grant), `access.matched` and `access.audit-mask`; `transaction.id` when
the write was staged in a transaction; and `outcome.success`, with
`outcome.errno` on a failure. A failure also carries `request.timed-out`.
Value records add `object.key.value.name`; a value write adds the value's
type and length and a digest of its data, and `mutation.sequence`, with
`mutation.sequence-expected` on a compare-and-swap; a tombstone change
adds `operation.name` (`set` or `clear`); a hide adds `mutation.sequence`.
A field the operation had not reached when it failed is left out. <a id="cite-lcs-audit.write.payload-fields"></a>

A value's data is never recorded. In its place a record carries the data's
type, its length and its SHA-256 digest, so two records can be compared
without either holding the data. Every digest LCS records, of a value or
of a security descriptor, is SHA-256. <a id="cite-lcs-audit.write.data-recorded-as-sha256-digest"></a>

A value write outside a transaction also records the value it replaced, as
`object.key.value.type-previous`, `.length-previous` and
`.digest-previous`: the effective value before the write, across every
layer. A value delete records the value it removed the same way. <a id="cite-lcs-audit.write.previous-value-recorded"></a>

A write whose source does not answer before the request timeout fails
with `ETIMEDOUT`, and its record carries `request.timed-out` true. The
source is not told to cancel, so the change may still land; for a value
write or descriptor change outside a transaction, LCS also applies the
write's kernel-side effects when the late reply arrives, and nothing
records who made the write then. Read a timed-out record as "may have
been applied later". <a id="cite-lcs-audit.write.timed-out-may-apply-later"></a>

A write made in a transaction is recorded when it is staged, with
`transaction.id`. Its `outcome.success` then says the source accepted it
into the transaction, not that it took effect. <a id="cite-lcs-audit.write.transacted-recorded-when-staged"></a>

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

### Transaction ends

A transaction that staged at least one recorded write — a write or a key
creation whose record was emitted — writes one
`lcs.audit.transaction.committed` when it ends, and only one: at a
`REG_IOC_COMMIT` that leaves it committed or otherwise finished, at its
timeout, or when its fd is closed without a commit. A commit that fails
and leaves the transaction open writes nothing yet. <a id="cite-lcs-audit.txn-committed.once-per-recorded-transaction"></a>

It carries the caller summary, `transaction.id` and `transaction.state`,
the state it ended in, and `outcome.success`, true only for `committed`.
A failure adds `transaction.commit-outstanding` and `outcome.reason`:
`aborted` (closed without a commit, or a layer it wrote was deleted),
`timed-out` or `source-error`; and `outcome.errno` when a
`REG_IOC_COMMIT` call failed. <a id="cite-lcs-audit.txn-committed.payload-fields"></a>

On `REG_IOC_COMMIT` the subject is the caller who committed, not the one
who staged the writes. A transaction that ended by timeout or by its fd
closing has nobody acting, and names the subject that staged its first
recorded write. The timer that ends a transaction runs in softirq context,
which cannot build a record; the record is written from the work item
that aborts the transaction at the source. <a id="cite-lcs-audit.txn-committed.subject"></a>

A commit whose reply does not arrive in time reports `timed-out` with
`transaction.commit-outstanding` true: the source may have committed it
before the reply was lost.

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

## Key creation

`lcs.audit.key.created` records a key a create made. Creating a key
checks only `KEY_CREATE_SUB_KEY` on its parent, so the parent's SACL
decides, by the rule that decides `lcs.audit.key.opened`: a success audit
ACE on the parent that matches the caller. <a id="cite-lcs-audit.key-created.on-parent-sacl-match"></a>

Only a key that was made is recorded. A create that found the key already
present and opened it instead writes nothing here. The record is written
once the key exists, or is staged in a transaction, so a create whose
handle then fails to reach the caller is still recorded. <a id="cite-lcs-audit.key-created.only-made-keys"></a>

It carries the caller summary; `object.kind`; the new key's
`object.key.guid`, `object.key.path` and `object.key.layer.name`;
`object.key.created` (true), `object.key.volatile`,
`object.key.volatile-requested` and `object.key.symlink`; the new key's
descriptor as `object.sd.length` and `object.sd.owner`; `access.requested`
(`KEY_CREATE_SUB_KEY`) and `access.granted`, from the parent check;
`transaction.id` when staged; and `outcome.success`. <a id="cite-lcs-audit.key-created.payload-fields"></a>

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

## Descriptor changes

`lcs.audit.key.descriptor.changed` records `REG_IOC_SET_SECURITY` through
a key handle.

A change that includes the SACL is recorded whatever the handle's mask
says. It is recorded once the handle's own gate has admitted it, which
takes `ACCESS_SYSTEM_SECURITY`: a handle without that right is refused
first, and asking for a SACL change writes no record. <a id="cite-lcs-audit.descriptor-changed.sacl-change-always-recorded"></a>

Any other change is recorded when the right it needs — `WRITE_OWNER` for
the owner or group, `WRITE_DAC` for the DACL — overlaps the handle's
mask, and then failures are recorded as writes' are. <a id="cite-lcs-audit.descriptor-changed.other-changes-follow-mask"></a>

The record carries what a write record does, without a layer, and the
descriptors: `object.sd.components`, the `security_info` bits asked for;
and for the descriptor written and the one it replaced, `object.sd.length`
and `object.sd.length-previous`, their SHA-256 digests `object.sd.digest`
and `object.sd.digest-previous`, and their owners `object.sd.owner` and
`object.sd.owner-previous`. `access.requested` is every right the change
needs, and `access.matched` is zero when only the SACL made the record
exist. <a id="cite-lcs-audit.descriptor-changed.payload-fields"></a>

<a id="trm-5-4-4-6"></a>

## Privilege use on opens

A registry open whose access check used a privilege — `SeSecurityPrivilege`
for `ACCESS_SYSTEM_SECURITY`, `SeTakeOwnershipPrivilege` for
`WRITE_OWNER` — writes KACS's `kacs.audit.privilege.used` when the
caller's token audit policy asks for privilege use, in the shape KACS
uses for its own access checks, with `object.kind` `key`. The key's
identity is not carried. The checks LCS makes for layer writes and on a
create's parent record none. <a id="cite-lcs-audit.open.privilege-use-recorded"></a>

<a id="trm-5-4-4-7"></a>

## Backup and restore

`lcs.audit.backup.started` and `lcs.audit.restore.started` carry the
caller summary, `object.key.guid` for the subtree root, and
`operation.fd`, the descriptor the stream is written to or read from.

`lcs.audit.backup.ended` and `lcs.audit.restore.ended` carry the
caller summary, `object.key.guid` and `outcome.success`. When the
operation failed they also carry `outcome.errno`, the error as a
negative errno; on success it is absent.

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

## Source validation failures

`lcs.source.response.rejected` carries the source slot as
`source.rsi.slot` and then, where each is known, the hive name as
`source.rsi.hive`, the RSI request id and operation code as
`request.id` and `request.op-code`, and the key GUID as
`object.key.guid`. <a id="cite-lcs-audit.validation-failure.payload-fields"></a> `outcome.reason` names what was wrong.
There are twelve:

`malformed-security-descriptor`, `malformed-layer-name`,
`unknown-rsi-status-code`, `future-sequence-number`,
`duplicate-winning-sequence-tie`,
`malformed-layer-metadata-security-descriptor`,
`malformed-key-name`, `malformed-value-name`,
`malformed-response-payload`, `malformed-key-metadata`,
`malformed-value-payload`, `malformed-delete-layer-orphan-list`. <a id="cite-lcs-audit.validation-failure.twelve-classes"></a>

The three name classes are field-specific: layer-name fields, key
component or child-name fields, and value-name fields respectively. <a id="cite-lcs-audit.validation-failure.name-classes"></a>

The structural classes cover a response whose operation-specific
payload has the wrong shape or trailing bytes; a lookup or
enumeration whose metadata block is incomplete, duplicated,
unreferenced or nil; a value payload with an invalid type, a
tombstone/data mismatch or oversized data; and an invalid orphan GUID
array from `RSI_DELETE_LAYER`. <a id="cite-lcs-audit.validation-failure.structural-classes"></a>

<a id="trm-5-4-4-9"></a>

## Configuration

`lcs.config.value.rejected` has the same shape as KMES's
`kmes.config.value.rejected`, with every field under one `config`
map. It carries the offending parameter's key and name as
`config.key.path` and `config.name`; the expected type and numeric
range as `config.expected.type`, `config.expected.min` and
`config.expected.max`; what was actually received as
`config.received.kind` — one of `missing`, `wrong-type` or
`out-of-range` — with `config.received.type` for a value of the wrong
type or `config.received.value` for one out of range; and, as
`config.value`, the value LCS retained instead. <a id="cite-lcs-audit.self-config.payload-fields"></a>

Because `missing` counts as invalid, a first boot before seed restore
emits one of these per parameter on each refresh: nineteen events
against an empty `Registry\` key. <a id="cite-lcs-audit.self-config.missing-counts-as-invalid"></a> That is correct and expected, but it
is a noticeable share of the boot audit stream.

<a id="trm-5-4-4-10"></a>

## What happens when emission fails

The policy differs per event, and the differences are the point.

- **`lcs.audit.key.opened`.** If LCS cannot *construct* a valid payload —
  corrupt internal state, allocation failure, anything on the LCS side
  — the open fails with `EIO` and no key fd is published. <a id="cite-lcs-audit.emit-failure.key-open-construct-failure-fails-the-open"></a> If the
  payload is valid but KMES cannot *retain* the event — unavailable,
  ring drops, capacity pressure, no consumer — the access decision and
  the fd publication are unaffected. Loss accounting is KMES's problem. <a id="cite-lcs-audit.emit-failure.key-open-retain-failure-is-harmless"></a>
- **`lcs.audit.backup.started`, `lcs.audit.restore.started`.** Emission
  failure returns `EIO` and the operation does not start. Nothing is
  read and nothing is written. <a id="cite-lcs-audit.emit-failure.start-events-block-the-operation"></a>
- **`lcs.audit.backup.ended`, `lcs.audit.restore.ended`.** The operation
  has already finished. Emission is attempted; failure does not change
  the result. <a id="cite-lcs-audit.emit-failure.complete-events-are-best-effort"></a>
- **`lcs.source.response.rejected`.** The triggering operation is
  already failing with `EIO`. Emission is attempted; failure does not
  change that. <a id="cite-lcs-audit.emit-failure.validation-failure-is-best-effort"></a>
- **`lcs.config.value.rejected`.** The invalid value has already been
  ignored and the previous known-good value retained. Emission is
  attempted; failure leaves the retained configuration in force. <a id="cite-lcs-audit.emit-failure.self-config-is-best-effort"></a>
- **The write, creation, descriptor-change and transaction records.**
  Each is written after the source has applied or refused the operation,
  or after the transaction's state is final. Emission is attempted; a
  record that cannot be built or retained leaves the caller's result as
  it was. <a id="cite-lcs-audit.emit-failure.write-records-preserve-result"></a>
  These records fire no `lcs:lcs_audit_emit` or `lcs:lcs_audit_emit_failed`
  tracepoint; the tracepoints' event-type codes cover the other seven.

The rule underneath them all: an audit failure blocks an operation only
where the audit record is the *point* of the operation being permitted.
A privileged bulk export whose start could not be recorded does not
happen. A key open whose decision could not be recorded does not
happen. Everything downstream of an already-determined outcome records
what it can.

LCS constructs the payload and attempts to enqueue it before
continuing past the audit point. It never waits for a userspace
consumer to observe or retain the event. <a id="cite-lcs-audit.enqueue-without-awaiting-a-consumer"></a>
