2
* Copyright (C) 1998-2005 Novell/SUSE
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License as
6
* published by the Free Software Foundation, version 2 of the
9
* AppArmor internal prototypes
18
/* defn of linux_binprm */
19
#include <linux/binfmts.h>
23
/* Control parameters (0 or 1), settable thru module/boot flags or
24
* via /sys/kernel/security/subdomain/control */
25
extern int subdomain_complain;
26
extern int subdomain_debug;
27
extern int subdomain_audit;
28
extern int subdomain_logsyscall;
30
#define SD_UNCONSTRAINED "unconstrained"
32
/* $ echo -n subdomain.o | md5sum | cut -c -8 */
33
#define SD_ID_MAGIC 0x8c235e38
35
#define PROFILE_COMPLAIN(_profile) \
36
(subdomain_complain == 1 || ((_profile) && (_profile)->flags.complain))
38
#define SUBDOMAIN_COMPLAIN(_sd) \
39
(subdomain_complain == 1 || \
40
((_sd) && (_sd)->active && (_sd)->active->flags.complain))
42
#define SUBDOMAIN_AUDIT(_sd) \
43
(subdomain_audit == 1 || \
44
((_sd) && (_sd)->active && (_sd)->active->flags.audit))
47
* DEBUG remains global (no per profile flag) since it is mostly used in sysctl
48
* which is not related to profile accesses.
51
#define SD_DEBUG(fmt, args...) \
53
if (subdomain_debug) \
54
printk(KERN_DEBUG "AppArmor: " fmt, ##args); \
56
#define SD_INFO(fmt, args...) printk(KERN_INFO "AppArmor: " fmt, ##args)
57
#define SD_WARN(fmt, args...) printk(KERN_WARNING "AppArmor: " fmt, ##args)
58
#define SD_ERROR(fmt, args...) printk(KERN_ERR "AppArmor: " fmt, ##args)
60
/* apparmor logged syscall reject caching */
63
AA_SYSCALL_SYSCTL_WRITE,
68
#define AA_SYSCALL_TO_MASK(X) (1 << (X))
70
/* basic AppArmor data structures */
86
* sd_entry - file ACL *
87
* Each entry describes a file and an allowed access mode.
91
int mode; /* mode is 'or' of READ, WRITE, EXECUTE,
92
* INHERIT, UNCONSTRAINED, and LIBRARY
93
* (meaning don't prefetch). */
95
enum entry_t entry_type;
98
struct list_head list;
99
struct list_head listp[POS_SD_FILE_MAX + 1];
102
#define SD_SECURE_EXEC_NEEDED 0x00000001
104
#define SD_EXEC_MODIFIER_MASK(mask) ((mask) & SD_EXEC_MODIFIERS)
106
#define SD_EXEC_MASK(mask) ((mask) & (SD_MAY_EXEC | SD_EXEC_MODIFIERS))
108
#define SD_EXEC_UNSAFE_MASK(mask) ((mask) & (SD_MAY_EXEC |\
113
* sdprofile - basic confinement data
115
* The AppArmor profile contains the basic confinement data. Each profile
116
* has a name and potentially a list of subdomain entries. The profiles are
117
* connected in a list
120
char *name; /* profile name */
122
struct list_head file_entry; /* file ACL */
123
struct list_head file_entryp[POS_SD_FILE_MAX + 1];
124
struct list_head list; /* list of profiles */
125
struct list_head sub; /* sub profiles, for change_hat */
126
struct flagval flags; /* per profile debug flags */
128
int isstale; /* is profile stale */
130
int num_file_entries;
131
int num_file_pentries[POS_SD_FILE_MAX + 1];
133
kernel_cap_t capabilities;
135
atomic_t count; /* reference count */
144
* sdfile - file pointer confinement data
146
* Data structure assigned to each open file (by subdomain_file_alloc_security)
149
enum sdfile_type type;
150
struct sdprofile *profile;
154
* subdomain - a task's subdomain
156
* Contains the original profile obtained from execve() as well as the
157
* current active profile (which could change due to change_hat). Plus
158
* the hat_magic needed during change_hat.
161
__u32 sd_magic; /* magic value to distinguish blobs */
162
struct sdprofile *profile; /* The profile obtained from execve() */
163
struct sdprofile *active; /* The current active profile */
164
__u32 sd_hat_magic; /* used with change_hat */
165
struct list_head list; /* list of subdomains */
166
struct task_struct *task;
168
kernel_cap_t cached_caps;
169
unsigned int cached_syscalls;
172
typedef int (*sd_iter) (struct subdomain *, void *);
175
* temp (cookie) data used by sd_path_* functions, see inline.h
177
struct sd_path_data {
178
struct dentry *root, *dentry;
179
struct namespace *namespace;
180
struct list_head *head, *pos;
184
#define SD_SUBDOMAIN(sec) ((struct subdomain*)(sec))
185
#define SD_PROFILE(sec) ((struct sdprofile*)(sec))
187
/* Lock protecting access to 'struct subdomain' accesses */
188
extern rwlock_t sd_lock;
190
extern struct sdprofile *null_profile;
191
extern struct sdprofile *null_complain_profile;
199
unsigned short type, flags;
201
unsigned int gfp_mask;
213
#define SD_AUDITTYPE_FILE 1
214
#define SD_AUDITTYPE_DIR 2
215
#define SD_AUDITTYPE_ATTR 3
216
#define SD_AUDITTYPE_XATTR 4
217
#define SD_AUDITTYPE_LINK 5
218
#define SD_AUDITTYPE_CAP 6
219
#define SD_AUDITTYPE_MSG 7
220
#define SD_AUDITTYPE_SYSCALL 8
221
#define SD_AUDITTYPE__END 9
224
#define SD_AUDITFLAG_AUDITSS_SYSCALL 1 /* log syscall context */
225
#define SD_AUDITFLAG_LOGERR 2 /* log operations that failed due to
226
non permission errors */
228
#define HINT_UNKNOWN_HAT "unknown_hat"
229
#define HINT_FORK "fork"
230
#define HINT_MANDPROF "missing_mandatory_profile"
231
#define HINT_CHGPROF "changing_profile"
233
#define LOG_HINT(sd, gfp, hint, fmt, args...) \
235
sd_audit_message(sd, gfp, 0, \
236
"LOGPROF-HINT " hint " " fmt, ##args);\
240
#define SD_DIR_MKDIR 0
241
#define SD_DIR_RMDIR 1
244
#define SD_XATTR_GET 0
245
#define SD_XATTR_SET 1
246
#define SD_XATTR_LIST 2
247
#define SD_XATTR_REMOVE 3
250
extern int alloc_nullprofiles(void);
251
extern void free_nullprofiles(void);
252
extern int sd_audit_message(struct subdomain *, unsigned int gfp, int,
254
extern int sd_audit_syscallreject(struct subdomain *, unsigned int gfp,
255
enum aasyscall call);
256
extern int sd_audit(struct subdomain *, const struct sd_audit *);
257
extern char *sd_get_name(struct dentry *dentry, struct vfsmount *mnt);
259
extern int sd_attr(struct subdomain *sd, struct dentry *dentry,
260
struct iattr *iattr);
261
extern int sd_xattr(struct subdomain *sd, struct dentry *dentry,
262
const char *xattr, int xattroptype);
263
extern int sd_capability(struct subdomain *sd, int cap);
264
extern int sd_perm(struct subdomain *sd, struct dentry *dentry,
265
struct vfsmount *mnt, int mask);
266
extern int sd_perm_nameidata(struct subdomain *sd, struct nameidata *nd,
268
extern int sd_perm_dentry(struct subdomain *sd, struct dentry *dentry,
270
extern int sd_perm_dir(struct subdomain *sd, struct dentry *dentry,
272
extern int sd_link(struct subdomain *sd,
273
struct dentry *link, struct dentry *target);
274
extern int sd_fork(struct task_struct *p);
275
extern int sd_register(struct linux_binprm *bprm);
276
extern void sd_release(struct task_struct *p);
277
extern int sd_change_hat(const char *id, __u32 hat_magic);
278
extern int sd_associate_filp(struct file *filp);
281
extern struct sdprofile *sd_profilelist_find(const char *name);
282
extern int sd_profilelist_add(struct sdprofile *profile);
283
extern struct sdprofile *sd_profilelist_remove(const char *name);
284
extern void sd_profilelist_release(void);
285
extern struct sdprofile *sd_profilelist_replace(struct sdprofile *profile);
286
extern void sd_profile_dump(struct sdprofile *);
287
extern void sd_profilelist_dump(void);
288
extern void sd_subdomainlist_add(struct subdomain *);
289
extern void sd_subdomainlist_remove(struct subdomain *);
290
extern void sd_subdomainlist_iterate(sd_iter, void *);
291
extern void sd_subdomainlist_iterateremove(sd_iter, void *);
292
extern void sd_subdomainlist_release(void);
294
/* subdomain_interface.c */
295
extern void free_sdprofile(struct sdprofile *profile);
296
extern int sd_sys_security(unsigned int id, unsigned call, unsigned long *args);
299
extern size_t sd_getprocattr(struct subdomain *sd, char *str, size_t size);
300
extern int sd_setprocattr_changehat(char *hatinfo, size_t infosize);
301
extern int sd_setprocattr_setprofile(struct task_struct *p, char *profilename,
305
extern int create_subdomainfs(void);
306
extern int destroy_subdomainfs(void);
309
extern const char *capability_to_name(unsigned int cap);
310
extern const char *syscall_to_name(enum aasyscall call);
312
/* apparmor_version.c */
313
extern const char *apparmor_version(void);
314
extern const char *apparmor_version_nl(void);
316
#endif /* __SUBDOMAIN_H */