security/lsm_syscalls.c
Source file repositories/reference/linux-study-clean/security/lsm_syscalls.c
File Facts
- System
- Linux kernel
- Corpus path
security/lsm_syscalls.c- Extension
.c- Size
- 3845 bytes
- Lines
- 130
- Domain
- Core OS
- Bucket
- Security And Isolation
- Inferred role
- Core OS: syscall or user/kernel boundary
- Status
- core implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Defines or participates in a user/kernel boundary; inspect argument validation, copy_from_user/copy_to_user, credentials, and dispatch target.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
asm/current.hlinux/compiler_types.hlinux/err.hlinux/errno.hlinux/security.hlinux/stddef.hlinux/syscalls.hlinux/types.hlinux/lsm_hooks.huapi/linux/lsm.hlsm.h
Detected Declarations
syscall lsm_set_self_attrsyscall lsm_get_self_attrsyscall lsm_list_modulesfunction Copyright
Annotated Snippet
SYSCALL_DEFINE4(lsm_set_self_attr, unsigned int, attr, struct lsm_ctx __user *,
ctx, u32, size, u32, flags)
{
int rc;
rc = mutex_lock_interruptible(¤t->signal->cred_guard_mutex);
if (rc < 0)
return rc;
rc = security_setselfattr(attr, ctx, size, flags);
mutex_unlock(¤t->signal->cred_guard_mutex);
return rc;
}
/**
* sys_lsm_get_self_attr - Return current task's security module attributes
* @attr: which attribute to return
* @ctx: the user-space destination for the information, or NULL
* @size: pointer to the size of space available to receive the data
* @flags: special handling options. LSM_FLAG_SINGLE indicates that only
* attributes associated with the LSM identified in the passed @ctx be
* reported.
*
* Returns the calling task's LSM contexts. On success this
* function returns the number of @ctx array elements. This value
* may be zero if there are no LSM contexts assigned. If @size is
* insufficient to contain the return data -E2BIG is returned and
* @size is set to the minimum required size. In all other cases
* a negative value indicating the error is returned.
*/
SYSCALL_DEFINE4(lsm_get_self_attr, unsigned int, attr, struct lsm_ctx __user *,
ctx, u32 __user *, size, u32, flags)
{
return security_getselfattr(attr, ctx, size, flags);
}
/**
* sys_lsm_list_modules - Return a list of the active security modules
* @ids: the LSM module ids
* @size: pointer to size of @ids, updated on return
* @flags: reserved for future use, must be zero
*
* Returns a list of the active LSM ids. On success this function
* returns the number of @ids array elements. This value may be zero
* if there are no LSMs active. If @size is insufficient to contain
* the return data -E2BIG is returned and @size is set to the minimum
* required size. In all other cases a negative value indicating the
* error is returned.
*/
SYSCALL_DEFINE3(lsm_list_modules, u64 __user *, ids, u32 __user *, size,
u32, flags)
{
u32 total_size = lsm_active_cnt * sizeof(*ids);
u32 usize;
int i;
if (flags)
return -EINVAL;
if (get_user(usize, size))
return -EFAULT;
if (put_user(total_size, size) != 0)
return -EFAULT;
if (usize < total_size)
return -E2BIG;
for (i = 0; i < lsm_active_cnt; i++)
if (put_user(lsm_idlist[i]->id, ids++))
return -EFAULT;
return lsm_active_cnt;
}
Annotation
- Immediate include surface: `asm/current.h`, `linux/compiler_types.h`, `linux/err.h`, `linux/errno.h`, `linux/security.h`, `linux/stddef.h`, `linux/syscalls.h`, `linux/types.h`.
- Detected declarations: `syscall lsm_set_self_attr`, `syscall lsm_get_self_attr`, `syscall lsm_list_modules`, `function Copyright`.
- Atlas domain: Core OS / Security And Isolation.
- Implementation status: core implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.