diff options
Diffstat (limited to 'security/apparmor/include')
| -rw-r--r-- | security/apparmor/include/apparmor.h | 92 | ||||
| -rw-r--r-- | security/apparmor/include/apparmorfs.h | 20 | ||||
| -rw-r--r-- | security/apparmor/include/audit.h | 123 | ||||
| -rw-r--r-- | security/apparmor/include/capability.h | 45 | ||||
| -rw-r--r-- | security/apparmor/include/context.h | 154 | ||||
| -rw-r--r-- | security/apparmor/include/domain.h | 36 | ||||
| -rw-r--r-- | security/apparmor/include/file.h | 217 | ||||
| -rw-r--r-- | security/apparmor/include/ipc.h | 28 | ||||
| -rw-r--r-- | security/apparmor/include/match.h | 132 | ||||
| -rw-r--r-- | security/apparmor/include/path.h | 31 | ||||
| -rw-r--r-- | security/apparmor/include/policy.h | 305 | ||||
| -rw-r--r-- | security/apparmor/include/policy_unpack.h | 20 | ||||
| -rw-r--r-- | security/apparmor/include/procattr.h | 26 | ||||
| -rw-r--r-- | security/apparmor/include/resource.h | 46 | ||||
| -rw-r--r-- | security/apparmor/include/sid.h | 24 |
15 files changed, 1299 insertions, 0 deletions
diff --git a/security/apparmor/include/apparmor.h b/security/apparmor/include/apparmor.h new file mode 100644 index 00000000000..38ccaea0820 --- /dev/null +++ b/security/apparmor/include/apparmor.h | |||
| @@ -0,0 +1,92 @@ | |||
| 1 | /* | ||
| 2 | * AppArmor security module | ||
| 3 | * | ||
| 4 | * This file contains AppArmor basic global and lib definitions | ||
| 5 | * | ||
| 6 | * Copyright (C) 1998-2008 Novell/SUSE | ||
| 7 | * Copyright 2009-2010 Canonical Ltd. | ||
| 8 | * | ||
| 9 | * This program is free software; you can redistribute it and/or | ||
| 10 | * modify it under the terms of the GNU General Public License as | ||
| 11 | * published by the Free Software Foundation, version 2 of the | ||
| 12 | * License. | ||
| 13 | */ | ||
| 14 | |||
| 15 | #ifndef __APPARMOR_H | ||
| 16 | #define __APPARMOR_H | ||
| 17 | |||
| 18 | #include <linux/fs.h> | ||
| 19 | |||
| 20 | #include "match.h" | ||
| 21 | |||
| 22 | /* Control parameters settable through module/boot flags */ | ||
| 23 | extern enum audit_mode aa_g_audit; | ||
| 24 | extern int aa_g_audit_header; | ||
| 25 | extern int aa_g_debug; | ||
| 26 | extern int aa_g_lock_policy; | ||
| 27 | extern int aa_g_logsyscall; | ||
| 28 | extern int aa_g_paranoid_load; | ||
| 29 | extern unsigned int aa_g_path_max; | ||
| 30 | |||
| 31 | /* | ||
| 32 | * DEBUG remains global (no per profile flag) since it is mostly used in sysctl | ||
| 33 | * which is not related to profile accesses. | ||
| 34 | */ | ||
| 35 | |||
| 36 | #define AA_DEBUG(fmt, args...) \ | ||
| 37 | do { \ | ||
| 38 | if (aa_g_debug && printk_ratelimit()) \ | ||
| 39 | printk(KERN_DEBUG "AppArmor: " fmt, ##args); \ | ||
| 40 | } while (0) | ||
| 41 | |||
| 42 | #define AA_ERROR(fmt, args...) \ | ||
| 43 | do { \ | ||
| 44 | if (printk_ratelimit()) \ | ||
| 45 | printk(KERN_ERR "AppArmor: " fmt, ##args); \ | ||
| 46 | } while (0) | ||
| 47 | |||
| 48 | /* Flag indicating whether initialization completed */ | ||
| 49 | extern int apparmor_initialized __initdata; | ||
| 50 | |||
| 51 | /* fn's in lib */ | ||
| 52 | char *aa_split_fqname(char *args, char **ns_name); | ||
| 53 | void aa_info_message(const char *str); | ||
| 54 | void *kvmalloc(size_t size); | ||
| 55 | void kvfree(void *buffer); | ||
| 56 | |||
| 57 | |||
| 58 | /** | ||
| 59 | * aa_strneq - compare null terminated @str to a non null terminated substring | ||
| 60 | * @str: a null terminated string | ||
| 61 | * @sub: a substring, not necessarily null terminated | ||
| 62 | * @len: length of @sub to compare | ||
| 63 | * | ||
| 64 | * The @str string must be full consumed for this to be considered a match | ||
| 65 | */ | ||
| 66 | static inline bool aa_strneq(const char *str, const char *sub, int len) | ||
| 67 | { | ||
| 68 | return !strncmp(str, sub, len) && !str[len]; | ||
| 69 | } | ||
| 70 | |||
| 71 | /** | ||
| 72 | * aa_dfa_null_transition - step to next state after null character | ||
| 73 | * @dfa: the dfa to match against | ||
| 74 | * @start: the state of the dfa to start matching in | ||
| 75 | * | ||
| 76 | * aa_dfa_null_transition transitions to the next state after a null | ||
| 77 | * character which is not used in standard matching and is only | ||
| 78 | * used to separate pairs. | ||
| 79 | */ | ||
| 80 | static inline unsigned int aa_dfa_null_transition(struct aa_dfa *dfa, | ||
| 81 | unsigned int start) | ||
| 82 | { | ||
| 83 | /* the null transition only needs the string's null terminator byte */ | ||
| 84 | return aa_dfa_match_len(dfa, start, "", 1); | ||
| 85 | } | ||
| 86 | |||
| 87 | static inline bool mediated_filesystem(struct inode *inode) | ||
| 88 | { | ||
| 89 | return !(inode->i_sb->s_flags & MS_NOUSER); | ||
| 90 | } | ||
| 91 | |||
| 92 | #endif /* __APPARMOR_H */ | ||
diff --git a/security/apparmor/include/apparmorfs.h b/security/apparmor/include/apparmorfs.h new file mode 100644 index 00000000000..cb1e93a114d --- /dev/null +++ b/security/apparmor/include/apparmorfs.h | |||
| @@ -0,0 +1,20 @@ | |||
| 1 | /* | ||
| 2 | * AppArmor security module | ||
| 3 | * | ||
| 4 | * This file contains AppArmor filesystem definitions. | ||
| 5 | * | ||
| 6 | * Copyright (C) 1998-2008 Novell/SUSE | ||
| 7 | * Copyright 2009-2010 Canonical Ltd. | ||
| 8 | * | ||
| 9 | * This program is free software; you can redistribute it and/or | ||
| 10 | * modify it under the terms of the GNU General Public License as | ||
| 11 | * published by the Free Software Foundation, version 2 of the | ||
| 12 | * License. | ||
| 13 | */ | ||
| 14 | |||
| 15 | #ifndef __AA_APPARMORFS_H | ||
| 16 | #define __AA_APPARMORFS_H | ||
| 17 | |||
| 18 | extern void __init aa_destroy_aafs(void); | ||
| 19 | |||
| 20 | #endif /* __AA_APPARMORFS_H */ | ||
diff --git a/security/apparmor/include/audit.h b/security/apparmor/include/audit.h new file mode 100644 index 00000000000..1951786d32e --- /dev/null +++ b/security/apparmor/include/audit.h | |||
| @@ -0,0 +1,123 @@ | |||
| 1 | /* | ||
| 2 | * AppArmor security module | ||
| 3 | * | ||
| 4 | * This file contains AppArmor auditing function definitions. | ||
| 5 | * | ||
| 6 | * Copyright (C) 1998-2008 Novell/SUSE | ||
| 7 | * Copyright 2009-2010 Canonical Ltd. | ||
| 8 | * | ||
| 9 | * This program is free software; you can redistribute it and/or | ||
| 10 | * modify it under the terms of the GNU General Public License as | ||
| 11 | * published by the Free Software Foundation, version 2 of the | ||
| 12 | * License. | ||
| 13 | */ | ||
| 14 | |||
| 15 | #ifndef __AA_AUDIT_H | ||
| 16 | #define __AA_AUDIT_H | ||
| 17 | |||
| 18 | #include <linux/audit.h> | ||
| 19 | #include <linux/fs.h> | ||
| 20 | #include <linux/lsm_audit.h> | ||
| 21 | #include <linux/sched.h> | ||
| 22 | #include <linux/slab.h> | ||
| 23 | |||
| 24 | #include "file.h" | ||
| 25 | |||
| 26 | struct aa_profile; | ||
| 27 | |||
| 28 | extern const char *audit_mode_names[]; | ||
| 29 | #define AUDIT_MAX_INDEX 5 | ||
| 30 | |||
| 31 | #define AUDIT_APPARMOR_AUTO 0 /* auto choose audit message type */ | ||
| 32 | |||
| 33 | enum audit_mode { | ||
| 34 | AUDIT_NORMAL, /* follow normal auditing of accesses */ | ||
| 35 | AUDIT_QUIET_DENIED, /* quiet all denied access messages */ | ||
| 36 | AUDIT_QUIET, /* quiet all messages */ | ||
| 37 | AUDIT_NOQUIET, /* do not quiet audit messages */ | ||
| 38 | AUDIT_ALL /* audit all accesses */ | ||
| 39 | }; | ||
| 40 | |||
| 41 | enum audit_type { | ||
| 42 | AUDIT_APPARMOR_AUDIT, | ||
| 43 | AUDIT_APPARMOR_ALLOWED, | ||
| 44 | AUDIT_APPARMOR_DENIED, | ||
| 45 | AUDIT_APPARMOR_HINT, | ||
| 46 | AUDIT_APPARMOR_STATUS, | ||
| 47 | AUDIT_APPARMOR_ERROR, | ||
| 48 | AUDIT_APPARMOR_KILL | ||
| 49 | }; | ||
| 50 | |||
| 51 | extern const char *op_table[]; | ||
| 52 | enum aa_ops { | ||
| 53 | OP_NULL, | ||
| 54 | |||
| 55 | OP_SYSCTL, | ||
| 56 | OP_CAPABLE, | ||
| 57 | |||
| 58 | OP_UNLINK, | ||
| 59 | OP_MKDIR, | ||
| 60 | OP_RMDIR, | ||
| 61 | OP_MKNOD, | ||
| 62 | OP_TRUNC, | ||
| 63 | OP_LINK, | ||
| 64 | OP_SYMLINK, | ||
| 65 | OP_RENAME_SRC, | ||
| 66 | OP_RENAME_DEST, | ||
| 67 | OP_CHMOD, | ||
| 68 | OP_CHOWN, | ||
| 69 | OP_GETATTR, | ||
| 70 | OP_OPEN, | ||
| 71 | |||
| 72 | OP_FPERM, | ||
| 73 | OP_FLOCK, | ||
| 74 | OP_FMMAP, | ||
| 75 | OP_FMPROT, | ||
| 76 | |||
| 77 | OP_CREATE, | ||
| 78 | OP_POST_CREATE, | ||
| 79 | OP_BIND, | ||
| 80 | OP_CONNECT, | ||
| 81 | OP_LISTEN, | ||
| 82 | OP_ACCEPT, | ||
| 83 | OP_SENDMSG, | ||
| 84 | OP_RECVMSG, | ||
| 85 | OP_GETSOCKNAME, | ||
| 86 | OP_GETPEERNAME, | ||
| 87 | OP_GETSOCKOPT, | ||
| 88 | OP_SETSOCKOPT, | ||
| 89 | OP_SOCK_SHUTDOWN, | ||
| 90 | |||
| 91 | OP_PTRACE, | ||
| 92 | |||
| 93 | OP_EXEC, | ||
| 94 | OP_CHANGE_HAT, | ||
| 95 | OP_CHANGE_PROFILE, | ||
| 96 | OP_CHANGE_ONEXEC, | ||
| 97 | |||
| 98 | OP_SETPROCATTR, | ||
| 99 | OP_SETRLIMIT, | ||
| 100 | |||
| 101 | OP_PROF_REPL, | ||
| 102 | OP_PROF_LOAD, | ||
| 103 | OP_PROF_RM, | ||
| 104 | }; | ||
| 105 | |||
| 106 | |||
| 107 | /* define a short hand for apparmor_audit_data portion of common_audit_data */ | ||
| 108 | #define aad apparmor_audit_data | ||
| 109 | |||
| 110 | void aa_audit_msg(int type, struct common_audit_data *sa, | ||
| 111 | void (*cb) (struct audit_buffer *, void *)); | ||
| 112 | int aa_audit(int type, struct aa_profile *profile, gfp_t gfp, | ||
| 113 | struct common_audit_data *sa, | ||
| 114 | void (*cb) (struct audit_buffer *, void *)); | ||
| 115 | |||
| 116 | static inline int complain_error(int error) | ||
| 117 | { | ||
| 118 | if (error == -EPERM || error == -EACCES) | ||
| 119 | return 0; | ||
| 120 | return error; | ||
| 121 | } | ||
| 122 | |||
| 123 | #endif /* __AA_AUDIT_H */ | ||
diff --git a/security/apparmor/include/capability.h b/security/apparmor/include/capability.h new file mode 100644 index 00000000000..c24d2959ea0 --- /dev/null +++ b/security/apparmor/include/capability.h | |||
| @@ -0,0 +1,45 @@ | |||
| 1 | /* | ||
| 2 | * AppArmor security module | ||
| 3 | * | ||
| 4 | * This file contains AppArmor capability mediation definitions. | ||
| 5 | * | ||
| 6 | * Copyright (C) 1998-2008 Novell/SUSE | ||
| 7 | * Copyright 2009-2010 Canonical Ltd. | ||
| 8 | * | ||
| 9 | * This program is free software; you can redistribute it and/or | ||
| 10 | * modify it under the terms of the GNU General Public License as | ||
| 11 | * published by the Free Software Foundation, version 2 of the | ||
| 12 | * License. | ||
| 13 | */ | ||
| 14 | |||
| 15 | #ifndef __AA_CAPABILITY_H | ||
| 16 | #define __AA_CAPABILITY_H | ||
| 17 | |||
| 18 | #include <linux/sched.h> | ||
| 19 | |||
| 20 | struct aa_profile; | ||
| 21 | |||
| 22 | /* aa_caps - confinement data for capabilities | ||
| 23 | * @allowed: capabilities mask | ||
| 24 | * @audit: caps that are to be audited | ||
| 25 | * @quiet: caps that should not be audited | ||
| 26 | * @kill: caps that when requested will result in the task being killed | ||
| 27 | * @extended: caps that are subject finer grained mediation | ||
| 28 | */ | ||
| 29 | struct aa_caps { | ||
| 30 | kernel_cap_t allow; | ||
| 31 | kernel_cap_t audit; | ||
| 32 | kernel_cap_t quiet; | ||
| 33 | kernel_cap_t kill; | ||
| 34 | kernel_cap_t extended; | ||
| 35 | }; | ||
| 36 | |||
| 37 | int aa_capable(struct task_struct *task, struct aa_profile *profile, int cap, | ||
| 38 | int audit); | ||
| 39 | |||
| 40 | static inline void aa_free_cap_rules(struct aa_caps *caps) | ||
| 41 | { | ||
| 42 | /* NOP */ | ||
| 43 | } | ||
| 44 | |||
| 45 | #endif /* __AA_CAPBILITY_H */ | ||
diff --git a/security/apparmor/include/context.h b/security/apparmor/include/context.h new file mode 100644 index 00000000000..a9cbee4d9e4 --- /dev/null +++ b/security/apparmor/include/context.h | |||
| @@ -0,0 +1,154 @@ | |||
| 1 | /* | ||
| 2 | * AppArmor security module | ||
| 3 | * | ||
| 4 | * This file contains AppArmor contexts used to associate "labels" to objects. | ||
| 5 | * | ||
| 6 | * Copyright (C) 1998-2008 Novell/SUSE | ||
| 7 | * Copyright 2009-2010 Canonical Ltd. | ||
| 8 | * | ||
| 9 | * This program is free software; you can redistribute it and/or | ||
| 10 | * modify it under the terms of the GNU General Public License as | ||
| 11 | * published by the Free Software Foundation, version 2 of the | ||
| 12 | * License. | ||
| 13 | */ | ||
| 14 | |||
| 15 | #ifndef __AA_CONTEXT_H | ||
| 16 | #define __AA_CONTEXT_H | ||
| 17 | |||
| 18 | #include <linux/cred.h> | ||
| 19 | #include <linux/slab.h> | ||
| 20 | #include <linux/sched.h> | ||
| 21 | |||
| 22 | #include "policy.h" | ||
| 23 | |||
| 24 | /* struct aa_file_cxt - the AppArmor context the file was opened in | ||
| 25 | * @perms: the permission the file was opened with | ||
| 26 | * | ||
| 27 | * The file_cxt could currently be directly stored in file->f_security | ||
| 28 | * as the profile reference is now stored in the f_cred. However the | ||
| 29 | * cxt struct will expand in the future so we keep the struct. | ||
| 30 | */ | ||
| 31 | struct aa_file_cxt { | ||
| 32 | u16 allow; | ||
| 33 | }; | ||
| 34 | |||
| 35 | /** | ||
| 36 | * aa_alloc_file_context - allocate file_cxt | ||
| 37 | * @gfp: gfp flags for allocation | ||
| 38 | * | ||
| 39 | * Returns: file_cxt or NULL on failure | ||
| 40 | */ | ||
| 41 | static inline struct aa_file_cxt *aa_alloc_file_context(gfp_t gfp) | ||
| 42 | { | ||
| 43 | return kzalloc(sizeof(struct aa_file_cxt), gfp); | ||
| 44 | } | ||
| 45 | |||
| 46 | /** | ||
| 47 | * aa_free_file_context - free a file_cxt | ||
| 48 | * @cxt: file_cxt to free (MAYBE_NULL) | ||
| 49 | */ | ||
| 50 | static inline void aa_free_file_context(struct aa_file_cxt *cxt) | ||
| 51 | { | ||
| 52 | if (cxt) | ||
| 53 | kzfree(cxt); | ||
| 54 | } | ||
| 55 | |||
| 56 | /** | ||
| 57 | * struct aa_task_cxt - primary label for confined tasks | ||
| 58 | * @profile: the current profile (NOT NULL) | ||
| 59 | * @exec: profile to transition to on next exec (MAYBE NULL) | ||
| 60 | * @previous: profile the task may return to (MAYBE NULL) | ||
| 61 | * @token: magic value the task must know for returning to @previous_profile | ||
| 62 | * | ||
| 63 | * Contains the task's current profile (which could change due to | ||
| 64 | * change_hat). Plus the hat_magic needed during change_hat. | ||
| 65 | * | ||
| 66 | * TODO: make so a task can be confined by a stack of contexts | ||
| 67 | */ | ||
| 68 | struct aa_task_cxt { | ||
| 69 | struct aa_profile *profile; | ||
| 70 | struct aa_profile *onexec; | ||
| 71 | struct aa_profile *previous; | ||
| 72 | u64 token; | ||
| 73 | }; | ||
| 74 | |||
| 75 | struct aa_task_cxt *aa_alloc_task_context(gfp_t flags); | ||
| 76 | void aa_free_task_context(struct aa_task_cxt *cxt); | ||
| 77 | void aa_dup_task_context(struct aa_task_cxt *new, | ||
| 78 | const struct aa_task_cxt *old); | ||
| 79 | int aa_replace_current_profile(struct aa_profile *profile); | ||
| 80 | int aa_set_current_onexec(struct aa_profile *profile); | ||
| 81 | int aa_set_current_hat(struct aa_profile *profile, u64 token); | ||
| 82 | int aa_restore_previous_profile(u64 cookie); | ||
| 83 | |||
| 84 | /** | ||
| 85 | * __aa_task_is_confined - determine if @task has any confinement | ||
| 86 | * @task: task to check confinement of (NOT NULL) | ||
| 87 | * | ||
| 88 | * If @task != current needs to be called in RCU safe critical section | ||
| 89 | */ | ||
| 90 | static inline bool __aa_task_is_confined(struct task_struct *task) | ||
| 91 | { | ||
| 92 | struct aa_task_cxt *cxt = __task_cred(task)->security; | ||
| 93 | |||
| 94 | BUG_ON(!cxt || !cxt->profile); | ||
| 95 | if (unconfined(aa_newest_version(cxt->profile))) | ||
| 96 | return 0; | ||
| 97 | |||
| 98 | return 1; | ||
| 99 | } | ||
| 100 | |||
| 101 | /** | ||
| 102 | * aa_cred_profile - obtain cred's profiles | ||
| 103 | * @cred: cred to obtain profiles from (NOT NULL) | ||
| 104 | * | ||
| 105 | * Returns: confining profile | ||
| 106 | * | ||
| 107 | * does NOT increment reference count | ||
| 108 | */ | ||
| 109 | static inline struct aa_profile *aa_cred_profile(const struct cred *cred) | ||
| 110 | { | ||
| 111 | struct aa_task_cxt *cxt = cred->security; | ||
| 112 | BUG_ON(!cxt || !cxt->profile); | ||
| 113 | return aa_newest_version(cxt->profile); | ||
| 114 | } | ||
| 115 | |||
| 116 | /** | ||
| 117 | * __aa_current_profile - find the current tasks confining profile | ||
| 118 | * | ||
| 119 | * Returns: up to date confining profile or the ns unconfined profile (NOT NULL) | ||
| 120 | * | ||
| 121 | * This fn will not update the tasks cred to the most up to date version | ||
| 122 | * of the profile so it is safe to call when inside of locks. | ||
| 123 | */ | ||
| 124 | static inline struct aa_profile *__aa_current_profile(void) | ||
| 125 | { | ||
| 126 | return aa_cred_profile(current_cred()); | ||
| 127 | } | ||
| 128 | |||
| 129 | /** | ||
| 130 | * aa_current_profile - find the current tasks confining profile and do updates | ||
| 131 | * | ||
| 132 | * Returns: up to date confining profile or the ns unconfined profile (NOT NULL) | ||
| 133 | * | ||
| 134 | * This fn will update the tasks cred structure if the profile has been | ||
| 135 | * replaced. Not safe to call inside locks | ||
| 136 | */ | ||
| 137 | static inline struct aa_profile *aa_current_profile(void) | ||
| 138 | { | ||
| 139 | const struct aa_task_cxt *cxt = current_cred()->security; | ||
| 140 | struct aa_profile *profile; | ||
| 141 | BUG_ON(!cxt || !cxt->profile); | ||
| 142 | |||
| 143 | profile = aa_newest_version(cxt->profile); | ||
| 144 | /* | ||
| 145 | * Whether or not replacement succeeds, use newest profile so | ||
| 146 | * there is no need to update it after replacement. | ||
| 147 | */ | ||
| 148 | if (unlikely((cxt->profile != profile))) | ||
| 149 | aa_replace_current_profile(profile); | ||
| 150 | |||
| 151 | return profile; | ||
| 152 | } | ||
| 153 | |||
| 154 | #endif /* __AA_CONTEXT_H */ | ||
diff --git a/security/apparmor/include/domain.h b/security/apparmor/include/domain.h new file mode 100644 index 00000000000..de04464f0a3 --- /dev/null +++ b/security/apparmor/include/domain.h | |||
| @@ -0,0 +1,36 @@ | |||
| 1 | /* | ||
| 2 | * AppArmor security module | ||
| 3 | * | ||
| 4 | * This file contains AppArmor security domain transition function definitions. | ||
| 5 | * | ||
| 6 | * Copyright (C) 1998-2008 Novell/SUSE | ||
| 7 | * Copyright 2009-2010 Canonical Ltd. | ||
| 8 | * | ||
| 9 | * This program is free software; you can redistribute it and/or | ||
| 10 | * modify it under the terms of the GNU General Public License as | ||
| 11 | * published by the Free Software Foundation, version 2 of the | ||
| 12 | * License. | ||
| 13 | */ | ||
| 14 | |||
| 15 | #include <linux/binfmts.h> | ||
| 16 | #include <linux/types.h> | ||
| 17 | |||
| 18 | #ifndef __AA_DOMAIN_H | ||
| 19 | #define __AA_DOMAIN_H | ||
| 20 | |||
| 21 | struct aa_domain { | ||
| 22 | int size; | ||
| 23 | char **table; | ||
| 24 | }; | ||
| 25 | |||
| 26 | int apparmor_bprm_set_creds(struct linux_binprm *bprm); | ||
| 27 | int apparmor_bprm_secureexec(struct linux_binprm *bprm); | ||
| 28 | void apparmor_bprm_committing_creds(struct linux_binprm *bprm); | ||
| 29 | void apparmor_bprm_committed_creds(struct linux_binprm *bprm); | ||
| 30 | |||
| 31 | void aa_free_domain_entries(struct aa_domain *domain); | ||
| 32 | int aa_change_hat(const char *hats[], int count, u64 token, bool permtest); | ||
| 33 | int aa_change_profile(const char *ns_name, const char *name, bool onexec, | ||
| 34 | bool permtest); | ||
| 35 | |||
| 36 | #endif /* __AA_DOMAIN_H */ | ||
diff --git a/security/apparmor/include/file.h b/security/apparmor/include/file.h new file mode 100644 index 00000000000..be36feabb16 --- /dev/null +++ b/security/apparmor/include/file.h | |||
| @@ -0,0 +1,217 @@ | |||
| 1 | /* | ||
| 2 | * AppArmor security module | ||
| 3 | * | ||
| 4 | * This file contains AppArmor file mediation function definitions. | ||
| 5 | * | ||
| 6 | * Copyright (C) 1998-2008 Novell/SUSE | ||
| 7 | * Copyright 2009-2010 Canonical Ltd. | ||
| 8 | * | ||
| 9 | * This program is free software; you can redistribute it and/or | ||
| 10 | * modify it under the terms of the GNU General Public License as | ||
| 11 | * published by the Free Software Foundation, version 2 of the | ||
| 12 | * License. | ||
| 13 | */ | ||
| 14 | |||
| 15 | #ifndef __AA_FILE_H | ||
| 16 | #define __AA_FILE_H | ||
| 17 | |||
| 18 | #include <linux/path.h> | ||
| 19 | |||
| 20 | #include "domain.h" | ||
| 21 | #include "match.h" | ||
| 22 | |||
| 23 | struct aa_profile; | ||
| 24 | |||
| 25 | /* | ||
| 26 | * We use MAY_EXEC, MAY_WRITE, MAY_READ, MAY_APPEND and the following flags | ||
| 27 | * for profile permissions | ||
| 28 | */ | ||
| 29 | #define AA_MAY_CREATE 0x0010 | ||
| 30 | #define AA_MAY_DELETE 0x0020 | ||
| 31 | #define AA_MAY_META_WRITE 0x0040 | ||
| 32 | #define AA_MAY_META_READ 0x0080 | ||
| 33 | |||
| 34 | #define AA_MAY_CHMOD 0x0100 | ||
| 35 | #define AA_MAY_CHOWN 0x0200 | ||
| 36 | #define AA_MAY_LOCK 0x0400 | ||
| 37 | #define AA_EXEC_MMAP 0x0800 | ||
| 38 | |||
| 39 | #define AA_MAY_LINK 0x1000 | ||
| 40 | #define AA_LINK_SUBSET AA_MAY_LOCK /* overlaid */ | ||
| 41 | #define AA_MAY_ONEXEC 0x40000000 /* exec allows onexec */ | ||
| 42 | #define AA_MAY_CHANGE_PROFILE 0x80000000 | ||
| 43 | #define AA_MAY_CHANGEHAT 0x80000000 /* ctrl auditing only */ | ||
| 44 | |||
| 45 | #define AA_AUDIT_FILE_MASK (MAY_READ | MAY_WRITE | MAY_EXEC | MAY_APPEND |\ | ||
| 46 | AA_MAY_CREATE | AA_MAY_DELETE | \ | ||
| 47 | AA_MAY_META_READ | AA_MAY_META_WRITE | \ | ||
| 48 | AA_MAY_CHMOD | AA_MAY_CHOWN | AA_MAY_LOCK | \ | ||
| 49 | AA_EXEC_MMAP | AA_MAY_LINK) | ||
| 50 | |||
| 51 | /* | ||
| 52 | * The xindex is broken into 3 parts | ||
| 53 | * - index - an index into either the exec name table or the variable table | ||
| 54 | * - exec type - which determines how the executable name and index are used | ||
| 55 | * - flags - which modify how the destination name is applied | ||
| 56 | */ | ||
| 57 | #define AA_X_INDEX_MASK 0x03ff | ||
| 58 | |||
| 59 | #define AA_X_TYPE_MASK 0x0c00 | ||
| 60 | #define AA_X_TYPE_SHIFT 10 | ||
| 61 | #define AA_X_NONE 0x0000 | ||
| 62 | #define AA_X_NAME 0x0400 /* use executable name px */ | ||
| 63 | #define AA_X_TABLE 0x0800 /* use a specified name ->n# */ | ||
| 64 | |||
| 65 | #define AA_X_UNSAFE 0x1000 | ||
| 66 | #define AA_X_CHILD 0x2000 /* make >AA_X_NONE apply to children */ | ||
| 67 | #define AA_X_INHERIT 0x4000 | ||
| 68 | #define AA_X_UNCONFINED 0x8000 | ||
| 69 | |||
| 70 | /* AA_SECURE_X_NEEDED - is passed in the bprm->unsafe field */ | ||
| 71 | #define AA_SECURE_X_NEEDED 0x8000 | ||
| 72 | |||
| 73 | /* need to make conditional which ones are being set */ | ||
| 74 | struct path_cond { | ||
| 75 | uid_t uid; | ||
| 76 | umode_t mode; | ||
| 77 | }; | ||
| 78 | |||
| 79 | /* struct file_perms - file permission | ||
| 80 | * @allow: mask of permissions that are allowed | ||
| 81 | * @audit: mask of permissions to force an audit message for | ||
| 82 | * @quiet: mask of permissions to quiet audit messages for | ||
| 83 | * @kill: mask of permissions that when matched will kill the task | ||
| 84 | * @xindex: exec transition index if @allow contains MAY_EXEC | ||
| 85 | * | ||
| 86 | * The @audit and @queit mask should be mutually exclusive. | ||
| 87 | */ | ||
| 88 | struct file_perms { | ||
| 89 | u32 allow; | ||
| 90 | u32 audit; | ||
| 91 | u32 quiet; | ||
| 92 | u32 kill; | ||
| 93 | u16 xindex; | ||
| 94 | }; | ||
| 95 | |||
| 96 | extern struct file_perms nullperms; | ||
| 97 | |||
| 98 | #define COMBINED_PERM_MASK(X) ((X).allow | (X).audit | (X).quiet | (X).kill) | ||
| 99 | |||
| 100 | /* FIXME: split perms from dfa and match this to description | ||
| 101 | * also add delegation info. | ||
| 102 | */ | ||
| 103 | static inline u16 dfa_map_xindex(u16 mask) | ||
| 104 | { | ||
| 105 | u16 old_index = (mask >> 10) & 0xf; | ||
| 106 | u16 index = 0; | ||
| 107 | |||
| 108 | if (mask & 0x100) | ||
| 109 | index |= AA_X_UNSAFE; | ||
| 110 | if (mask & 0x200) | ||
| 111 | index |= AA_X_INHERIT; | ||
| 112 | if (mask & 0x80) | ||
| 113 | index |= AA_X_UNCONFINED; | ||
| 114 | |||
| 115 | if (old_index == 1) { | ||
| 116 | index |= AA_X_UNCONFINED; | ||
| 117 | } else if (old_index == 2) { | ||
| 118 | index |= AA_X_NAME; | ||
| 119 | } else if (old_index == 3) { | ||
| 120 | index |= AA_X_NAME | AA_X_CHILD; | ||
| 121 | } else { | ||
| 122 | index |= AA_X_TABLE; | ||
| 123 | index |= old_index - 4; | ||
| 124 | } | ||
| 125 | |||
| 126 | return index; | ||
| 127 | } | ||
| 128 | |||
| 129 | /* | ||
| 130 | * map old dfa inline permissions to new format | ||
| 131 | */ | ||
| 132 | #define dfa_user_allow(dfa, state) (((ACCEPT_TABLE(dfa)[state]) & 0x7f) | \ | ||
| 133 | ((ACCEPT_TABLE(dfa)[state]) & 0x80000000)) | ||
| 134 | #define dfa_user_audit(dfa, state) ((ACCEPT_TABLE2(dfa)[state]) & 0x7f) | ||
| 135 | #define dfa_user_quiet(dfa, state) (((ACCEPT_TABLE2(dfa)[state]) >> 7) & 0x7f) | ||
| 136 | #define dfa_user_xindex(dfa, state) \ | ||
| 137 | (dfa_map_xindex(ACCEPT_TABLE(dfa)[state] & 0x3fff)) | ||
| 138 | |||
| 139 | #define dfa_other_allow(dfa, state) ((((ACCEPT_TABLE(dfa)[state]) >> 14) & \ | ||
| 140 | 0x7f) | \ | ||
| 141 | ((ACCEPT_TABLE(dfa)[state]) & 0x80000000)) | ||
| 142 | #define dfa_other_audit(dfa, state) (((ACCEPT_TABLE2(dfa)[state]) >> 14) & 0x7f) | ||
| 143 | #define dfa_other_quiet(dfa, state) \ | ||
| 144 | ((((ACCEPT_TABLE2(dfa)[state]) >> 7) >> 14) & 0x7f) | ||
| 145 | #define dfa_other_xindex(dfa, state) \ | ||
| 146 | dfa_map_xindex((ACCEPT_TABLE(dfa)[state] >> 14) & 0x3fff) | ||
| 147 | |||
| 148 | int aa_audit_file(struct aa_profile *profile, struct file_perms *perms, | ||
| 149 | gfp_t gfp, int op, u32 request, const char *name, | ||
| 150 | const char *target, uid_t ouid, const char *info, int error); | ||
| 151 | |||
| 152 | /** | ||
| 153 | * struct aa_file_rules - components used for file rule permissions | ||
| 154 | * @dfa: dfa to match path names and conditionals against | ||
| 155 | * @perms: permission table indexed by the matched state accept entry of @dfa | ||
| 156 | * @trans: transition table for indexed by named x transitions | ||
| 157 | * | ||
| 158 | * File permission are determined by matching a path against @dfa and then | ||
| 159 | * then using the value of the accept entry for the matching state as | ||
| 160 | * an index into @perms. If a named exec transition is required it is | ||
| 161 | * looked up in the transition table. | ||
| 162 | */ | ||
| 163 | struct aa_file_rules { | ||
| 164 | unsigned int start; | ||
| 165 | struct aa_dfa *dfa; | ||
| 166 | /* struct perms perms; */ | ||
| 167 | struct aa_domain trans; | ||
| 168 | /* TODO: add delegate table */ | ||
| 169 | }; | ||
| 170 | |||
| 171 | unsigned int aa_str_perms(struct aa_dfa *dfa, unsigned int start, | ||
| 172 | const char *name, struct path_cond *cond, | ||
| 173 | struct file_perms *perms); | ||
| 174 | |||
| 175 | int aa_path_perm(int op, struct aa_profile *profile, struct path *path, | ||
| 176 | int flags, u32 request, struct path_cond *cond); | ||
| 177 | |||
| 178 | int aa_path_link(struct aa_profile *profile, struct dentry *old_dentry, | ||
| 179 | struct path *new_dir, struct dentry *new_dentry); | ||
| 180 | |||
| 181 | int aa_file_perm(int op, struct aa_profile *profile, struct file *file, | ||
| 182 | u32 request); | ||
| 183 | |||
| 184 | static inline void aa_free_file_rules(struct aa_file_rules *rules) | ||
| 185 | { | ||
| 186 | aa_put_dfa(rules->dfa); | ||
| 187 | aa_free_domain_entries(&rules->trans); | ||
| 188 | } | ||
| 189 | |||
| 190 | #define ACC_FMODE(x) (("\000\004\002\006"[(x)&O_ACCMODE]) | (((x) << 1) & 0x40)) | ||
| 191 | |||
| 192 | /* from namei.c */ | ||
| 193 | #define MAP_OPEN_FLAGS(x) ((((x) + 1) & O_ACCMODE) ? (x) + 1 : (x)) | ||
| 194 | |||
| 195 | /** | ||
| 196 | * aa_map_file_perms - map file flags to AppArmor permissions | ||
| 197 | * @file: open file to map flags to AppArmor permissions | ||
| 198 | * | ||
| 199 | * Returns: apparmor permission set for the file | ||
| 200 | */ | ||
| 201 | static inline u32 aa_map_file_to_perms(struct file *file) | ||
| 202 | { | ||
| 203 | int flags = MAP_OPEN_FLAGS(file->f_flags); | ||
| 204 | u32 perms = ACC_FMODE(file->f_mode); | ||
| 205 | |||
| 206 | if ((flags & O_APPEND) && (perms & MAY_WRITE)) | ||
| 207 | perms = (perms & ~MAY_WRITE) | MAY_APPEND; | ||
| 208 | /* trunc implies write permission */ | ||
| 209 | if (flags & O_TRUNC) | ||
| 210 | perms |= MAY_WRITE; | ||
| 211 | if (flags & O_CREAT) | ||
| 212 | perms |= AA_MAY_CREATE; | ||
| 213 | |||
| 214 | return perms; | ||
| 215 | } | ||
| 216 | |||
| 217 | #endif /* __AA_FILE_H */ | ||
diff --git a/security/apparmor/include/ipc.h b/security/apparmor/include/ipc.h new file mode 100644 index 00000000000..aeda0fbc8b2 --- /dev/null +++ b/security/apparmor/include/ipc.h | |||
| @@ -0,0 +1,28 @@ | |||
| 1 | /* | ||
| 2 | * AppArmor security module | ||
| 3 | * | ||
| 4 | * This file contains AppArmor ipc mediation function definitions. | ||
| 5 | * | ||
| 6 | * Copyright (C) 1998-2008 Novell/SUSE | ||
| 7 | * Copyright 2009-2010 Canonical Ltd. | ||
| 8 | * | ||
| 9 | * This program is free software; you can redistribute it and/or | ||
| 10 | * modify it under the terms of the GNU General Public License as | ||
| 11 | * published by the Free Software Foundation, version 2 of the | ||
| 12 | * License. | ||
| 13 | */ | ||
| 14 | |||
| 15 | #ifndef __AA_IPC_H | ||
| 16 | #define __AA_IPC_H | ||
| 17 | |||
| 18 | #include <linux/sched.h> | ||
| 19 | |||
| 20 | struct aa_profile; | ||
| 21 | |||
| 22 | int aa_may_ptrace(struct task_struct *tracer_task, struct aa_profile *tracer, | ||
| 23 | struct aa_profile *tracee, unsigned int mode); | ||
| 24 | |||
| 25 | int aa_ptrace(struct task_struct *tracer, struct task_struct *tracee, | ||
| 26 | unsigned int mode); | ||
| 27 | |||
| 28 | #endif /* __AA_IPC_H */ | ||
diff --git a/security/apparmor/include/match.h b/security/apparmor/include/match.h new file mode 100644 index 00000000000..734a6d35112 --- /dev/null +++ b/security/apparmor/include/match.h | |||
| @@ -0,0 +1,132 @@ | |||
| 1 | /* | ||
| 2 | * AppArmor security module | ||
| 3 | * | ||
| 4 | * This file contains AppArmor policy dfa matching engine definitions. | ||
| 5 | * | ||
| 6 | * Copyright (C) 1998-2008 Novell/SUSE | ||
| 7 | * Copyright 2009-2010 Canonical Ltd. | ||
| 8 | * | ||
| 9 | * This program is free software; you can redistribute it and/or | ||
| 10 | * modify it under the terms of the GNU General Public License as | ||
| 11 | * published by the Free Software Foundation, version 2 of the | ||
| 12 | * License. | ||
| 13 | */ | ||
| 14 | |||
| 15 | #ifndef __AA_MATCH_H | ||
| 16 | #define __AA_MATCH_H | ||
| 17 | |||
| 18 | #include <linux/workqueue.h> | ||
| 19 | |||
| 20 | #define DFA_NOMATCH 0 | ||
| 21 | #define DFA_START 1 | ||
| 22 | |||
| 23 | #define DFA_VALID_PERM_MASK 0xffffffff | ||
| 24 | #define DFA_VALID_PERM2_MASK 0xffffffff | ||
| 25 | |||
| 26 | /** | ||
| 27 | * The format used for transition tables is based on the GNU flex table | ||
| 28 | * file format (--tables-file option; see Table File Format in the flex | ||
| 29 | * info pages and the flex sources for documentation). The magic number | ||
| 30 | * used in the header is 0x1B5E783D insted of 0xF13C57B1 though, because | ||
| 31 | * the YY_ID_CHK (check) and YY_ID_DEF (default) tables are used | ||
| 32 | * slightly differently (see the apparmor-parser package). | ||
| 33 | */ | ||
| 34 | |||
| 35 | #define YYTH_MAGIC 0x1B5E783D | ||
| 36 | #define YYTH_DEF_RECURSE 0x1 /* DEF Table is recursive */ | ||
| 37 | |||
| 38 | struct table_set_header { | ||
| 39 | u32 th_magic; /* YYTH_MAGIC */ | ||
| 40 | u32 th_hsize; | ||
| 41 | u32 th_ssize; | ||
| 42 | u16 th_flags; | ||
| 43 | char th_version[]; | ||
| 44 | }; | ||
| 45 | |||
| 46 | /* The YYTD_ID are one less than flex table mappings. The flex id | ||
| 47 | * has 1 subtracted at table load time, this allows us to directly use the | ||
| 48 | * ID's as indexes. | ||
| 49 | */ | ||
| 50 | #define YYTD_ID_ACCEPT 0 | ||
| 51 | #define YYTD_ID_BASE 1 | ||
| 52 | #define YYTD_ID_CHK 2 | ||
| 53 | #define YYTD_ID_DEF 3 | ||
| 54 | #define YYTD_ID_EC 4 | ||
| 55 | #define YYTD_ID_META 5 | ||
| 56 | #define YYTD_ID_ACCEPT2 6 | ||
| 57 | #define YYTD_ID_NXT 7 | ||
| 58 | #define YYTD_ID_TSIZE 8 | ||
| 59 | |||
| 60 | #define YYTD_DATA8 1 | ||
| 61 | #define YYTD_DATA16 2 | ||
| 62 | #define YYTD_DATA32 4 | ||
| 63 | #define YYTD_DATA64 8 | ||
| 64 | |||
| 65 | /* Each ACCEPT2 table gets 6 dedicated flags, YYTD_DATAX define the | ||
| 66 | * first flags | ||
| 67 | */ | ||
| 68 | #define ACCEPT1_FLAGS(X) ((X) & 0x3f) | ||
| 69 | #define ACCEPT2_FLAGS(X) ACCEPT1_FLAGS((X) >> YYTD_ID_ACCEPT2) | ||
| 70 | #define TO_ACCEPT1_FLAG(X) ACCEPT1_FLAGS(X) | ||
| 71 | #define TO_ACCEPT2_FLAG(X) (ACCEPT1_FLAGS(X) << YYTD_ID_ACCEPT2) | ||
| 72 | #define DFA_FLAG_VERIFY_STATES 0x1000 | ||
| 73 | |||
| 74 | struct table_header { | ||
| 75 | u16 td_id; | ||
| 76 | u16 td_flags; | ||
| 77 | u32 td_hilen; | ||
| 78 | u32 td_lolen; | ||
| 79 | char td_data[]; | ||
| 80 | }; | ||
| 81 | |||
| 82 | #define DEFAULT_TABLE(DFA) ((u16 *)((DFA)->tables[YYTD_ID_DEF]->td_data)) | ||
| 83 | #define BASE_TABLE(DFA) ((u32 *)((DFA)->tables[YYTD_ID_BASE]->td_data)) | ||
| 84 | #define NEXT_TABLE(DFA) ((u16 *)((DFA)->tables[YYTD_ID_NXT]->td_data)) | ||
| 85 | #define CHECK_TABLE(DFA) ((u16 *)((DFA)->tables[YYTD_ID_CHK]->td_data)) | ||
| 86 | #define EQUIV_TABLE(DFA) ((u8 *)((DFA)->tables[YYTD_ID_EC]->td_data)) | ||
| 87 | #define ACCEPT_TABLE(DFA) ((u32 *)((DFA)->tables[YYTD_ID_ACCEPT]->td_data)) | ||
| 88 | #define ACCEPT_TABLE2(DFA) ((u32 *)((DFA)->tables[YYTD_ID_ACCEPT2]->td_data)) | ||
| 89 | |||
| 90 | struct aa_dfa { | ||
| 91 | struct kref count; | ||
| 92 | u16 flags; | ||
| 93 | struct table_header *tables[YYTD_ID_TSIZE]; | ||
| 94 | }; | ||
| 95 | |||
| 96 | #define byte_to_byte(X) (X) | ||
| 97 | |||
| 98 | #define UNPACK_ARRAY(TABLE, BLOB, LEN, TYPE, NTOHX) \ | ||
| 99 | do { \ | ||
| 100 | typeof(LEN) __i; \ | ||
| 101 | TYPE *__t = (TYPE *) TABLE; \ | ||
| 102 | TYPE *__b = (TYPE *) BLOB; \ | ||
| 103 | for (__i = 0; __i < LEN; __i++) { \ | ||
| 104 | __t[__i] = NTOHX(__b[__i]); \ | ||
| 105 | } \ | ||
| 106 | } while (0) | ||
| 107 | |||
| 108 | static inline size_t table_size(size_t len, size_t el_size) | ||
| 109 | { | ||
| 110 | return ALIGN(sizeof(struct table_header) + len * el_size, 8); | ||
| 111 | } | ||
| 112 | |||
| 113 | struct aa_dfa *aa_dfa_unpack(void *blob, size_t size, int flags); | ||
| 114 | unsigned int aa_dfa_match_len(struct aa_dfa *dfa, unsigned int start, | ||
| 115 | const char *str, int len); | ||
| 116 | unsigned int aa_dfa_match(struct aa_dfa *dfa, unsigned int start, | ||
| 117 | const char *str); | ||
| 118 | void aa_dfa_free_kref(struct kref *kref); | ||
| 119 | |||
| 120 | /** | ||
| 121 | * aa_put_dfa - put a dfa refcount | ||
| 122 | * @dfa: dfa to put refcount (MAYBE NULL) | ||
| 123 | * | ||
| 124 | * Requires: if @dfa != NULL that a valid refcount be held | ||
| 125 | */ | ||
| 126 | static inline void aa_put_dfa(struct aa_dfa *dfa) | ||
| 127 | { | ||
| 128 | if (dfa) | ||
| 129 | kref_put(&dfa->count, aa_dfa_free_kref); | ||
| 130 | } | ||
| 131 | |||
| 132 | #endif /* __AA_MATCH_H */ | ||
diff --git a/security/apparmor/include/path.h b/security/apparmor/include/path.h new file mode 100644 index 00000000000..27b327a7fae --- /dev/null +++ b/security/apparmor/include/path.h | |||
| @@ -0,0 +1,31 @@ | |||
| 1 | /* | ||
| 2 | * AppArmor security module | ||
| 3 | * | ||
| 4 | * This file contains AppArmor basic path manipulation function definitions. | ||
| 5 | * | ||
| 6 | * Copyright (C) 1998-2008 Novell/SUSE | ||
| 7 | * Copyright 2009-2010 Canonical Ltd. | ||
| 8 | * | ||
| 9 | * This program is free software; you can redistribute it and/or | ||
| 10 | * modify it under the terms of the GNU General Public License as | ||
| 11 | * published by the Free Software Foundation, version 2 of the | ||
| 12 | * License. | ||
| 13 | */ | ||
| 14 | |||
| 15 | #ifndef __AA_PATH_H | ||
| 16 | #define __AA_PATH_H | ||
| 17 | |||
| 18 | |||
| 19 | enum path_flags { | ||
| 20 | PATH_IS_DIR = 0x1, /* path is a directory */ | ||
| 21 | PATH_CONNECT_PATH = 0x4, /* connect disconnected paths to / */ | ||
| 22 | PATH_CHROOT_REL = 0x8, /* do path lookup relative to chroot */ | ||
| 23 | PATH_CHROOT_NSCONNECT = 0x10, /* connect paths that are at ns root */ | ||
| 24 | |||
| 25 | PATH_DELEGATE_DELETED = 0x08000, /* delegate deleted files */ | ||
| 26 | PATH_MEDIATE_DELETED = 0x10000, /* mediate deleted paths */ | ||
| 27 | }; | ||
| 28 | |||
| 29 | int aa_get_name(struct path *path, int flags, char **buffer, const char **name); | ||
| 30 | |||
| 31 | #endif /* __AA_PATH_H */ | ||
diff --git a/security/apparmor/include/policy.h b/security/apparmor/include/policy.h new file mode 100644 index 00000000000..aeda5cf5690 --- /dev/null +++ b/security/apparmor/include/policy.h | |||
| @@ -0,0 +1,305 @@ | |||
| 1 | /* | ||
| 2 | * AppArmor security module | ||
| 3 | * | ||
| 4 | * This file contains AppArmor policy definitions. | ||
| 5 | * | ||
| 6 | * Copyright (C) 1998-2008 Novell/SUSE | ||
| 7 | * Copyright 2009-2010 Canonical Ltd. | ||
| 8 | * | ||
| 9 | * This program is free software; you can redistribute it and/or | ||
| 10 | * modify it under the terms of the GNU General Public License as | ||
| 11 | * published by the Free Software Foundation, version 2 of the | ||
| 12 | * License. | ||
| 13 | */ | ||
| 14 | |||
| 15 | #ifndef __AA_POLICY_H | ||
| 16 | #define __AA_POLICY_H | ||
| 17 | |||
| 18 | #include <linux/capability.h> | ||
| 19 | #include <linux/cred.h> | ||
| 20 | #include <linux/kref.h> | ||
| 21 | #include <linux/sched.h> | ||
| 22 | #include <linux/slab.h> | ||
| 23 | #include <linux/socket.h> | ||
| 24 | |||
| 25 | #include "apparmor.h" | ||
| 26 | #include "audit.h" | ||
| 27 | #include "capability.h" | ||
| 28 | #include "domain.h" | ||
| 29 | #include "file.h" | ||
| 30 | #include "resource.h" | ||
| 31 | |||
| 32 | extern const char *profile_mode_names[]; | ||
| 33 | #define APPARMOR_NAMES_MAX_INDEX 3 | ||
| 34 | |||
| 35 | #define COMPLAIN_MODE(_profile) \ | ||
| 36 | ((aa_g_profile_mode == APPARMOR_COMPLAIN) || \ | ||
| 37 | ((_profile)->mode == APPARMOR_COMPLAIN)) | ||
| 38 | |||
| 39 | #define KILL_MODE(_profile) \ | ||
| 40 | ((aa_g_profile_mode == APPARMOR_KILL) || \ | ||
| 41 | ((_profile)->mode == APPARMOR_KILL)) | ||
| 42 | |||
| 43 | #define PROFILE_IS_HAT(_profile) ((_profile)->flags & PFLAG_HAT) | ||
| 44 | |||
| 45 | /* | ||
| 46 | * FIXME: currently need a clean way to replace and remove profiles as a | ||
| 47 | * set. It should be done at the namespace level. | ||
| 48 | * Either, with a set of profiles loaded at the namespace level or via | ||
| 49 | * a mark and remove marked interface. | ||
| 50 | */ | ||
| 51 | enum profile_mode { | ||
| 52 | APPARMOR_ENFORCE, /* enforce access rules */ | ||
| 53 | APPARMOR_COMPLAIN, /* allow and log access violations */ | ||
| 54 | APPARMOR_KILL, /* kill task on access violation */ | ||
| 55 | }; | ||
| 56 | |||
| 57 | enum profile_flags { | ||
| 58 | PFLAG_HAT = 1, /* profile is a hat */ | ||
| 59 | PFLAG_UNCONFINED = 2, /* profile is an unconfined profile */ | ||
| 60 | PFLAG_NULL = 4, /* profile is null learning profile */ | ||
| 61 | PFLAG_IX_ON_NAME_ERROR = 8, /* fallback to ix on name lookup fail */ | ||
| 62 | PFLAG_IMMUTABLE = 0x10, /* don't allow changes/replacement */ | ||
| 63 | PFLAG_USER_DEFINED = 0x20, /* user based profile - lower privs */ | ||
| 64 | PFLAG_NO_LIST_REF = 0x40, /* list doesn't keep profile ref */ | ||
| 65 | PFLAG_OLD_NULL_TRANS = 0x100, /* use // as the null transition */ | ||
| 66 | |||
| 67 | /* These flags must correspond with PATH_flags */ | ||
| 68 | PFLAG_MEDIATE_DELETED = 0x10000, /* mediate instead delegate deleted */ | ||
| 69 | }; | ||
| 70 | |||
| 71 | struct aa_profile; | ||
| 72 | |||
| 73 | /* struct aa_policy - common part of both namespaces and profiles | ||
| 74 | * @name: name of the object | ||
| 75 | * @hname - The hierarchical name | ||
| 76 | * @count: reference count of the obj | ||
| 77 | * @list: list policy object is on | ||
| 78 | * @profiles: head of the profiles list contained in the object | ||
| 79 | */ | ||
| 80 | struct aa_policy { | ||
| 81 | char *name; | ||
| 82 | char *hname; | ||
| 83 | struct kref count; | ||
| 84 | struct list_head list; | ||
| 85 | struct list_head profiles; | ||
| 86 | }; | ||
| 87 | |||
| 88 | /* struct aa_ns_acct - accounting of profiles in namespace | ||
| 89 | * @max_size: maximum space allowed for all profiles in namespace | ||
| 90 | * @max_count: maximum number of profiles that can be in this namespace | ||
| 91 | * @size: current size of profiles | ||
| 92 | * @count: current count of profiles (includes null profiles) | ||
| 93 | */ | ||
| 94 | struct aa_ns_acct { | ||
| 95 | int max_size; | ||
| 96 | int max_count; | ||
| 97 | int size; | ||
| 98 | int count; | ||
| 99 | }; | ||
| 100 | |||
| 101 | /* struct aa_namespace - namespace for a set of profiles | ||
| 102 | * @base: common policy | ||
| 103 | * @parent: parent of namespace | ||
| 104 | * @lock: lock for modifying the object | ||
| 105 | * @acct: accounting for the namespace | ||
| 106 | * @unconfined: special unconfined profile for the namespace | ||
| 107 | * @sub_ns: list of namespaces under the current namespace. | ||
| 108 | * | ||
| 109 | * An aa_namespace defines the set profiles that are searched to determine | ||
| 110 | * which profile to attach to a task. Profiles can not be shared between | ||
| 111 | * aa_namespaces and profile names within a namespace are guaranteed to be | ||
| 112 | * unique. When profiles in separate namespaces have the same name they | ||
| 113 | * are NOT considered to be equivalent. | ||
| 114 | * | ||
| 115 | * Namespaces are hierarchical and only namespaces and profiles below the | ||
| 116 | * current namespace are visible. | ||
| 117 | * | ||
| 118 | * Namespace names must be unique and can not contain the characters :/\0 | ||
| 119 | * | ||
| 120 | * FIXME TODO: add vserver support of namespaces (can it all be done in | ||
| 121 | * userspace?) | ||
| 122 | */ | ||
| 123 | struct aa_namespace { | ||
| 124 | struct aa_policy base; | ||
| 125 | struct aa_namespace *parent; | ||
| 126 | rwlock_t lock; | ||
| 127 | struct aa_ns_acct acct; | ||
| 128 | struct aa_profile *unconfined; | ||
| 129 | struct list_head sub_ns; | ||
| 130 | }; | ||
| 131 | |||
| 132 | /* struct aa_profile - basic confinement data | ||
| 133 | * @base - base components of the profile (name, refcount, lists, lock ...) | ||
| 134 | * @parent: parent of profile | ||
| 135 | * @ns: namespace the profile is in | ||
| 136 | * @replacedby: is set to the profile that replaced this profile | ||
| 137 | * @rename: optional profile name that this profile renamed | ||
| 138 | * @xmatch: optional extended matching for unconfined executables names | ||
| 139 | * @xmatch_len: xmatch prefix len, used to determine xmatch priority | ||
| 140 | * @sid: the unique security id number of this profile | ||
| 141 | * @audit: the auditing mode of the profile | ||
| 142 | * @mode: the enforcement mode of the profile | ||
| 143 | * @flags: flags controlling profile behavior | ||
| 144 | * @path_flags: flags controlling path generation behavior | ||
| 145 | * @size: the memory consumed by this profiles rules | ||
| 146 | * @file: The set of rules governing basic file access and domain transitions | ||
| 147 | * @caps: capabilities for the profile | ||
| 148 | * @rlimits: rlimits for the profile | ||
| 149 | * | ||
| 150 | * The AppArmor profile contains the basic confinement data. Each profile | ||
| 151 | * has a name, and exists in a namespace. The @name and @exec_match are | ||
| 152 | * used to determine profile attachment against unconfined tasks. All other | ||
| 153 | * attachments are determined by profile X transition rules. | ||
| 154 | * | ||
| 155 | * The @replacedby field is write protected by the profile lock. Reads | ||
| 156 | * are assumed to be atomic, and are done without locking. | ||
| 157 | * | ||
| 158 | * Profiles have a hierarchy where hats and children profiles keep | ||
| 159 | * a reference to their parent. | ||
| 160 | * | ||
| 161 | * Profile names can not begin with a : and can not contain the \0 | ||
| 162 | * character. If a profile name begins with / it will be considered when | ||
| 163 | * determining profile attachment on "unconfined" tasks. | ||
| 164 | */ | ||
| 165 | struct aa_profile { | ||
| 166 | struct aa_policy base; | ||
| 167 | struct aa_profile *parent; | ||
| 168 | |||
| 169 | struct aa_namespace *ns; | ||
| 170 | struct aa_profile *replacedby; | ||
| 171 | const char *rename; | ||
| 172 | |||
| 173 | struct aa_dfa *xmatch; | ||
| 174 | int xmatch_len; | ||
| 175 | u32 sid; | ||
| 176 | enum audit_mode audit; | ||
| 177 | enum profile_mode mode; | ||
| 178 | u32 flags; | ||
| 179 | u32 path_flags; | ||
| 180 | int size; | ||
| 181 | |||
| 182 | struct aa_file_rules file; | ||
| 183 | struct aa_caps caps; | ||
| 184 | struct aa_rlimit rlimits; | ||
| 185 | }; | ||
| 186 | |||
| 187 | extern struct aa_namespace *root_ns; | ||
| 188 | extern enum profile_mode aa_g_profile_mode; | ||
| 189 | |||
| 190 | void aa_add_profile(struct aa_policy *common, struct aa_profile *profile); | ||
| 191 | |||
| 192 | bool aa_ns_visible(struct aa_namespace *curr, struct aa_namespace *view); | ||
| 193 | const char *aa_ns_name(struct aa_namespace *parent, struct aa_namespace *child); | ||
| 194 | int aa_alloc_root_ns(void); | ||
| 195 | void aa_free_root_ns(void); | ||
| 196 | void aa_free_namespace_kref(struct kref *kref); | ||
| 197 | |||
| 198 | struct aa_namespace *aa_find_namespace(struct aa_namespace *root, | ||
| 199 | const char *name); | ||
| 200 | |||
| 201 | static inline struct aa_policy *aa_get_common(struct aa_policy *c) | ||
| 202 | { | ||
| 203 | if (c) | ||
| 204 | kref_get(&c->count); | ||
| 205 | |||
| 206 | return c; | ||
| 207 | } | ||
| 208 | |||
| 209 | /** | ||
| 210 | * aa_get_namespace - increment references count on @ns | ||
| 211 | * @ns: namespace to increment reference count of (MAYBE NULL) | ||
| 212 | * | ||
| 213 | * Returns: pointer to @ns, if @ns is NULL returns NULL | ||
| 214 | * Requires: @ns must be held with valid refcount when called | ||
| 215 | */ | ||
| 216 | static inline struct aa_namespace *aa_get_namespace(struct aa_namespace *ns) | ||
| 217 | { | ||
| 218 | if (ns) | ||
| 219 | kref_get(&(ns->base.count)); | ||
| 220 | |||
| 221 | return ns; | ||
| 222 | } | ||
| 223 | |||
| 224 | /** | ||
| 225 | * aa_put_namespace - decrement refcount on @ns | ||
| 226 | * @ns: namespace to put reference of | ||
| 227 | * | ||
| 228 | * Decrement reference count of @ns and if no longer in use free it | ||
| 229 | */ | ||
| 230 | static inline void aa_put_namespace(struct aa_namespace *ns) | ||
| 231 | { | ||
| 232 | if (ns) | ||
| 233 | kref_put(&ns->base.count, aa_free_namespace_kref); | ||
| 234 | } | ||
| 235 | |||
| 236 | struct aa_profile *aa_alloc_profile(const char *name); | ||
| 237 | struct aa_profile *aa_new_null_profile(struct aa_profile *parent, int hat); | ||
| 238 | void aa_free_profile_kref(struct kref *kref); | ||
| 239 | struct aa_profile *aa_find_child(struct aa_profile *parent, const char *name); | ||
| 240 | struct aa_profile *aa_lookup_profile(struct aa_namespace *ns, const char *name); | ||
| 241 | struct aa_profile *aa_match_profile(struct aa_namespace *ns, const char *name); | ||
| 242 | |||
| 243 | ssize_t aa_replace_profiles(void *udata, size_t size, bool noreplace); | ||
| 244 | ssize_t aa_remove_profiles(char *name, size_t size); | ||
| 245 | |||
| 246 | #define PROF_ADD 1 | ||
| 247 | #define PROF_REPLACE 0 | ||
| 248 | |||
| 249 | #define unconfined(X) ((X)->flags & PFLAG_UNCONFINED) | ||
| 250 | |||
| 251 | /** | ||
| 252 | * aa_newest_version - find the newest version of @profile | ||
| 253 | * @profile: the profile to check for newer versions of (NOT NULL) | ||
| 254 | * | ||
| 255 | * Returns: newest version of @profile, if @profile is the newest version | ||
| 256 | * return @profile. | ||
| 257 | * | ||
| 258 | * NOTE: the profile returned is not refcounted, The refcount on @profile | ||
| 259 | * must be held until the caller decides what to do with the returned newest | ||
| 260 | * version. | ||
| 261 | */ | ||
| 262 | static inline struct aa_profile *aa_newest_version(struct aa_profile *profile) | ||
| 263 | { | ||
| 264 | while (profile->replacedby) | ||
| 265 | profile = profile->replacedby; | ||
| 266 | |||
| 267 | return profile; | ||
| 268 | } | ||
| 269 | |||
| 270 | /** | ||
| 271 | * aa_get_profile - increment refcount on profile @p | ||
| 272 | * @p: profile (MAYBE NULL) | ||
| 273 | * | ||
| 274 | * Returns: pointer to @p if @p is NULL will return NULL | ||
| 275 | * Requires: @p must be held with valid refcount when called | ||
| 276 | */ | ||
| 277 | static inline struct aa_profile *aa_get_profile(struct aa_profile *p) | ||
| 278 | { | ||
| 279 | if (p) | ||
| 280 | kref_get(&(p->base.count)); | ||
| 281 | |||
| 282 | return p; | ||
| 283 | } | ||
| 284 | |||
| 285 | /** | ||
| 286 | * aa_put_profile - decrement refcount on profile @p | ||
| 287 | * @p: profile (MAYBE NULL) | ||
| 288 | */ | ||
| 289 | static inline void aa_put_profile(struct aa_profile *p) | ||
| 290 | { | ||
| 291 | if (p) | ||
| 292 | kref_put(&p->base.count, aa_free_profile_kref); | ||
| 293 | } | ||
| 294 | |||
| 295 | static inline int AUDIT_MODE(struct aa_profile *profile) | ||
| 296 | { | ||
| 297 | if (aa_g_audit != AUDIT_NORMAL) | ||
| 298 | return aa_g_audit; | ||
| 299 | |||
| 300 | return profile->audit; | ||
| 301 | } | ||
| 302 | |||
| 303 | bool aa_may_manage_policy(int op); | ||
| 304 | |||
| 305 | #endif /* __AA_POLICY_H */ | ||
diff --git a/security/apparmor/include/policy_unpack.h b/security/apparmor/include/policy_unpack.h new file mode 100644 index 00000000000..a2dcccac45a --- /dev/null +++ b/security/apparmor/include/policy_unpack.h | |||
| @@ -0,0 +1,20 @@ | |||
| 1 | /* | ||
| 2 | * AppArmor security module | ||
| 3 | * | ||
| 4 | * This file contains AppArmor policy loading interface function definitions. | ||
| 5 | * | ||
| 6 | * Copyright (C) 1998-2008 Novell/SUSE | ||
| 7 | * Copyright 2009-2010 Canonical Ltd. | ||
| 8 | * | ||
| 9 | * This program is free software; you can redistribute it and/or | ||
| 10 | * modify it under the terms of the GNU General Public License as | ||
| 11 | * published by the Free Software Foundation, version 2 of the | ||
| 12 | * License. | ||
| 13 | */ | ||
| 14 | |||
| 15 | #ifndef __POLICY_INTERFACE_H | ||
| 16 | #define __POLICY_INTERFACE_H | ||
| 17 | |||
| 18 | struct aa_profile *aa_unpack(void *udata, size_t size, const char **ns); | ||
| 19 | |||
| 20 | #endif /* __POLICY_INTERFACE_H */ | ||
diff --git a/security/apparmor/include/procattr.h b/security/apparmor/include/procattr.h new file mode 100644 index 00000000000..544aa6b766a --- /dev/null +++ b/security/apparmor/include/procattr.h | |||
| @@ -0,0 +1,26 @@ | |||
| 1 | /* | ||
| 2 | * AppArmor security module | ||
| 3 | * | ||
| 4 | * This file contains AppArmor /proc/<pid>/attr/ interface function definitions. | ||
| 5 | * | ||
| 6 | * Copyright (C) 1998-2008 Novell/SUSE | ||
| 7 | * Copyright 2009-2010 Canonical Ltd. | ||
| 8 | * | ||
| 9 | * This program is free software; you can redistribute it and/or | ||
| 10 | * modify it under the terms of the GNU General Public License as | ||
| 11 | * published by the Free Software Foundation, version 2 of the | ||
| 12 | * License. | ||
| 13 | */ | ||
| 14 | |||
| 15 | #ifndef __AA_PROCATTR_H | ||
| 16 | #define __AA_PROCATTR_H | ||
| 17 | |||
| 18 | #define AA_DO_TEST 1 | ||
| 19 | #define AA_ONEXEC 1 | ||
| 20 | |||
| 21 | int aa_getprocattr(struct aa_profile *profile, char **string); | ||
| 22 | int aa_setprocattr_changehat(char *args, size_t size, int test); | ||
| 23 | int aa_setprocattr_changeprofile(char *fqname, bool onexec, int test); | ||
| 24 | int aa_setprocattr_permipc(char *fqname); | ||
| 25 | |||
| 26 | #endif /* __AA_PROCATTR_H */ | ||
diff --git a/security/apparmor/include/resource.h b/security/apparmor/include/resource.h new file mode 100644 index 00000000000..3c88be94649 --- /dev/null +++ b/security/apparmor/include/resource.h | |||
| @@ -0,0 +1,46 @@ | |||
| 1 | /* | ||
| 2 | * AppArmor security module | ||
| 3 | * | ||
| 4 | * This file contains AppArmor resource limits function definitions. | ||
| 5 | * | ||
| 6 | * Copyright (C) 1998-2008 Novell/SUSE | ||
| 7 | * Copyright 2009-2010 Canonical Ltd. | ||
| 8 | * | ||
| 9 | * This program is free software; you can redistribute it and/or | ||
| 10 | * modify it under the terms of the GNU General Public License as | ||
| 11 | * published by the Free Software Foundation, version 2 of the | ||
| 12 | * License. | ||
| 13 | */ | ||
| 14 | |||
| 15 | #ifndef __AA_RESOURCE_H | ||
| 16 | #define __AA_RESOURCE_H | ||
| 17 | |||
| 18 | #include <linux/resource.h> | ||
| 19 | #include <linux/sched.h> | ||
| 20 | |||
| 21 | struct aa_profile; | ||
| 22 | |||
| 23 | /* struct aa_rlimit - rlimit settings for the profile | ||
| 24 | * @mask: which hard limits to set | ||
| 25 | * @limits: rlimit values that override task limits | ||
| 26 | * | ||
| 27 | * AppArmor rlimits are used to set confined task rlimits. Only the | ||
| 28 | * limits specified in @mask will be controlled by apparmor. | ||
| 29 | */ | ||
| 30 | struct aa_rlimit { | ||
| 31 | unsigned int mask; | ||
| 32 | struct rlimit limits[RLIM_NLIMITS]; | ||
| 33 | }; | ||
| 34 | |||
| 35 | int aa_map_resource(int resource); | ||
| 36 | int aa_task_setrlimit(struct aa_profile *profile, unsigned int resource, | ||
| 37 | struct rlimit *new_rlim); | ||
| 38 | |||
| 39 | void __aa_transition_rlimits(struct aa_profile *old, struct aa_profile *new); | ||
| 40 | |||
| 41 | static inline void aa_free_rlimit_rules(struct aa_rlimit *rlims) | ||
| 42 | { | ||
| 43 | /* NOP */ | ||
| 44 | } | ||
| 45 | |||
| 46 | #endif /* __AA_RESOURCE_H */ | ||
diff --git a/security/apparmor/include/sid.h b/security/apparmor/include/sid.h new file mode 100644 index 00000000000..020db35c301 --- /dev/null +++ b/security/apparmor/include/sid.h | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | /* | ||
| 2 | * AppArmor security module | ||
| 3 | * | ||
| 4 | * This file contains AppArmor security identifier (sid) definitions | ||
| 5 | * | ||
| 6 | * Copyright 2009-2010 Canonical Ltd. | ||
| 7 | * | ||
| 8 | * This program is free software; you can redistribute it and/or | ||
| 9 | * modify it under the terms of the GNU General Public License as | ||
| 10 | * published by the Free Software Foundation, version 2 of the | ||
| 11 | * License. | ||
| 12 | */ | ||
| 13 | |||
| 14 | #ifndef __AA_SID_H | ||
| 15 | #define __AA_SID_H | ||
| 16 | |||
| 17 | #include <linux/types.h> | ||
| 18 | |||
| 19 | struct aa_profile; | ||
| 20 | |||
| 21 | u32 aa_alloc_sid(void); | ||
| 22 | void aa_free_sid(u32 sid); | ||
| 23 | |||
| 24 | #endif /* __AA_SID_H */ | ||
