security/landlock/cred.c
Source file repositories/reference/linux-study-clean/security/landlock/cred.c
File Facts
- System
- Linux kernel
- Corpus path
security/landlock/cred.c- Extension
.c- Size
- 1644 bytes
- Lines
- 70
- 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
linux/binfmts.hlinux/cred.hlinux/lsm_hooks.hcommon.hcred.hruleset.hsetup.h
Detected Declarations
function hook_cred_transferfunction hook_cred_preparefunction hook_cred_freefunction hook_bprm_creds_for_execfunction landlock_add_cred_hooks
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
/*
* Landlock - Credential hooks
*
* Copyright © 2017-2020 Mickaël Salaün <mic@digikod.net>
* Copyright © 2018-2020 ANSSI
* Copyright © 2024-2025 Microsoft Corporation
*/
#include <linux/binfmts.h>
#include <linux/cred.h>
#include <linux/lsm_hooks.h>
#include "common.h"
#include "cred.h"
#include "ruleset.h"
#include "setup.h"
static void hook_cred_transfer(struct cred *const new,
const struct cred *const old)
{
const struct landlock_cred_security *const old_llcred =
landlock_cred(old);
landlock_get_ruleset(old_llcred->domain);
*landlock_cred(new) = *old_llcred;
}
static int hook_cred_prepare(struct cred *const new,
const struct cred *const old, const gfp_t gfp)
{
hook_cred_transfer(new, old);
return 0;
}
static void hook_cred_free(struct cred *const cred)
{
struct landlock_ruleset *const dom = landlock_cred(cred)->domain;
if (dom)
landlock_put_ruleset_deferred(dom);
}
#ifdef CONFIG_AUDIT
static int hook_bprm_creds_for_exec(struct linux_binprm *const bprm)
{
/* Resets for each execution. */
landlock_cred(bprm->cred)->domain_exec = 0;
return 0;
}
#endif /* CONFIG_AUDIT */
static struct security_hook_list landlock_hooks[] __ro_after_init = {
LSM_HOOK_INIT(cred_prepare, hook_cred_prepare),
LSM_HOOK_INIT(cred_transfer, hook_cred_transfer),
LSM_HOOK_INIT(cred_free, hook_cred_free),
#ifdef CONFIG_AUDIT
LSM_HOOK_INIT(bprm_creds_for_exec, hook_bprm_creds_for_exec),
#endif /* CONFIG_AUDIT */
};
__init void landlock_add_cred_hooks(void)
{
security_add_hooks(landlock_hooks, ARRAY_SIZE(landlock_hooks),
&landlock_lsmid);
}
Annotation
- Immediate include surface: `linux/binfmts.h`, `linux/cred.h`, `linux/lsm_hooks.h`, `common.h`, `cred.h`, `ruleset.h`, `setup.h`.
- Detected declarations: `function hook_cred_transfer`, `function hook_cred_prepare`, `function hook_cred_free`, `function hook_bprm_creds_for_exec`, `function landlock_add_cred_hooks`.
- 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.