diff options
Diffstat (limited to 'scripts/selinux')
-rw-r--r-- | scripts/selinux/Makefile | 4 | ||||
-rw-r--r-- | scripts/selinux/genheaders/.gitignore | 1 | ||||
-rw-r--r-- | scripts/selinux/genheaders/Makefile | 5 | ||||
-rw-r--r-- | scripts/selinux/genheaders/genheaders.c | 118 | ||||
-rw-r--r-- | scripts/selinux/mdp/mdp.c | 151 |
5 files changed, 154 insertions, 125 deletions
diff --git a/scripts/selinux/Makefile b/scripts/selinux/Makefile index ca4b1ec01822..e8049da1831f 100644 --- a/scripts/selinux/Makefile +++ b/scripts/selinux/Makefile | |||
@@ -1,2 +1,2 @@ | |||
1 | subdir-y := mdp | 1 | subdir-y := mdp genheaders |
2 | subdir- += mdp | 2 | subdir- += mdp genheaders |
diff --git a/scripts/selinux/genheaders/.gitignore b/scripts/selinux/genheaders/.gitignore new file mode 100644 index 000000000000..4c0b646ff8d5 --- /dev/null +++ b/scripts/selinux/genheaders/.gitignore | |||
@@ -0,0 +1 @@ | |||
genheaders | |||
diff --git a/scripts/selinux/genheaders/Makefile b/scripts/selinux/genheaders/Makefile new file mode 100644 index 000000000000..417b165008ee --- /dev/null +++ b/scripts/selinux/genheaders/Makefile | |||
@@ -0,0 +1,5 @@ | |||
1 | hostprogs-y := genheaders | ||
2 | HOST_EXTRACFLAGS += -Isecurity/selinux/include | ||
3 | |||
4 | always := $(hostprogs-y) | ||
5 | clean-files := $(hostprogs-y) | ||
diff --git a/scripts/selinux/genheaders/genheaders.c b/scripts/selinux/genheaders/genheaders.c new file mode 100644 index 000000000000..24626968055d --- /dev/null +++ b/scripts/selinux/genheaders/genheaders.c | |||
@@ -0,0 +1,118 @@ | |||
1 | #include <stdio.h> | ||
2 | #include <stdlib.h> | ||
3 | #include <unistd.h> | ||
4 | #include <string.h> | ||
5 | #include <errno.h> | ||
6 | #include <ctype.h> | ||
7 | |||
8 | struct security_class_mapping { | ||
9 | const char *name; | ||
10 | const char *perms[sizeof(unsigned) * 8 + 1]; | ||
11 | }; | ||
12 | |||
13 | #include "classmap.h" | ||
14 | #include "initial_sid_to_string.h" | ||
15 | |||
16 | #define max(x, y) (((int)(x) > (int)(y)) ? x : y) | ||
17 | |||
18 | const char *progname; | ||
19 | |||
20 | static void usage(void) | ||
21 | { | ||
22 | printf("usage: %s flask.h av_permissions.h\n", progname); | ||
23 | exit(1); | ||
24 | } | ||
25 | |||
26 | static char *stoupperx(const char *s) | ||
27 | { | ||
28 | char *s2 = strdup(s); | ||
29 | char *p; | ||
30 | |||
31 | if (!s2) { | ||
32 | fprintf(stderr, "%s: out of memory\n", progname); | ||
33 | exit(3); | ||
34 | } | ||
35 | |||
36 | for (p = s2; *p; p++) | ||
37 | *p = toupper(*p); | ||
38 | return s2; | ||
39 | } | ||
40 | |||
41 | int main(int argc, char *argv[]) | ||
42 | { | ||
43 | int i, j, k; | ||
44 | int isids_len; | ||
45 | FILE *fout; | ||
46 | |||
47 | progname = argv[0]; | ||
48 | |||
49 | if (argc < 3) | ||
50 | usage(); | ||
51 | |||
52 | fout = fopen(argv[1], "w"); | ||
53 | if (!fout) { | ||
54 | fprintf(stderr, "Could not open %s for writing: %s\n", | ||
55 | argv[1], strerror(errno)); | ||
56 | exit(2); | ||
57 | } | ||
58 | |||
59 | for (i = 0; secclass_map[i].name; i++) { | ||
60 | struct security_class_mapping *map = &secclass_map[i]; | ||
61 | map->name = stoupperx(map->name); | ||
62 | for (j = 0; map->perms[j]; j++) | ||
63 | map->perms[j] = stoupperx(map->perms[j]); | ||
64 | } | ||
65 | |||
66 | isids_len = sizeof(initial_sid_to_string) / sizeof (char *); | ||
67 | for (i = 1; i < isids_len; i++) | ||
68 | initial_sid_to_string[i] = stoupperx(initial_sid_to_string[i]); | ||
69 | |||
70 | fprintf(fout, "/* This file is automatically generated. Do not edit. */\n"); | ||
71 | fprintf(fout, "#ifndef _SELINUX_FLASK_H_\n#define _SELINUX_FLASK_H_\n\n"); | ||
72 | |||
73 | for (i = 0; secclass_map[i].name; i++) { | ||
74 | struct security_class_mapping *map = &secclass_map[i]; | ||
75 | fprintf(fout, "#define SECCLASS_%s", map->name); | ||
76 | for (j = 0; j < max(1, 40 - strlen(map->name)); j++) | ||
77 | fprintf(fout, " "); | ||
78 | fprintf(fout, "%2d\n", i+1); | ||
79 | } | ||
80 | |||
81 | fprintf(fout, "\n"); | ||
82 | |||
83 | for (i = 1; i < isids_len; i++) { | ||
84 | char *s = initial_sid_to_string[i]; | ||
85 | fprintf(fout, "#define SECINITSID_%s", s); | ||
86 | for (j = 0; j < max(1, 40 - strlen(s)); j++) | ||
87 | fprintf(fout, " "); | ||
88 | fprintf(fout, "%2d\n", i); | ||
89 | } | ||
90 | fprintf(fout, "\n#define SECINITSID_NUM %d\n", i-1); | ||
91 | fprintf(fout, "\n#endif\n"); | ||
92 | fclose(fout); | ||
93 | |||
94 | fout = fopen(argv[2], "w"); | ||
95 | if (!fout) { | ||
96 | fprintf(stderr, "Could not open %s for writing: %s\n", | ||
97 | argv[2], strerror(errno)); | ||
98 | exit(4); | ||
99 | } | ||
100 | |||
101 | fprintf(fout, "/* This file is automatically generated. Do not edit. */\n"); | ||
102 | fprintf(fout, "#ifndef _SELINUX_AV_PERMISSIONS_H_\n#define _SELINUX_AV_PERMISSIONS_H_\n\n"); | ||
103 | |||
104 | for (i = 0; secclass_map[i].name; i++) { | ||
105 | struct security_class_mapping *map = &secclass_map[i]; | ||
106 | for (j = 0; map->perms[j]; j++) { | ||
107 | fprintf(fout, "#define %s__%s", map->name, | ||
108 | map->perms[j]); | ||
109 | for (k = 0; k < max(1, 40 - strlen(map->name) - strlen(map->perms[j])); k++) | ||
110 | fprintf(fout, " "); | ||
111 | fprintf(fout, "0x%08xUL\n", (1<<j)); | ||
112 | } | ||
113 | } | ||
114 | |||
115 | fprintf(fout, "\n#endif\n"); | ||
116 | fclose(fout); | ||
117 | exit(0); | ||
118 | } | ||
diff --git a/scripts/selinux/mdp/mdp.c b/scripts/selinux/mdp/mdp.c index b4ced8562587..62b34ce1f50d 100644 --- a/scripts/selinux/mdp/mdp.c +++ b/scripts/selinux/mdp/mdp.c | |||
@@ -29,86 +29,27 @@ | |||
29 | #include <unistd.h> | 29 | #include <unistd.h> |
30 | #include <string.h> | 30 | #include <string.h> |
31 | 31 | ||
32 | #include "flask.h" | ||
33 | |||
34 | static void usage(char *name) | 32 | static void usage(char *name) |
35 | { | 33 | { |
36 | printf("usage: %s [-m] policy_file context_file\n", name); | 34 | printf("usage: %s [-m] policy_file context_file\n", name); |
37 | exit(1); | 35 | exit(1); |
38 | } | 36 | } |
39 | 37 | ||
40 | static void find_common_name(char *cname, char *dest, int len) | 38 | /* Class/perm mapping support */ |
41 | { | 39 | struct security_class_mapping { |
42 | char *start, *end; | 40 | const char *name; |
43 | 41 | const char *perms[sizeof(unsigned) * 8 + 1]; | |
44 | start = strchr(cname, '_')+1; | ||
45 | end = strchr(start, '_'); | ||
46 | if (!start || !end || start-cname > len || end-start > len) { | ||
47 | printf("Error with commons defines\n"); | ||
48 | exit(1); | ||
49 | } | ||
50 | strncpy(dest, start, end-start); | ||
51 | dest[end-start] = '\0'; | ||
52 | } | ||
53 | |||
54 | #define S_(x) x, | ||
55 | static char *classlist[] = { | ||
56 | #include "class_to_string.h" | ||
57 | NULL | ||
58 | }; | 42 | }; |
59 | #undef S_ | ||
60 | 43 | ||
44 | #include "classmap.h" | ||
61 | #include "initial_sid_to_string.h" | 45 | #include "initial_sid_to_string.h" |
62 | 46 | ||
63 | #define TB_(x) char *x[] = { | ||
64 | #define TE_(x) NULL }; | ||
65 | #define S_(x) x, | ||
66 | #include "common_perm_to_string.h" | ||
67 | #undef TB_ | ||
68 | #undef TE_ | ||
69 | #undef S_ | ||
70 | |||
71 | struct common { | ||
72 | char *cname; | ||
73 | char **perms; | ||
74 | }; | ||
75 | struct common common[] = { | ||
76 | #define TB_(x) { #x, x }, | ||
77 | #define S_(x) | ||
78 | #define TE_(x) | ||
79 | #include "common_perm_to_string.h" | ||
80 | #undef TB_ | ||
81 | #undef TE_ | ||
82 | #undef S_ | ||
83 | }; | ||
84 | |||
85 | #define S_(x, y, z) {x, #y}, | ||
86 | struct av_inherit { | ||
87 | int class; | ||
88 | char *common; | ||
89 | }; | ||
90 | struct av_inherit av_inherit[] = { | ||
91 | #include "av_inherit.h" | ||
92 | }; | ||
93 | #undef S_ | ||
94 | |||
95 | #include "av_permissions.h" | ||
96 | #define S_(x, y, z) {x, y, z}, | ||
97 | struct av_perms { | ||
98 | int class; | ||
99 | int perm_i; | ||
100 | char *perm_s; | ||
101 | }; | ||
102 | struct av_perms av_perms[] = { | ||
103 | #include "av_perm_to_string.h" | ||
104 | }; | ||
105 | #undef S_ | ||
106 | |||
107 | int main(int argc, char *argv[]) | 47 | int main(int argc, char *argv[]) |
108 | { | 48 | { |
109 | int i, j, mls = 0; | 49 | int i, j, mls = 0; |
50 | int initial_sid_to_string_len; | ||
110 | char **arg, *polout, *ctxout; | 51 | char **arg, *polout, *ctxout; |
111 | int classlist_len, initial_sid_to_string_len; | 52 | |
112 | FILE *fout; | 53 | FILE *fout; |
113 | 54 | ||
114 | if (argc < 3) | 55 | if (argc < 3) |
@@ -127,64 +68,25 @@ int main(int argc, char *argv[]) | |||
127 | usage(argv[0]); | 68 | usage(argv[0]); |
128 | } | 69 | } |
129 | 70 | ||
130 | classlist_len = sizeof(classlist) / sizeof(char *); | ||
131 | /* print out the classes */ | 71 | /* print out the classes */ |
132 | for (i=1; i < classlist_len; i++) { | 72 | for (i = 0; secclass_map[i].name; i++) |
133 | if(classlist[i]) | 73 | fprintf(fout, "class %s\n", secclass_map[i].name); |
134 | fprintf(fout, "class %s\n", classlist[i]); | ||
135 | else | ||
136 | fprintf(fout, "class user%d\n", i); | ||
137 | } | ||
138 | fprintf(fout, "\n"); | 74 | fprintf(fout, "\n"); |
139 | 75 | ||
140 | initial_sid_to_string_len = sizeof(initial_sid_to_string) / sizeof (char *); | 76 | initial_sid_to_string_len = sizeof(initial_sid_to_string) / sizeof (char *); |
141 | /* print out the sids */ | 77 | /* print out the sids */ |
142 | for (i=1; i < initial_sid_to_string_len; i++) | 78 | for (i = 1; i < initial_sid_to_string_len; i++) |
143 | fprintf(fout, "sid %s\n", initial_sid_to_string[i]); | 79 | fprintf(fout, "sid %s\n", initial_sid_to_string[i]); |
144 | fprintf(fout, "\n"); | 80 | fprintf(fout, "\n"); |
145 | 81 | ||
146 | /* print out the commons */ | ||
147 | for (i=0; i< sizeof(common)/sizeof(struct common); i++) { | ||
148 | char cname[101]; | ||
149 | find_common_name(common[i].cname, cname, 100); | ||
150 | cname[100] = '\0'; | ||
151 | fprintf(fout, "common %s\n{\n", cname); | ||
152 | for (j=0; common[i].perms[j]; j++) | ||
153 | fprintf(fout, "\t%s\n", common[i].perms[j]); | ||
154 | fprintf(fout, "}\n\n"); | ||
155 | } | ||
156 | fprintf(fout, "\n"); | ||
157 | |||
158 | /* print out the class permissions */ | 82 | /* print out the class permissions */ |
159 | for (i=1; i < classlist_len; i++) { | 83 | for (i = 0; secclass_map[i].name; i++) { |
160 | if (classlist[i]) { | 84 | struct security_class_mapping *map = &secclass_map[i]; |
161 | int firstperm = -1, numperms = 0; | 85 | fprintf(fout, "class %s\n", map->name); |
162 | 86 | fprintf(fout, "{\n"); | |
163 | fprintf(fout, "class %s\n", classlist[i]); | 87 | for (j = 0; map->perms[j]; j++) |
164 | /* does it inherit from a common? */ | 88 | fprintf(fout, "\t%s\n", map->perms[j]); |
165 | for (j=0; j < sizeof(av_inherit)/sizeof(struct av_inherit); j++) | 89 | fprintf(fout, "}\n\n"); |
166 | if (av_inherit[j].class == i) | ||
167 | fprintf(fout, "inherits %s\n", av_inherit[j].common); | ||
168 | |||
169 | for (j=0; j < sizeof(av_perms)/sizeof(struct av_perms); j++) { | ||
170 | if (av_perms[j].class == i) { | ||
171 | if (firstperm == -1) | ||
172 | firstperm = j; | ||
173 | numperms++; | ||
174 | } | ||
175 | } | ||
176 | if (!numperms) { | ||
177 | fprintf(fout, "\n"); | ||
178 | continue; | ||
179 | } | ||
180 | |||
181 | fprintf(fout, "{\n"); | ||
182 | /* print out the av_perms */ | ||
183 | for (j=0; j < numperms; j++) { | ||
184 | fprintf(fout, "\t%s\n", av_perms[firstperm+j].perm_s); | ||
185 | } | ||
186 | fprintf(fout, "}\n\n"); | ||
187 | } | ||
188 | } | 90 | } |
189 | fprintf(fout, "\n"); | 91 | fprintf(fout, "\n"); |
190 | 92 | ||
@@ -197,31 +99,34 @@ int main(int argc, char *argv[]) | |||
197 | /* types, roles, and allows */ | 99 | /* types, roles, and allows */ |
198 | fprintf(fout, "type base_t;\n"); | 100 | fprintf(fout, "type base_t;\n"); |
199 | fprintf(fout, "role base_r types { base_t };\n"); | 101 | fprintf(fout, "role base_r types { base_t };\n"); |
200 | for (i=1; i < classlist_len; i++) { | 102 | for (i = 0; secclass_map[i].name; i++) |
201 | if (classlist[i]) | 103 | fprintf(fout, "allow base_t base_t:%s *;\n", |
202 | fprintf(fout, "allow base_t base_t:%s *;\n", classlist[i]); | 104 | secclass_map[i].name); |
203 | else | ||
204 | fprintf(fout, "allow base_t base_t:user%d *;\n", i); | ||
205 | } | ||
206 | fprintf(fout, "user user_u roles { base_r };\n"); | 105 | fprintf(fout, "user user_u roles { base_r };\n"); |
207 | fprintf(fout, "\n"); | 106 | fprintf(fout, "\n"); |
208 | 107 | ||
209 | /* default sids */ | 108 | /* default sids */ |
210 | for (i=1; i < initial_sid_to_string_len; i++) | 109 | for (i = 1; i < initial_sid_to_string_len; i++) |
211 | fprintf(fout, "sid %s user_u:base_r:base_t\n", initial_sid_to_string[i]); | 110 | fprintf(fout, "sid %s user_u:base_r:base_t\n", initial_sid_to_string[i]); |
212 | fprintf(fout, "\n"); | 111 | fprintf(fout, "\n"); |
213 | 112 | ||
214 | |||
215 | fprintf(fout, "fs_use_xattr ext2 user_u:base_r:base_t;\n"); | 113 | fprintf(fout, "fs_use_xattr ext2 user_u:base_r:base_t;\n"); |
216 | fprintf(fout, "fs_use_xattr ext3 user_u:base_r:base_t;\n"); | 114 | fprintf(fout, "fs_use_xattr ext3 user_u:base_r:base_t;\n"); |
115 | fprintf(fout, "fs_use_xattr ext4 user_u:base_r:base_t;\n"); | ||
217 | fprintf(fout, "fs_use_xattr jfs user_u:base_r:base_t;\n"); | 116 | fprintf(fout, "fs_use_xattr jfs user_u:base_r:base_t;\n"); |
218 | fprintf(fout, "fs_use_xattr xfs user_u:base_r:base_t;\n"); | 117 | fprintf(fout, "fs_use_xattr xfs user_u:base_r:base_t;\n"); |
219 | fprintf(fout, "fs_use_xattr reiserfs user_u:base_r:base_t;\n"); | 118 | fprintf(fout, "fs_use_xattr reiserfs user_u:base_r:base_t;\n"); |
119 | fprintf(fout, "fs_use_xattr jffs2 user_u:base_r:base_t;\n"); | ||
120 | fprintf(fout, "fs_use_xattr gfs2 user_u:base_r:base_t;\n"); | ||
121 | fprintf(fout, "fs_use_xattr lustre user_u:base_r:base_t;\n"); | ||
220 | 122 | ||
123 | fprintf(fout, "fs_use_task eventpollfs user_u:base_r:base_t;\n"); | ||
221 | fprintf(fout, "fs_use_task pipefs user_u:base_r:base_t;\n"); | 124 | fprintf(fout, "fs_use_task pipefs user_u:base_r:base_t;\n"); |
222 | fprintf(fout, "fs_use_task sockfs user_u:base_r:base_t;\n"); | 125 | fprintf(fout, "fs_use_task sockfs user_u:base_r:base_t;\n"); |
223 | 126 | ||
127 | fprintf(fout, "fs_use_trans mqueue user_u:base_r:base_t;\n"); | ||
224 | fprintf(fout, "fs_use_trans devpts user_u:base_r:base_t;\n"); | 128 | fprintf(fout, "fs_use_trans devpts user_u:base_r:base_t;\n"); |
129 | fprintf(fout, "fs_use_trans hugetlbfs user_u:base_r:base_t;\n"); | ||
225 | fprintf(fout, "fs_use_trans tmpfs user_u:base_r:base_t;\n"); | 130 | fprintf(fout, "fs_use_trans tmpfs user_u:base_r:base_t;\n"); |
226 | fprintf(fout, "fs_use_trans shm user_u:base_r:base_t;\n"); | 131 | fprintf(fout, "fs_use_trans shm user_u:base_r:base_t;\n"); |
227 | 132 | ||