KACS-Native Open

kacs_open takes an explicit desired access mask. The caller names every right it will need — FILE_READ_DATA, FILE_WRITE_DATA, WRITE_DAC, READ_CONTROL, any combination — and AccessCheck evaluates the whole requested mask at open. If every requested right is granted the descriptor's mask is set to the requested mask; if any is denied, the open fails. This is the strict mode, in contrast to the legacy path's subset behaviour (Legacy Open Compatibility).

MAXIMUM_ALLOWED asks for everything the caller may have. Any concrete bits named with it have to be granted; the cached mask is then the full computed maximum rather than the requested set. MAXIMUM_ALLOWED may also be named alone. The maximum includes the rights granted through the parent directory, described below, and excludes the rights a read-only file withholds (Special Attributes).

A caller reads back what an open was granted with kacs_query_open, which reports the cached mask, the open's share access, and whether the file is delete-pending. It is how a caller learns the result of a MAXIMUM_ALLOWED open. The query needs no right: it reveals only what the descriptor already carries. It fails with EOPNOTSUPP on an unmanaged descriptor, including an O_PATH one.

Handle modes #

A Linux open file has a mode — readable, writable, or neither — which the VFS uses for its own accounting, such as write access to an executable and file leases. A native open derives that mode from the rights it is granted: FILE_READ_DATA gives FMODE_READ, either write right gives FMODE_WRITE, and FILE_EXECUTE gives FMODE_EXEC, which enables execveat(fd, "", ..., AT_EMPTY_PATH).

An open granted none of these is a control handle: a managed descriptor with no data mode, carrying only metadata, security or delete rights. It can read attributes, read and change the security descriptor, set a delete disposition, rename, and take part in share checks. It cannot read or write the file's contents. No native open needs to name a data right to obtain a descriptor.

The mode is chosen before the file is opened, so that the VFS never takes write access, read accounting or a lease break for an open that does not hold the matching right. For an explicit mask the mode follows the requested bits. For MAXIMUM_ALLOWED, KACS first evaluates the maximum against the file's current descriptor and takes the mode from the data rights that maximum contains.

The open hook then runs the authoritative check, as for every open. If the descriptor changed between the two evaluations, the hook's result stands. A strict request that is now denied fails as any denied open does. A MAXIMUM_ALLOWED open is stamped with the new maximum, less any data right its mode cannot exercise, so that kacs_query_open never reports a right the descriptor cannot use.

A MAXIMUM_ALLOWED open granted a write right takes write access like any writer. Such an open of a file being executed fails with ETXTBSY, and it breaks other holders' read leases.

Directories #

Directory rights share bit positions with file data rights: FILE_LIST_DIRECTORY is FILE_READ_DATA (0x0001), FILE_ADD_FILE is FILE_WRITE_DATA (0x0002), and FILE_ADD_SUBDIRECTORY is FILE_APPEND_DATA (0x0004). A directory open with FILE_LIST_DIRECTORY is opened FMODE_READ; a directory open without it is a control handle.

The two write aliases are not cacheable directory handle rights, though. kacs_open rejects a desired mask naming FILE_ADD_FILE, FILE_ADD_SUBDIRECTORY or FILE_DELETE_CHILD on a directory with EOPNOTSUPP. Those are parent-directory authorization rights for namespace operations, evaluated live at the operation, not rights a handle carries.

Existing FIFOs, pathname socket nodes, and character and block device nodes on managed mounts are ordinary filesystem file objects for authorization: the file object type, the file right mapping, and the file GenericMapping for metadata, standard and generic rights.

A special node still has to be opened with a data right, because its driver decides what an open without one means; a FIFO refuses it. A native open of a special node granted no data right fails with EINVAL. FILE_EXECUTE is not a valid data substitute for them — a kacs_open naming it on such a node fails closed. The Linux object implementation may still impose its own device- or filesystem-specific denial after KACS has authorized the file object.

Symlink objects are file objects for kacs_get_sd, kacs_set_sd and readlink, but they are not opened as terminal objects by kacs_open. Following is the default resolution behaviour, and AT_SYMLINK_NOFOLLOW fails with ELOOP. This differs deliberately from kacs_get_sd and kacs_set_sd, where the same flag resolves the symlink object itself.

Rights granted through the parent #

Two rights may be granted by the parent directory when the file's own descriptor withholds them, as NTFS grants them (MS-FSA 2.1.5.1.2.1):

  • DELETE is granted if the parent grants FILE_DELETE_CHILD.
  • FILE_READ_ATTRIBUTES is granted if the parent grants FILE_LIST_DIRECTORY. A caller who may list a directory may already see what its entries' attributes would show.

AccessCheck runs first against the file. For each of these two rights that it does not grant, it runs again against the parent directory for the parent right. The parent is the directory the open resolved the file through, so for a file with several hard links it is the parent of the link that was opened. A MAXIMUM_ALLOWED open includes whichever of the two the parent grants.

The same pair of checks governs every other operation that deletes or reads attributes by name: unlink, rmdir and rename by path, delete on close, superseding a file, and stat by path (Use-Time Semantics).

Share access #

Every open of a regular file or directory on a managed mount takes part in NT share-mode checking (Sharing and Deletion). A native open states the sharing it allows in kacs_open_how.share_access, read only when flags carries KACS_OPEN_SHARE_ACCESS:

ValueNameOthers may open with
0x1KACS_FILE_SHARE_READFILE_READ_DATA or FILE_EXECUTE
0x2KACS_FILE_SHARE_WRITEFILE_WRITE_DATA or FILE_APPEND_DATA
0x4KACS_FILE_SHARE_DELETEDELETE

Without the flag the open shares all three, as a legacy open does, and share_access has to be zero. An open that conflicts with another fails with EBUSY and the status KACS_STATUS_SHARING_VIOLATION.

Create dispositions #

ValueNameIf it existsIf it does not
0FILE_SUPERSEDEDelete and recreateCreate
1FILE_OPENOpenFail
2FILE_CREATEFailCreate
3FILE_OPEN_IFOpenCreate
4FILE_OVERWRITETruncate to zeroFail
5FILE_OVERWRITE_IFTruncate to zeroCreate

FILE_SUPERSEDE deletes the existing name and creates a new file under it, requiring DELETE on the existing file — or FILE_DELETE_CHILD on the parent — together with FILE_ADD_FILE on the parent. The existing file's other opens have to share DELETE, and a read-only or delete-pending file cannot be superseded. The new file gets a new inode and a new descriptor, inherited or caller-supplied. The superseded pathname is broken away from the old hardlink set and names the new inode; other pre-existing hardlinks continue to name the old inode, and already-open descriptors still reference it.

FILE_OVERWRITE truncates in place — same inode, same descriptor, hardlinks preserved — and requires FILE_WRITE_DATA.

On an unmanaged mount, FILE_OPEN and FILE_OPEN_IF succeed and return an unmanaged descriptor with no stamped mask rather than failing; the creating dispositions fail with EOPNOTSUPP.

Create options #

ValueNameDescription
0x0001KACS_CREATE_OPT_DIRECTORYThe target has to be a directory. When creating, create a directory rather than a regular file; when opening an existing non-directory, fail with ENOTDIR.
0x0002KACS_CREATE_OPT_DELETE_ON_CLOSEMark the file for deletion when this open closes. Requires DELETE, which may come through the parent.

All other bits are reserved and have to be zero; a nonzero reserved bit fails with EINVAL.

Delete-on-close is NT's: the obligation belongs to the open, and when the open closes the file becomes delete-pending. The name is removed at the last close of any open of the file, from any process (Sharing and Deletion). dup(), fork() and SCM_RIGHTS preserve the obligation because they preserve the open file description; it is discharged when the description's last reference closes. kacs_set_disposition with KACS_DISPOSITION_ON_CLOSE sets or clears it on an open that has DELETE.

Delete-on-close applies to regular files and directories. A directory is removed only if it is empty when it is deleted. A read-only regular file cannot be opened with delete-on-close: the open fails with EPERM and the status KACS_STATUS_CANNOT_DELETE.

Caller-supplied descriptors #

The descriptor format and size bound are defined in SD Structure.

When a disposition results in a new file the caller may supply a descriptor. A null pointer with zero length means the new file's descriptor is inherited from the parent directory through the inheritance algorithm.

Supplying one on a branch that opens an existing object is invalid input rather than something silently ignored. FILE_OPEN_IF resolving to an existing object fails with EINVAL, and so do FILE_OVERWRITE and the existing-object branch of FILE_OVERWRITE_IF, since those retain the existing inode and its descriptor. FILE_OPEN with a descriptor supplied fails with EOPNOTSUPP.

Creator-supplied descriptors are validated at create time. An owner SID has to be the caller's own or a token group marked SE_GROUP_OWNER, unless SeRestorePrivilege is enabled, in which case any owner is allowed. A supplied SACL is treated as a full SACL input rather than a label-only fragment, and therefore requires SeSecurityPrivilege. If that SACL carries an explicit mandatory label ACE, the label also has to satisfy the ordinary label-write constraint: at or below the caller's integrity level, unless SeRelabelPrivilege is held.

Generic rights in the descriptor's ACEs are mapped to file rights when the descriptor is stored, whether it was supplied, inherited or taken from the token's default DACL (The Set-Security Interface).

The creator's access #

The parent's create rights authorize the creation: FILE_ADD_FILE or FILE_ADD_SUBDIRECTORY, together with the supersede rules above. The handle a creating open returns is then granted the access it asked for, as in Windows, even where the new file's descriptor would not grant it to its creator. A creator can therefore create a file with a restrictive descriptor and still write it, in one step, and a folder can accept files whose inherited permissions exclude the people who put them there.

The grant replaces only the normal discretionary pass. The kernel computes the new object's descriptor first, then runs the strict check against it, with the normal DACL walk treated as granting the creator everything. Every other layer still evaluates the new descriptor and can refuse:

  • the mandatory integrity label and PIP;
  • the restricted-token pass;
  • confinement, which stays absolute (Application Confinement);
  • central access and auditing policy; and
  • privilege-only rights, such as ACCESS_SYSTEM_SECURITY.

So a low-integrity creator under an inherited high-integrity label cannot write what it created, and a confined application cannot write outside what its confinement identity is granted. A MAXIMUM_ALLOWED creating open is granted every right of the object type that those layers allow. A refused check rolls the creation back — the newly created file or directory is removed — and the syscall fails.

The grant belongs to the creating open alone. FILE_OPEN_IF or FILE_OVERWRITE_IF that finds an existing object is an ordinary open, and every later open of the new object is checked against its descriptor as normal.

Ancestor pinning #

KACS_OPEN_PIN_ANCESTORS pins the opened file's ancestor directories: while the open lasts, none of them can be renamed or removed by anyone (Sharing and Deletion). It requires SeLockParentagePrivilege enabled; without it the open fails with EPERM.

Lease keys #

With KACS_OPEN_LEASE_KEY, kacs_open_how.lease_key and lease_fd identify the opener to the lease manager given by lease_fd. Opening a file does not break leases that the same manager holds under the same key (Leases). lease_fd has to be a lease-manager descriptor, or the open fails with EBADF.

Modes and status #

kacs_open_how carries no POSIX mode field, so the raw Linux inode mode for native creation is fixed: 0600 for regular files, 0700 for directories. These are compatibility metadata only — and if Linux DAC ever denies an operation KACS would have authorized, the operation fails closed.

Native creation does not create FIFOs, socket nodes, device nodes or symlinks. Those stay on the Linux namespace APIs — mknod(), mkfifo(), Unix bind() to a path — governed by the namespace hooks. NTFS is excluded from native creation entirely.

kacs_open_how is size-versioned. A caller passes the size it was built with — 32 bytes for the original layout, 56 bytes with the lease fields — and fields beyond that size read as zero. A size below 16 bytes fails with EINVAL. New fields are added at the end, behind a flag, so that an existing caller's meaning never changes.

The syscall reports what happened through status_out: created, opened, overwritten, or superseded. KACS_STATUS_SUPERSEDED is used only when an existing object was actually replaced — a FILE_SUPERSEDE that finds no target and simply creates one reports KACS_STATUS_CREATED.

When the open fails for a reason one errno cannot tell apart, status_out also names the NT condition:

StatusErrnoCondition
KACS_STATUS_SHARING_VIOLATIONEBUSYAnother open's share access conflicts with this one.
KACS_STATUS_DELETE_PENDINGEBUSYThe file is delete-pending.
KACS_STATUS_CANNOT_DELETEEPERMDelete-on-close on a read-only file.

On any other failure status_out is left unwritten.

Edit this page