security/landlock/syscalls.c
Source file repositories/reference/linux-study-clean/security/landlock/syscalls.c
File Facts
- System
- Linux kernel
- Corpus path
security/landlock/syscalls.c- Extension
.c- Size
- 20300 bytes
- Lines
- 632
- Domain
- Core OS
- Bucket
- Security And Isolation
- Inferred role
- Core OS: syscall or user/kernel boundary
- Status
- core 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 participates in a user/kernel boundary; inspect argument validation, copy_from_user/copy_to_user, credentials, and dispatch target.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
asm/current.hlinux/anon_inodes.hlinux/bitops.hlinux/build_bug.hlinux/capability.hlinux/cleanup.hlinux/compiler_types.hlinux/dcache.hlinux/err.hlinux/errno.hlinux/fs.hlinux/limits.hlinux/mount.hlinux/path.hlinux/sched.hlinux/security.hlinux/stddef.hlinux/syscalls.hlinux/types.hlinux/uaccess.huapi/linux/landlock.hcred.hdomain.hfs.hlimits.hnet.hruleset.hsetup.htsync.h
Detected Declarations
syscall landlock_create_rulesetsyscall landlock_add_rulesyscall landlock_restrict_selffunction is_initializedfunction copy_struct_from_userfunction BUILD_BUG_ONfunction fop_ruleset_releasefunction fop_dummy_readfunction fop_dummy_writefunction landlock_put_rulesetfunction get_path_from_fdfunction add_rule_path_beneathfunction add_rule_net_portfunction set
Annotated Snippet
SYSCALL_DEFINE3(landlock_create_ruleset,
const struct landlock_ruleset_attr __user *const, attr,
const size_t, size, const __u32, flags)
{
struct landlock_ruleset_attr ruleset_attr;
struct landlock_ruleset *ruleset;
int err, ruleset_fd;
/* Build-time checks. */
build_check_abi();
if (!is_initialized())
return -EOPNOTSUPP;
if (flags) {
if (attr || size)
return -EINVAL;
if (flags == LANDLOCK_CREATE_RULESET_VERSION)
return landlock_abi_version;
if (flags == LANDLOCK_CREATE_RULESET_ERRATA)
return landlock_errata;
return -EINVAL;
}
/* Copies raw user space buffer. */
err = copy_min_struct_from_user(&ruleset_attr, sizeof(ruleset_attr),
offsetofend(typeof(ruleset_attr),
handled_access_fs),
attr, size);
if (err)
return err;
/* Checks content (and 32-bits cast). */
if ((ruleset_attr.handled_access_fs | LANDLOCK_MASK_ACCESS_FS) !=
LANDLOCK_MASK_ACCESS_FS)
return -EINVAL;
/* Checks network content (and 32-bits cast). */
if ((ruleset_attr.handled_access_net | LANDLOCK_MASK_ACCESS_NET) !=
LANDLOCK_MASK_ACCESS_NET)
return -EINVAL;
/* Checks IPC scoping content (and 32-bits cast). */
if ((ruleset_attr.scoped | LANDLOCK_MASK_SCOPE) != LANDLOCK_MASK_SCOPE)
return -EINVAL;
/*
* Check that quiet masks are subsets of the respective handled masks.
* Because of the checks above this is sufficient to also ensure that
* the quiet masks are valid access masks.
*/
if ((ruleset_attr.quiet_access_fs | ruleset_attr.handled_access_fs) !=
ruleset_attr.handled_access_fs)
return -EINVAL;
if ((ruleset_attr.quiet_access_net | ruleset_attr.handled_access_net) !=
ruleset_attr.handled_access_net)
return -EINVAL;
if ((ruleset_attr.quiet_scoped | ruleset_attr.scoped) !=
ruleset_attr.scoped)
return -EINVAL;
/* Checks arguments and transforms to kernel struct. */
ruleset = landlock_create_ruleset(ruleset_attr.handled_access_fs,
ruleset_attr.handled_access_net,
ruleset_attr.scoped);
if (IS_ERR(ruleset))
return PTR_ERR(ruleset);
ruleset->quiet_masks.fs = ruleset_attr.quiet_access_fs;
ruleset->quiet_masks.net = ruleset_attr.quiet_access_net;
ruleset->quiet_masks.scope = ruleset_attr.quiet_scoped;
/* Creates anonymous FD referring to the ruleset. */
ruleset_fd = anon_inode_getfd("[landlock-ruleset]", &ruleset_fops,
ruleset, O_RDWR | O_CLOEXEC);
if (ruleset_fd < 0)
landlock_put_ruleset(ruleset);
return ruleset_fd;
}
/*
* Returns an owned ruleset from a FD. It is thus needed to call
* landlock_put_ruleset() on the return value.
*/
static struct landlock_ruleset *get_ruleset_from_fd(const int fd,
const fmode_t mode)
{
Annotation
- Immediate include surface: `asm/current.h`, `linux/anon_inodes.h`, `linux/bitops.h`, `linux/build_bug.h`, `linux/capability.h`, `linux/cleanup.h`, `linux/compiler_types.h`, `linux/dcache.h`.
- Detected declarations: `syscall landlock_create_ruleset`, `syscall landlock_add_rule`, `syscall landlock_restrict_self`, `function is_initialized`, `function copy_struct_from_user`, `function BUILD_BUG_ON`, `function fop_ruleset_release`, `function fop_dummy_read`, `function fop_dummy_write`, `function landlock_put_ruleset`.
- Atlas domain: Core OS / Security And Isolation.
- Implementation status: core implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
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.