~ubuntu-branches/ubuntu/raring/apparmor/raring

« back to all changes in this revision

Viewing changes to module-deprecated/apparmor.h

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook
  • Date: 2007-03-23 16:42:01 UTC
  • Revision ID: james.westby@ubuntu.com-20070323164201-jkax6f0oku087b7l
Tags: upstream-2.0.1+510.dfsg
ImportĀ upstreamĀ versionĀ 2.0.1+510.dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *      Copyright (C) 1998-2005 Novell/SUSE
 
3
 *
 
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
 
7
 *      License.
 
8
 *
 
9
 *      AppArmor internal prototypes
 
10
 */
 
11
 
 
12
#ifndef __SUBDOMAIN_H
 
13
#define __SUBDOMAIN_H
 
14
 
 
15
/* defn of iattr */
 
16
#include <linux/fs.h>
 
17
 
 
18
/* defn of linux_binprm */
 
19
#include <linux/binfmts.h>
 
20
 
 
21
#include "shared.h"
 
22
 
 
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;
 
29
 
 
30
#define SD_UNCONSTRAINED "unconstrained"
 
31
 
 
32
/* $ echo -n subdomain.o | md5sum | cut -c -8 */
 
33
#define  SD_ID_MAGIC            0x8c235e38
 
34
 
 
35
#define PROFILE_COMPLAIN(_profile) \
 
36
        (subdomain_complain == 1 || ((_profile) && (_profile)->flags.complain))
 
37
 
 
38
#define SUBDOMAIN_COMPLAIN(_sd) \
 
39
        (subdomain_complain == 1 || \
 
40
         ((_sd) && (_sd)->active && (_sd)->active->flags.complain))
 
41
 
 
42
#define SUBDOMAIN_AUDIT(_sd) \
 
43
        (subdomain_audit == 1 || \
 
44
         ((_sd) && (_sd)->active && (_sd)->active->flags.audit))
 
45
 
 
46
/*
 
47
 * DEBUG remains global (no per profile flag) since it is mostly used in sysctl
 
48
 * which is not related to profile accesses.
 
49
 */
 
50
 
 
51
#define SD_DEBUG(fmt, args...)                                          \
 
52
        do {                                                            \
 
53
                if (subdomain_debug)                                    \
 
54
                        printk(KERN_DEBUG "AppArmor: " fmt, ##args);    \
 
55
        } while (0)
 
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)
 
59
 
 
60
/* apparmor logged syscall reject caching */
 
61
enum aasyscall {
 
62
        AA_SYSCALL_PTRACE,
 
63
        AA_SYSCALL_SYSCTL_WRITE,
 
64
        AA_SYSCALL_MOUNT,
 
65
        AA_SYSCALL_UMOUNT
 
66
};
 
67
 
 
68
#define AA_SYSCALL_TO_MASK(X) (1 << (X))
 
69
 
 
70
/* basic AppArmor data structures */
 
71
 
 
72
struct flagval {
 
73
        int debug;
 
74
        int complain;
 
75
        int audit;
 
76
};
 
77
 
 
78
enum entry_t {
 
79
        sd_entry_literal,
 
80
        sd_entry_tailglob,
 
81
        sd_entry_pattern,
 
82
        sd_entry_invalid
 
83
};
 
84
 
 
85
/**
 
86
 * sd_entry - file ACL *
 
87
 * Each entry describes a file and an allowed access mode.
 
88
 */
 
89
struct sd_entry {
 
90
        char *filename;
 
91
        int mode;               /* mode is 'or' of READ, WRITE, EXECUTE,
 
92
                                 * INHERIT, UNCONSTRAINED, and LIBRARY
 
93
                                 * (meaning don't prefetch). */
 
94
 
 
95
        enum entry_t entry_type;
 
96
        void *extradata;
 
97
 
 
98
        struct list_head list;
 
99
        struct list_head listp[POS_SD_FILE_MAX + 1];
 
100
};
 
101
 
 
102
#define SD_SECURE_EXEC_NEEDED 0x00000001
 
103
 
 
104
#define SD_EXEC_MODIFIER_MASK(mask) ((mask) & SD_EXEC_MODIFIERS)
 
105
 
 
106
#define SD_EXEC_MASK(mask) ((mask) & (SD_MAY_EXEC | SD_EXEC_MODIFIERS))
 
107
 
 
108
#define SD_EXEC_UNSAFE_MASK(mask) ((mask) & (SD_MAY_EXEC |\
 
109
                                             SD_EXEC_MODIFIERS |\
 
110
                                             SD_EXEC_UNSAFE))
 
111
 
 
112
/**
 
113
 * sdprofile - basic confinement data
 
114
 *
 
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
 
118
 */
 
119
struct sdprofile {
 
120
        char *name;                     /* profile name */
 
121
 
 
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 */
 
127
 
 
128
        int isstale;                    /* is profile stale */
 
129
 
 
130
        int num_file_entries;
 
131
        int num_file_pentries[POS_SD_FILE_MAX + 1];
 
132
 
 
133
        kernel_cap_t capabilities;
 
134
 
 
135
        atomic_t count;                 /* reference count */
 
136
};
 
137
 
 
138
enum sdfile_type {
 
139
        sd_file_default,
 
140
        sd_file_shmem
 
141
};
 
142
 
 
143
/**
 
144
 * sdfile - file pointer confinement data
 
145
 *
 
146
 * Data structure assigned to each open file (by subdomain_file_alloc_security)
 
147
 */
 
148
struct sdfile {
 
149
        enum sdfile_type type;
 
150
        struct sdprofile *profile;
 
151
};
 
152
 
 
153
/**
 
154
 * subdomain - a task's subdomain
 
155
 *
 
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.
 
159
 */
 
160
struct subdomain {
 
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;
 
167
 
 
168
        kernel_cap_t cached_caps;
 
169
        unsigned int cached_syscalls;
 
170
};
 
171
 
 
172
typedef int (*sd_iter) (struct subdomain *, void *);
 
173
 
 
174
/* sd_path_data
 
175
 * temp (cookie) data used by sd_path_* functions, see inline.h
 
176
 */
 
177
struct sd_path_data {
 
178
        struct dentry *root, *dentry;
 
179
        struct namespace *namespace;
 
180
        struct list_head *head, *pos;
 
181
        int errno;
 
182
};
 
183
 
 
184
#define SD_SUBDOMAIN(sec)       ((struct subdomain*)(sec))
 
185
#define SD_PROFILE(sec)         ((struct sdprofile*)(sec))
 
186
 
 
187
/* Lock protecting access to 'struct subdomain' accesses */
 
188
extern rwlock_t sd_lock;
 
189
 
 
190
extern struct sdprofile *null_profile;
 
191
extern struct sdprofile *null_complain_profile;
 
192
 
 
193
/** sd_audit
 
194
 *
 
195
 * Auditing structure
 
196
 */
 
197
 
 
198
struct sd_audit {
 
199
        unsigned short type, flags;
 
200
        unsigned int result;
 
201
        unsigned int gfp_mask;
 
202
        int errorcode;
 
203
 
 
204
        const char *name;
 
205
        unsigned int ival;
 
206
        union{
 
207
                const void *pval;
 
208
                va_list vaval;
 
209
        };
 
210
};
 
211
 
 
212
/* audit types */
 
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
 
222
 
 
223
/* audit flags */
 
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  */
 
227
 
 
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"
 
232
 
 
233
#define LOG_HINT(sd, gfp, hint, fmt, args...) \
 
234
        do {\
 
235
                sd_audit_message(sd, gfp, 0, \
 
236
                        "LOGPROF-HINT " hint " " fmt, ##args);\
 
237
        } while(0)
 
238
 
 
239
/* diroptype */
 
240
#define SD_DIR_MKDIR 0
 
241
#define SD_DIR_RMDIR 1
 
242
 
 
243
/* xattroptype */
 
244
#define SD_XATTR_GET    0
 
245
#define SD_XATTR_SET    1
 
246
#define SD_XATTR_LIST   2
 
247
#define SD_XATTR_REMOVE 3
 
248
 
 
249
/* main.c */
 
250
extern int alloc_nullprofiles(void);
 
251
extern void free_nullprofiles(void);
 
252
extern int sd_audit_message(struct subdomain *, unsigned int gfp, int,
 
253
                            const char *, ...);
 
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);
 
258
 
 
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,
 
267
                             int mask);
 
268
extern int sd_perm_dentry(struct subdomain *sd, struct dentry *dentry,
 
269
                          int mask);
 
270
extern int sd_perm_dir(struct subdomain *sd, struct dentry *dentry,
 
271
                       int diroptype);
 
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);
 
279
 
 
280
/* list.c */
 
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);
 
293
 
 
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);
 
297
 
 
298
/* procattr.c */
 
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,
 
302
                                     size_t profilesize);
 
303
 
 
304
/* apparmorfs.c */
 
305
extern int create_subdomainfs(void);
 
306
extern int destroy_subdomainfs(void);
 
307
 
 
308
/* capabilities.c */
 
309
extern const char *capability_to_name(unsigned int cap);
 
310
extern const char *syscall_to_name(enum aasyscall call);
 
311
 
 
312
/* apparmor_version.c */
 
313
extern const char *apparmor_version(void);
 
314
extern const char *apparmor_version_nl(void);
 
315
 
 
316
#endif                          /* __SUBDOMAIN_H */