security/tomoyo/common.c
Source file repositories/reference/linux-study-clean/security/tomoyo/common.c
File Facts
- System
- Linux kernel
- Corpus path
security/tomoyo/common.c- Extension
.c- Size
- 82079 bytes
- Lines
- 3026
- 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.
- 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.
- 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/uaccess.hlinux/slab.hlinux/security.hlinux/string_helpers.hcommon.hbuiltin-policy.h
Detected Declarations
struct tomoyo_queryfunction tomoyo_addprintffunction tomoyo_flushfunction tomoyo_set_stringfunction tomoyo_io_printffunction tomoyo_set_spacefunction tomoyo_set_lffunction tomoyo_set_slashfunction tomoyo_init_policy_namespacefunction tomoyo_print_namespacefunction tomoyo_print_name_unionfunction tomoyo_print_name_union_quotedfunction tomoyo_print_number_union_nospacefunction tomoyo_print_number_unionfunction tomoyo_find_yesnofunction tomoyo_set_uintfunction tomoyo_set_modefunction tomoyo_write_profilefunction tomoyo_print_configfunction tomoyo_read_profilefunction tomoyo_same_managerfunction tomoyo_read_lockfunction tomoyo_read_lockfunction tomoyo_read_lockfunction tomoyo_read_lockfunction srcu_read_lock_heldfunction tomoyo_read_lockfunction tomoyo_same_task_aclfunction tomoyo_read_lockfunction tomoyo_read_lockfunction srcu_read_lock_heldfunction tomoyo_read_lockfunction tomoyo_read_lockfunction tomoyo_print_conditionfunction tomoyo_set_groupfunction tomoyo_print_entryfunction tomoyo_read_lockfunction tomoyo_read_lockfunction tomoyo_write_pidfunction tomoyo_write_pidfunction tomoyo_read_lockfunction tomoyo_read_lockfunction list_for_each_cookiefunction list_for_each_cookiefunction tomoyo_read_lockfunction list_for_each_cookiefunction tomoyo_read_lockfunction tomoyo_truncate
Annotated Snippet
struct tomoyo_query {
struct list_head list;
struct tomoyo_domain_info *domain;
char *query;
size_t query_len;
unsigned int serial;
u8 timer;
u8 answer;
u8 retry;
};
/* The list for "struct tomoyo_query". */
static LIST_HEAD(tomoyo_query_list);
/* Lock for manipulating tomoyo_query_list. */
static DEFINE_SPINLOCK(tomoyo_query_list_lock);
/*
* Number of "struct file" referring /sys/kernel/security/tomoyo/query
* interface.
*/
static atomic_t tomoyo_query_observers = ATOMIC_INIT(0);
/**
* tomoyo_truncate - Truncate a line.
*
* @str: String to truncate.
*
* Returns length of truncated @str.
*/
static int tomoyo_truncate(char *str)
{
char *start = str;
while (*(unsigned char *) str > (unsigned char) ' ')
str++;
*str = '\0';
return strlen(start) + 1;
}
/**
* tomoyo_numscan - sscanf() which stores the length of a decimal integer value.
*
* @str: String to scan.
* @head: Leading string that must start with.
* @width: Pointer to "int" for storing length of a decimal integer value after @head.
* @tail: Optional character that must match after a decimal integer value.
*
* Returns whether @str starts with @head and a decimal value follows @head.
*/
static bool tomoyo_numscan(const char *str, const char *head, int *width, const char tail)
{
const char *cp;
const int n = strlen(head);
if (!strncmp(str, head, n)) {
cp = str + n;
while (*cp && *cp >= '0' && *cp <= '9')
cp++;
if (*cp == tail || !tail) {
*width = cp - (str + n);
return *width != 0;
}
}
*width = 0;
return 0;
}
/**
* tomoyo_patternize_path - Make patterns for file path. Used by learning mode.
*
* @buffer: Destination buffer.
* @len: Size of @buffer.
* @entry: Original line.
*
* Returns nothing.
*/
static void tomoyo_patternize_path(char *buffer, const int len, char *entry)
{
int width;
char *cp = entry;
/* Nothing to do if this line is not for "file" related entry. */
if (strncmp(entry, "file ", 5))
goto flush;
/*
* Nothing to do if there is no colon in this line, for this rewriting
* applies to only filesystems where numeric values in the path are volatile.
*/
cp = strchr(entry + 5, ':');
Annotation
- Immediate include surface: `linux/uaccess.h`, `linux/slab.h`, `linux/security.h`, `linux/string_helpers.h`, `common.h`, `builtin-policy.h`.
- Detected declarations: `struct tomoyo_query`, `function tomoyo_addprintf`, `function tomoyo_flush`, `function tomoyo_set_string`, `function tomoyo_io_printf`, `function tomoyo_set_space`, `function tomoyo_set_lf`, `function tomoyo_set_slash`, `function tomoyo_init_policy_namespace`, `function tomoyo_print_namespace`.
- Atlas domain: Core OS / Security And Isolation.
- Implementation status: source 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.