1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * AppArmor security module
5 * This file contains AppArmor policy loading interface function definitions.
7 * Copyright (C) 1998-2008 Novell/SUSE
8 * Copyright 2009-2010 Canonical Ltd.
11 #ifndef __POLICY_INTERFACE_H
12 #define __POLICY_INTERFACE_H
14 #include <linux/list.h>
15 #include <linux/kref.h>
16 #include <linux/dcache.h>
17 #include <linux/workqueue.h>
21 struct list_head list
;
22 struct aa_profile
*new;
23 struct aa_profile
*old
;
24 struct aa_profile
*rename
;
28 void aa_load_ent_free(struct aa_load_ent
*ent
);
29 struct aa_load_ent
*aa_load_ent_alloc(void);
31 #define PACKED_FLAG_HAT 1
32 #define PACKED_FLAG_DEBUG1 2
33 #define PACKED_FLAG_DEBUG2 4
35 #define PACKED_MODE_ENFORCE 0
36 #define PACKED_MODE_COMPLAIN 1
37 #define PACKED_MODE_KILL 2
38 #define PACKED_MODE_UNCONFINED 3
39 #define PACKED_MODE_USER 4
44 AAFS_LOADDATA_ABI
= 0,
45 AAFS_LOADDATA_REVISION
,
48 AAFS_LOADDATA_COMPRESSED_SIZE
,
49 AAFS_LOADDATA_DIR
, /* must be last actual entry */
50 AAFS_LOADDATA_NDENTS
/* count of entries */
54 * The AppArmor interface treats data as a type byte followed by the
55 * actual data. The interface has the notion of a named entry
56 * which has a name (AA_NAME typecode followed by name string) followed by
57 * the entries typecode and data. Named types allow for optional
58 * elements and extensions to be added and tested for without breaking
59 * backwards compatibility.
67 AA_NAME
, /* same as string except it is items name */
79 * aa_ext is the read of the buffer containing the serialized profile. The
80 * data is copied into a kernel buffer in apparmorfs and then handed off to
81 * the unpack routines.
86 void *pos
; /* pointer to current position in the buffer */
91 * struct aa_loaddata - buffer of policy raw_data set
93 * there is no loaddata ref for being on ns list, nor a ref from
94 * d_inode(@dentry) when grab a ref from these, @ns->lock must be held
95 * && __aa_get_loaddata() needs to be used, and the return value
96 * checked, if NULL the loaddata is already being reaped and should be
101 struct list_head list
;
102 struct work_struct work
;
103 struct dentry
*dents
[AAFS_LOADDATA_NDENTS
];
106 size_t size
; /* the original size of the payload */
107 size_t compressed_size
; /* the compressed size of the payload */
108 long revision
; /* the ns policy revision this caused */
112 /* Pointer to payload. If @compressed_size > 0, then this is the
113 * compressed version of the payload, else it is the uncompressed
114 * version (with the size indicated by @size).
119 int aa_unpack(struct aa_loaddata
*udata
, struct list_head
*lh
, const char **ns
);
122 * __aa_get_loaddata - get a reference count to uncounted data reference
123 * @data: reference to get a count on
125 * Returns: pointer to reference OR NULL if race is lost and reference is
127 * Requires: @data->ns->lock held, and the return code MUST be checked
129 * Use only from inode->i_private and @data->list found references
131 static inline struct aa_loaddata
*
132 __aa_get_loaddata(struct aa_loaddata
*data
)
134 if (data
&& kref_get_unless_zero(&(data
->count
)))
141 * aa_get_loaddata - get a reference count from a counted data reference
142 * @data: reference to get a count on
144 * Returns: point to reference
145 * Requires: @data to have a valid reference count on it. It is a bug
146 * if the race to reap can be encountered when it is used.
148 static inline struct aa_loaddata
*
149 aa_get_loaddata(struct aa_loaddata
*data
)
151 struct aa_loaddata
*tmp
= __aa_get_loaddata(data
);
153 AA_BUG(data
&& !tmp
);
158 void __aa_loaddata_update(struct aa_loaddata
*data
, long revision
);
159 bool aa_rawdata_eq(struct aa_loaddata
*l
, struct aa_loaddata
*r
);
160 void aa_loaddata_kref(struct kref
*kref
);
161 struct aa_loaddata
*aa_loaddata_alloc(size_t size
);
162 static inline void aa_put_loaddata(struct aa_loaddata
*data
)
165 kref_put(&data
->count
, aa_loaddata_kref
);
168 #if IS_ENABLED(CONFIG_KUNIT)
169 bool aa_inbounds(struct aa_ext
*e
, size_t size
);
170 size_t aa_unpack_u16_chunk(struct aa_ext
*e
, char **chunk
);
171 bool aa_unpack_X(struct aa_ext
*e
, enum aa_code code
);
172 bool aa_unpack_nameX(struct aa_ext
*e
, enum aa_code code
, const char *name
);
173 bool aa_unpack_u32(struct aa_ext
*e
, u32
*data
, const char *name
);
174 bool aa_unpack_u64(struct aa_ext
*e
, u64
*data
, const char *name
);
175 bool aa_unpack_array(struct aa_ext
*e
, const char *name
, u16
*size
);
176 size_t aa_unpack_blob(struct aa_ext
*e
, char **blob
, const char *name
);
177 int aa_unpack_str(struct aa_ext
*e
, const char **string
, const char *name
);
178 int aa_unpack_strdup(struct aa_ext
*e
, char **string
, const char *name
);
181 #endif /* __POLICY_INTERFACE_H */