security/commoncap.c
Source file repositories/reference/linux-study-clean/security/commoncap.c
File Facts
- System
- Linux kernel
- Corpus path
security/commoncap.c- Extension
.c- Size
- 45073 bytes
- Lines
- 1528
- Domain
- Core OS
- Bucket
- Security And Isolation
- Inferred role
- Core OS: implementation source
- Status
- source 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/capability.hlinux/audit.hlinux/init.hlinux/kernel.hlinux/lsm_hooks.hlinux/file.hlinux/mm.hlinux/mman.hlinux/pagemap.hlinux/swap.hlinux/skbuff.hlinux/netlink.hlinux/ptrace.hlinux/xattr.hlinux/hugetlb.hlinux/mount.hlinux/sched.hlinux/prctl.hlinux/securebits.hlinux/user_namespace.hlinux/binfmts.hlinux/personality.hlinux/mnt_idmapping.huapi/linux/lsm.htrace/events/capability.hcommoncap_test.c
Detected Declarations
function uidfunction cap_capable_helperfunction has_ns_capability_noauditfunction cap_settimefunction cap_ptrace_access_checkfunction cap_ptrace_tracemefunction cap_capgetfunction cap_inh_is_cappedfunction cap_capsetfunction inode_killprivfunction cap_inode_killprivfunction kuid_root_in_nsfunction vfsuid_root_in_currentnsfunction sansflagsfunction is_v2headerfunction is_v3headerfunction vfs_getxattr_allocfunction rootid_from_xattrfunction validheaderfunction cap_convert_nscapfunction bprm_caps_from_vfs_capsfunction get_vfs_caps_from_diskfunction execvefunction root_privilegedfunction __is_realfunction __is_efffunction __is_suidfunction handle_privileged_rootfunction nonroot_raised_pEfunction execvefunction cap_inode_setxattrfunction cap_inode_removexattrfunction cap_emulate_setxuidfunction setuidfunction cap_safe_nicefunction cap_task_setschedulerfunction cap_task_setiopriofunction cap_task_setnicefunction cap_prctl_dropfunction cap_task_prctlfunction privilegefunction cap_vm_enough_memoryfunction cap_mmap_addrfunction capability_init
Annotated Snippet
if (alloc) {
if (!nscap) {
/* v2 -> v3 conversion */
nscap = kzalloc(size, GFP_ATOMIC);
if (!nscap) {
size = -ENOMEM;
goto out_free;
}
nsmagic = VFS_CAP_REVISION_3;
magic = le32_to_cpu(cap->magic_etc);
if (magic & VFS_CAP_FLAGS_EFFECTIVE)
nsmagic |= VFS_CAP_FLAGS_EFFECTIVE;
memcpy(&nscap->data, &cap->data, sizeof(__le32) * 2 * VFS_CAP_U32);
nscap->magic_etc = cpu_to_le32(nsmagic);
} else {
/* use allocated v3 buffer */
tmpbuf = NULL;
}
nscap->rootid = cpu_to_le32(mappedroot);
*buffer = nscap;
}
goto out_free;
}
if (!vfsuid_root_in_currentns(vfsroot)) {
size = -EOVERFLOW;
goto out_free;
}
/* This comes from a parent namespace. Return as a v2 capability */
size = sizeof(struct vfs_cap_data);
if (alloc) {
if (nscap) {
/* v3 -> v2 conversion */
cap = kzalloc(size, GFP_ATOMIC);
if (!cap) {
size = -ENOMEM;
goto out_free;
}
magic = VFS_CAP_REVISION_2;
nsmagic = le32_to_cpu(nscap->magic_etc);
if (nsmagic & VFS_CAP_FLAGS_EFFECTIVE)
magic |= VFS_CAP_FLAGS_EFFECTIVE;
memcpy(&cap->data, &nscap->data, sizeof(__le32) * 2 * VFS_CAP_U32);
cap->magic_etc = cpu_to_le32(magic);
} else {
/* use unconverted v2 */
tmpbuf = NULL;
}
*buffer = cap;
}
out_free:
kfree(tmpbuf);
return size;
}
/**
* rootid_from_xattr - translate root uid of vfs caps
*
* @value: vfs caps value which may be modified by this function
* @size: size of @ivalue
* @task_ns: user namespace of the caller
*/
static vfsuid_t rootid_from_xattr(const void *value, size_t size,
struct user_namespace *task_ns)
{
const struct vfs_ns_cap_data *nscap = value;
uid_t rootid = 0;
if (size == XATTR_CAPS_SZ_3)
rootid = le32_to_cpu(nscap->rootid);
return VFSUIDT_INIT(make_kuid(task_ns, rootid));
}
static bool validheader(size_t size, const struct vfs_cap_data *cap)
{
return is_v2header(size, cap) || is_v3header(size, cap);
}
/**
* cap_convert_nscap - check vfs caps
*
* @idmap: idmap of the mount the inode was found from
* @dentry: used to retrieve inode to check permissions on
* @ivalue: vfs caps value which may be modified by this function
* @size: size of @ivalue
*
* User requested a write of security.capability. If needed, update the
* xattr to change from v2 to v3, or to fixup the v3 rootid.
Annotation
- Immediate include surface: `linux/capability.h`, `linux/audit.h`, `linux/init.h`, `linux/kernel.h`, `linux/lsm_hooks.h`, `linux/file.h`, `linux/mm.h`, `linux/mman.h`.
- Detected declarations: `function uid`, `function cap_capable_helper`, `function has_ns_capability_noaudit`, `function cap_settime`, `function cap_ptrace_access_check`, `function cap_ptrace_traceme`, `function cap_capget`, `function cap_inh_is_capped`, `function cap_capset`, `function inode_killpriv`.
- Atlas domain: Core OS / Security And Isolation.
- Implementation status: source implementation candidate.
- 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.