security/tomoyo/file.c
Source file repositories/reference/linux-study-clean/security/tomoyo/file.c
File Facts
- System
- Linux kernel
- Corpus path
security/tomoyo/file.c- Extension
.c- Size
- 30068 bytes
- Lines
- 1051
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
common.hlinux/slab.h
Detected Declarations
function tomoyo_put_name_unionfunction tomoyo_compare_name_unionfunction tomoyo_put_number_unionfunction tomoyo_compare_number_unionfunction tomoyo_add_slashfunction tomoyo_get_realpathfunction tomoyo_audit_path_logfunction tomoyo_audit_path2_logfunction tomoyo_audit_mkdev_logfunction tomoyo_audit_path_number_logfunction tomoyo_check_path_aclfunction tomoyo_check_path_number_aclfunction tomoyo_check_path2_aclfunction tomoyo_check_mkdev_aclfunction tomoyo_same_path_aclfunction tomoyo_merge_path_aclfunction tomoyo_read_lockfunction tomoyo_same_mkdev_aclfunction tomoyo_merge_mkdev_aclfunction tomoyo_read_lockfunction tomoyo_same_path2_aclfunction tomoyo_merge_path2_aclfunction tomoyo_read_lockfunction tomoyo_read_lockfunction tomoyo_read_lockfunction tomoyo_same_path_number_aclfunction tomoyo_merge_path_number_aclfunction tomoyo_update_path_number_aclfunction tomoyo_path_number_permfunction tomoyo_check_open_permissionfunction tomoyo_init_request_infofunction tomoyo_path_permfunction tomoyo_mkdev_permfunction tomoyo_path2_permfunction tomoyo_same_mount_aclfunction tomoyo_read_lockfunction tomoyo_read_lock
Annotated Snippet
if (!tomoyo_get_realpath(&buf, path)) {
error = -ENOMEM;
goto out;
}
r.obj = &obj;
if (acc_mode & MAY_READ)
error = tomoyo_path_permission(&r, TOMOYO_TYPE_READ,
&buf);
if (!error && (acc_mode & MAY_WRITE))
error = tomoyo_path_permission(&r, (flag & O_APPEND) ?
TOMOYO_TYPE_APPEND :
TOMOYO_TYPE_WRITE,
&buf);
}
out:
kfree(buf.name);
tomoyo_read_unlock(idx);
if (r.mode != TOMOYO_CONFIG_ENFORCING)
error = 0;
return error;
}
/**
* tomoyo_path_perm - Check permission for "unlink", "rmdir", "truncate", "symlink", "append", "chroot" and "unmount".
*
* @operation: Type of operation.
* @path: Pointer to "struct path".
* @target: Symlink's target if @operation is TOMOYO_TYPE_SYMLINK,
* NULL otherwise.
*
* Returns 0 on success, negative value otherwise.
*/
int tomoyo_path_perm(const u8 operation, const struct path *path, const char *target)
{
struct tomoyo_request_info r;
struct tomoyo_obj_info obj = {
.path1 = { .mnt = path->mnt, .dentry = path->dentry },
};
int error;
struct tomoyo_path_info buf;
bool is_enforce;
struct tomoyo_path_info symlink_target;
int idx;
if (tomoyo_init_request_info(&r, NULL, tomoyo_p2mac[operation])
== TOMOYO_CONFIG_DISABLED)
return 0;
is_enforce = (r.mode == TOMOYO_CONFIG_ENFORCING);
error = -ENOMEM;
buf.name = NULL;
idx = tomoyo_read_lock();
if (!tomoyo_get_realpath(&buf, path))
goto out;
r.obj = &obj;
switch (operation) {
case TOMOYO_TYPE_RMDIR:
case TOMOYO_TYPE_CHROOT:
tomoyo_add_slash(&buf);
break;
case TOMOYO_TYPE_SYMLINK:
symlink_target.name = tomoyo_encode(target);
if (!symlink_target.name)
goto out;
tomoyo_fill_path_info(&symlink_target);
obj.symlink_target = &symlink_target;
break;
}
error = tomoyo_path_permission(&r, operation, &buf);
if (operation == TOMOYO_TYPE_SYMLINK)
kfree(symlink_target.name);
out:
kfree(buf.name);
tomoyo_read_unlock(idx);
if (!is_enforce)
error = 0;
return error;
}
/**
* tomoyo_mkdev_perm - Check permission for "mkblock" and "mkchar".
*
* @operation: Type of operation. (TOMOYO_TYPE_MKCHAR or TOMOYO_TYPE_MKBLOCK)
* @path: Pointer to "struct path".
* @mode: Create mode.
* @dev: Device number.
*
* Returns 0 on success, negative value otherwise.
*/
int tomoyo_mkdev_perm(const u8 operation, const struct path *path,
const unsigned int mode, unsigned int dev)
Annotation
- Immediate include surface: `common.h`, `linux/slab.h`.
- Detected declarations: `function tomoyo_put_name_union`, `function tomoyo_compare_name_union`, `function tomoyo_put_number_union`, `function tomoyo_compare_number_union`, `function tomoyo_add_slash`, `function tomoyo_get_realpath`, `function tomoyo_audit_path_log`, `function tomoyo_audit_path2_log`, `function tomoyo_audit_mkdev_log`, `function tomoyo_audit_path_number_log`.
- Atlas domain: Core OS / Security And Isolation.
- Implementation status: source implementation candidate.
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.