Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags   |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /* SPDX-License-Identifier: GPL-2.0-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * AppArmor security module
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * This file contains AppArmor label definitions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Copyright 2017 Canonical Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #ifndef __AA_LABEL_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #define __AA_LABEL_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/atomic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/audit.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/rbtree.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/rcupdate.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include "apparmor.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include "lib.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) struct aa_ns;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #define LOCAL_VEC_ENTRIES 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #define DEFINE_VEC(T, V)						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	struct aa_ ## T *(_ ## V ## _localtmp)[LOCAL_VEC_ENTRIES];	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	struct aa_ ## T **(V)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #define vec_setup(T, V, N, GFP)						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) ({									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	if ((N) <= LOCAL_VEC_ENTRIES) {					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 		typeof(N) i;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 		(V) = (_ ## V ## _localtmp);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 		for (i = 0; i < (N); i++)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 			(V)[i] = NULL;					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	} else								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 		(V) = kzalloc(sizeof(struct aa_ ## T *) * (N), (GFP));	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	(V) ? 0 : -ENOMEM;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #define vec_cleanup(T, V, N)						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) do {									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	int i;								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	for (i = 0; i < (N); i++) {					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 		if (!IS_ERR_OR_NULL((V)[i]))				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 			aa_put_ ## T((V)[i]);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	}								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	if ((V) != _ ## V ## _localtmp)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		kfree(V);						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) #define vec_last(VEC, SIZE) ((VEC)[(SIZE) - 1])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) #define vec_ns(VEC, SIZE) (vec_last((VEC), (SIZE))->ns)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) #define vec_labelset(VEC, SIZE) (&vec_ns((VEC), (SIZE))->labels)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) #define cleanup_domain_vec(V, L) cleanup_label_vec((V), (L)->size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) struct aa_profile;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) #define VEC_FLAG_TERMINATE 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) int aa_vec_unique(struct aa_profile **vec, int n, int flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) struct aa_label *aa_vec_find_or_create_label(struct aa_profile **vec, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 					     gfp_t gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) #define aa_sort_and_merge_vec(N, V) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	aa_sort_and_merge_profiles((N), (struct aa_profile **)(V))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) /* struct aa_labelset - set of labels for a namespace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67)  * Labels are reference counted; aa_labelset does not contribute to label
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68)  * reference counts. Once a label's last refcount is put it is removed from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69)  * the set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) struct aa_labelset {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	rwlock_t lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	struct rb_root root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) #define __labelset_for_each(LS, N) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	for ((N) = rb_first(&(LS)->root); (N); (N) = rb_next(N))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) void aa_labelset_destroy(struct aa_labelset *ls);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) void aa_labelset_init(struct aa_labelset *ls);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) enum label_flags {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	FLAG_HAT = 1,			/* profile is a hat */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	FLAG_UNCONFINED = 2,		/* label unconfined only if all */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	FLAG_NULL = 4,			/* profile is null learning profile */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	FLAG_IX_ON_NAME_ERROR = 8,	/* fallback to ix on name lookup fail */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	FLAG_IMMUTIBLE = 0x10,		/* don't allow changes/replacement */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	FLAG_USER_DEFINED = 0x20,	/* user based profile - lower privs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	FLAG_NO_LIST_REF = 0x40,	/* list doesn't keep profile ref */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	FLAG_NS_COUNT = 0x80,		/* carries NS ref count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	FLAG_IN_TREE = 0x100,		/* label is in tree */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	FLAG_PROFILE = 0x200,		/* label is a profile */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	FLAG_EXPLICIT = 0x400,		/* explicit static label */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	FLAG_STALE = 0x800,		/* replaced/removed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	FLAG_RENAMED = 0x1000,		/* label has renaming in it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	FLAG_REVOKED = 0x2000,		/* label has revocation in it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	/* These flags must correspond with PATH_flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	/* TODO: add new path flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) struct aa_label;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) struct aa_proxy {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	struct kref count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	struct aa_label __rcu *label;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) struct label_it {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	int i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) /* struct aa_label - lazy labeling struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)  * @count: ref count of active users
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)  * @node: rbtree position
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)  * @rcu: rcu callback struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)  * @proxy: is set to the label that replaced this label
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)  * @hname: text representation of the label (MAYBE_NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)  * @flags: stale and other flags - values may change under label set lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)  * @secid: secid that references this label
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)  * @size: number of entries in @ent[]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)  * @ent: set of profiles for label, actual size determined by @size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) struct aa_label {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	struct kref count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	struct rb_node node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	struct rcu_head rcu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	struct aa_proxy *proxy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	__counted char *hname;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	u32 secid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	int size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	struct aa_profile *vec[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) #define last_error(E, FN)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) do {							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	int __subE = (FN);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	if (__subE)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		(E) = __subE;				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) #define label_isprofile(X) ((X)->flags & FLAG_PROFILE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) #define label_unconfined(X) ((X)->flags & FLAG_UNCONFINED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) #define unconfined(X) label_unconfined(X)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) #define label_is_stale(X) ((X)->flags & FLAG_STALE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) #define __label_make_stale(X) ((X)->flags |= FLAG_STALE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) #define labels_ns(X) (vec_ns(&((X)->vec[0]), (X)->size))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) #define labels_set(X) (&labels_ns(X)->labels)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) #define labels_profile(X) ((X)->vec[(X)->size - 1])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) int aa_label_next_confined(struct aa_label *l, int i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) /* for each profile in a label */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) #define label_for_each(I, L, P)						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	for ((I).i = 0; ((P) = (L)->vec[(I).i]); ++((I).i))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) /* assumes break/goto ended label_for_each */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) #define label_for_each_cont(I, L, P)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	for (++((I).i); ((P) = (L)->vec[(I).i]); ++((I).i))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) #define next_comb(I, L1, L2)						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) do {									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	(I).j++;							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	if ((I).j >= (L2)->size) {					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		(I).i++;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		(I).j = 0;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	}								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) /* for each combination of P1 in L1, and P2 in L2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) #define label_for_each_comb(I, L1, L2, P1, P2)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) for ((I).i = (I).j = 0;							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	((P1) = (L1)->vec[(I).i]) && ((P2) = (L2)->vec[(I).j]);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	(I) = next_comb(I, L1, L2))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) #define fn_for_each_comb(L1, L2, P1, P2, FN)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) ({									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	struct label_it i;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	int __E = 0;							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	label_for_each_comb(i, (L1), (L2), (P1), (P2)) {		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		last_error(__E, (FN));					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	}								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	__E;								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) /* for each profile that is enforcing confinement in a label */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) #define label_for_each_confined(I, L, P)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	for ((I).i = aa_label_next_confined((L), 0);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	     ((P) = (L)->vec[(I).i]);					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	     (I).i = aa_label_next_confined((L), (I).i + 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) #define label_for_each_in_merge(I, A, B, P)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	for ((I).i = (I).j = 0;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	     ((P) = aa_label_next_in_merge(&(I), (A), (B)));		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	     )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) #define label_for_each_not_in_set(I, SET, SUB, P)			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	for ((I).i = (I).j = 0;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	     ((P) = __aa_label_next_not_in_set(&(I), (SET), (SUB)));	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	     )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) #define next_in_ns(i, NS, L)						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) ({									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	typeof(i) ___i = (i);						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	while ((L)->vec[___i] && (L)->vec[___i]->ns != (NS))		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		(___i)++;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	(___i);								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) #define label_for_each_in_ns(I, NS, L, P)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	for ((I).i = next_in_ns(0, (NS), (L));				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	     ((P) = (L)->vec[(I).i]);					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	     (I).i = next_in_ns((I).i + 1, (NS), (L)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) #define fn_for_each_in_ns(L, P, FN)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) ({									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	struct label_it __i;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	struct aa_ns *__ns = labels_ns(L);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	int __E = 0;							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	label_for_each_in_ns(__i, __ns, (L), (P)) {			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		last_error(__E, (FN));					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	}								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	__E;								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) #define fn_for_each_XXX(L, P, FN, ...)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) ({									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	struct label_it i;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	int __E = 0;							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	label_for_each ## __VA_ARGS__(i, (L), (P)) {			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		last_error(__E, (FN));					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	}								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	__E;								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) #define fn_for_each(L, P, FN) fn_for_each_XXX(L, P, FN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) #define fn_for_each_confined(L, P, FN) fn_for_each_XXX(L, P, FN, _confined)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) #define fn_for_each2_XXX(L1, L2, P, FN, ...)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) ({									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	struct label_it i;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	int __E = 0;							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	label_for_each ## __VA_ARGS__(i, (L1), (L2), (P)) {		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		last_error(__E, (FN));					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	}								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	__E;								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) #define fn_for_each_in_merge(L1, L2, P, FN)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	fn_for_each2_XXX((L1), (L2), P, FN, _in_merge)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) #define fn_for_each_not_in_set(L1, L2, P, FN)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	fn_for_each2_XXX((L1), (L2), P, FN, _not_in_set)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) #define LABEL_MEDIATES(L, C)						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) ({									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	struct aa_profile *profile;					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	struct label_it i;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	int ret = 0;							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	label_for_each(i, (L), profile) {				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		if (PROFILE_MEDIATES(profile, (C))) {			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 			ret = 1;					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 			break;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		}							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	}								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	ret;								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) void aa_labelset_destroy(struct aa_labelset *ls);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) void aa_labelset_init(struct aa_labelset *ls);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) void __aa_labelset_update_subtree(struct aa_ns *ns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) void aa_label_destroy(struct aa_label *label);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) void aa_label_free(struct aa_label *label);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) void aa_label_kref(struct kref *kref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) bool aa_label_init(struct aa_label *label, int size, gfp_t gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) struct aa_label *aa_label_alloc(int size, struct aa_proxy *proxy, gfp_t gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) bool aa_label_is_subset(struct aa_label *set, struct aa_label *sub);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) bool aa_label_is_unconfined_subset(struct aa_label *set, struct aa_label *sub);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) struct aa_profile *__aa_label_next_not_in_set(struct label_it *I,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 					     struct aa_label *set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 					     struct aa_label *sub);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) bool aa_label_remove(struct aa_label *label);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) struct aa_label *aa_label_insert(struct aa_labelset *ls, struct aa_label *l);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) bool aa_label_replace(struct aa_label *old, struct aa_label *new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) bool aa_label_make_newest(struct aa_labelset *ls, struct aa_label *old,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 			  struct aa_label *new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) struct aa_label *aa_label_find(struct aa_label *l);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) struct aa_profile *aa_label_next_in_merge(struct label_it *I,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 					  struct aa_label *a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 					  struct aa_label *b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) struct aa_label *aa_label_find_merge(struct aa_label *a, struct aa_label *b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) struct aa_label *aa_label_merge(struct aa_label *a, struct aa_label *b,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 				gfp_t gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) bool aa_update_label_name(struct aa_ns *ns, struct aa_label *label, gfp_t gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) #define FLAGS_NONE 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) #define FLAG_SHOW_MODE 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) #define FLAG_VIEW_SUBNS 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) #define FLAG_HIDDEN_UNCONFINED 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) #define FLAG_ABS_ROOT 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) int aa_label_snxprint(char *str, size_t size, struct aa_ns *view,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		      struct aa_label *label, int flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) int aa_label_asxprint(char **strp, struct aa_ns *ns, struct aa_label *label,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 		      int flags, gfp_t gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) int aa_label_acntsxprint(char __counted **strp, struct aa_ns *ns,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 			 struct aa_label *label, int flags, gfp_t gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) void aa_label_xaudit(struct audit_buffer *ab, struct aa_ns *ns,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 		     struct aa_label *label, int flags, gfp_t gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) void aa_label_seq_xprint(struct seq_file *f, struct aa_ns *ns,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 			 struct aa_label *label, int flags, gfp_t gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) void aa_label_xprintk(struct aa_ns *ns, struct aa_label *label, int flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		      gfp_t gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) void aa_label_audit(struct audit_buffer *ab, struct aa_label *label, gfp_t gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) void aa_label_seq_print(struct seq_file *f, struct aa_label *label, gfp_t gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) void aa_label_printk(struct aa_label *label, gfp_t gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) struct aa_label *aa_label_strn_parse(struct aa_label *base, const char *str,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 				     size_t n, gfp_t gfp, bool create,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 				     bool force_stack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) struct aa_label *aa_label_parse(struct aa_label *base, const char *str,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 				gfp_t gfp, bool create, bool force_stack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) static inline const char *aa_label_strn_split(const char *str, int n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	const char *pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	unsigned int state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	state = aa_dfa_matchn_until(stacksplitdfa, DFA_START, str, n, &pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	if (!ACCEPT_TABLE(stacksplitdfa)[state])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	return pos - 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) static inline const char *aa_label_str_split(const char *str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	const char *pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	unsigned int state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	state = aa_dfa_match_until(stacksplitdfa, DFA_START, str, &pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	if (!ACCEPT_TABLE(stacksplitdfa)[state])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	return pos - 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) struct aa_perms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) int aa_label_match(struct aa_profile *profile, struct aa_label *label,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 		   unsigned int state, bool subns, u32 request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 		   struct aa_perms *perms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367)  * __aa_get_label - get a reference count to uncounted label reference
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)  * @l: reference to get a count on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)  * Returns: pointer to reference OR NULL if race is lost and reference is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)  *          being repeated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)  * Requires: lock held, and the return code MUST be checked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) static inline struct aa_label *__aa_get_label(struct aa_label *l)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	if (l && kref_get_unless_zero(&l->count))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 		return l;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) static inline struct aa_label *aa_get_label(struct aa_label *l)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	if (l)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 		kref_get(&(l->count));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	return l;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)  * aa_get_label_rcu - increment refcount on a label that can be replaced
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)  * @l: pointer to label that can be replaced (NOT NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)  * Returns: pointer to a refcounted label.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)  *     else NULL if no label
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) static inline struct aa_label *aa_get_label_rcu(struct aa_label __rcu **l)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	struct aa_label *c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 		c = rcu_dereference(*l);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	} while (c && !kref_get_unless_zero(&c->count));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	return c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412)  * aa_get_newest_label - find the newest version of @l
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)  * @l: the label to check for newer versions of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415)  * Returns: refcounted newest version of @l taking into account
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)  *          replacement, renames and removals
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)  *          return @l.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) static inline struct aa_label *aa_get_newest_label(struct aa_label *l)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	if (!l)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	if (label_is_stale(l)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 		struct aa_label *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 		AA_BUG(!l->proxy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 		AA_BUG(!l->proxy->label);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 		/* BUG: only way this can happen is @l ref count and its
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 		 * replacement count have gone to 0 and are on their way
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 		 * to destruction. ie. we have a refcounting error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 		tmp = aa_get_label_rcu(&l->proxy->label);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 		AA_BUG(!tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 		return tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	return aa_get_label(l);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) static inline void aa_put_label(struct aa_label *l)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	if (l)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 		kref_put(&l->count, aa_label_kref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) struct aa_proxy *aa_alloc_proxy(struct aa_label *l, gfp_t gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) void aa_proxy_kref(struct kref *kref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) static inline struct aa_proxy *aa_get_proxy(struct aa_proxy *proxy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	if (proxy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 		kref_get(&(proxy->count));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	return proxy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) static inline void aa_put_proxy(struct aa_proxy *proxy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	if (proxy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 		kref_put(&proxy->count, aa_proxy_kref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) void __aa_proxy_redirect(struct aa_label *orig, struct aa_label *new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) #endif /* __AA_LABEL_H */