security/tomoyo/util.c
Source file repositories/reference/linux-study-clean/security/tomoyo/util.c
File Facts
- System
- Linux kernel
- Corpus path
security/tomoyo/util.c- Extension
.c- Size
- 28275 bytes
- Lines
- 1107
- 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/slab.hlinux/rculist.hcommon.h
Detected Declarations
function tomoyo_convert_timefunction strncmpfunction tomoyo_parse_ulongfunction tomoyo_print_ulongfunction tomoyo_parse_name_unionfunction tomoyo_parse_number_unionfunction tomoyo_byte_rangefunction tomoyo_alphabet_charfunction tomoyo_make_bytefunction tomoyo_validfunction tomoyo_invalidfunction tomoyo_str_startsfunction tomoyo_normalize_linefunction tomoyo_correct_word2function tomoyo_correct_wordfunction tomoyo_correct_path2function tomoyo_correct_pathfunction tomoyo_correct_domainfunction tomoyo_domain_deffunction tomoyo_read_lockfunction srcu_read_lock_heldfunction tomoyo_const_part_lengthfunction tomoyo_fill_path_infofunction tomoyo_file_matches_pattern2function tomoyo_file_matches_patternfunction tomoyo_path_matches_pattern2function tomoyo_path_matches_patternfunction tomoyo_realpathfunction tomoyo_get_modefunction tomoyo_init_request_infofunction tomoyo_read_lockfunction srcu_read_lock_held
Annotated Snippet
if (c == 'x' || c == 'X') {
base = 16;
cp += 2;
} else if (c >= '0' && c <= '7') {
base = 8;
cp++;
}
}
*result = simple_strtoul(cp, &ep, base);
if (cp == ep)
return TOMOYO_VALUE_TYPE_INVALID;
*str = ep;
switch (base) {
case 16:
return TOMOYO_VALUE_TYPE_HEXADECIMAL;
case 8:
return TOMOYO_VALUE_TYPE_OCTAL;
default:
return TOMOYO_VALUE_TYPE_DECIMAL;
}
}
/**
* tomoyo_print_ulong - Print an "unsigned long" value.
*
* @buffer: Pointer to buffer.
* @buffer_len: Size of @buffer.
* @value: An "unsigned long" value.
* @type: Type of @value.
*
* Returns nothing.
*/
void tomoyo_print_ulong(char *buffer, const int buffer_len,
const unsigned long value, const u8 type)
{
if (type == TOMOYO_VALUE_TYPE_DECIMAL)
snprintf(buffer, buffer_len, "%lu", value);
else if (type == TOMOYO_VALUE_TYPE_OCTAL)
snprintf(buffer, buffer_len, "0%lo", value);
else if (type == TOMOYO_VALUE_TYPE_HEXADECIMAL)
snprintf(buffer, buffer_len, "0x%lX", value);
else
snprintf(buffer, buffer_len, "type(%u)", type);
}
/**
* tomoyo_parse_name_union - Parse a tomoyo_name_union.
*
* @param: Pointer to "struct tomoyo_acl_param".
* @ptr: Pointer to "struct tomoyo_name_union".
*
* Returns true on success, false otherwise.
*/
bool tomoyo_parse_name_union(struct tomoyo_acl_param *param,
struct tomoyo_name_union *ptr)
{
char *filename;
if (param->data[0] == '@') {
param->data++;
ptr->group = tomoyo_get_group(param, TOMOYO_PATH_GROUP);
return ptr->group != NULL;
}
filename = tomoyo_read_token(param);
if (!tomoyo_correct_word(filename))
return false;
ptr->filename = tomoyo_get_name(filename);
return ptr->filename != NULL;
}
/**
* tomoyo_parse_number_union - Parse a tomoyo_number_union.
*
* @param: Pointer to "struct tomoyo_acl_param".
* @ptr: Pointer to "struct tomoyo_number_union".
*
* Returns true on success, false otherwise.
*/
bool tomoyo_parse_number_union(struct tomoyo_acl_param *param,
struct tomoyo_number_union *ptr)
{
char *data;
u8 type;
unsigned long v;
memset(ptr, 0, sizeof(*ptr));
if (param->data[0] == '@') {
param->data++;
ptr->group = tomoyo_get_group(param, TOMOYO_NUMBER_GROUP);
return ptr->group != NULL;
Annotation
- Immediate include surface: `linux/slab.h`, `linux/rculist.h`, `common.h`.
- Detected declarations: `function tomoyo_convert_time`, `function strncmp`, `function tomoyo_parse_ulong`, `function tomoyo_print_ulong`, `function tomoyo_parse_name_union`, `function tomoyo_parse_number_union`, `function tomoyo_byte_range`, `function tomoyo_alphabet_char`, `function tomoyo_make_byte`, `function tomoyo_valid`.
- 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.