Special Attributes
KACS keeps a file's special attributes in the extended attribute
security.peios.sattr, beside its security descriptor in
security.peios.sd. There are two today:
- Read-only, which KACS enforces for every process.
- Created At, a settable creation date.
Reading and writing them #
The attribute is read and written with the ordinary extended-attribute
calls — getxattr, setxattr and their descriptor and *at forms —
using struct kacs_sattr as the value. KACS answers these calls
itself. Reading needs FILE_READ_ATTRIBUTES, and writing or removing
needs FILE_WRITE_ATTRIBUTES, rather than the extended-attribute
rights. Through a descriptor, the right comes from the handle's
granted mask; by path, from a live check, which may grant
FILE_READ_ATTRIBUTES through the parent (KACS-Native Open).
| Field | Meaning |
|---|---|
version | KACS_SATTR_VERSION, currently 1. |
valid | The fields a write changes. A read sets every bit. |
attributes | KACS_SATTR_READONLY (0x1). |
flags | On a read, KACS_SATTR_CREATED_AT_SET if Created At is set. On a write, KACS_SATTR_CREATED_AT_CLEAR unsets it. |
created_at_sec, created_at_nsec | Created At, as seconds and nanoseconds since the Unix epoch. |
A write changes only the fields its valid mask names and leaves the
others as they are. Two programs changing different attributes at once
therefore cannot undo each other's change. A write with an unknown
version, valid bit, attribute or flag, a nonzero __pad, a value of
the wrong size, or XATTR_CREATE or XATTR_REPLACE fails with
EINVAL. Removing the attribute clears read-only and unsets Created
At.
The attribute is stored only while something is set, and reading a
file that has none fails with ENODATA: it is not read-only, and has no
Created At.
Tools that copy extended attributes copy a stored attribute with the
rest; a copy that should keep an unset Created At has to read it and
set it on the copy.
Read-only #
Read-only protects a file against accidental change, and binds its owner too, without anyone rewriting its permissions. It is the attribute Windows programs set and check, and source-control tools mark checked-in files with it.
On a regular file marked read-only, for every process:
- An open asking
FILE_WRITE_DATAorFILE_APPEND_DATAfails withEACCES. A legacy open for writing fails the same way. AMAXIMUM_ALLOWEDopen is granted neither right, norFILE_ADD_SUBDIRECTORYorFILE_DELETE_CHILD, following MS-FSA 2.1.5.1.2.1.FILE_OVERWRITEandFILE_SUPERSEDEfail withEACCES. truncateby path fails withEACCES.- Deleting it fails with
EPERM:unlink(2), a rename that would replace it, a delete disposition, and an open with delete-on-close, which a native open reports asKACS_STATUS_CANNOT_DELETE. The disposition and rename calls can set this aside with theirIGNORE_READONLYflags (Sharing and Deletion).
The check is made at open and at deletion, not on every write: a handle
opened for writing before the file was marked read-only keeps working,
as on Windows. Renaming a read-only file, and changing its other
attributes or its descriptor, are not affected. Anyone with
FILE_WRITE_ATTRIBUTES can clear the flag.
On a directory, read-only is kept and reported but not enforced. Windows uses the flag on folders to mark them as customized, not to protect them.
Created At #
Created At records when a file was created, in the sense a person or a
copy tool means: a copy can carry its original's creation date, and a
Windows client can set it. It is distinct from the filesystem's
birth time, which statx reports, which nobody can set, and which
records when this inode came into being. Birth time is the forensic
fact; Created At is the user-facing date.
While Created At has not been set, a file's creation date is its birth
time: a reader that finds no Created At, or finds
KACS_SATTR_CREATED_AT_SET clear, takes the date from statx. KACS
never changes Created At itself, and statx continues to report the
birth time.