···2233#mol-chapter("Security Contexts")
4455-Security Contexts are objects that threads attach to in-order to inherit the
66-permissions inside the context. The contexts store capabilities, allowing for userspace
77-programs to add capabilities to contexts, and kernel space to efficiently search
88-through them to determine whether a process has the permissions to perform a memory access.
55+Security Contexts are objects that threads attach to in-order to inherit access
66+rights, represented as capabilities, inside the context. Additionally, a thread
77+can attach to multiple security contexts, but can only utilize the permissions
88+granted by one unless they switch @twizzler. The contexts store capabilities,
99+allowing for userspace programs to add capabilities to contexts, and kernel
1010+space to efficiently search through them to determine whether a process has the
1111+permissions to perform a memory access.
9121013== Base
1114···2427```
25282629=== Map
2727-The map holds positions to Capabilities relevant to some target object, which
2828-the relevant security context implementations for kernel and userspace to
2929-parse security context objects. Implicitly, the kernel uses
3030-this map for lookup while the user interacts with this map to indicate the insertion, removal, or modification of
3131-a capability. The `Map` type here and for `masks` is a flat data-structure, and stores
3232-offsets into the object where capabilities can be found for a target object.
3030+The map contains positions of capabilities related to a target object, enabling
3131+kernel and userspace to look for capabilities inside security contexts.
3232+Implicitly, the kernel uses this map for lookup while the user interacts with
3333+this map to indicate the insertion, removal, or modification of a capability.
3434+The `Map` type here and for `masks` is a flat data-structure, and stores offsets
3535+into the object where capabilities can be found for a target object.
333634373538=== Masks
3636-Masks act as a restraint on the permissions this context can provide for some targeted object.
3939+Masks act as a restraint on the permissions a context can provide for some target object.
3740This allows for more expressive security policy, such as being able to quickly restrict
3841permissions for an object, without having to remove a capability and recreating one with the
3942dersired restricted permissions.
···55585659All enforcement happens inside the kernel, which has a seperate view into Security Contexts
5760than userspace. The kernel keeps track of all security contexts that threads in Twizzler
5858-attach to, instantiating a cache inside each one. Additionally, a thread can attach
5959-to multiple security contexts, but can only utilize the permissions granted by one unless
6060-they switch @twizzler. To manage these threads, the kernel assigns a Security Context Manager,
6161+attach to, instantiating a cache in each one. To manage these threads, the kernel assigns a Security Context Manager,
6162which holds onto security context references that a thread has.
62636364There exists only 1 point of enforcement for security policy if we wish
6465to keep the kernel out of the access path; the creation of the path itself!
6565-On page fault, the point in which a process requests the kernel to map an object in is
6666+On page fault, the point in which a process requests the kernel to map in an object, is
6667when we have access to the security policy we seek to enforce (the signed capabilities inside the security context), the
6768target object, and most importantly, kernel execution! Its the only time
6868-we can program the mmu according to the desired protections, and transfer control
6969+we can program the MMU according to the desired protections, and transfer control
6970of enforcement to the hardware @twizzler.
70717172Upon page fault, the kernel inspects the target object and identifies the
7273default permissions of that object. Then the kernel checks if the currently active
7374security context for the accessing thread has either cached or capabilities that provide
7474-permissions. If default permissions + the active context permissions arent enough to
7575-permit the access, the kernel then checks each of the inactive contexts to see if they
7575+permissions. If default permissions plus the active context permissions arent enough to
7676+permit the access and the security context isn't a jail, the kernel then checks each of the inactive contexts to see if they
7677have any relevant permissions. If there exists such permissions, then the kernel will
7778switch the active context of that process to the previously inactive context where the permission
7879was found. If it fails all of these, then the kernel terminates the process, citing inadequate