Peios Learn
Documentation

Peios

Peios Peios Kernel Universal Directory Project

Developer Tools

Trail Acta Provium clackatoo CAF GCSL Pekit

Applications

Framewright

Standards and Conventions

Standards and Conventions Peios Specifications
Peios Kernel

Start here

Single-page view · as markdown

Overview

Peios Kernel / Internals / StrataFS / Start here

stratafs presents an ordered set of existing directories — its strata, or layers, which give it its name — as one merged directory tree. Each stratum is an ordinary directory on an ordinary filesystem, owned and written by whatever agent owns it, with no coordination with stratafs and no notification to it. The merged view reflects changes to any stratum without a remount.

It is a stacking filesystem in the strict sense: it stores no file data, no directory entries, and no security descriptors. Every object reachable through a stratafs mount is a real object on a real stratum, and every data and metadata operation is performed against that object. stratafs inodes carry no address-space operations, so there is no second page cache to keep coherent; reads, writes, mappings and splices are forwarded to a backing file opened on the provider.

Unlike overlayfs, stratafs has no whiteouts and no opaque-directory markers. There is no mechanism anywhere in the filesystem for recording that a name should be absent. That single omission accounts for most of what is unusual about it: removing a name can leave the name visible, some names cannot be removed at all, and several operations that succeed on an ordinary filesystem are refused here rather than faked. Failure Modes collects the consequences.

Where it sits #

stratafs lives in fs/stratafs, alongside PKM. It is built by CONFIG_STRATAFS_FS — a boolean option, so it is linked into vmlinux — and registered by an fs_initcall. The option depends on CONFIG_SECURITY_PKM, because stratafs reaches KACS for every access decision and for the whole of the copy-up context. That reach is through <linux/kacs_stratafs.h>, a kernel-private header in include/linux whose symbols are deliberately not exported to modules. This is a private in-kernel integration interface, not a userspace API.

The filesystem type registers under the name stratafs, with the superblock magic 0x53545241 — ASCII STRA — and the flags FS_USERNS_MOUNT and FS_RENAME_DOES_D_MOVE. It takes no device; superblocks come from get_tree_nodev, so the device identifier reported for every object in a mount is an anonymous one belonging to the mount rather than to any stratum.

A small part of the filesystem is written in Rust. The crate stratafs-core compiles the sources in security/pkm/stratafs_core and holds three pure, allocation-free decisions: validating the stack-wide flag rules, selecting the provider from a presence bitmap, and routing one modifying operation. Everything else — the VFS glue, resolution, enumeration, copy-up — is C.

The model #

A mount is defined by its stratum stack: an ordered list of strata, highest-precedence first, fixed for the life of the mount. A stratum is identified by its path, not by the directory that path resolved to at mount time, which is what allows a package transaction to replace a whole stratum by renaming trees around underneath a live mount.

For a given name in a given directory, the provider is the highest-precedence stratum that holds it. A name whose provider is a directory, and which lower strata also hold as a directory, resolves to a merged directory whose entries are the union of theirs. A name whose provider is anything else masks every lower entry of that name completely, subtree and all.

At most one stratum carries the create flag. That create stratum receives newly created objects and is the destination of copy-up — the replication of an object into the create stratum so that a modification can be applied without touching the stratum that provides it. A stack may have no create stratum, in which case nothing can be created and nothing copied up.

Routing a modification is a decision about strata alone. It happens when the modifying operation is performed, never at open, and it never consults the caller: by the time an operation reaches stratafs, KACS has already decided the caller was entitled to perform it. Write Routing sets out why no other formulation is implementable.

What it delegates #

stratafs holds no security descriptors, so it makes no access decisions of its own about the objects it presents. The descriptor evaluated for an operation is the one on the object the operation will be performed against, and KACS reads it through the ordinary extended-attribute path, which the stacking layer forwards down to the provider. A stratafs mount cannot grant access its provider stratum would refuse.

A merged directory is the exception, because it stands for several real directories with several descriptors and forwarding yields only the provider's. Those checks stratafs performs itself, against every participating directory, requiring all of them to succeed (Checks on Merged Directories).

Copy-up is the other exception, in the opposite direction. It is machinery serving an operation that was already authorised, not an operation a caller requests, so it must introduce no new checks against whichever task happens to execute it. KACS provides a kernel-internal copy-up context for exactly this, described in full at The StrataFS Copy-Up Context; Descriptors on Copy-Up covers the stratafs half.

This chapter #

The Stratum Stack covers the stack, the mount options that define it, what a mounter must be entitled to, and absent strata. Lookup covers resolution: providers, merging, type conflicts, and enumeration. The Coherency Model covers coherency — how uncoordinated change is observed, and the inode identity presented over it. Write Routing covers mutation: routing, copy-up, creation, removal, rename, links, locking and durability. Access Check Delegation covers the security seam with KACS, and The Origin Attribute the one interface stratafs synthesises for userspace. Failure Modes collects the failure modes, including the divergences from ordinary filesystem behaviour that follow from having no whiteouts, and Constants the constants.

Mounting and testing #

See StrataFS mount options for operation, and StrataFS test hooks for development.

Topics #

  • Security
  • Mutation
  • Strata and mounting
  • Name resolution
  • Coherency

The Origin Attribute

Peios Kernel / Internals / StrataFS / Start here

A merged path does not reveal which stratum provided it. stratafs exposes that through one synthetic extended attribute, system.stratafs.origin, and deliberately through nothing else — a tool that instead re-implemented Lookup's resolution rules against the strata would be a second implementation of them, and would eventually disagree with the first.

Together with the mount table (Mount Options), which gives the stratum stack, it is enough to explain any path in a mount without privilege beyond what reading the path itself requires.

The value #

Reading the attribute returns the absolute path of the object that provides it:

  • For a non-directory, the provider's path in its stratum.
  • For a merged directory, the paths of every participating directory in precedence order, separated by newlines.

Each element is the stratum's own path, then a / where the relative part is non-empty and the base does not already end in one, then the relative path. Within a path, a newline or a backslash is escaped by a preceding backslash; those two are the whole escape set, and the / stratafs itself inserts is not escaped. Stratum paths are absolute because the mount parser required them to be (Mount Options).

There is no trailing newline and no trailing NUL. A null buffer returns the length required; an undersized one returns ERANGE.

The value is synthesised at each read from the current resolution. It is not stored, and it is not the value of any attribute on any stratum. Because non-root dentries are always invalidated (Revalidation), a read by path always reflects a fresh resolution.

Constraints #

The attribute is not settable. Any set or removal in the reserved namespace fails with EPERM, before the provider is reached at all.

It is not reported by an attribute listing. The listing handler filters reserved names out of both its sizing pass and its copy pass, and the synthetic name is never added to any listing. Hiding it keeps archivers, copy tools and backup software from discovering it, attempting to preserve it, and failing.

The whole system.stratafs. namespace is reserved. No read, write or removal of any name in it is forwarded to the provider: a read of any name other than origin returns ENODATA, and a write or removal returns EPERM. Where a provider object carries a real attribute of one of these names, it is masked — the synthesised value is returned instead, and the provider's attribute is absent from listings through the mount.

Two details of the implementation are worth stating exactly. The namespace test is a fixed-length prefix comparison against system.stratafs. including the trailing dot, so the bare name system.stratafs is not reserved and would be forwarded to the provider. And the reserved set is one name wider than the namespace suggests: the staging marker attribute, security.peios.stratafs_staging, receives the same treatment — EPERM to write, ENODATA to read, hidden from listings, masked from providers — despite lying outside the system.stratafs. namespace.

Access #

Reading the attribute requires the access that reading an extended attribute of the object requires, and is refused where that would be refused. The right to read the object's stat attributes is not sufficient: the request is for the read-EA right, which KACS's getxattr hook demands on the stratafs dentry before stratafs's own handler runs.

For a merged directory the value names every participating directory, so it discloses more than any one of them. Reading it requires that access on every participating directory and is refused where any refuses — the same intersection Checks on Merged Directories applies to enumeration, and for the same reason: a caller who may not know a restricted directory participates must not learn it from this attribute.

Where the attribute is read through a directory descriptor, the participating set is the one settled when that descriptor was opened (Enumeration), and the value names that set rather than the current one. The access decision was likewise made at open and is recorded on the dentry, so the read consults a stored verdict rather than re-checking. A stratum that has joined since is not disclosed, because the check that would have covered it was never run; a settled participant that has since ceased to hold the directory is still named, for the same reason.

Where it is read by path, the participating set is the current one, resolved afresh, and the read-EA right is required against each of its members at that moment.

Failure Modes

Peios Kernel / Internals / StrataFS / Start here

This section consolidates the conditions under which a stratafs operation fails and the error each produces. The sections above remain authoritative for the conditions themselves.

Mount-time #

ConditionError
Caller lacks the access to resolve a stratum path or read its attributesEACCES
Empty stratum stack, or strata= absentEINVAL
Stack longer than 16 strataEINVAL
More than one stratum carries createEINVAL
A stratum carries both create and roEINVAL
The same directory appears twice in the stackEINVAL
Any malformed strata= value (Mount Options)EINVAL
A remount's strata= differs from the mounted stack (Mount Options)EINVAL
An allocation failure while parsingENOMEM
A create-bearing stack established outside the initial user namespace, or without CAP_SYS_ADMIN thereEPERM
A stratum path names a non-directoryENOTDIR
A stratum is absent without amENOENT
A stratum lies within the mount point, or within another stratafs mount whose strata include this mount pointELOOP
The composed stack reaches the kernel's maximum stacking depthELOOP
Sixteen consecutive collisions allocating a mount cookieEAGAIN

The option-only conditions are decided before any path is touched, and the EPERM admission test before any path is resolved. The per-path conditions follow. Mount Admission records the one place the specified ordering is not achieved.

Resolution #

ConditionError
No participating stratum holds the nameENOENT
An ancestor of the path is masked by a non-directory providerENOTDIR
Operation requires a non-directory; provider is a directoryEISDIR
Traverse or list refused on any participating directoryEACCES
A stratum walk fails for a reason other than absencethat error
A joined stratum path or child relative path exceeds PATH_MAXENAMETOOLONG
A task re-enters the same superblock while resolvingELOOP

Mutation #

ConditionError
Provider will not accept modification, and no create stratum has higher precedenceEROFS
Any mutation on a read-only-mounted stratafsEROFS
Creation, unnamed-file creation, or unnamed-file link with no create stratum, or it absentEROFS
Create stratum holds a path component as a non-directoryENOTDIR
Exclusive creation where any stratum holds the nameEEXIST
Copy-up cannot preserve an extended attributeEIO
Copy-up cannot preserve the descriptorEACCES, EOPNOTSUPP, EINVAL, ESTALE or ENOMEM, as KACS reported it
Copy-up for a descriptor whose object is no longer the provider, or whose target name is taken at publicationESTALE
Copy-up of a device node, FIFO or socketEROFS
Unlink where the provider will not accept modificationEROFS, or EPERM where the provider inode is immutable
Rmdir where another stratum holds entries withinENOTEMPTY
Rmdir or directory rename where list is refused on a participantEACCES
Modifying a special file's mode, descriptor or extended attributes where its provider will not accept modificationEROFS
Establishing a shared write-capable mapping where routing yields read-onlyEROFS
A route change after shared mapping preparation could require another copy-upEAGAIN; retry the whole mmap call
StrataFS or FUSE passthrough layers exceed the supported stacking depth during shared mapping preparationELOOP
Replacing disposition where Removal would refuse the removal, or where a stratum above the create stratum would still hold the nameEROFS
Replacing disposition on anything but a regular fileEOPNOTSUPP
Rename where the source's provider will not accept modificationEROFS
Rename where a stratum above the source's provider provides the destinationEROFS
Rename where the source's provider does not hold the destination's directoryEXDEV
Rename of a directory containing entries from other strataEXDEV
Rename of a non-directory onto a directory providerEISDIR
Rename of a directory onto a non-directory providerENOTDIR
Rename onto a destination directory not empty across every stratumENOTEMPTY
RENAME_NOREPLACE where any stratum holds the destinationEEXIST
RENAME_EXCHANGE where the two names are not provided by one stratum that accepts modificationEROFS
RENAME_EXCHANGE where another stratum holds entries under either directory nameEXDEV
RENAME_WHITEOUTEINVAL
Hard link whose source's provider will not accept modification, or does not hold the destination's directoryEXDEV
Hard link where any stratum holds the destinationEEXIST
Linking an unnamed file into a different mountEXDEV
A dentry whose private state is missing, or whose provider identity no longer matchesESTALE
ioctl on a regular fileENOTTY, or ENOIOCTLCMD for the compat form
remap_file_range with flags outside dedupe and advisoryEINVAL

Shared mapping preparation can publish a copy-up before a later mapping check fails. That copy remains published; the mapping failure does not restore the earlier provider. Copies completed by earlier layers also remain if preparation fails deeper in the backing chain.

Interface #

ConditionError
Set or remove of any reserved attributeEPERM
Read of a reserved attribute other than originENODATA
Origin read where read-EA is refused on any participantEACCES
Origin read into an undersized bufferERANGE
Freezing the filesystemEOPNOTSUPP
Reading a mount's policy without TCB privilegerefused by KACS

Intended divergences #

None of the following is a defect. Each is described above, and each follows from stratafs having no way to record that a name should be absent, or from a merged path standing for objects in more than one stratum.

  • Removing a name may not remove it from the view. Where a lower stratum also holds the name, it becomes the provider and the name remains, now resolving to different content (Removal).
  • A name may be unremovable. Where the provider will not accept modification, removal fails however the caller is privileged (Removal).
  • Rename may be refused for an unmodified file. Where the source's provider will not accept modification, rename fails rather than silently copying (Rename).
  • Hard links may be refused within one directory. Where the source's provider will not accept modification, linking fails with EXDEV (Links).
  • An object's inode number may change. Where the provider for a path changes, a new inode is presented (Inode Identity and Lifecycle).
  • Two callers may hold non-contending locks on one path. Locks are held on the object a descriptor resolved to, so callers who opened either side of a change of provider — including one caused by a copy-up neither of them performed — have locked different objects (Locking).
  • Copy-up severs hard links. Two names that shared an object in a lower stratum, and compared equal by inode number, refer to different objects once one of them is written through the mount; only the written one is copied up (Copy-Up).
  • An open may succeed where the first write then fails. Routing happens when a modifying operation is performed, not at open, so an open for writing against a provider that will not accept modification succeeds and the EROFS arrives at the write, the truncate, or the attempt to establish a shared writable mapping (Write Routing).
  • A copy-up moves an object out from under descriptors already open on it. Only the descriptor whose operation caused the copy-up refers to the copy; others continue to refer to the original, and locks held on it stay there (Write Routing, Locking).
  • A write may fail ESTALE on a descriptor that was valid when opened. Where another descriptor, another mount, or a direct writer has since caused that name to be provided by a different object, a copy-up cannot proceed and the caller must reopen (Copy-Up).
  • fstat and stat may report different inode numbers for one file. After a copy-up, the descriptor that caused it keeps the inode it was opened against while a fresh resolution of the path yields a new one, so the two disagree for as long as that descriptor lives — though both name the copy (Inode Identity and Lifecycle).
  • A directory's link count is always 1. The true count of subdirectories spans strata and cannot be maintained (Inode Identity and Lifecycle).
  • Directory positions do not survive a reopen. A readdir offset is an ordinal into a per-descriptor capture, carrying no provider cookie (Enumeration).

Every one of the first four is the result of refusing to invent a hidden record — a whiteout — that would make an entry in someone else's directory unreachable without their knowledge. The alternative buys POSIX fidelity at the cost of a stratum no longer meaning what its owner wrote in it, which is the property The Stratum Stack exists to protect.

Generated constants

Peios Kernel / Internals / StrataFS / Start here

Every value below is generated from the source by tools/docs/peios-reference/generators/gen-stratafs-constants.py. Nothing here is transcribed by hand, and the generator's --check mode fails if the two drift apart.

Filesystem identity #

ConstantValueMeaning
STRATAFS_MAGIC0x53545241Superblock magic, reported by statfs (Mount Options)
STRATAFS_NAME"stratafs"The name the filesystem registers under
STRATAFS_MAX_STRATA16Longest stratum stack accepted (The Stratum Stack)

STRATAFS_MAGIC is an alias for STRATAFS_SUPER_MAGIC, which is declared in the header stratafs shares with KACS so that the mount policy class keyed on it cannot drift (Mount Policy).

Stratum flags #

ConstantValueMeaning
STRATAFS_F_CREATE0x1The create flag (The Stratum Stack)
STRATAFS_F_RO0x2The ro flag
STRATAFS_F_AM0x4The am flag

Extended attributes #

ConstantValueMeaning
STRATAFS_XATTR_PREFIX"system.stratafs."Reserved namespace; never forwarded to a provider (The Origin Attribute)
STRATAFS_XATTR_ORIGIN"system.stratafs.origin"Synthetic, read-only, hidden from listings (The Origin Attribute)
STRATAFS_XATTR_STAGING"security.peios.stratafs_staging"Copy-up staging marker; also reserved (Copy-Up)

STRATAFS_XATTR_STAGING is an alias for STRATAFS_STAGING_XATTR, declared in the shared header. Note the name it resolves to lies outside the reserved system.stratafs. namespace, yet receives the same treatment (The Origin Attribute).

The canonical security-descriptor attribute is KACS's, not stratafs's; stratafs only detects it in order to exclude it from copy-up replication (Descriptors on Copy-Up).

Copy-up and staging #

ConstantValueMeaning
STRATAFS_STAGE_MARKER_MAGIC0x53544731Marker magic
STRATAFS_STAGE_MARKER_VERSION1Marker version
STRATAFS_COPY_BUFFER_SIZE65536Copy-up read/write chunk, in bytes (Copy-Up)
STRATAFS_STAGE_PREFIX".stratafs-stage-"Staged-name prefix
STRATAFS_RECOVERY_BATCH128Names scanned per staging-recovery pass

The staging marker #

struct stratafs_stage_marker is packed and 24 bytes, all fields little-endian. It is the value of the staging attribute above.

OffsetSizeFieldType
04magic__le32
42version__le16
62size__le16
88boot_cookie__le64
168mount_cookie__le64

Routing #

The value route_existing returns (Write Routing), as the Rust decision core names it and as the C glue mirrors it. The discriminants match.

C enumeratorValueRust
STRATAFS_ROUTE_IN_PLACE0InPlace
STRATAFS_ROUTE_COPY_UP1CopyUp
STRATAFS_ROUTE_READ_ONLY2ReadOnly

The decision core #

stratafs-core holds the stack-wide flag rules, provider selection, and routing. Its flag bits match the C ones above exactly.

ConstantValue
MAX_STRATA16
FLAG_CREATE0x1
FLAG_READ_ONLY0x2
FLAG_ABSENT_MAY0x4
FLAG_MASK0x7

The crate distinguishes these configuration errors. The C boundary collapses all of them to EINVAL, so the distinction is not observable to a caller (The Stratum Stack).

ErrorDiscriminant
Empty1
TooMany2
UnknownFlag3
RepeatedCreate4
CreateReadOnly5

Build configuration #

stratafs is built by CONFIG_STRATAFS_FS, a boolean option, so what it builds is linked into vmlinux rather than loaded. It depends on CONFIG_SECURITY_PKM and selects FS_STACK. Its sources are staged into the kernel tree as fs/stratafs, separate from PKM's own security/pkm. CONFIG_STRATAFS_FS_TEST_HOOKS compiles the test rendezvous and fail points (Stratum flags), inert unless the kernel is booted with stratafs.test_hooks=1. CONFIG_STRATAFS_KUNIT_TEST builds the in-kernel unit tests.

The translation units are:

  • super.o
  • lookup.o
  • inode.o
  • file.o
  • dir.o
  • dir_cache.o
  • xattr.o
  • copy_up.o

Peios Learn — documentation for Peios software.

Built with Trail.