diff options
author | Glenn Elliott <gelliott@cs.unc.edu> | 2012-03-04 19:47:13 -0500 |
---|---|---|
committer | Glenn Elliott <gelliott@cs.unc.edu> | 2012-03-04 19:47:13 -0500 |
commit | c71c03bda1e86c9d5198c5d83f712e695c4f2a1e (patch) | |
tree | ecb166cb3e2b7e2adb3b5e292245fefd23381ac8 /security/apparmor | |
parent | ea53c912f8a86a8567697115b6a0d8152beee5c8 (diff) | |
parent | 6a00f206debf8a5c8899055726ad127dbeeed098 (diff) |
Merge branch 'mpi-master' into wip-k-fmlpwip-k-fmlp
Conflicts:
litmus/sched_cedf.c
Diffstat (limited to 'security/apparmor')
-rw-r--r-- | security/apparmor/.gitignore | 1 | ||||
-rw-r--r-- | security/apparmor/Makefile | 38 | ||||
-rw-r--r-- | security/apparmor/apparmorfs.c | 13 | ||||
-rw-r--r-- | security/apparmor/include/file.h | 3 | ||||
-rw-r--r-- | security/apparmor/include/match.h | 3 | ||||
-rw-r--r-- | security/apparmor/lsm.c | 18 | ||||
-rw-r--r-- | security/apparmor/match.c | 4 | ||||
-rw-r--r-- | security/apparmor/path.c | 2 | ||||
-rw-r--r-- | security/apparmor/policy.c | 2 | ||||
-rw-r--r-- | security/apparmor/policy_unpack.c | 6 |
10 files changed, 62 insertions, 28 deletions
diff --git a/security/apparmor/.gitignore b/security/apparmor/.gitignore index 0a0a99f3b083..4d995aeaebc0 100644 --- a/security/apparmor/.gitignore +++ b/security/apparmor/.gitignore | |||
@@ -3,3 +3,4 @@ | |||
3 | # | 3 | # |
4 | af_names.h | 4 | af_names.h |
5 | capability_names.h | 5 | capability_names.h |
6 | rlim_names.h | ||
diff --git a/security/apparmor/Makefile b/security/apparmor/Makefile index f204869399ea..2dafe50a2e25 100644 --- a/security/apparmor/Makefile +++ b/security/apparmor/Makefile | |||
@@ -6,19 +6,47 @@ apparmor-y := apparmorfs.o audit.o capability.o context.o ipc.o lib.o match.o \ | |||
6 | path.o domain.o policy.o policy_unpack.o procattr.o lsm.o \ | 6 | path.o domain.o policy.o policy_unpack.o procattr.o lsm.o \ |
7 | resource.o sid.o file.o | 7 | resource.o sid.o file.o |
8 | 8 | ||
9 | clean-files: capability_names.h af_names.h | 9 | clean-files := capability_names.h rlim_names.h |
10 | 10 | ||
11 | |||
12 | # Build a lower case string table of capability names | ||
13 | # Transforms lines from | ||
14 | # #define CAP_DAC_OVERRIDE 1 | ||
15 | # to | ||
16 | # [1] = "dac_override", | ||
11 | quiet_cmd_make-caps = GEN $@ | 17 | quiet_cmd_make-caps = GEN $@ |
12 | cmd_make-caps = echo "static const char *capability_names[] = {" > $@ ; sed -n -e "/CAP_FS_MASK/d" -e "s/^\#define[ \\t]\\+CAP_\\([A-Z0-9_]\\+\\)[ \\t]\\+\\([0-9]\\+\\)\$$/[\\2] = \"\\1\",/p" $< | tr A-Z a-z >> $@ ; echo "};" >> $@ | 18 | cmd_make-caps = echo "static const char *capability_names[] = {" > $@ ;\ |
19 | sed $< >>$@ -r -n -e '/CAP_FS_MASK/d' \ | ||
20 | -e 's/^\#define[ \t]+CAP_([A-Z0-9_]+)[ \t]+([0-9]+)/[\2] = "\L\1",/p';\ | ||
21 | echo "};" >> $@ | ||
22 | |||
13 | 23 | ||
24 | # Build a lower case string table of rlimit names. | ||
25 | # Transforms lines from | ||
26 | # #define RLIMIT_STACK 3 /* max stack size */ | ||
27 | # to | ||
28 | # [RLIMIT_STACK] = "stack", | ||
29 | # | ||
30 | # and build a second integer table (with the second sed cmd), that maps | ||
31 | # RLIMIT defines to the order defined in asm-generic/resource.h Thi is | ||
32 | # required by policy load to map policy ordering of RLIMITs to internal | ||
33 | # ordering for architectures that redefine an RLIMIT. | ||
34 | # Transforms lines from | ||
35 | # #define RLIMIT_STACK 3 /* max stack size */ | ||
36 | # to | ||
37 | # RLIMIT_STACK, | ||
14 | quiet_cmd_make-rlim = GEN $@ | 38 | quiet_cmd_make-rlim = GEN $@ |
15 | cmd_make-rlim = echo "static const char *rlim_names[] = {" > $@ ; sed -n --e "/AF_MAX/d" -e "s/^\# \\?define[ \\t]\\+RLIMIT_\\([A-Z0-9_]\\+\\)[ \\t]\\+\\([0-9]\\+\\)\\(.*\\)\$$/[\\2] = \"\\1\",/p" $< | tr A-Z a-z >> $@ ; echo "};" >> $@ ; echo "static const int rlim_map[] = {" >> $@ ; sed -n -e "/AF_MAX/d" -e "s/^\# \\?define[ \\t]\\+\\(RLIMIT_[A-Z0-9_]\\+\\)[ \\t]\\+\\([0-9]\\+\\)\\(.*\\)\$$/\\1,/p" $< >> $@ ; echo "};" >> $@ | 39 | cmd_make-rlim = echo "static const char *rlim_names[] = {" > $@ ;\ |
40 | sed $< >> $@ -r -n \ | ||
41 | -e 's/^\# ?define[ \t]+(RLIMIT_([A-Z0-9_]+)).*/[\1] = "\L\2",/p';\ | ||
42 | echo "};" >> $@ ;\ | ||
43 | echo "static const int rlim_map[] = {" >> $@ ;\ | ||
44 | sed -r -n "s/^\# ?define[ \t]+(RLIMIT_[A-Z0-9_]+).*/\1,/p" $< >> $@ ;\ | ||
45 | echo "};" >> $@ | ||
16 | 46 | ||
17 | $(obj)/capability.o : $(obj)/capability_names.h | 47 | $(obj)/capability.o : $(obj)/capability_names.h |
18 | $(obj)/resource.o : $(obj)/rlim_names.h | 48 | $(obj)/resource.o : $(obj)/rlim_names.h |
19 | $(obj)/capability_names.h : $(srctree)/include/linux/capability.h | 49 | $(obj)/capability_names.h : $(srctree)/include/linux/capability.h |
20 | $(call cmd,make-caps) | 50 | $(call cmd,make-caps) |
21 | $(obj)/af_names.h : $(srctree)/include/linux/socket.h | ||
22 | $(call cmd,make-af) | ||
23 | $(obj)/rlim_names.h : $(srctree)/include/asm-generic/resource.h | 51 | $(obj)/rlim_names.h : $(srctree)/include/asm-generic/resource.h |
24 | $(call cmd,make-rlim) | 52 | $(call cmd,make-rlim) |
diff --git a/security/apparmor/apparmorfs.c b/security/apparmor/apparmorfs.c index 7320331b44ab..0848292982a2 100644 --- a/security/apparmor/apparmorfs.c +++ b/security/apparmor/apparmorfs.c | |||
@@ -29,7 +29,7 @@ | |||
29 | * aa_simple_write_to_buffer - common routine for getting policy from user | 29 | * aa_simple_write_to_buffer - common routine for getting policy from user |
30 | * @op: operation doing the user buffer copy | 30 | * @op: operation doing the user buffer copy |
31 | * @userbuf: user buffer to copy data from (NOT NULL) | 31 | * @userbuf: user buffer to copy data from (NOT NULL) |
32 | * @alloc_size: size of user buffer | 32 | * @alloc_size: size of user buffer (REQUIRES: @alloc_size >= @copy_size) |
33 | * @copy_size: size of data to copy from user buffer | 33 | * @copy_size: size of data to copy from user buffer |
34 | * @pos: position write is at in the file (NOT NULL) | 34 | * @pos: position write is at in the file (NOT NULL) |
35 | * | 35 | * |
@@ -42,6 +42,8 @@ static char *aa_simple_write_to_buffer(int op, const char __user *userbuf, | |||
42 | { | 42 | { |
43 | char *data; | 43 | char *data; |
44 | 44 | ||
45 | BUG_ON(copy_size > alloc_size); | ||
46 | |||
45 | if (*pos != 0) | 47 | if (*pos != 0) |
46 | /* only writes from pos 0, that is complete writes */ | 48 | /* only writes from pos 0, that is complete writes */ |
47 | return ERR_PTR(-ESPIPE); | 49 | return ERR_PTR(-ESPIPE); |
@@ -86,7 +88,8 @@ static ssize_t profile_load(struct file *f, const char __user *buf, size_t size, | |||
86 | } | 88 | } |
87 | 89 | ||
88 | static const struct file_operations aa_fs_profile_load = { | 90 | static const struct file_operations aa_fs_profile_load = { |
89 | .write = profile_load | 91 | .write = profile_load, |
92 | .llseek = default_llseek, | ||
90 | }; | 93 | }; |
91 | 94 | ||
92 | /* .replace file hook fn to load and/or replace policy */ | 95 | /* .replace file hook fn to load and/or replace policy */ |
@@ -107,7 +110,8 @@ static ssize_t profile_replace(struct file *f, const char __user *buf, | |||
107 | } | 110 | } |
108 | 111 | ||
109 | static const struct file_operations aa_fs_profile_replace = { | 112 | static const struct file_operations aa_fs_profile_replace = { |
110 | .write = profile_replace | 113 | .write = profile_replace, |
114 | .llseek = default_llseek, | ||
111 | }; | 115 | }; |
112 | 116 | ||
113 | /* .remove file hook fn to remove loaded policy */ | 117 | /* .remove file hook fn to remove loaded policy */ |
@@ -134,7 +138,8 @@ static ssize_t profile_remove(struct file *f, const char __user *buf, | |||
134 | } | 138 | } |
135 | 139 | ||
136 | static const struct file_operations aa_fs_profile_remove = { | 140 | static const struct file_operations aa_fs_profile_remove = { |
137 | .write = profile_remove | 141 | .write = profile_remove, |
142 | .llseek = default_llseek, | ||
138 | }; | 143 | }; |
139 | 144 | ||
140 | /** Base file system setup **/ | 145 | /** Base file system setup **/ |
diff --git a/security/apparmor/include/file.h b/security/apparmor/include/file.h index be36feabb16a..ab8c6d87f758 100644 --- a/security/apparmor/include/file.h +++ b/security/apparmor/include/file.h | |||
@@ -15,12 +15,11 @@ | |||
15 | #ifndef __AA_FILE_H | 15 | #ifndef __AA_FILE_H |
16 | #define __AA_FILE_H | 16 | #define __AA_FILE_H |
17 | 17 | ||
18 | #include <linux/path.h> | ||
19 | |||
20 | #include "domain.h" | 18 | #include "domain.h" |
21 | #include "match.h" | 19 | #include "match.h" |
22 | 20 | ||
23 | struct aa_profile; | 21 | struct aa_profile; |
22 | struct path; | ||
24 | 23 | ||
25 | /* | 24 | /* |
26 | * We use MAY_EXEC, MAY_WRITE, MAY_READ, MAY_APPEND and the following flags | 25 | * We use MAY_EXEC, MAY_WRITE, MAY_READ, MAY_APPEND and the following flags |
diff --git a/security/apparmor/include/match.h b/security/apparmor/include/match.h index 734a6d35112c..a4a863997bd5 100644 --- a/security/apparmor/include/match.h +++ b/security/apparmor/include/match.h | |||
@@ -15,6 +15,7 @@ | |||
15 | #ifndef __AA_MATCH_H | 15 | #ifndef __AA_MATCH_H |
16 | #define __AA_MATCH_H | 16 | #define __AA_MATCH_H |
17 | 17 | ||
18 | #include <linux/kref.h> | ||
18 | #include <linux/workqueue.h> | 19 | #include <linux/workqueue.h> |
19 | 20 | ||
20 | #define DFA_NOMATCH 0 | 21 | #define DFA_NOMATCH 0 |
@@ -27,7 +28,7 @@ | |||
27 | * The format used for transition tables is based on the GNU flex table | 28 | * 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 | * 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 | * info pages and the flex sources for documentation). The magic number |
30 | * used in the header is 0x1B5E783D insted of 0xF13C57B1 though, because | 31 | * used in the header is 0x1B5E783D instead of 0xF13C57B1 though, because |
31 | * the YY_ID_CHK (check) and YY_ID_DEF (default) tables are used | 32 | * the YY_ID_CHK (check) and YY_ID_DEF (default) tables are used |
32 | * slightly differently (see the apparmor-parser package). | 33 | * slightly differently (see the apparmor-parser package). |
33 | */ | 34 | */ |
diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c index cf1de4462ccd..3d2fd141dff7 100644 --- a/security/apparmor/lsm.c +++ b/security/apparmor/lsm.c | |||
@@ -22,6 +22,7 @@ | |||
22 | #include <linux/ctype.h> | 22 | #include <linux/ctype.h> |
23 | #include <linux/sysctl.h> | 23 | #include <linux/sysctl.h> |
24 | #include <linux/audit.h> | 24 | #include <linux/audit.h> |
25 | #include <linux/user_namespace.h> | ||
25 | #include <net/sock.h> | 26 | #include <net/sock.h> |
26 | 27 | ||
27 | #include "include/apparmor.h" | 28 | #include "include/apparmor.h" |
@@ -136,11 +137,11 @@ static int apparmor_capget(struct task_struct *target, kernel_cap_t *effective, | |||
136 | } | 137 | } |
137 | 138 | ||
138 | static int apparmor_capable(struct task_struct *task, const struct cred *cred, | 139 | static int apparmor_capable(struct task_struct *task, const struct cred *cred, |
139 | int cap, int audit) | 140 | struct user_namespace *ns, int cap, int audit) |
140 | { | 141 | { |
141 | struct aa_profile *profile; | 142 | struct aa_profile *profile; |
142 | /* cap_capable returns 0 on success, else -EPERM */ | 143 | /* cap_capable returns 0 on success, else -EPERM */ |
143 | int error = cap_capable(task, cred, cap, audit); | 144 | int error = cap_capable(task, cred, ns, cap, audit); |
144 | if (!error) { | 145 | if (!error) { |
145 | profile = aa_cred_profile(cred); | 146 | profile = aa_cred_profile(cred); |
146 | if (!unconfined(profile)) | 147 | if (!unconfined(profile)) |
@@ -592,7 +593,8 @@ static int apparmor_setprocattr(struct task_struct *task, char *name, | |||
592 | sa.aad.op = OP_SETPROCATTR; | 593 | sa.aad.op = OP_SETPROCATTR; |
593 | sa.aad.info = name; | 594 | sa.aad.info = name; |
594 | sa.aad.error = -EINVAL; | 595 | sa.aad.error = -EINVAL; |
595 | return aa_audit(AUDIT_APPARMOR_DENIED, NULL, GFP_KERNEL, | 596 | return aa_audit(AUDIT_APPARMOR_DENIED, |
597 | __aa_current_profile(), GFP_KERNEL, | ||
596 | &sa, NULL); | 598 | &sa, NULL); |
597 | } | 599 | } |
598 | } else if (strcmp(name, "exec") == 0) { | 600 | } else if (strcmp(name, "exec") == 0) { |
@@ -610,7 +612,7 @@ static int apparmor_setprocattr(struct task_struct *task, char *name, | |||
610 | static int apparmor_task_setrlimit(struct task_struct *task, | 612 | static int apparmor_task_setrlimit(struct task_struct *task, |
611 | unsigned int resource, struct rlimit *new_rlim) | 613 | unsigned int resource, struct rlimit *new_rlim) |
612 | { | 614 | { |
613 | struct aa_profile *profile = aa_current_profile(); | 615 | struct aa_profile *profile = __aa_current_profile(); |
614 | int error = 0; | 616 | int error = 0; |
615 | 617 | ||
616 | if (!unconfined(profile)) | 618 | if (!unconfined(profile)) |
@@ -693,11 +695,9 @@ static struct kernel_param_ops param_ops_aalockpolicy = { | |||
693 | 695 | ||
694 | static int param_set_audit(const char *val, struct kernel_param *kp); | 696 | static int param_set_audit(const char *val, struct kernel_param *kp); |
695 | static int param_get_audit(char *buffer, struct kernel_param *kp); | 697 | static int param_get_audit(char *buffer, struct kernel_param *kp); |
696 | #define param_check_audit(name, p) __param_check(name, p, int) | ||
697 | 698 | ||
698 | static int param_set_mode(const char *val, struct kernel_param *kp); | 699 | static int param_set_mode(const char *val, struct kernel_param *kp); |
699 | static int param_get_mode(char *buffer, struct kernel_param *kp); | 700 | static int param_get_mode(char *buffer, struct kernel_param *kp); |
700 | #define param_check_mode(name, p) __param_check(name, p, int) | ||
701 | 701 | ||
702 | /* Flag values, also controllable via /sys/module/apparmor/parameters | 702 | /* Flag values, also controllable via /sys/module/apparmor/parameters |
703 | * We define special types as we want to do additional mediation. | 703 | * We define special types as we want to do additional mediation. |
@@ -922,7 +922,7 @@ static int __init apparmor_init(void) | |||
922 | error = register_security(&apparmor_ops); | 922 | error = register_security(&apparmor_ops); |
923 | if (error) { | 923 | if (error) { |
924 | AA_ERROR("Unable to register AppArmor\n"); | 924 | AA_ERROR("Unable to register AppArmor\n"); |
925 | goto register_security_out; | 925 | goto set_init_cxt_out; |
926 | } | 926 | } |
927 | 927 | ||
928 | /* Report that AppArmor successfully initialized */ | 928 | /* Report that AppArmor successfully initialized */ |
@@ -936,6 +936,9 @@ static int __init apparmor_init(void) | |||
936 | 936 | ||
937 | return error; | 937 | return error; |
938 | 938 | ||
939 | set_init_cxt_out: | ||
940 | aa_free_task_context(current->real_cred->security); | ||
941 | |||
939 | register_security_out: | 942 | register_security_out: |
940 | aa_free_root_ns(); | 943 | aa_free_root_ns(); |
941 | 944 | ||
@@ -944,7 +947,6 @@ alloc_out: | |||
944 | 947 | ||
945 | apparmor_enabled = 0; | 948 | apparmor_enabled = 0; |
946 | return error; | 949 | return error; |
947 | |||
948 | } | 950 | } |
949 | 951 | ||
950 | security_initcall(apparmor_init); | 952 | security_initcall(apparmor_init); |
diff --git a/security/apparmor/match.c b/security/apparmor/match.c index 5cb4dc1f6992..94de6b4907c8 100644 --- a/security/apparmor/match.c +++ b/security/apparmor/match.c | |||
@@ -194,8 +194,8 @@ void aa_dfa_free_kref(struct kref *kref) | |||
194 | * @flags: flags controlling what type of accept tables are acceptable | 194 | * @flags: flags controlling what type of accept tables are acceptable |
195 | * | 195 | * |
196 | * Unpack a dfa that has been serialized. To find information on the dfa | 196 | * Unpack a dfa that has been serialized. To find information on the dfa |
197 | * format look in Documentation/apparmor.txt | 197 | * format look in Documentation/security/apparmor.txt |
198 | * Assumes the dfa @blob stream has been aligned on a 8 byte boundry | 198 | * Assumes the dfa @blob stream has been aligned on a 8 byte boundary |
199 | * | 199 | * |
200 | * Returns: an unpacked dfa ready for matching or ERR_PTR on failure | 200 | * Returns: an unpacked dfa ready for matching or ERR_PTR on failure |
201 | */ | 201 | */ |
diff --git a/security/apparmor/path.c b/security/apparmor/path.c index 82396050f186..36cc0cc39e78 100644 --- a/security/apparmor/path.c +++ b/security/apparmor/path.c | |||
@@ -72,10 +72,8 @@ static int d_namespace_path(struct path *path, char *buf, int buflen, | |||
72 | path_get(&root); | 72 | path_get(&root); |
73 | } | 73 | } |
74 | 74 | ||
75 | spin_lock(&dcache_lock); | ||
76 | tmp = root; | 75 | tmp = root; |
77 | res = __d_path(path, &tmp, buf, buflen); | 76 | res = __d_path(path, &tmp, buf, buflen); |
78 | spin_unlock(&dcache_lock); | ||
79 | 77 | ||
80 | *name = res; | 78 | *name = res; |
81 | /* handle error conditions - and still allow a partial path to | 79 | /* handle error conditions - and still allow a partial path to |
diff --git a/security/apparmor/policy.c b/security/apparmor/policy.c index 52cc865f1464..4f0eadee78b8 100644 --- a/security/apparmor/policy.c +++ b/security/apparmor/policy.c | |||
@@ -306,7 +306,7 @@ static struct aa_namespace *alloc_namespace(const char *prefix, | |||
306 | return ns; | 306 | return ns; |
307 | 307 | ||
308 | fail_unconfined: | 308 | fail_unconfined: |
309 | kzfree(ns->base.name); | 309 | kzfree(ns->base.hname); |
310 | fail_ns: | 310 | fail_ns: |
311 | kzfree(ns); | 311 | kzfree(ns); |
312 | return NULL; | 312 | return NULL; |
diff --git a/security/apparmor/policy_unpack.c b/security/apparmor/policy_unpack.c index eb3700e9fd37..d6d9a57b5652 100644 --- a/security/apparmor/policy_unpack.c +++ b/security/apparmor/policy_unpack.c | |||
@@ -12,8 +12,8 @@ | |||
12 | * published by the Free Software Foundation, version 2 of the | 12 | * published by the Free Software Foundation, version 2 of the |
13 | * License. | 13 | * License. |
14 | * | 14 | * |
15 | * AppArmor uses a serialized binary format for loading policy. | 15 | * AppArmor uses a serialized binary format for loading policy. To find |
16 | * To find policy format documentation look in Documentation/apparmor.txt | 16 | * policy format documentation look in Documentation/security/apparmor.txt |
17 | * All policy is validated before it is used. | 17 | * All policy is validated before it is used. |
18 | */ | 18 | */ |
19 | 19 | ||
@@ -359,7 +359,7 @@ fail: | |||
359 | * @e: serialized data extent information (NOT NULL) | 359 | * @e: serialized data extent information (NOT NULL) |
360 | * @profile: profile to add the accept table to (NOT NULL) | 360 | * @profile: profile to add the accept table to (NOT NULL) |
361 | * | 361 | * |
362 | * Returns: 1 if table succesfully unpacked | 362 | * Returns: 1 if table successfully unpacked |
363 | */ | 363 | */ |
364 | static bool unpack_trans_table(struct aa_ext *e, struct aa_profile *profile) | 364 | static bool unpack_trans_table(struct aa_ext *e, struct aa_profile *profile) |
365 | { | 365 | { |