xref: /openbmc/linux/security/apparmor/include/policy.h (revision b97d6790d03b763eca08847a9a5869a4291b9f9a)
1b886d83cSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
2c88d4c7bSJohn Johansen /*
3c88d4c7bSJohn Johansen  * AppArmor security module
4c88d4c7bSJohn Johansen  *
5c88d4c7bSJohn Johansen  * This file contains AppArmor policy definitions.
6c88d4c7bSJohn Johansen  *
7c88d4c7bSJohn Johansen  * Copyright (C) 1998-2008 Novell/SUSE
8c88d4c7bSJohn Johansen  * Copyright 2009-2010 Canonical Ltd.
9c88d4c7bSJohn Johansen  */
10c88d4c7bSJohn Johansen 
11c88d4c7bSJohn Johansen #ifndef __AA_POLICY_H
12c88d4c7bSJohn Johansen #define __AA_POLICY_H
13c88d4c7bSJohn Johansen 
14c88d4c7bSJohn Johansen #include <linux/capability.h>
15c88d4c7bSJohn Johansen #include <linux/cred.h>
16c88d4c7bSJohn Johansen #include <linux/kref.h>
17e025be0fSWilliam Hua #include <linux/rhashtable.h>
18c88d4c7bSJohn Johansen #include <linux/sched.h>
19c88d4c7bSJohn Johansen #include <linux/slab.h>
20c88d4c7bSJohn Johansen #include <linux/socket.h>
21c88d4c7bSJohn Johansen 
22c88d4c7bSJohn Johansen #include "apparmor.h"
23c88d4c7bSJohn Johansen #include "audit.h"
24c88d4c7bSJohn Johansen #include "capability.h"
25c88d4c7bSJohn Johansen #include "domain.h"
26c88d4c7bSJohn Johansen #include "file.h"
2712557dcbSJohn Johansen #include "lib.h"
28637f688dSJohn Johansen #include "label.h"
2956974a6fSJohn Johansen #include "net.h"
30fc7e0b26SJohn Johansen #include "perms.h"
31c88d4c7bSJohn Johansen #include "resource.h"
32c88d4c7bSJohn Johansen 
33cff281f6SJohn Johansen 
3498849dffSJohn Johansen struct aa_ns;
35cff281f6SJohn Johansen 
362bd8dbbfSJohn Johansen extern int unprivileged_userns_apparmor_policy;
372bd8dbbfSJohn Johansen 
380d259f04SJohn Johansen extern const char *const aa_profile_mode_names[];
390d259f04SJohn Johansen #define APPARMOR_MODE_NAMES_MAX_INDEX 4
40c88d4c7bSJohn Johansen 
4150c5ecd5SJohn Johansen #define PROFILE_MODE(_profile, _mode)		\
4250c5ecd5SJohn Johansen 	((aa_g_profile_mode == (_mode)) ||	\
4350c5ecd5SJohn Johansen 	 ((_profile)->mode == (_mode)))
44c88d4c7bSJohn Johansen 
4550c5ecd5SJohn Johansen #define COMPLAIN_MODE(_profile)	PROFILE_MODE((_profile), APPARMOR_COMPLAIN)
4650c5ecd5SJohn Johansen 
4722fac8a0SJohn Johansen #define USER_MODE(_profile)	PROFILE_MODE((_profile), APPARMOR_USER)
4822fac8a0SJohn Johansen 
4950c5ecd5SJohn Johansen #define KILL_MODE(_profile) PROFILE_MODE((_profile), APPARMOR_KILL)
50c88d4c7bSJohn Johansen 
51637f688dSJohn Johansen #define PROFILE_IS_HAT(_profile) ((_profile)->label.flags & FLAG_HAT)
52c88d4c7bSJohn Johansen 
53c1ed5da1SJohn Johansen #define CHECK_DEBUG1(_profile) ((_profile)->label.flags & FLAG_DEBUG1)
54c1ed5da1SJohn Johansen 
55c1ed5da1SJohn Johansen #define CHECK_DEBUG2(_profile) ((_profile)->label.flags & FLAG_DEBUG2)
56c1ed5da1SJohn Johansen 
57637f688dSJohn Johansen #define profile_is_stale(_profile) (label_is_stale(&(_profile)->label))
5877b071b3SJohn Johansen 
5901e2b670SJohn Johansen #define on_list_rcu(X) (!list_empty(X) && (X)->prev != LIST_POISON2)
6001e2b670SJohn Johansen 
61c88d4c7bSJohn Johansen /*
62c88d4c7bSJohn Johansen  * FIXME: currently need a clean way to replace and remove profiles as a
63c88d4c7bSJohn Johansen  * set.  It should be done at the namespace level.
64c88d4c7bSJohn Johansen  * Either, with a set of profiles loaded at the namespace level or via
65c88d4c7bSJohn Johansen  * a mark and remove marked interface.
66c88d4c7bSJohn Johansen  */
67c88d4c7bSJohn Johansen enum profile_mode {
68c88d4c7bSJohn Johansen 	APPARMOR_ENFORCE,	/* enforce access rules */
69c88d4c7bSJohn Johansen 	APPARMOR_COMPLAIN,	/* allow and log access violations */
70c88d4c7bSJohn Johansen 	APPARMOR_KILL,		/* kill task on access violation */
7103816507SJohn Johansen 	APPARMOR_UNCONFINED,	/* profile set to unconfined */
7222fac8a0SJohn Johansen 	APPARMOR_USER,		/* modified complain mode to userspace */
73c88d4c7bSJohn Johansen };
74c88d4c7bSJohn Johansen 
75c88d4c7bSJohn Johansen 
76ad5ff3dbSJohn Johansen /* struct aa_policydb - match engine for a policy
77ad5ff3dbSJohn Johansen  * dfa: dfa pattern match
7890917d5bSJohn Johansen  * perms: table of permissions
7990917d5bSJohn Johansen  * strs: table of strings, index by x
80ad5ff3dbSJohn Johansen  * start: set of start states for the different classes of data
81ad5ff3dbSJohn Johansen  */
82ad5ff3dbSJohn Johansen struct aa_policydb {
83ad5ff3dbSJohn Johansen 	struct aa_dfa *dfa;
84fd1b2b95SJohn Johansen 	struct {
85e2967edeSJohn Johansen 		struct aa_perms *perms;
86fd1b2b95SJohn Johansen 		u32 size;
87fd1b2b95SJohn Johansen 	};
8890917d5bSJohn Johansen 	struct aa_str_table trans;
8933fc95d8SJohn Johansen 	aa_state_t start[AA_CLASS_LAST + 1];
90ad5ff3dbSJohn Johansen };
91ad5ff3dbSJohn Johansen 
aa_destroy_policydb(struct aa_policydb * policy)9253bdc46fSJohn Johansen static inline void aa_destroy_policydb(struct aa_policydb *policy)
9353bdc46fSJohn Johansen {
9453bdc46fSJohn Johansen 	aa_put_dfa(policy->dfa);
9553bdc46fSJohn Johansen 	if (policy->perms)
9653bdc46fSJohn Johansen 		kvfree(policy->perms);
9790917d5bSJohn Johansen 	aa_free_str_table(&policy->trans);
9853bdc46fSJohn Johansen 
9953bdc46fSJohn Johansen }
10053bdc46fSJohn Johansen 
aa_lookup_perms(struct aa_policydb * policy,aa_state_t state)101e844fe9bSJohn Johansen static inline struct aa_perms *aa_lookup_perms(struct aa_policydb *policy,
10233fc95d8SJohn Johansen 					       aa_state_t state)
103e844fe9bSJohn Johansen {
104e844fe9bSJohn Johansen 	unsigned int index = ACCEPT_TABLE(policy->dfa)[state];
105e844fe9bSJohn Johansen 
106e844fe9bSJohn Johansen 	if (!(policy->perms))
107e844fe9bSJohn Johansen 		return &default_perms;
108e844fe9bSJohn Johansen 
109e844fe9bSJohn Johansen 	return &(policy->perms[index]);
110e844fe9bSJohn Johansen }
111e844fe9bSJohn Johansen 
112e844fe9bSJohn Johansen 
113e025be0fSWilliam Hua /* struct aa_data - generic data structure
114e025be0fSWilliam Hua  * key: name for retrieving this data
115e025be0fSWilliam Hua  * size: size of data in bytes
116e025be0fSWilliam Hua  * data: binary data
117e025be0fSWilliam Hua  * head: reserved for rhashtable
118e025be0fSWilliam Hua  */
119e025be0fSWilliam Hua struct aa_data {
120e025be0fSWilliam Hua 	char *key;
121e025be0fSWilliam Hua 	u32 size;
122e025be0fSWilliam Hua 	char *data;
123e025be0fSWilliam Hua 	struct rhash_head head;
124e025be0fSWilliam Hua };
125e025be0fSWilliam Hua 
126217af7e2SJohn Johansen /* struct aa_ruleset - data covering mediation rules
1271ad22fccSJohn Johansen  * @list: list the rule is on
128217af7e2SJohn Johansen  * @size: the memory consumed by this ruleset
129217af7e2SJohn Johansen  * @policy: general match rules governing policy
130217af7e2SJohn Johansen  * @file: The set of rules governing basic file access and domain transitions
131217af7e2SJohn Johansen  * @caps: capabilities for the profile
132217af7e2SJohn Johansen  * @rlimits: rlimits for the profile
133217af7e2SJohn Johansen  * @secmark_count: number of secmark entries
134217af7e2SJohn Johansen  * @secmark: secmark label match info
135217af7e2SJohn Johansen  */
136217af7e2SJohn Johansen struct aa_ruleset {
1371ad22fccSJohn Johansen 	struct list_head list;
1381ad22fccSJohn Johansen 
139217af7e2SJohn Johansen 	int size;
140217af7e2SJohn Johansen 
141217af7e2SJohn Johansen 	/* TODO: merge policy and file */
142217af7e2SJohn Johansen 	struct aa_policydb policy;
143217af7e2SJohn Johansen 	struct aa_policydb file;
144217af7e2SJohn Johansen 	struct aa_caps caps;
145217af7e2SJohn Johansen 
146217af7e2SJohn Johansen 	struct aa_rlimit rlimits;
147217af7e2SJohn Johansen 
148217af7e2SJohn Johansen 	int secmark_count;
149217af7e2SJohn Johansen 	struct aa_secmark *secmark;
150217af7e2SJohn Johansen };
151217af7e2SJohn Johansen 
152217af7e2SJohn Johansen /* struct aa_attachment - data and rules for a profiles attachment
1531ad22fccSJohn Johansen  * @list:
154217af7e2SJohn Johansen  * @xmatch_str: human readable attachment string
155217af7e2SJohn Johansen  * @xmatch: optional extended matching for unconfined executables names
156217af7e2SJohn Johansen  * @xmatch_len: xmatch prefix len, used to determine xmatch priority
157217af7e2SJohn Johansen  * @xattr_count: number of xattrs in table
158217af7e2SJohn Johansen  * @xattrs: table of xattrs
159217af7e2SJohn Johansen  */
160217af7e2SJohn Johansen struct aa_attachment {
161217af7e2SJohn Johansen 	const char *xmatch_str;
162217af7e2SJohn Johansen 	struct aa_policydb xmatch;
163217af7e2SJohn Johansen 	unsigned int xmatch_len;
164217af7e2SJohn Johansen 	int xattr_count;
165217af7e2SJohn Johansen 	char **xattrs;
166217af7e2SJohn Johansen };
16777b071b3SJohn Johansen 
168c88d4c7bSJohn Johansen /* struct aa_profile - basic confinement data
169c88d4c7bSJohn Johansen  * @base - base components of the profile (name, refcount, lists, lock ...)
170637f688dSJohn Johansen  * @label - label this profile is an extension of
171c88d4c7bSJohn Johansen  * @parent: parent of profile
172c88d4c7bSJohn Johansen  * @ns: namespace the profile is in
173c88d4c7bSJohn Johansen  * @rename: optional profile name that this profile renamed
174217af7e2SJohn Johansen  *
175c88d4c7bSJohn Johansen  * @audit: the auditing mode of the profile
176c88d4c7bSJohn Johansen  * @mode: the enforcement mode of the profile
177c88d4c7bSJohn Johansen  * @path_flags: flags controlling path generation behavior
17872c8a768SJohn Johansen  * @disconnected: what to prepend if attach_disconnected is specified
179217af7e2SJohn Johansen  * @attach: attachment rules for the profile
180217af7e2SJohn Johansen  * @rules: rules to be enforced
181c88d4c7bSJohn Johansen  *
1820d259f04SJohn Johansen  * @dents: dentries for the profiles file entries in apparmorfs
1830d259f04SJohn Johansen  * @dirname: name of the profile dir in apparmorfs
184e025be0fSWilliam Hua  * @data: hashtable for free-form policy aa_data
1850d259f04SJohn Johansen  *
186c88d4c7bSJohn Johansen  * The AppArmor profile contains the basic confinement data.  Each profile
187c88d4c7bSJohn Johansen  * has a name, and exists in a namespace.  The @name and @exec_match are
188c88d4c7bSJohn Johansen  * used to determine profile attachment against unconfined tasks.  All other
189c88d4c7bSJohn Johansen  * attachments are determined by profile X transition rules.
190c88d4c7bSJohn Johansen  *
191c88d4c7bSJohn Johansen  * Profiles have a hierarchy where hats and children profiles keep
192c88d4c7bSJohn Johansen  * a reference to their parent.
193c88d4c7bSJohn Johansen  *
194c88d4c7bSJohn Johansen  * Profile names can not begin with a : and can not contain the \0
195c88d4c7bSJohn Johansen  * character.  If a profile name begins with / it will be considered when
196c88d4c7bSJohn Johansen  * determining profile attachment on "unconfined" tasks.
197c88d4c7bSJohn Johansen  */
198c88d4c7bSJohn Johansen struct aa_profile {
199c88d4c7bSJohn Johansen 	struct aa_policy base;
20001e2b670SJohn Johansen 	struct aa_profile __rcu *parent;
201c88d4c7bSJohn Johansen 
20298849dffSJohn Johansen 	struct aa_ns *ns;
203c88d4c7bSJohn Johansen 	const char *rename;
204c88d4c7bSJohn Johansen 
205c88d4c7bSJohn Johansen 	enum audit_mode audit;
20603816507SJohn Johansen 	long mode;
207c88d4c7bSJohn Johansen 	u32 path_flags;
20872c8a768SJohn Johansen 	const char *disconnected;
209c88d4c7bSJohn Johansen 
210217af7e2SJohn Johansen 	struct aa_attachment attach;
2111ad22fccSJohn Johansen 	struct list_head rules;
2129caafbe2SMatthew Garrett 
2135ac8c355SJohn Johansen 	struct aa_loaddata *rawdata;
214f8eb8a13SJohn Johansen 	unsigned char *hash;
2150d259f04SJohn Johansen 	char *dirname;
2160d259f04SJohn Johansen 	struct dentry *dents[AAFS_PROF_SIZEOF];
217e025be0fSWilliam Hua 	struct rhashtable *data;
218637f688dSJohn Johansen 	struct aa_label label;
219c88d4c7bSJohn Johansen };
220c88d4c7bSJohn Johansen 
221c88d4c7bSJohn Johansen extern enum profile_mode aa_g_profile_mode;
222c88d4c7bSJohn Johansen 
22318e99f19SJohn Johansen #define AA_MAY_LOAD_POLICY	AA_MAY_APPEND
22418e99f19SJohn Johansen #define AA_MAY_REPLACE_POLICY	AA_MAY_WRITE
22518e99f19SJohn Johansen #define AA_MAY_REMOVE_POLICY	AA_MAY_DELETE
22618e99f19SJohn Johansen 
227637f688dSJohn Johansen #define profiles_ns(P) ((P)->ns)
228637f688dSJohn Johansen #define name_is_shared(A, B) ((A)->hname && (A)->hname == (B)->hname)
229cff281f6SJohn Johansen 
230c88d4c7bSJohn Johansen void aa_add_profile(struct aa_policy *common, struct aa_profile *profile);
231c88d4c7bSJohn Johansen 
232c88d4c7bSJohn Johansen 
2338399588aSJohn Johansen void aa_free_proxy_kref(struct kref *kref);
2341ad22fccSJohn Johansen struct aa_ruleset *aa_alloc_ruleset(gfp_t gfp);
235637f688dSJohn Johansen struct aa_profile *aa_alloc_profile(const char *name, struct aa_proxy *proxy,
236637f688dSJohn Johansen 				    gfp_t gfp);
23758f89ce5SJohn Johansen struct aa_profile *aa_alloc_null(struct aa_profile *parent, const char *name,
23858f89ce5SJohn Johansen 				 gfp_t gfp);
23958f89ce5SJohn Johansen struct aa_profile *aa_new_learning_profile(struct aa_profile *parent, bool hat,
240181f7c97SJohn Johansen 					   const char *base, gfp_t gfp);
2418651e1d6SJohn Johansen void aa_free_profile(struct aa_profile *profile);
242c88d4c7bSJohn Johansen void aa_free_profile_kref(struct kref *kref);
243c88d4c7bSJohn Johansen struct aa_profile *aa_find_child(struct aa_profile *parent, const char *name);
2441741e9ebSJohn Johansen struct aa_profile *aa_lookupn_profile(struct aa_ns *ns, const char *hname,
2451741e9ebSJohn Johansen 				      size_t n);
24698849dffSJohn Johansen struct aa_profile *aa_lookup_profile(struct aa_ns *ns, const char *name);
247637f688dSJohn Johansen struct aa_profile *aa_fqlookupn_profile(struct aa_label *base,
24831617ddfSJohn Johansen 					const char *fqname, size_t n);
24998849dffSJohn Johansen struct aa_profile *aa_match_profile(struct aa_ns *ns, const char *name);
250c88d4c7bSJohn Johansen 
251637f688dSJohn Johansen ssize_t aa_replace_profiles(struct aa_ns *view, struct aa_label *label,
25218e99f19SJohn Johansen 			    u32 mask, struct aa_loaddata *udata);
253637f688dSJohn Johansen ssize_t aa_remove_profiles(struct aa_ns *view, struct aa_label *label,
25412dd7171SJohn Johansen 			   char *name, size_t size);
255cff281f6SJohn Johansen void __aa_profile_list_release(struct list_head *head);
256c88d4c7bSJohn Johansen 
257c88d4c7bSJohn Johansen #define PROF_ADD 1
258c88d4c7bSJohn Johansen #define PROF_REPLACE 0
259c88d4c7bSJohn Johansen 
260637f688dSJohn Johansen #define profile_unconfined(X) ((X)->mode == APPARMOR_UNCONFINED)
261637f688dSJohn Johansen 
262637f688dSJohn Johansen /**
263637f688dSJohn Johansen  * aa_get_newest_profile - simple wrapper fn to wrap the label version
264637f688dSJohn Johansen  * @p: profile (NOT NULL)
265637f688dSJohn Johansen  *
266637f688dSJohn Johansen  * Returns refcount to newest version of the profile (maybe @p)
267637f688dSJohn Johansen  *
268637f688dSJohn Johansen  * Requires: @p must be held with a valid refcount
269637f688dSJohn Johansen  */
aa_get_newest_profile(struct aa_profile * p)270637f688dSJohn Johansen static inline struct aa_profile *aa_get_newest_profile(struct aa_profile *p)
271637f688dSJohn Johansen {
272637f688dSJohn Johansen 	return labels_profile(aa_get_newest_label(&p->label));
273637f688dSJohn Johansen }
274c88d4c7bSJohn Johansen 
RULE_MEDIATES(struct aa_ruleset * rules,unsigned char class)275217af7e2SJohn Johansen static inline aa_state_t RULE_MEDIATES(struct aa_ruleset *rules,
27623375b13SJohn Johansen 				       unsigned char class)
27723375b13SJohn Johansen {
27823375b13SJohn Johansen 	if (class <= AA_CLASS_LAST)
279217af7e2SJohn Johansen 		return rules->policy.start[class];
28023375b13SJohn Johansen 	else
281217af7e2SJohn Johansen 		return aa_dfa_match_len(rules->policy.dfa,
282217af7e2SJohn Johansen 					rules->policy.start[0], &class, 1);
28323375b13SJohn Johansen }
28423375b13SJohn Johansen 
RULE_MEDIATES_AF(struct aa_ruleset * rules,u16 AF)285217af7e2SJohn Johansen static inline aa_state_t RULE_MEDIATES_AF(struct aa_ruleset *rules, u16 AF)
286217af7e2SJohn Johansen {
287217af7e2SJohn Johansen 	aa_state_t state = RULE_MEDIATES(rules, AA_CLASS_NET);
28856974a6fSJohn Johansen 	__be16 be_af = cpu_to_be16(AF);
28956974a6fSJohn Johansen 
29056974a6fSJohn Johansen 	if (!state)
29133fc95d8SJohn Johansen 		return DFA_NOMATCH;
292217af7e2SJohn Johansen 	return aa_dfa_match_len(rules->policy.dfa, state, (char *) &be_af, 2);
29356974a6fSJohn Johansen }
29456974a6fSJohn Johansen 
ANY_RULE_MEDIATES(struct list_head * head,unsigned char class)2951ad22fccSJohn Johansen static inline aa_state_t ANY_RULE_MEDIATES(struct list_head *head,
2961ad22fccSJohn Johansen 					   unsigned char class)
2971ad22fccSJohn Johansen {
2981ad22fccSJohn Johansen 	struct aa_ruleset *rule;
2991ad22fccSJohn Johansen 
3001ad22fccSJohn Johansen 	/* TODO: change to list walk */
3011ad22fccSJohn Johansen 	rule = list_first_entry(head, typeof(*rule), list);
3021ad22fccSJohn Johansen 	return RULE_MEDIATES(rule, class);
3031ad22fccSJohn Johansen }
3041ad22fccSJohn Johansen 
305c88d4c7bSJohn Johansen /**
306c88d4c7bSJohn Johansen  * aa_get_profile - increment refcount on profile @p
307c88d4c7bSJohn Johansen  * @p: profile  (MAYBE NULL)
308c88d4c7bSJohn Johansen  *
309c88d4c7bSJohn Johansen  * Returns: pointer to @p if @p is NULL will return NULL
310c88d4c7bSJohn Johansen  * Requires: @p must be held with valid refcount when called
311c88d4c7bSJohn Johansen  */
aa_get_profile(struct aa_profile * p)312c88d4c7bSJohn Johansen static inline struct aa_profile *aa_get_profile(struct aa_profile *p)
313c88d4c7bSJohn Johansen {
314c88d4c7bSJohn Johansen 	if (p)
315637f688dSJohn Johansen 		kref_get(&(p->label.count));
316c88d4c7bSJohn Johansen 
317c88d4c7bSJohn Johansen 	return p;
318c88d4c7bSJohn Johansen }
319c88d4c7bSJohn Johansen 
320c88d4c7bSJohn Johansen /**
32101e2b670SJohn Johansen  * aa_get_profile_not0 - increment refcount on profile @p found via lookup
32201e2b670SJohn Johansen  * @p: profile  (MAYBE NULL)
32301e2b670SJohn Johansen  *
32401e2b670SJohn Johansen  * Returns: pointer to @p if @p is NULL will return NULL
32501e2b670SJohn Johansen  * Requires: @p must be held with valid refcount when called
32601e2b670SJohn Johansen  */
aa_get_profile_not0(struct aa_profile * p)32701e2b670SJohn Johansen static inline struct aa_profile *aa_get_profile_not0(struct aa_profile *p)
32801e2b670SJohn Johansen {
329637f688dSJohn Johansen 	if (p && kref_get_unless_zero(&p->label.count))
33001e2b670SJohn Johansen 		return p;
33101e2b670SJohn Johansen 
33201e2b670SJohn Johansen 	return NULL;
33301e2b670SJohn Johansen }
33401e2b670SJohn Johansen 
33501e2b670SJohn Johansen /**
33601e2b670SJohn Johansen  * aa_get_profile_rcu - increment a refcount profile that can be replaced
33701e2b670SJohn Johansen  * @p: pointer to profile that can be replaced (NOT NULL)
33801e2b670SJohn Johansen  *
33901e2b670SJohn Johansen  * Returns: pointer to a refcounted profile.
34001e2b670SJohn Johansen  *     else NULL if no profile
34101e2b670SJohn Johansen  */
aa_get_profile_rcu(struct aa_profile __rcu ** p)34201e2b670SJohn Johansen static inline struct aa_profile *aa_get_profile_rcu(struct aa_profile __rcu **p)
34301e2b670SJohn Johansen {
34401e2b670SJohn Johansen 	struct aa_profile *c;
34501e2b670SJohn Johansen 
34601e2b670SJohn Johansen 	rcu_read_lock();
34701e2b670SJohn Johansen 	do {
34801e2b670SJohn Johansen 		c = rcu_dereference(*p);
349637f688dSJohn Johansen 	} while (c && !kref_get_unless_zero(&c->label.count));
35001e2b670SJohn Johansen 	rcu_read_unlock();
35101e2b670SJohn Johansen 
35201e2b670SJohn Johansen 	return c;
35301e2b670SJohn Johansen }
35401e2b670SJohn Johansen 
35501e2b670SJohn Johansen /**
356c88d4c7bSJohn Johansen  * aa_put_profile - decrement refcount on profile @p
357c88d4c7bSJohn Johansen  * @p: profile  (MAYBE NULL)
358c88d4c7bSJohn Johansen  */
aa_put_profile(struct aa_profile * p)359c88d4c7bSJohn Johansen static inline void aa_put_profile(struct aa_profile *p)
360c88d4c7bSJohn Johansen {
361742058b0SJohn Johansen 	if (p)
362637f688dSJohn Johansen 		kref_put(&p->label.count, aa_label_kref);
363fa2ac468SJohn Johansen }
364fa2ac468SJohn Johansen 
AUDIT_MODE(struct aa_profile * profile)365c88d4c7bSJohn Johansen static inline int AUDIT_MODE(struct aa_profile *profile)
366c88d4c7bSJohn Johansen {
367c88d4c7bSJohn Johansen 	if (aa_g_audit != AUDIT_NORMAL)
368c88d4c7bSJohn Johansen 		return aa_g_audit;
369c88d4c7bSJohn Johansen 
370c88d4c7bSJohn Johansen 	return profile->audit;
371c88d4c7bSJohn Johansen }
372c88d4c7bSJohn Johansen 
373*690f33e1SJohn Johansen bool aa_policy_view_capable(const struct cred *subj_cred,
374*690f33e1SJohn Johansen 			    struct aa_label *label, struct aa_ns *ns);
375*690f33e1SJohn Johansen bool aa_policy_admin_capable(const struct cred *subj_cred,
376*690f33e1SJohn Johansen 			     struct aa_label *label, struct aa_ns *ns);
377*690f33e1SJohn Johansen int aa_may_manage_policy(const struct cred *subj_cred,
378*690f33e1SJohn Johansen 			 struct aa_label *label, struct aa_ns *ns,
37918e99f19SJohn Johansen 			 u32 mask);
38092de220aSJohn Johansen bool aa_current_policy_view_capable(struct aa_ns *ns);
38192de220aSJohn Johansen bool aa_current_policy_admin_capable(struct aa_ns *ns);
382c88d4c7bSJohn Johansen 
383c88d4c7bSJohn Johansen #endif /* __AA_POLICY_H */
384