# Security

---

# Security

_Peios Kernel / Internals / StrataFS / Security_

> Find the Peios kernel articles about security.

Use these articles to understand security in the Peios kernel.

- [KACS admission and object phases](</kernel/internals/stratafs/security/kacs-admission-and-object-phases.md>)
- [Copy-up descriptors](</kernel/internals/stratafs/security/copy-up-descriptors.md>)
- [Access Check Delegation](</kernel/internals/stratafs/security/access-check-delegation.md>)
- [Checks on Merged Directories](</kernel/internals/stratafs/security/checks-on-merged-directories.md>)
- [Mount Policy](</kernel/internals/stratafs/security/mount-policy.md>)
- [Audit](</kernel/internals/stratafs/security/audit.md>)

---

# KACS admission and object phases

_Peios Kernel / Internals / StrataFS / Security_

> KACS admission and object phases: behaviour and implementation of the Peios kernel.

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

StrataFS copy-up is the internal realisation of an operation already
authorized against a StrataFS handle — not a second caller-requested
operation. KACS therefore provides a kernel-internal context so that
the mechanics of copy-up introduce no new rights checks against the
task that happens to execute them.

The context exempts **KACS caller authorization only**. It does not
replace credentials, borrow an identity, grant a privilege, bypass
another LSM, neutralise an underlying filesystem check, make a
read-only mount writable, or suppress immutable, append-only, quota,
space, I/O or format errors. <a id="cite-facs.stratafs-copy-up.exempts-kacs-only"></a> Every exemption is a return before the
authorize call, and every mutation still goes through the ordinary
`vfs_*` path under `mnt_want_write()`. <a id="cite-facs.stratafs-copy-up.mutations-via-vfs"></a>

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

## Admission and lifetime

Only the in-kernel StrataFS implementation can create or enter a
context. There is no userspace surface of any kind — no ABI, file
descriptor, token, ioctl, syscall or securityfs control — and the
copy-up API is declared in a kernel-private header with no exported
symbols. <a id="cite-facs.stratafs-copy-up.no-userspace-surface"></a>

A context is created only after the StrataFS operation requiring
copy-up has passed its complete outer authorization. KACS does not
verify that: the context creation call performs no check, and the
ordering is satisfied by StrataFS calling in the right order. <a id="cite-facs.stratafs-copy-up.creation-performs-no-check"></a> The
context is not itself an alternative authorization path.

The exemption covers namespace creation the outer handle authorises
without an add-entry right on the create stratum, so the context is
reachable only from a create-enabled mount established by a caller
holding `CAP_SYS_ADMIN` in the **initial** user namespace. That
closure rests on an explicit test of the mounter's user namespace at
stack establishment — the capability half contributes nothing to it,
because the KACS switchboard discards the target namespace and answers
from `SeTcbPrivilege` alone ([DAC Neutralisation](</kernel/internals/kacs/linux-credentials/dac-neutralisation.md#trm-3-10-2>)). The check is made when the
immutable stack is established rather than when a copy-up runs, so
descriptor delegation cannot reintroduce acting-task authorization.
Reconfiguration cannot re-supply the strata list.

A context attaches to at most one task, and a task carries at most
one. <a id="cite-facs.stratafs-copy-up.one-context-per-task"></a> It is not inherited by `fork()`, `clone()` or `execve()` — exec
explicitly clears it. <a id="cite-facs.stratafs-copy-up.not-inherited"></a> A refcounted context can be transferred to a
kernel worker, but the originating task leaves it first. <a id="cite-facs.stratafs-copy-up.worker-transfer"></a> Leaving,
task exit, every error path, and completion all remove the attachment
and clear any armed phase. <a id="cite-facs.stratafs-copy-up.detach-clears-phase"></a>

The interface fails closed on nesting, concurrent attachment, a stale
phase, or an object mismatch. <a id="cite-facs.stratafs-copy-up.fails-closed-on-misuse"></a> A mismatched operation is evaluated
normally and neither consumes nor broadens the armed exemption. <a id="cite-facs.stratafs-copy-up.mismatch-evaluated-normally"></a>

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

## Object and phase binding

Creation pins the exact provider path, its current inode, a complete
validated copy of its effective descriptor, and the provider-visible
`security.capability` value or its absence. <a id="cite-facs.stratafs-copy-up.creation-pins-provider"></a> Every later positive path
is paired with a pinned inode as well — retaining a dentry alone is
insufficient, because an unlink followed by recreation can
reinstantiate it over a different inode. <a id="cite-facs.stratafs-copy-up.paths-paired-with-inode"></a>

One phase is armed at a time: <a id="cite-facs.stratafs-copy-up.one-phase-armed"></a>

| Phase | Objects admitted |
|---|---|
| Source read | The pinned provider only. |
| Create | One pinned provider, one destination parent, and either one named negative dentry or one anonymous creation in that parent. Used for both parent materialisation and the staged object. |
| Populate | The pinned provider and the one staged object bound to the context. |
| Publish by link | The bound staged object, one destination parent, one absent destination dentry. |
| Publish by rename | The bound staged object and its parent, one destination parent, one absent destination dentry. |
| Cleanup | One bound staging or materialisation dentry and its exact parent. |
| Orphan cleanup | One positive provider dentry carrying an authenticated stale staging marker, and its exact parent. |
| Orphan-marker cleanup | The exact positive provider dentry whose authenticated stale marker is being removed after publication. |

Path, dentry, inode, parent, object type and operation kind are all
compared wherever the hook supplies them — and path comparison
includes the mount, so the same dentry reached through a different
mount of the same superblock does not match. <a id="cite-facs.stratafs-copy-up.match-includes-mount"></a> An inode-only hook can
match the pinned inode, but that does not authorize a pathname
operation on another dentry, and a phase never acts as a wildcard for
other objects of the same filesystem or directory. <a id="cite-facs.stratafs-copy-up.no-wildcard-matching"></a>

The staged binding stays valid only while its dentry names the pinned
inode under the pinned staging parent, and that parent still names its
own pinned inode. A rename or parent substitution invalidates the
populate, protected-metadata and publish exemptions even when the
staged dentry and inode are themselves unchanged. <a id="cite-facs.stratafs-copy-up.rename-invalidates-binding"></a>

Named creation is bound to the exact final component. <a id="cite-facs.stratafs-copy-up.named-creation-exact-component"></a> Anonymous
creation is bound to its parent, expected object type, the attached
task, and the single armed create phase — and once created, the
anonymous object has to be bound as the staged object before populate,
publish or cleanup can use it. <a id="cite-facs.stratafs-copy-up.anonymous-must-be-bound"></a>

Where the destination is a stacking filesystem creating a real inode
below the armed destination dentry, the transition is authenticated at
the exact outer dentry, and only the one subsequent real-inode
security initialisation of the expected type receives the pinned
provider descriptor. <a id="cite-facs.stratafs-copy-up.stacking-transition-authenticated"></a> The real inode is not the staged binding: the
outer inode is separately anchored, through the matching post-create
event for an anonymous object or an explicit confirmation of the exact
positive outer dentry for a named one. A missing, repeated, mismatched
or out-of-order transition fails closed, and an inner post-create
event from the real filesystem is rejected as the outer anchor by
superblock comparison. <a id="cite-facs.stratafs-copy-up.transition-out-of-order-fails"></a>

KACS retains the exact path, inode, parent path and parent inode of
every named object whose creation it admits. Cleanup can be armed only
for one of those or for the exact bound staging object; an unrelated
positive dentry fails with `ESTALE`. <a id="cite-facs.stratafs-copy-up.cleanup-victim-restricted"></a> The cleanup setup call is not
itself authority to choose a deletion victim.

After an atomic rename or link publishes the staged inode, the staging
identity can be rebound to the published path, but only while mount,
inode, parent dentry and pinned parent inode all still match. <a id="cite-facs.stratafs-copy-up.rebind-conditions"></a> The
rebind API exists and is **not called** by StrataFS: the link case is
rebound internally by the publish path, and the rename case relies on
publish preserving the dentry. <a id="cite-facs.stratafs-copy-up.rebind-unused"></a> That holds because publication always
renames within a single parent. A cross-directory publish rename would
silently invalidate the staging binding, since the rename-publish
entry point does not require the destination parent to equal the
staging parent — currently unreachable, but the guard is the caller's
discipline rather than the interface's.

Named staging entries carry `security.peios.stratafs_staging`.
Caller-originated writes and removals of it are denied. <a id="cite-facs.stratafs-copy-up.staging-marker-writes-denied"></a> A write or
removal is admitted only on the exact bound staging inode during
populate, or on the exact orphan-marker object during authenticated
recovery — where the predicate admits a *write* as well as a removal,
being shared between the setxattr and removexattr hooks. <a id="cite-facs.stratafs-copy-up.staging-marker-admission"></a> Probing the
marker for recovery is a kernel-only raw read conveying no caller
authority, and orphan deletion is bound to the exact dentry, inode,
parent dentry and parent inode supplied when the phase was armed, so
an arbitrary name sharing the staging prefix never matches. <a id="cite-facs.stratafs-copy-up.orphan-deletion-exact-binding"></a> Recovery
processes at most 128 entries per batch.

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

## Exempt operations <a id="cite-facs.stratafs-copy-up.exempt-operations"></a>

For a matching object in a matching phase, the ordinary AccessCheck,
cached-grant check, privilege check and caller-access audit decision
are omitted at these points:

| Copy-up action | Enforcement points |
|---|---|
| Open and read provider data or a symlink target | `security_inode_permission`, `security_file_open`, `security_file_permission`, `security_inode_readlink` |
| Read provider attributes and extended attributes | the inode and file getattr, setattr-preflight, getxattr and listxattr paths as applicable |
| Create a staged file, directory or symlink, and materialise parents | `security_inode_permission`, `security_inode_create`, `security_inode_mkdir`, `security_inode_symlink`, `security_inode_init_security`; for a stacking destination also `security_dentry_create_files_as` and, for an anonymous object, `security_inode_post_create_tmpfile` |
| Populate staged data, attributes and eligible non-descriptor xattrs | `security_inode_permission`, `security_file_open`, `security_file_permission`, the inode and file setattr paths, setxattr and removexattr. `security.capability` uses only the dedicated clone call below. |
| Publish | `security_inode_permission` on the exact staged object or destination parent, then `security_inode_link` or `security_inode_rename` |
| Remove staging or roll back materialised entries | `security_inode_permission` on the exact parent, then `security_inode_unlink` or `security_inode_rmdir` |

A `security_inode_permission` or `security_file_permission` match also
matches the requested mask. <a id="cite-facs.stratafs-copy-up.mask-must-match"></a> Provider access is
read-only — write, append and non-directory execute requests never
match it. <a id="cite-facs.stratafs-copy-up.provider-read-only"></a> Staging access is limited to the read, write and append
masks population needs, plus execute and chdir for directories, and
namespace parents to the write and traverse masks the one armed action
needs, plus open and chdir. <a id="cite-facs.stratafs-copy-up.staging-mask-limits"></a> Unknown mask bits fail closed. <a id="cite-facs.stratafs-copy-up.unknown-mask-fails-closed"></a>

The list is exhaustive. The context does not exempt execution, memory
mapping, ioctl, locking, arbitrary `fcntl`, device access, process
access, socket access, mount operations, or operations on a descriptor
installed into a userspace file table — each verified by the absence
of any copy-up branch on those paths. <a id="cite-facs.stratafs-copy-up.list-exhaustive"></a> Internal copy-up files are
additionally denied `statfs`, `truncate`, `fsync` and `fallocate`. <a id="cite-facs.stratafs-copy-up.internal-file-denied-ops"></a>

A file opened internally under the exemption is marked
copy-up-internal in its blob and carries a granted mask of zero. <a id="cite-facs.stratafs-copy-up.internal-file-zero-mask"></a> It is
usable without a cached caller grant only while the same context is
attached and its phase admits that exact file. Use after phase
completion, from another task, or after transfer through `SCM_RIGHTS`
fails closed. <a id="cite-facs.stratafs-copy-up.internal-file-scope"></a> Each armed phase has a distinct monotonically increasing
generation — overflowing it fails closed — and an internal file is
sealed to the generation it was opened in, so a later phase of the
same kind after a worker transfer cannot reactivate an older file. <a id="cite-facs.stratafs-copy-up.generation-seal"></a>
Final release drops the context reference.

The one exception is the read-only provider-directory cursor used by
bounded staging recovery. StrataFS may retain that file while it
leaves the context to clean one captured batch, then resume it after
re-entering the same context and arming a new source-read phase. Only
a directory file already marked internal for that exact context, still
naming the pinned provider path and inode, opened for read without
write, execute or path-only mode, and inside that attached
source-read phase, resumes; it is then resealed to the new generation. <a id="cite-facs.stratafs-copy-up.directory-cursor-resume"></a>
Between phases it is unusable and conveys no deletion authority.

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

## Backing-file adoption <a id="cite-facs.stratafs-copy-up.backing-adoption"></a>

Before a regular-file copy is published, one exact copy-up-internal
backing file can become the backing file for the outer StrataFS open
description. The staging binding is verified, and the backing file's
recorded user path is confirmed to be that same outer description;
the outer description's immutable granted and continuous-audit
snapshot is then copied across and the internal marker removed. <a id="cite-facs.stratafs-copy-up.adoption-copies-snapshot"></a> This
is a transfer of authority already attached to the descriptor, not a
new AccessCheck against the task that caused the copy-up, which is
what preserves descriptor delegation when that task is not the opener.
It is one-shot, and requires the backing file mode. <a id="cite-facs.stratafs-copy-up.adoption-one-shot"></a>

StrataFS performs adoption after opening the staged file and **before**
publishing the anonymous staged object. KACS verifies the still-bound
staging object while the owned context has no armed phase.
<a id="cite-facs.stratafs-copy-up.adoption-before-publish"></a>

If the staged file belongs to OverlayFS, adoption also follows its exact
private backing files. Each child must be the parent's stored real file,
name that parent's upper object on its upper mount, and record the parent
as its user path. Matching a path alone does not establish this relationship.
The child must have an ordinary managed grant, no copy-up context or phase
generation, and no inherited backing grant.

KACS pins and validates the entire bounded chain before changing any file's
snapshot. A stale association, repeated file, or excessive depth rejects the
handoff without changing those snapshots. Once validation succeeds, every
admitted file receives the original outer description's granted and
continuous-audit masks in both security blobs. This preserves delegated
authority without consulting the task's credentials or weakening phase
precedence.

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

## Auditing <a id="cite-facs.stratafs-copy-up.auditing"></a>

The outer authorized handle operation remains subject to ordinary
audit. No second caller AccessCheck or privilege-use audit is emitted
for an exempt internal sub-operation, since that would attribute
StrataFS mechanics to a caller decision that never happened — and
internal files carry a continuous-audit mask of zero, so they generate
no per-operation events either. <a id="cite-facs.stratafs-copy-up.no-second-audit"></a> The `CAP_SETFCAP` satisfaction path
returns before the capability check that would record privilege use.

StrataFS decides when its own copy-up lifecycle and failure events —
`stratafs.file.copied-up` and `stratafs.mutation.refused` ([Audit](</kernel/internals/stratafs/security/audit.md#trm-4-6-5>)) —
occur; KACS supplies the kernel-only emitter, so KMES stamps each
event with the effective token of the task whose operation caused it
([Event Model](</kernel/internals/kmes/event-model.md#trm-2-2>)). Two of those emissions are best-effort: an allocation failure,
or an operation string that is empty or over 64 bytes, drops the event
silently. <a id="cite-facs.stratafs-copy-up.emission-best-effort"></a>

Denied mismatches, and operations performed with no active matching
context, follow the ordinary authorization and audit paths.

## Related explanations

- [Deferred deletion](</kernel/internals/stratafs/mutation/deferred-deletion.md>)
- [Copy-up descriptors](</kernel/internals/stratafs/security/copy-up-descriptors.md>)

---

# Copy-up descriptors

_Peios Kernel / Internals / StrataFS / Security_

> Copy-up descriptors: behaviour and implementation of the Peios kernel.

<a id="trm-3-9-7-6"></a>

## Exact protected-metadata cloning <a id="cite-facs.stratafs-copy-up.descriptor-cloning"></a>

KACS owns descriptor cloning rather than StrataFS raw-xattr code.
Before a create phase is armed, the provider's complete effective
descriptor is resolved and pinned using the ordinary mount-policy and
corrupt-descriptor rules ([File Descriptor Storage](</kernel/internals/kacs/file-security/descriptor-storage-and-caching.md#trm-3-9-5>)). A missing, corrupt, unresolvable,
oversized or unsupported descriptor fails the phase before the
destination is created. <a id="cite-facs.stratafs-copy-up.unresolvable-descriptor-fails-phase"></a>

For a matching inode security initialisation, an exact byte-for-byte
copy of the pinned descriptor is installed instead of inheritance
running. <a id="cite-facs.stratafs-copy-up.exact-copy-not-inheritance"></a> The canonical xattr is installed as part of inode creation
and the inode's validated parsed cache is seeded from identical bytes
before the inode becomes usable. <a id="cite-facs.stratafs-copy-up.xattr-and-cache-seeded"></a> Failure to allocate, validate or
install either representation fails creation — there is no window in
which a named staging inode carries an inherited or otherwise weaker
descriptor. <a id="cite-facs.stratafs-copy-up.no-weak-window"></a>

On a stacking destination the same applies to the real inode created
below the outer dentry, with the authenticated outer transition as the
only authority to redirect installation there. The pinned bytes are
installed and cached during the real inode's creation, before the
outer object is confirmed or bound; inheriting the parent's descriptor
and repairing it afterwards would not be conforming. <a id="cite-facs.stratafs-copy-up.stacking-real-inode-install"></a>

The canonical descriptor is not copied by ordinary xattr enumeration —
it is reported as cancelled so a stacking filesystem discards it — and
raw canonical getxattr and setxattr stay denied even inside the
context, with the hook-side denial evaluated before any phase match. <a id="cite-facs.stratafs-copy-up.canonical-xattr-cancelled"></a>
The context does not override the unconditional denial of POSIX ACL
mutation either. <a id="cite-facs.stratafs-copy-up.posix-acl-still-denied"></a>

Raw setxattr, including through an internal copy-up file, remains
unable to install `security.capability`. <a id="cite-facs.stratafs-copy-up.raw-setcap-denied"></a> Where the provider has one,
StrataFS calls the dedicated clone entry point during populate, after
any operation that might clear file capabilities. That call accepts
only a kernel buffer exactly matching the pinned value, under the same
user namespace it was pinned in, for the still-bound staged inode. <a id="cite-facs.stratafs-copy-up.clone-call-preconditions"></a> It
re-reads the provider immediately before installing and fails with
`ESTALE` if the value or its presence changed. <a id="cite-facs.stratafs-copy-up.clone-estale-on-change"></a>

The call copies the caller's buffer before comparing, and installs
with `XATTR_CREATE` through the ordinary VFS path, so mount-idmap
conversion, xattr validation, filesystem permission and format checks
and other LSM checks all still apply. <a id="cite-facs.stratafs-copy-up.clone-through-vfs"></a> The otherwise-dead
`CAP_SETFCAP` gate is satisfied only synchronously inside that
validated call, and the corresponding setxattr re-entry is admitted
only after the first hook matches the exact staged inode. <a id="cite-facs.stratafs-copy-up.setfcap-synchronous-only"></a> The
capability answer targets only the pinned caller namespace or the
staged inode's filesystem namespace, and the condition is cleared on
every return. Nothing is installed when the provider had no attribute,
a different one, or an unreadable or invalid one. <a id="cite-facs.stratafs-copy-up.no-install-on-mismatch"></a> The exception does
not revive exec-time file-capability grants.

There is one asymmetry here: the removal path does not reject
`security.capability` the way the set path does, so an internal
copy-up descriptor can remove it from the staged object during
populate. <a id="cite-facs.stratafs-copy-up.removal-path-asymmetry"></a>

Other eligible provider xattrs follow StrataFS's replication rules
while KACS's caller checks on their source and staging objects are
exempted as above. An ineligible xattr that cannot be replicated
triggers StrataFS's ordinary copy-up failure rule rather than being
silently omitted.

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

Copy-up produces a second instance of an existing object. Its security
descriptor is the source's — owner, group, discretionary list, system
list and integrity label alike — and it is KACS that carries it, not
stratafs. <a id="cite-security.copy-up-descriptor-preserved"></a>

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

## How it is carried <a id="cite-security.copy-up-never-inherits-descriptor"></a>

When a copy-up context is created, the provider's complete effective
descriptor is resolved and pinned as a byte string on the context. Each
create phase copies those bytes into the phase, and the inode security
initialisation for the created object installs them verbatim instead of
running inheritance. Nothing is reconstructed field by field: it is a
copy of the source bytes, so all five components are preserved together.

The canonical descriptor attribute is deliberately excluded from
stratafs's own extended-attribute replication, precisely so that the
two mechanisms cannot disagree.

The separation inside KACS is clean and explicit. The inode security
initialisation takes the copy-up branch first, and taking it
short-circuits the inheritance builder entirely. Ordinary creation in a
create stratum inherits from its parent ([Creation](</kernel/internals/stratafs/mutation/creation.md#trm-4-5-3>)); copy-up preserves.
There is no path on which a copied-up object receives an inherited
descriptor.

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

### Descriptors of materialised parents <a id="cite-security.materialised-parents-use-provider-descriptor"></a>

Directories materialised in the create stratum to hold a copied-up
object are handled the same way, each carrying the descriptor of the
corresponding **provider** directory — the merged provider of that same
relative path, which is what the pre-check of [Checks on Merged Directories](</kernel/internals/stratafs/security/checks-on-merged-directories.md#trm-4-6-2>) evaluated against.

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

## Failure <a id="cite-security.copy-up-descriptor-failure-fails-operation"></a>

Where the source descriptor cannot be replicated, the copy-up fails and
the operation that required it fails. A missing, corrupt, unresolvable,
oversized or unsupported descriptor fails the phase before the
destination is created, and an absent pinned descriptor at install time
fails the create.

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

### Protection precedes publication <a id="cite-security.descriptor-installed-before-publication"></a>

Nothing publishes a copied-up object carrying any
other descriptor: the descriptor is installed at inode creation, before
any content, and publication is a link or rename of an object already
stamped, so there is no window in which a differently-protected object
is reachable.

The failure errno is not the specified one. [Failure Modes](</kernel/internals/stratafs/start-here/failure-modes.md#trm-4-8>)'s table pairs
descriptor failure with `EIO` alongside extended-attribute failure, and
the extended-attribute half does report `EIO`. The descriptor half is
carried by KACS, whose failures surface as `EACCES`, `EOPNOTSUPP`,
`EINVAL`, `ESTALE` or `ENOMEM`; there is no `EIO` anywhere on that
path. This is tracked as a defect.

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

## Why preservation rather than inheritance

Copy-up is reachable by any caller with the right to modify the source
object. That right does not include the right to modify the source's
descriptor, which is a separate right.

Were a copied-up object to receive an inherited descriptor, a caller
holding only write access to a restrictively protected object could
cause a copy of it to exist carrying the create stratum directory's
inheritable entries — and that copy, having higher precedence, would
become what the merged path resolves to. The object's confinement would
have been replaced by the directory's, through an operation the caller
was entitled to perform, without their ever holding the right to alter
a descriptor.

Preserving the source descriptor closes that: a copy is exactly as
reachable as its original, and copy-up changes which stratum holds an
object without changing who may reach it.

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

## Provenance <a id="cite-security.copy-up-descriptor-owner-is-source"></a>

Because the descriptor is preserved, the copy's descriptor-level owner
is the owner of the object it was copied from, not the caller who
caused the copy. Ownership therefore does not record who created the
copy and cannot be relied on to; the audit record of [Audit](</kernel/internals/stratafs/security/audit.md#trm-4-6-5>) is where
that is available.

Setting the copying caller as the descriptor owner would have preserved
provenance, and was rejected: an owner holds implicit rights over an
object's descriptor, so making the caller the owner would reintroduce
the escalation this section exists to prevent by a slightly longer
route.

The POSIX owner is preserved separately and for a different reason —
[Copy-Up](</kernel/internals/stratafs/mutation/copy-up.md#trm-4-5-2>) covers the chown and [Durability and Accounting](</kernel/internals/stratafs/mutation/durability-and-accounting.md#trm-4-5-8>) what it means for accounting.

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

## What "the source's descriptor" means <a id="cite-security.copy-up-pins-effective-descriptor"></a>

The descriptor pinned at the start of a copy-up is the provider's
**effective** descriptor rather than its raw stored attribute. On a
provider mount whose own policy class synthesises, that would be the
synthesised value. In practice that case is unreachable: reaching the
object through the stratafs mount at all requires a real descriptor,
under stratafs's own deny-missing class ([Mount Policy](</kernel/internals/stratafs/security/mount-policy.md#trm-4-6-4>)). A provider on an
unmanaged mount is refused outright.

---

# Access Check Delegation

_Peios Kernel / Internals / StrataFS / Security_

> stratafs stores no descriptors and allocates its inodes bare — who performs which access check, and when.

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

stratafs stores no security descriptors. It allocates its outer inodes
bare and never runs the inode security initialisation over them, and
neither its inode state nor its superblock state has anywhere to put a
descriptor. Every object reachable through a mount has its descriptor
on its own stratum, and that descriptor is what governs access to it. <a id="cite-security.descriptor-on-provider-stratum"></a>

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

## The rule <a id="cite-security.check-evaluates-target-descriptor"></a>

An access check for an operation on an object reachable through a
stratafs mount evaluates the security descriptor of the object the
operation will be performed against. For an operation on a
non-directory, that is the provider's object; for a merged directory,
[Checks on Merged Directories](</kernel/internals/stratafs/security/checks-on-merged-directories.md#trm-4-6-2>) defines which participants' descriptors apply.

stratafs synthesises no descriptor, supplies none of its own, and
applies no mount-level template. It could not: constructing one would
require a synthesising mount policy class, and stratafs is pinned to
the class that denies where a descriptor is missing ([Mount Policy](</kernel/internals/stratafs/security/mount-policy.md#trm-4-6-4>)).

Because the descriptor evaluated is the provider's own, a stratafs
mount cannot grant access that the provider's stratum would refuse.
That property is structural rather than a matter of care in
implementation: there is no descriptor for stratafs to get wrong,
because it holds none.

The guarantee is one-directional, which is the direction that matters.
Where the provider carries no descriptor there is nothing to evaluate
and the mount's own policy decides, which is to refuse — so such an
object is unreachable through the mount even where its own filesystem's
policy would have admitted it.

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

## Who performs which check <a id="cite-security.merged-checks-are-stratafs-own"></a>

For an object with a single provider, the descriptor comes back through
ordinary forwarding. KACS reads the canonical descriptor attribute the
same way it does for any file, the stacking layer forwards the
`getxattr` down to the provider, and the descriptor that comes back is
the provider's. For metadata and extended-attribute operations, stratafs
re-targets the pending one-shot KACS decision onto the provider inode,
so the check is made against the object the operation will reach.

A merged directory is not that case. It stands for several directories
with several descriptors, and forwarding yields only the provider's.
Those checks are **stratafs's own**: it walks every present
participating directory and evaluates each one's descriptor, failing on
the first refusal.

KACS cooperates by standing down on stratafs inodes entirely. Its
`inode_permission` hook, and its create, mkdir, mknod, symlink, link,
unlink, rmdir and rename hooks, all return success immediately for a
superblock carrying the stratafs magic. The checks that matter are made
by stratafs against the real objects, or by KACS against the real
objects once stratafs has resolved them.

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

## Timing <a id="cite-security.open-grant-frozen"></a>

The descriptor evaluated is the provider's at the time the check runs,
and the open-time grant is frozen into the file's KACS state — the
check-at-open principle applies unchanged, and copy-up transfers that
immutable snapshot to the new backing file rather than deciding again.

For merged-directory checks, stratafs reads each participant's descriptor
attribute on every check. KACS also refreshes an outer stratafs inode's
parsed descriptor whenever a check or descriptor query needs it. A writer
using the stratum directly therefore needs no invalidation protocol with
the merged view. Missing and corrupt descriptors are re-read too, so a
subsequent repair can take effect.

This refresh applies to retained handles as well as new pathname operations.
An `O_PATH` handle performs its live access check against the refreshed
descriptor. An ordinary file handle retains its granted access, but a
permitted descriptor query returns the provider's current descriptor, not
the one present when the file opened.

When copy-up rebinds a file's inode to the copy ([Inode Identity and Lifecycle](</kernel/internals/stratafs/coherency/inode-identity-and-lifecycle.md#trm-4-4-3>)), stratafs explicitly
invalidates the parsed descriptor. Subsequent descriptor queries follow the
new provider. The file's frozen grant remains unchanged; invalidating the
inode cache does not authorise or revoke access on an already-open file.

---

# Checks on Merged Directories

_Peios Kernel / Internals / StrataFS / Security_

> An operation on a merged directory is checked against every participating directory — including where the create stratum's directory does not exist.

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

A merged directory stands for several real directories, each with its
own security descriptor. An operation on one is checked against every
participating directory whose contents it depends on, and against the
directory it modifies. Where more than one applies, **all** must
succeed: the check walks participants in order and returns on the first
refusal, and nothing degrades an operation to the subset of strata the
caller may reach.

Two composite rights recur:

- **Search** — traverse on every participating directory, since every
  one is searched to resolve a name. The permission hook maps the
  kernel's execute intent onto it. <a id="cite-security.merged-search-right"></a>
- **Enumerate** — Search plus list on every participating directory.
  The permission hook maps the read intent onto the list right, and
  directory open demands both together. <a id="cite-security.merged-enumerate-right"></a>

| Operation | Checked against |
|---|---|
| Resolving a name | Search <a id="cite-security.rights.resolve"></a> |
| Enumerating | Enumerate, before the listing is captured <a id="cite-security.rights.enumerate"></a> |
| Reading an object's attributes | Search, plus whatever the object's own descriptor requires <a id="cite-security.rights.read-attributes"></a> |
| Reading the origin attribute on a merged directory | Search, plus read-EA on **every** participant ([The Origin Attribute](</kernel/internals/stratafs/start-here/the-origin-attribute.md#trm-4-7>)) <a id="cite-security.rights.read-origin"></a> |
| Creating a name | Search, plus add-file or add-subdirectory on the **create stratum's** directory <a id="cite-security.rights.create"></a> |
| Copy-up | Nothing beyond what the operation it serves already required <a id="cite-security.rights.copy-up"></a> |
| Removing a name | Search, plus delete-child on the **provider's** directory <a id="cite-security.rights.remove"></a> |
| Removing a directory | Enumerate — emptiness is judged across every participant — plus delete-child on the provider's directory <a id="cite-security.rights.rmdir"></a> |
| Rename, source | Search, plus delete-child on the source **provider's** directory <a id="cite-security.rights.rename-source"></a> |
| Rename, destination | Search, plus add-entry on the source provider's directory, which [Rename](</kernel/internals/stratafs/mutation/rename.md#trm-4-5-5>) requires to hold the destination, plus delete-child where that directory already holds the name <a id="cite-security.rights.rename-destination"></a> |
| Rename of a directory | Both of the above, plus Enumerate on the object being renamed, and Enumerate on the destination where its provider is a directory <a id="cite-security.rights.rename-directory"></a> |
| `RENAME_EXCHANGE` | Search on both, plus add-entry and delete-child on the directory of the stratum providing both names <a id="cite-security.rights.rename-exchange"></a> |
| Link | Search on both, plus add-file on the source provider's directory <a id="cite-security.rights.link"></a> |
| Creating or linking an unnamed file | Search, plus add-file on the **create stratum's** directory <a id="cite-security.rights.unnamed-file"></a> |

The mutating rights land on the directory that actually changes, which
follows from [Write Routing](</kernel/internals/stratafs/mutation/write-routing.md#trm-4-5-1>): an entry appears in the create stratum's directory
and disappears from the provider's, so in each case it is that
directory's descriptor that decides. The two coincide whenever the
create stratum is also the provider. <a id="cite-security.mutating-right-on-modified-directory"></a>

One right the table does not name is required anyway: the underlying
`vfs_link` makes KACS demand write-attributes on the **source object**,
which is an object-descriptor right outside the directory scope this
section covers. <a id="cite-security.link-requires-write-attributes-on-source"></a> Linking an unnamed file is exempt, since stratafs marks
the source for that purpose. <a id="cite-security.unnamed-link-exempt-from-source-check"></a>

The effective rights on a merged directory are therefore the
intersection of the rights on its participants, with mutating rights
additionally required on the directory that is actually modified.
Requiring the intersection is fail-closed and admits no partial
results: the alternative would let the names held by a restrictively
protected directory be enumerated by a caller who could not enumerate
it directly, because a permissive directory of higher precedence
happened to provide the merged path.

One consequence is worth stating plainly. Because creation is governed
by the create stratum's directory descriptor, and a created name
shadows the same name in every lower stratum, the right to create in
the create stratum's directory is the right to determine what every
lower stratum's entry of that name resolves to.

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

## Where the create stratum's directory does not exist <a id="cite-security.create-check-falls-back-to-provider-directory"></a>

A merged directory has a create stratum whether or not that
subdirectory exists ([Directory Merge](</kernel/internals/stratafs/name-resolution/directory-merge.md#trm-4-3-2>)), so a check naming "the create stratum's
directory" has to be evaluated against a directory that is not there
yet.

Every such check is performed before any part of the operation is
carried out, and in particular before any directory is materialised:
the authorisation call strictly precedes parent materialisation in
creation, in tmpfile creation, and in the unnamed-link path. Where the
checks fail, nothing has been created, so the create stratum is left
exactly as it was.

Where the create stratum does not hold the path, the check falls back
to the **corresponding provider directory** — the merged provider of
that same relative path — which is the descriptor the directory will
carry once materialised ([Descriptors on Copy-Up](</kernel/internals/stratafs/security/copy-up-descriptors.md#trm-4-6-3>)). It is never skipped, and never
substituted with an ancestor's descriptor. Where no provider exists
either, the result is `EROFS`.

Materialising the intervening directories is part of the operation, not
a separate one. No per-ancestor authorisation is taken; the mkdirs are
exempted by the copy-up context. Checking against the descriptor the
directory will have keeps the answer independent of how much of the
create stratum happens to have been materialised already: the first
caller to write into a deep path and the hundredth face the same check,
against the same descriptor.

A create that fails *after* materialisation for a reason other than a
check — `EEXIST`, `ENOSPC` — does leave the intervening directories in
place.

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

## Copy-up carries no separate authority <a id="cite-security.copy-up-requires-no-extra-right"></a>

A copy-up requires no right beyond those the operation that provoked it
already required. In particular it does not require the caller to hold
the right to read the provider's object, nor the right to add an entry
to the create stratum's directory. Neither copy-up path takes any
authorisation at all.

Copy-up is the mechanism by which an authorised modification is
realised, not an operation a caller requests. The read of the provider
is stratafs's own, and the copy carries the source's descriptor
unchanged ([Descriptors on Copy-Up](</kernel/internals/stratafs/security/copy-up-descriptors.md#trm-4-6-3>)), so the caller obtains nothing they did not already
have: the same content, under the same descriptor, at the same path.

The alternative cannot be expressed. Routing happens when a
modification is performed ([Write Routing](</kernel/internals/stratafs/mutation/write-routing.md#trm-4-5-1>)), and by then the authority that
governed the open is a mask cached on the descriptor, immutable and
carrying no token — so there is nothing to evaluate a fresh right
against. Checking the *acting* token instead would break descriptor
delegation, since a descriptor passed to another process would stop
working there.

What remains is a resource consideration rather than an access one: a
caller entitled to write a file in a stratum that will not accept
modification can cause an entry to appear in the create stratum without
holding rights over that directory. They gain neither access nor space
by it: [Durability and Accounting](</kernel/internals/stratafs/mutation/durability-and-accounting.md#trm-4-5-8>) records that the copy is accounted to the preserved owner
rather than to them.

That exemption is only enforceable because KACS provides a copy-up
context; without it the access-control layer would check the caller
against the create stratum's directory at exactly the point where the
authority to check no longer exists. [The StrataFS Copy-Up Context](</kernel/internals/stratafs/security/kacs-admission-and-object-phases.md#trm-3-9-7>) describes the context, its
phase binding and its exhaustive list of exempt operations. What
matters here is what stratafs must hold up its end of: the context
exempts caller authorisation only, so every mutation still goes through
the ordinary VFS path under write access on the target mount, a
read-only filesystem still refuses, and filesystem errors still
propagate. Nothing is performed under a borrowed or elevated identity —
every copy-up mutation runs with the calling task's own credentials.

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

### Recovery retains the mounter’s file credentials <a id="cite-security.staging-recovery-uses-mounter"></a>

The stale-staging recovery scan passes the **mounter's** credentials
to the internal directory open, which retains them as the file’s
credentials. That does not switch the calling task’s current
credentials or select a different KACS token. The scan runs in a
source-read copy-up context bound to that exact directory, so the
context admits its read before an ordinary token access check.

Consequently, neither the caller nor the mounter needs a directory-list
grant for that scoped recovery read. An ordinary open requesting list
access remains subject to the directory’s descriptor. Path resolution
separately uses the captured mounter credentials; the file-credential
argument is not itself an authority switch.

---

# Mount Policy

_Peios Kernel / Internals / StrataFS / Security_

> Every stratafs mount carries the FACS policy class that denies access to an object with no readable descriptor, and what follows from that.

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

A stratafs mount carries the FACS mount policy class that denies access
to an object with no readable security descriptor. The class is derived
from the filesystem magic, not from an administrative choice: the
policy resolver maps the stratafs magic to the deny-missing class, and
falls back to that mapping whenever a cached policy value is not one of
the valid ones. <a id="cite-security.mount-policy-is-deny-missing"></a>

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

## Policy changes are refused before validation <a id="cite-security.mount-policy-cannot-be-set"></a>

It cannot be set to anything else. The set path rejects a superblock
carrying the stratafs magic with `EOPNOTSUPP` **before** it validates
its arguments or checks privilege, and there is no mount option to
choose one — stratafs's parameter table holds exactly one entry, and
anything else is refused. Reading a mount's policy is itself privileged,
requiring TCB privilege, though for stratafs the answer is fixed.

Two classes are excluded for distinct reasons.

**The unmanaged class** declares that FACS does not apply to a mount and
that the kernel governs it by rules particular to that filesystem.
stratafs has no such rules: it delegates every decision to the provider
([Access Check Delegation](</kernel/internals/stratafs/security/access-check-delegation.md#trm-4-6-1>)). An unmanaged stratafs mount would therefore have no access
control at all — not delegated control, but none — for every object
reachable through it. That is not theoretical: enforcement points
consult the mount policy of the superblock an object belongs to before
performing their check, and treat an unmanaged mount as requiring none.
For a mount established over a directory of executables, that would
place every program on the system beyond the execute check.

**The synthesising classes** would have stratafs supply a descriptor of
its own for an object whose provider has none. Either consequence is
disqualifying: the mount would grant access to an object that is
unreachable through its own stratum, falsifying the guarantee the whole
of [Access Check Delegation](</kernel/internals/stratafs/security/access-check-delegation.md#trm-4-6-1>) rests on; and the class that persists a synthesised descriptor
would write it back onto the provider's object, which stratafs may not
do to any stratum and certainly not to one carrying `ro`.

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

## Missing descriptors <a id="cite-security.missing-descriptor-denied"></a>

Where a provider object has no descriptor, access through the stratafs
mount is denied under the mount's own policy, and the provider
filesystem's policy is not consulted. Both paths implement this:
stratafs's own merged-directory check turns `ENODATA` or `EOPNOTSUPP`
straight into `EACCES` rather than asking the provider's superblock to
synthesise, and an object open resolves the missing-descriptor policy
against the **stratafs** superblock, yielding a missing-descriptor
cache entry and then `EACCES`.

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

### Corrupt is not missing <a id="cite-security.corrupt-descriptor-does-not-use-mount-policy"></a>

A descriptor that is present but cannot be interpreted is a distinct
case and is not routed to mount policy. It takes the ordinary
corrupt-descriptor outcome: a corrupt cache entry and an emitted event
on the open path, and a validation failure on the merged-directory
path. The two produce the same errno by different routes, and mount
policy is consulted in neither.

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

## Consequence <a id="cite-security.merge-never-widens-access"></a>

A stratafs mount is uniform in the sense a mount policy requires: every
object reached through it is subject to the same policy, which is the
mount's own. What varies between objects is the descriptor evaluated,
which is a property of the object rather than of the policy.

Because the policy denies where a descriptor is absent, the divergence
from direct access is always in the refusing direction. An object with
no descriptor on a stratum whose own filesystem would synthesise one is
refused through the stratafs mount while remaining reachable through
its stratum path. An object reachable through its stratum path is never
made *more* reachable by being merged. The same holds for a stratum on
an unmanaged filesystem, whose objects carry no descriptors at all:
merging one is permitted but yields nothing readable, and is not a
useful arrangement.

---

# Audit

_Peios Kernel / Internals / StrataFS / Security_

> The two stratafs events recorded because the information cannot be recovered afterwards — plus two gaps and what is not audited at all.

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

Two classes of stratafs event carry information that cannot be
recovered from the filesystem afterwards, and are recorded when they
happen. Both are emitted through KACS's kernel-only emitter, so KMES
stamps each with the effective token of the task whose operation caused
it. <a id="cite-audit.events-stamped-with-effective-token"></a>

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

## Copy-up <a id="cite-audit.copy-up-always-emitted"></a>

Every copy-up emits a `stratafs.file.copied-up` record, successful or
not. Its payload carries these fields, each a path of nested maps:

| Field | |
|---|---|
| `object.file.path-relative` | The relative path within the mount, `/`-prefixed |
| `source.stratum.index` | The stratum the object was copied from |
| `source.stratum.path` | That stratum's path |
| `destination.stratum.index` | The stratum it was copied into |
| `destination.stratum.path` | That stratum's path |
| `outcome.success` | Whether the copy-up succeeded |
| `outcome.errno` | The failure, as a negative errno; absent on success |

The caller's identity is not in this payload. It does not need to be:
KMES stamps the effective, true and process token GUIDs onto every event
header at ring-write time, and because copy-up runs in the caller's own
context those are the caller's. The identity is carried in the
**envelope**, once, for every event — duplicating it into the payload
would give a reader a second copy that could disagree with the first.

Recording it matters because [Descriptors on Copy-Up](</kernel/internals/stratafs/security/copy-up-descriptors.md#trm-4-6-3>) preserves the source's descriptor,
so nothing about the resulting object records who caused it to exist.
A reader of these records must take the identity from the event header,
not look for it among the fields.

The `ENOTDIR` of parent materialisation is reported through this event
in its `outcome.errno` rather than through the refusal event below;
the required fields are all present, under a different event type.

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

## Refused mutation <a id="cite-audit.arrangement-refusal-emitted"></a>

A mutation refused because of how the mount is arranged emits a
`stratafs.mutation.refused` record carrying the relative path
(`object.file.path-relative`), the operation (`operation.name`), the
providing stratum (`source.stratum.index` and `source.stratum.path`),
the error (`outcome.errno`, negative) and whether the refusal was
deferred (`outcome.deferred`). The `source.stratum` fields are present
only where a provider is known; see below.

What counts as an arrangement refusal is one explicit list — `EROFS`,
`EXDEV`, `ENOTDIR`, `EISDIR`, `ENOTEMPTY`, `EEXIST`, `EINVAL`. Call
sites cover
every mutating path: writes, mappings, truncation, `fallocate`, splice,
`copy_file_range`, `remap_file_range`, `setattr`, `setxattr` and
`removexattr`, creation, tmpfile, unlink and rmdir, link, supersede,
and rename.

`EACCES` is deliberately absent from that list. A refusal produced by an
access check is audited by the mechanism that performed it, and
stratafs does not duplicate those records.

These refusals report a mismatch between what a caller attempted and
how the mount is arranged — software writing where it cannot, or an
arrangement that does not admit an operation someone expected. That is
diagnostic information about the system's configuration, and it is
otherwise visible only as an error returned to a caller that may
discard it.

Rollbacks are audited under the same event with the deferred flag set:
a create or link whose outer bookkeeping failed and whose lower object
could not be removed again, and a failed publication rollback after a
copy-up.

A refusal raised before a provider is known — creation, tmpfile, the
heads of link and rename — has no stratum to name. Its record has no
`source` map at all: `source.stratum.index` and `source.stratum.path`
are both absent, never `-1`, nil or an empty string, so a reader can
tell "no provider was involved" from "the provider's path is empty".

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

### One exception <a id="cite-audit.deferred-deletion-audited-on-any-error"></a>

A refused **deferred deletion** is audited on *any* non-zero result, not
only the arrangement errors, so one refused by an access check does get
a stratafs record. That is the right resolution of the two rules, since
the requirement to audit a deferred deletion is unconditional — nobody
is left to receive the error — but it is a deliberate exception to the
`EACCES` exclusion above.

The record is stratafs's whether or not stratafs was entered. The
delete-child check on the merged parent runs before `->unlink`, so a
directory whose descriptor tightened between the arm and the close
refuses the deletion before the filesystem sees it; KACS then raises
the stratafs record itself, with no `source.stratum` fields, since no
stratum was consulted.

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

## What is not audited <a id="cite-audit.lookup-not-audited"></a>

Resolution, revalidation and enumeration emit no records of their own.
They occur on every path operation, they reveal nothing the resulting
access check does not, and recording them would produce volume out of
all proportion to their significance. There is no audit call anywhere
in the lookup path.

Access checks performed against provider objects are audited by KACS,
under its own rules.
