Merge tag 'rproc-v6.14' of git://git.kernel.org/pub/scm/linux/kernel/git/remoteproc...
[linux.git] / security / landlock / cred.h
blobbf755459838a557348541183864a1885cd52f89d
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3 * Landlock LSM - Credential hooks
5 * Copyright © 2019-2020 Mickaël Salaün <mic@digikod.net>
6 * Copyright © 2019-2020 ANSSI
7 */
9 #ifndef _SECURITY_LANDLOCK_CRED_H
10 #define _SECURITY_LANDLOCK_CRED_H
12 #include <linux/cred.h>
13 #include <linux/init.h>
14 #include <linux/rcupdate.h>
16 #include "ruleset.h"
17 #include "setup.h"
19 struct landlock_cred_security {
20 struct landlock_ruleset *domain;
23 static inline struct landlock_cred_security *
24 landlock_cred(const struct cred *cred)
26 return cred->security + landlock_blob_sizes.lbs_cred;
29 static inline struct landlock_ruleset *landlock_get_current_domain(void)
31 return landlock_cred(current_cred())->domain;
35 * The call needs to come from an RCU read-side critical section.
37 static inline const struct landlock_ruleset *
38 landlock_get_task_domain(const struct task_struct *const task)
40 return landlock_cred(__task_cred(task))->domain;
43 static inline bool landlocked(const struct task_struct *const task)
45 bool has_dom;
47 if (task == current)
48 return !!landlock_get_current_domain();
50 rcu_read_lock();
51 has_dom = !!landlock_get_task_domain(task);
52 rcu_read_unlock();
53 return has_dom;
56 __init void landlock_add_cred_hooks(void);
58 #endif /* _SECURITY_LANDLOCK_CRED_H */