security/landlock/cred.h

Source file repositories/reference/linux-study-clean/security/landlock/cred.h

File Facts

System
Linux kernel
Corpus path
security/landlock/cred.h
Extension
.h
Size
4094 bytes
Lines
159
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.

Dependency Surface

Detected Declarations

Annotated Snippet

struct landlock_cred_security {
	/**
	 * @domain: Immutable ruleset enforced on a task.
	 */
	struct landlock_ruleset *domain;

#ifdef CONFIG_AUDIT
	/**
	 * @domain_exec: Bitmask identifying the domain layers that were enforced by
	 * the current task's executed file (i.e. no new execve(2) since
	 * landlock_restrict_self(2)).
	 */
	u16 domain_exec;
	/**
	 * @log_subdomains_off: Set if the domain descendants's log_status should be
	 * set to %LANDLOCK_LOG_DISABLED.  This is not a landlock_hierarchy
	 * configuration because it applies to future descendant domains and it does
	 * not require a current domain.
	 */
	u8 log_subdomains_off : 1;
#endif /* CONFIG_AUDIT */
} __packed;

#ifdef CONFIG_AUDIT

/* Makes sure all layer executions can be stored. */
static_assert(BITS_PER_TYPE(typeof_member(struct landlock_cred_security,
					  domain_exec)) >=
	      LANDLOCK_MAX_NUM_LAYERS);

#endif /* CONFIG_AUDIT */

static inline struct landlock_cred_security *
landlock_cred(const struct cred *cred)
{
	return cred->security + landlock_blob_sizes.lbs_cred;
}

static inline void landlock_cred_copy(struct landlock_cred_security *dst,
				      const struct landlock_cred_security *src)
{
	landlock_put_ruleset(dst->domain);

	*dst = *src;

	landlock_get_ruleset(src->domain);
}

static inline struct landlock_ruleset *landlock_get_current_domain(void)
{
	return landlock_cred(current_cred())->domain;
}

/*
 * The call needs to come from an RCU read-side critical section.
 */
static inline const struct landlock_ruleset *
landlock_get_task_domain(const struct task_struct *const task)
{
	return landlock_cred(__task_cred(task))->domain;
}

static inline bool landlocked(const struct task_struct *const task)
{
	bool has_dom;

	if (task == current)
		return !!landlock_get_current_domain();

	rcu_read_lock();
	has_dom = !!landlock_get_task_domain(task);
	rcu_read_unlock();
	return has_dom;
}

/**
 * landlock_get_applicable_subject - Return the subject's Landlock credential
 *                                   if its enforced domain applies to (i.e.
 *                                   handles) at least one of the access rights
 *                                   specified in @masks
 *
 * @cred: credential
 * @masks: access masks
 * @handle_layer: returned youngest layer handling a subset of @masks.  Not set
 *                if the function returns NULL.
 *
 * Return: landlock_cred(@cred) if any access rights specified in @masks is
 * handled, or NULL otherwise.
 */
static inline const struct landlock_cred_security *

Annotation

Implementation Notes