Expand description
This module provides types and hook APIs supporting Linux Security Modules functionality in Starnix. LSM provides a generic set of hooks, and opaque types, used to decouple the rest of the kernel from the details of any specific security enforcement subsystem (e.g. SELinux, POSIX.1e, etc).
Although this module is hard-wired to the SELinux implementation, callers should treat the types as opaque; hook implementations necessarily have access to kernel structures, but not the other way around.
Modules§
- testing
- yama
- YAMA hook implementations used to restirct ptrace access. This module implements the YAMA LSM functionality, used to lock down ptrace access.
Structs§
- Audit
Logger - Audit logging structure.
- Audit
Message - Audit message structure.
- Binder
Connection State - Opaque structure holding security state for a [
binderfs::BinderConnection]. - BpfMap
State - Opaque structure holding security state for a bpf [
ebpf_api::maps::Map]. - BpfProg
State - Opaque structure holding security state for a bpf
crate::bpf::program::Program. - File
Object State - Opaque structure holding security state for a
crate::vfs::FileObject. - File
System State - Opaque structure holding security state for a
crate::vfs::FileSystem. - FsNode
Security Xattr - Used to return an extended attribute name and value to apply to a
crate::vfs::FsNode. - FsNode
State - The opaque type used by
crate::vfs::FsNodeInfoto store security state. - Kernel
State - Opaque structure encapsulating security subsystem state for the whole system.
- Perf
Event State - Opaque structure holding security state for a PerfEventFileState.
- Permission
Flags - The flags about which permissions should be checked when opening an FsNode. Used in the
fs_node_permission()hook. - Resolved
ElfState - Structure holding security state associated with a
ResolvedElfinstance. TODO(https://fxbug.dev/378835222): Consider restructuring hook calls so that the kernel does not need to depend on the contents of this struct. - Socket
State - Opaque structure holding security state for a
crate::vfs::socket::Socket. - Task
State - Opaque structure encapsulating active security state for a
Task.
Enums§
- Audit
Request - Supported requests that manipulate the
AuditLogger - Auditable
- Container for a reference to kernel state from which to include details when emitting audit
logging.
Auditableinstances are created from references to objects viainto(), e.g: - Perf
Event Type - The flags about the PerfEvent types.
- Proc
Attr - Identifies one of the Security Context attributes associated with a task.
- Target
Task Type - The target task type. Used in the
check_perf_event_open_accessLSM hook.
Functions§
- binder_
connection_ alloc - Returns the security context to be assigned to a BinderConnection, based on the task that creates it.
- binder_
get_ context - Returns the serialized Security Context associated with the specified state. If the state’s SID cannot be resolved then None is returned.
- binder_
set_ context_ mgr - Checks whether the given
current_taskcan become the binder context manager. Corresponds to thebinder_set_context_mgrhook. - binder_
transaction - Checks whether the given
current_taskcan perform a transaction totarget_task. Corresponds to thebinder_transactionhook. - binder_
transfer_ binder - Checks whether the given
current_taskcan transfer Binder objects totarget_task. Corresponds to thebinder_transfer_binderhook. - binder_
transfer_ file - Checks whether the given
receiving_taskcan receivefilein a Binder transaction. Corresponds to thebinder_transfer_filehook. - bpf_
map_ alloc - Returns the security context to be assigned to a BPM map object, based on the task that
creates it.
Corresponds to the
bpf_map_alloc_security()LSM hook. - bpf_
prog_ alloc - Returns the security context to be assigned to a BPM program object, based on the task
that creates it.
Corresponds to the
bpf_prog_alloc_security()LSM hook. - bprm_
creds_ for_ exec - Checks if exec is allowed and if so, checks permissions related to the transition (if any) from the pre-exec security context to the post-exec context.
- check_
bpf_ access - Checks whether
current_taskcan perform the given bpfcmd. This hook is called from thesys_bpf()syscall after the attribute is copied into the kernel. Corresponds to thebpf()LSM hook. - check_
bpf_ map_ access - Checks whether
current_taskcan create a bpf_map. This hook is called from thesys_bpf()syscall when the kernel tries to generate and return a file descriptor for maps. Corresponds to thebpf_map()LSM hook. - check_
bpf_ prog_ access - Checks whether
current_taskcan create a bpf_program. This hook is called from thesys_bpf()syscall when the kernel tries to generate and return a file descriptor for programs. Corresponds to thebpf_prog()LSM hook. - check_
file_ fcntl_ access - Returns whether
current_taskhas the permissions to execute this fcntl syscall. Corresponds to thefile_fcntl()LSM hook. - check_
file_ ioctl_ access - Returns whether
current_taskcan issue an ioctl tofile. Corresponds to thefile_ioctl()LSM hook. - check_
file_ lock_ access - This hook is called by the
flocksyscall. Returns whethercurrent_taskcan perform a lock operation on the given file. - check_
fs_ node_ create_ access - Validate that
current_taskhas permission to create a regular file in theparentdirectory, with the specified filemode. Corresponds to theinode_create()LSM hook. - check_
fs_ node_ getattr_ access - Checks if
current_taskhas the permission to read file attributes forfs_node. Corresponds to theinode_getattr()hook. - check_
fs_ node_ getxattr_ access - Corresponds to the
inode_getxattr()LSM hook. - check_
fs_ node_ link_ access - Validate that
current_taskhas the permission to create a new hard link to a file. Corresponds to theinode_link()LSM hook. - check_
fs_ node_ listxattr_ access - Corresponds to the
inode_listxattr()LSM hook. - check_
fs_ node_ mkdir_ access - Validate that
current_taskhas permission to create a new directory in theparentdirectory, with the specified filemode. Corresponds to theinode_mkdir()LSM hook. - check_
fs_ node_ mknod_ access - Validate that
current_taskhas permission to create a new special file, socket or pipe, in theparentdirectory, and with the specified filemodeanddevice_id. For consistency any calls tomknod()with a filemodespecifying a regular file will be validated bycheck_fs_node_create_access()rather than by this hook. Corresponds to theinode_mknod()LSM hook. - check_
fs_ node_ read_ link_ access - Checks whether the
current_taskcan read the symbolic link infs_node. Corresponds to theinode_readlink()LSM hook. - check_
fs_ node_ removexattr_ access - Corresponds to the
inode_removexattr()LSM hook. - check_
fs_ node_ rename_ access - Checks whether the
current_taskcan rename the file or directorymoving_node. If the rename replaces an existing node,replaced_nodemust contain a reference to the existing node. Corresponds to theinode_rename()LSM hook. - check_
fs_ node_ rmdir_ access - Validate that
current_taskhas the permission to remove a directory. Corresponds to theinode_rmdir()LSM hook. - check_
fs_ node_ setattr_ access - Checks whether
current_taskcan set attributes onnode. Corresponds to theinode_setattr()LSM hook. - check_
fs_ node_ setxattr_ access - This is called by Starnix even for filesystems which support extended attributes, unlike Linux
LSM.
Partially corresponds to the
inode_setxattr()LSM hook: It is equivalent toinode_setxattr()for non-security xattrs, whilefs_node_setsecurity()is always called for security xattrs. See alsofs_node_setsecurity(). - check_
fs_ node_ symlink_ access - Validate that
current_taskhas permission to create a symlink toold_pathin theparentdirectory. Corresponds to theinode_symlink()LSM hook. - check_
fs_ node_ unlink_ access - Validate that
current_taskhas the permission to remove a hard link to a file. Corresponds to theinode_unlink()LSM hook. - check_
getcap_ access - Called when the current task queries the Linux capabilities of the
targettask. Corresponds to thecapget()LSM hook. - check_
getpgid_ access - Checks if getpgid is allowed.
Corresponds to the
task_getpgid()LSM hook. - check_
getsched_ access - Checks if
sourcemay exercise the “getsched” permission ontarget. Corresponds to thetask_getscheduler()LSM hook. - check_
netlink_ send_ access - Checks if the
current_taskis allowed to send a message ofmessage_typeon the Netlinksocket. Corresponds to thenetlink_send()LSM hook. - check_
perf_ event_ open_ access - Checks whether
current_taskhas the correct permissions to monitor the given target task or tasks. Corresponds to theperf_event_openLSM hook. - check_
perf_ event_ read_ access - Checks whether
current_taskhas the correct permissions to read the givenperf_event_fileCorresponds to theperf_event_readLSM hook. - check_
perf_ event_ write_ access - Checks whether
current_taskhas the correct permissions to write to the givenperf_event_file. Corresponds to theperf_event_writeLSM hook. - check_
setcap_ access - Called when the current task attempts to set the Linux capabilities of the
targettask. Corresponds to thecapset()LSM hook. - check_
setpgid_ access - Checks if setpgid is allowed.
Corresponds to the
task_setpgid()LSM hook. - check_
setsched_ access - Checks if setsched is allowed.
Corresponds to the
task_setscheduler()LSM hook. - check_
signal_ access - Checks if sending a signal is allowed.
Corresponds to the
task_kill()LSM hook. - check_
socket_ bind_ access - Checks if the
current_taskis allowed to perform a bind operation for thissocket. Corresponds to thesocket_bind()LSM hook. - check_
socket_ connect_ access - Checks if the
current_taskis allowed to initiate a connection withsocket. Corresponds to thesocket_connect()LSM hook. - check_
socket_ create_ access - Checks if creating a socket is allowed.
Corresponds to the
socket_create()LSM hook. - check_
socket_ getpeername_ access - Checks if the
current_taskis allowed to get the remote name ofsocket. Corresponds to thesocket_getpeername()LSM hook. - check_
socket_ getsockname_ access - Checks if the
current_taskis allowed to get the local name ofsocket. Corresponds to thesocket_getsockname()LSM hook. - check_
socket_ getsockopt_ access - Checks if the
current_taskis allowed to get socket options onsocket. Corresponds to thesocket_getsockopt()LSM hook. - check_
socket_ listen_ access - Checks if the
current_taskis allowed to listen onsocket_node. Corresponds to thesocket_listen()LSM hook. - check_
socket_ recvmsg_ access - Checks if the
current_taskis allowed to receive a message onsocket. Corresponds to thesocket_recvmsg()LSM hook. - check_
socket_ sendmsg_ access - Checks if the
current_taskis allowed to send a message onsocket. Corresponds to thesocket_sendmsg()LSM hook. - check_
socket_ setsockopt_ access - Checks if the
current_taskis allowed to set socket options onsocket. Corresponds to thesocket_getsockopt()LSM hook. - check_
socket_ shutdown_ access - Checks if the
current_taskis allowed to shutdownsocket. Corresponds to thesocket_shutdown()LSM hook. - check_
syslog_ access - Checks if a particular syslog action is allowed.
Corresponds to the
task_syslog()LSM hook. - check_
task_ capable - Checks if a task has the specified
capability. Corresponds to thecapable()LSM hook. - check_
task_ create_ access - Checks if creating a task is allowed.
Directly maps to the
selinux_task_createLSM hook from the original NSA white paper. Partially corresponds to thetask_alloc()LSM hook. Compared totask_alloc(), this hook doesn’t actually modify the task’s label, but instead verifies whether the task has the “fork” permission on itself. - check_
task_ getsid - Called when the current task queries the session Id of the
targettask. Corresponds to thetask_getsid()LSM hook. - check_
tun_ dev_ create_ access - Checks if the
current_taskhas permission to create a new TUN device. Corresponds to thetun_dev_create()LSM hook. - creds_
start_ internal_ operation - Marks the credentials as being used for an internal operation. All SELinux permission checks will be skipped on this task.
- exec_
binprm - Updates the SELinux thread group state on exec.
Corresponds to the
exec_binprmfunction described in the SELinux Notebook. - file_
alloc_ security - Returns the security state for a new file object created by
current_task. Corresponds to thefile_alloc_security()LSM hook. - file_
mprotect - Checks whether
current_taskis allowed to request setting the memory protection ofmappingtoprot. Corresponds to thefile_mprotectLSM hook. - file_
permission - Checks whether the
current_taskhas the specifiedpermission_flagsto thefile. Corresponds to thefile_permission()LSM hook. - file_
receive - Returns whether the
current_taskcan receivefilevia a socket IPC. Corresponds to thefile_receive()LSM hook. - file_
system_ init_ security - Returns security state to associate with a filesystem based on the supplied mount options.
This sits somewhere between
fs_context_parse_param()andsb_set_mnt_opts()in function. - file_
system_ post_ init_ security - Gives the hooks subsystem an opportunity to note that the new
file_systemneeds labeling, if SELinux is enabled, but no policy has yet been loaded. - file_
system_ resolve_ security - Resolves the labeling scheme and arguments for the
file_system, based on the loaded policy. If no policy has yet been loaded then no work is done, and thefile_systemwill instead be labeled when a policy is first loaded. If thefile_systemwas already labeled then no further work is done. - fs_
is_ xattr_ labeled - Returns true if SELinux is enabled on the kernel for this task.
- fs_
node_ copy_ up - Sets the security context of
CurrentTaskto be appropriate for a copy up operation onfs_node, then calldo_copy_up. The task’s security context will be reset before returning. - fs_
node_ getsecurity - Returns the value of the specified “security.*” attribute for
fs_node. If SELinux is enabled then requests for the “security.selinux” attribute will return the Security Context corresponding to the SID with whichfs_nodehas been labeled, even if the node’s file system does not generally support extended attributes. If SELinux is not enabled, or the node is not labeled with a SID, then the call is delegated to thecrate::vfs::FsNodeOps, so the returned value may not be a valid Security Context. Corresponds to theinode_getsecurity()LSM hook. - fs_
node_ init_ anon - Called on creation of anonymous
crate::vfs::FsNodes. APIs that create file-descriptors that are not linked into any filesystem directory structure create anonymous nodes, labeled by this hook rather thanfs_node_init_on_create()above. Corresponds to theinode_init_security_anon()LSM hook. - fs_
node_ init_ memfd - Called on creation of mem-FD
crate::vfs::FsNodes. Corresponds to theinode_init_security_anon()LSM hook, called with the mem-FD node-type. - fs_
node_ init_ on_ create - Called by file-system implementations when creating the
FsNodefor a new file, to determine the correct label based on theCurrentTaskandparentnode, and the policy-defined transition rules, and to initialize theFsNode’s security state accordingly. If no policy has yet been loaded then this is a no-op; if theFsNodecorresponds to an xattr- labeled file then it will receive the file-system’s “default” label once a policy is loaded. Returns an extended attribute value to set on the newly-created file if the labeling scheme isfs_use_xattr. For other labeling schemes (e.g.fs_use_trans, mountpoint-labeling) a label is set on theFsNodesecurity state, but no extended attribute is set nor returned. Thenamewith which the new node is being created allows name-conditionaltype_transitionrules to be applied when determining the label for thenew_node. Corresponds to theinode_init_security()LSM hook. - fs_
node_ init_ with_ dentry - Called by the VFS to initialize the security state for an
FsNodethat is being linked atdir_entry. If theFsNodesecurity state had already been initialized, or no policy is yet loaded, then this is a no-op. Corresponds to thed_instantiate()LSM hook. - fs_
node_ init_ with_ dentry_ deferred - fs_
node_ init_ with_ dentry_ no_ xattr - fs_
node_ listsecurity - If SELinux is enabled and
fs_nodeis in a filesystem without xattr support, returns the xattr name for the security label associated with inode. Otherwise returns None. - fs_
node_ notify_ security_ context - Applies the given label to the given node without checking any permissions.
Used by file-system implementations to set the label for a node, for example when it has
prefetched the label in the xattr rather than letting it get fetched by
fs_node_init_with_dentrylater. Calling this doesn’t need to exclude the use offs_node_init_with_dentry, it will just turn that call into a fast no-op. Corresponds to theinode_notifysecctxLSM hook. - fs_
node_ permission - Checks whether the
current_taskcan access an inode. Corresponds to theinode_permission()LSM hook. - fs_
node_ setsecurity - Called when an extended attribute with “security.”-prefixed
nameis being set, after having passed the discretionary andcheck_fs_node_setxattr_access()permission-checks. This allows the LSM (e.g. SELinux) to update internal state as necessary for xattr changes. - fs_
node_ xattr_ skipcap - Returns true if the security subsystem should skip capability checks on access to the named attribute, false otherwise.
- get_
procattr - Returns the Security Context associated with the
nameed entry for the specifiedtargettask. Corresponds to thegetprocattr()LSM hook. - has_
dontaudit_ access - Returns true if there exits a
dontauditrule forcurrent_taskaccess tofs_node, which includes theaudit_accesspseudo-permission. This appears to be handled via additional options & flags in other hooks, by LSM. - is_
task_ capable_ noaudit - Returns true if a task has the specified
capability. Corresponds to thecapable()LSM hook invoked with a no-audit flag set. - kernel_
init_ security - Returns the security state structure for the kernel, based on the supplied “selinux” argument contents.
- mmap_
file - Checks whether the
current_taskis allowed to mmapfileor memory using the givenProtectionFlagsandMappingOptions. Corresponds to themmap_file()LSM hook. - perf_
event_ alloc - Returns the security context to be assigned to a PerfEventFileState, based on the task that
creates it.
Corresponds to the
perf_event_allocLSM hook. - ptrace_
access_ check - Checks whether the current
current_taskis allowed to tracetracee_task. Corresponds to theptrace_access_check()LSM hook. - ptrace_
traceme - Checks whether the
parent_tracer_taskis allowed to trace thecurrent_task. Corresponds to theptrace_traceme()LSM hook. - sb_
eat_ lsm_ opts - Consumes the mount options from the supplied
MountParamsand returns the security mount options for the givenMountParams. Corresponds to thesb_eat_lsm_optshook. - sb_
kern_ mount - Check permission before mounting
fs. Corresponds to thesb_kern_mount()LSM hook. - sb_
mount - Check permission before mounting to
path.flagscontains the mount flags that determine the kind of mount operation done, and therefore the permissions that the caller requires. Corresponds to thesb_mount()LSM hook. - sb_
remount - Checks permission before remounting
mountwithnew_mount_params. Corresponds to thesb_remount()LSM hook. - sb_
show_ options - Writes the LSM mount options of
mountintobuf. Corresponds to thesb_show_optionsLSM hook. - sb_
statfs - Checks if
current_taskhas the permission to get the filesystem statistics offs. Corresponds to thesb_statfs()LSM hook. - sb_
umount - Checks if
current_taskhas the permission to unmount the filesystem mounted onnodeusing the unmount flagsflags. Corresponds to thesb_umount()LSM hook. - selinuxfs_
check_ access - Used by the “selinuxfs” module to perform checks on SELinux API file accesses.
- selinuxfs_
get_ admin_ api - Used by the “selinuxfs” module to access the SELinux administration API, if enabled.
- selinuxfs_
init_ null - Stashes a reference to the selinuxfs null file for later use by hooks that remap inaccessible file descriptors to null.
- selinuxfs_
policy_ loaded - Called by the “selinuxfs” when a policy has been successfully loaded, to allow policy-dependent initialization to be completed. This includes resolving labeling schemes and state for file-systems mounted prior to policy load (e.g. the “selinuxfs” itself), and initializing security state for any file nodes they may already contain.
- set_
procattr - Sets the Security Context associated with the
nameed entry for the current task. Corresponds to thesetprocattr()LSM hook. - socket_
accept - Checks if the
current_taskis allowed to accept connections onlistening_socket. Sets the security label and SID for the accepted socket to match those of the listening socket. Corresponds to thesocket_accept()LSM hook. - socket_
getpeersec_ dgram - Returns the Security Context with which the [
crate::vfs::Socket]’s is labeled, to return to the recipient viaSCM_SECURITYauxiliary data, ifSO_PASSSECis set. Corresponds to thesocket_getpeersec_dgram()LSM hook. - socket_
getpeersec_ stream - Returns the Security Context with which the [
crate::vfs::Socket]’s peer is labeled. Corresponds to thesocket_getpeersec_stream()LSM hook. - socket_
post_ create - Computes and updates the socket security class associated with a new socket.
Corresponds to the
socket_post_create()LSM hook. - socket_
socketpair - Sets the peer security context for each socket in the pair.
Corresponds to the
socket_socketpair()LSM hook. - task_
alloc - Returns
TaskStatefor a newTask, based on that ofcurrent_task, and the specified clone flags. Corresponds to thetask_alloc()LSM hook. - task_
alloc_ for_ kernel - Return the default initial
TaskStatefor kernel tasks. Corresponds to thetask_alloc()LSM hook, in the special case when current_task is null. - task_
for_ context - Returns
TaskStatefor a newTask, based on that of the providedcontext. The effect is similar to combining thetask_alloc()andsetprocattr()LSM hooks, with the difference that no access-checks are performed, and the “#” syntax may be used to have the Taskassigned one of the “initial” Security Contexts, to allow components to be run prior to a policy being loaded. - task_
prlimit - Called when the current task calls prlimit on a different task.
Corresponds to the
task_prlimit()LSM hook. - task_
setrlimit - Called before
sourcesets the resource limits oftargetfromold_limittonew_limit. Corresponds to thesecurity_task_setrlimithook. - task_
to_ fs_ node - Labels an
crate::vfs::FsNode, by attaching a pseudo-label to thefs_node, which allows indirect resolution of the effective label. Makes the security attributes offs_nodetrack thetask’s security attributes, even if the task’s security attributes change. Called for the /proc/FsNodes when they are created. Corresponds to thetask_to_inodeLSM hook. - unix_
may_ send - Checks if the Unix domain
sending_socketis allowed to send a message to thereceiving_socket. Corresponds to theunix_may_send()LSM hook. - unix_
stream_ connect - Checks if the Unix domain
client_socketis allowed to connect tolistening_socket, and initialises the peer information in the client and server sockets. Corresponds to theunix_stream_connect()LSM hook.