security/device_cgroup.c
Source file repositories/reference/linux-study-clean/security/device_cgroup.c
File Facts
- System
- Linux kernel
- Corpus path
security/device_cgroup.c- Extension
.c- Size
- 22174 bytes
- Lines
- 871
- Domain
- Core OS
- Bucket
- Security And Isolation
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/bpf-cgroup.hlinux/device_cgroup.hlinux/cgroup.hlinux/ctype.hlinux/list.hlinux/uaccess.hlinux/seq_file.hlinux/slab.hlinux/rcupdate.hlinux/mutex.h
Detected Declarations
struct dev_exception_itemstruct dev_cgroupenum devcg_behaviorfunction dev_exceptions_copyfunction list_for_each_entryfunction dev_exceptions_movefunction list_for_each_entry_safefunction dev_exception_addfunction list_for_each_entryfunction dev_exception_rmfunction list_for_each_entry_safefunction __dev_exception_cleanfunction list_for_each_entry_safefunction dev_exception_cleanfunction is_devcg_onlinefunction devcgroup_onlinefunction devcgroup_offlinefunction devcgroup_css_allocfunction devcgroup_css_freefunction seq_putaccessfunction seq_puttypefunction seq_putversionfunction devcgroup_seq_showfunction list_for_each_entry_rcufunction match_exceptionfunction list_for_each_entry_rcufunction match_exception_partialfunction list_for_each_entry_rcufunction verify_new_exfunction parent_has_permfunction parent_allows_removalfunction may_allow_allfunction revalidate_active_exceptionsfunction list_for_each_safefunction propagate_exceptionfunction css_for_each_descendant_prefunction allowedfunction devcgroup_access_writefunction devcgroup_legacy_check_permissionfunction devcgroup_check_permissionexport devcgroup_check_permission
Annotated Snippet
struct dev_exception_item {
u32 major, minor;
short type;
short access;
struct list_head list;
struct rcu_head rcu;
};
struct dev_cgroup {
struct cgroup_subsys_state css;
struct list_head exceptions;
enum devcg_behavior behavior;
};
static inline struct dev_cgroup *css_to_devcgroup(struct cgroup_subsys_state *s)
{
return s ? container_of(s, struct dev_cgroup, css) : NULL;
}
static inline struct dev_cgroup *task_devcgroup(struct task_struct *task)
{
return css_to_devcgroup(task_css(task, devices_cgrp_id));
}
/*
* called under devcgroup_mutex
*/
static int dev_exceptions_copy(struct list_head *dest, struct list_head *orig)
{
struct dev_exception_item *ex, *tmp, *new;
lockdep_assert_held(&devcgroup_mutex);
list_for_each_entry(ex, orig, list) {
new = kmemdup(ex, sizeof(*ex), GFP_KERNEL);
if (!new)
goto free_and_exit;
list_add_tail(&new->list, dest);
}
return 0;
free_and_exit:
list_for_each_entry_safe(ex, tmp, dest, list) {
list_del(&ex->list);
kfree(ex);
}
return -ENOMEM;
}
static void dev_exceptions_move(struct list_head *dest, struct list_head *orig)
{
struct dev_exception_item *ex, *tmp;
lockdep_assert_held(&devcgroup_mutex);
list_for_each_entry_safe(ex, tmp, orig, list) {
list_move_tail(&ex->list, dest);
}
}
/*
* called under devcgroup_mutex
*/
static int dev_exception_add(struct dev_cgroup *dev_cgroup,
struct dev_exception_item *ex)
{
struct dev_exception_item *excopy, *walk;
lockdep_assert_held(&devcgroup_mutex);
excopy = kmemdup(ex, sizeof(*ex), GFP_KERNEL);
if (!excopy)
return -ENOMEM;
list_for_each_entry(walk, &dev_cgroup->exceptions, list) {
if (walk->type != ex->type)
continue;
if (walk->major != ex->major)
continue;
if (walk->minor != ex->minor)
continue;
walk->access |= ex->access;
kfree(excopy);
excopy = NULL;
}
if (excopy != NULL)
list_add_tail_rcu(&excopy->list, &dev_cgroup->exceptions);
Annotation
- Immediate include surface: `linux/bpf-cgroup.h`, `linux/device_cgroup.h`, `linux/cgroup.h`, `linux/ctype.h`, `linux/list.h`, `linux/uaccess.h`, `linux/seq_file.h`, `linux/slab.h`.
- Detected declarations: `struct dev_exception_item`, `struct dev_cgroup`, `enum devcg_behavior`, `function dev_exceptions_copy`, `function list_for_each_entry`, `function dev_exceptions_move`, `function list_for_each_entry_safe`, `function dev_exception_add`, `function list_for_each_entry`, `function dev_exception_rm`.
- Atlas domain: Core OS / Security And Isolation.
- Implementation status: integration 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.