diff options
Diffstat (limited to 'security/tomoyo/mount.c')
-rw-r--r-- | security/tomoyo/mount.c | 176 |
1 files changed, 62 insertions, 114 deletions
diff --git a/security/tomoyo/mount.c b/security/tomoyo/mount.c index 9fc2e15841c9..bee09d062057 100644 --- a/security/tomoyo/mount.c +++ b/security/tomoyo/mount.c | |||
@@ -1,28 +1,22 @@ | |||
1 | /* | 1 | /* |
2 | * security/tomoyo/mount.c | 2 | * security/tomoyo/mount.c |
3 | * | 3 | * |
4 | * Copyright (C) 2005-2010 NTT DATA CORPORATION | 4 | * Copyright (C) 2005-2011 NTT DATA CORPORATION |
5 | */ | 5 | */ |
6 | 6 | ||
7 | #include <linux/slab.h> | 7 | #include <linux/slab.h> |
8 | #include "common.h" | 8 | #include "common.h" |
9 | 9 | ||
10 | /* Keywords for mount restrictions. */ | 10 | /* String table for special mount operations. */ |
11 | 11 | static const char * const tomoyo_mounts[TOMOYO_MAX_SPECIAL_MOUNT] = { | |
12 | /* Allow to call 'mount --bind /source_dir /dest_dir' */ | 12 | [TOMOYO_MOUNT_BIND] = "--bind", |
13 | #define TOMOYO_MOUNT_BIND_KEYWORD "--bind" | 13 | [TOMOYO_MOUNT_MOVE] = "--move", |
14 | /* Allow to call 'mount --move /old_dir /new_dir ' */ | 14 | [TOMOYO_MOUNT_REMOUNT] = "--remount", |
15 | #define TOMOYO_MOUNT_MOVE_KEYWORD "--move" | 15 | [TOMOYO_MOUNT_MAKE_UNBINDABLE] = "--make-unbindable", |
16 | /* Allow to call 'mount -o remount /dir ' */ | 16 | [TOMOYO_MOUNT_MAKE_PRIVATE] = "--make-private", |
17 | #define TOMOYO_MOUNT_REMOUNT_KEYWORD "--remount" | 17 | [TOMOYO_MOUNT_MAKE_SLAVE] = "--make-slave", |
18 | /* Allow to call 'mount --make-unbindable /dir' */ | 18 | [TOMOYO_MOUNT_MAKE_SHARED] = "--make-shared", |
19 | #define TOMOYO_MOUNT_MAKE_UNBINDABLE_KEYWORD "--make-unbindable" | 19 | }; |
20 | /* Allow to call 'mount --make-private /dir' */ | ||
21 | #define TOMOYO_MOUNT_MAKE_PRIVATE_KEYWORD "--make-private" | ||
22 | /* Allow to call 'mount --make-slave /dir' */ | ||
23 | #define TOMOYO_MOUNT_MAKE_SLAVE_KEYWORD "--make-slave" | ||
24 | /* Allow to call 'mount --make-shared /dir' */ | ||
25 | #define TOMOYO_MOUNT_MAKE_SHARED_KEYWORD "--make-shared" | ||
26 | 20 | ||
27 | /** | 21 | /** |
28 | * tomoyo_audit_mount_log - Audit mount log. | 22 | * tomoyo_audit_mount_log - Audit mount log. |
@@ -33,50 +27,42 @@ | |||
33 | */ | 27 | */ |
34 | static int tomoyo_audit_mount_log(struct tomoyo_request_info *r) | 28 | static int tomoyo_audit_mount_log(struct tomoyo_request_info *r) |
35 | { | 29 | { |
36 | const char *dev = r->param.mount.dev->name; | 30 | return tomoyo_supervisor(r, "file mount %s %s %s 0x%lX\n", |
37 | const char *dir = r->param.mount.dir->name; | 31 | r->param.mount.dev->name, |
38 | const char *type = r->param.mount.type->name; | 32 | r->param.mount.dir->name, |
39 | const unsigned long flags = r->param.mount.flags; | 33 | r->param.mount.type->name, |
40 | if (r->granted) | 34 | r->param.mount.flags); |
41 | return 0; | ||
42 | if (!strcmp(type, TOMOYO_MOUNT_REMOUNT_KEYWORD)) | ||
43 | tomoyo_warn_log(r, "mount -o remount %s 0x%lX", dir, flags); | ||
44 | else if (!strcmp(type, TOMOYO_MOUNT_BIND_KEYWORD) | ||
45 | || !strcmp(type, TOMOYO_MOUNT_MOVE_KEYWORD)) | ||
46 | tomoyo_warn_log(r, "mount %s %s %s 0x%lX", type, dev, dir, | ||
47 | flags); | ||
48 | else if (!strcmp(type, TOMOYO_MOUNT_MAKE_UNBINDABLE_KEYWORD) || | ||
49 | !strcmp(type, TOMOYO_MOUNT_MAKE_PRIVATE_KEYWORD) || | ||
50 | !strcmp(type, TOMOYO_MOUNT_MAKE_SLAVE_KEYWORD) || | ||
51 | !strcmp(type, TOMOYO_MOUNT_MAKE_SHARED_KEYWORD)) | ||
52 | tomoyo_warn_log(r, "mount %s %s 0x%lX", type, dir, flags); | ||
53 | else | ||
54 | tomoyo_warn_log(r, "mount -t %s %s %s 0x%lX", type, dev, dir, | ||
55 | flags); | ||
56 | return tomoyo_supervisor(r, | ||
57 | TOMOYO_KEYWORD_ALLOW_MOUNT "%s %s %s 0x%lX\n", | ||
58 | tomoyo_pattern(r->param.mount.dev), | ||
59 | tomoyo_pattern(r->param.mount.dir), type, | ||
60 | flags); | ||
61 | } | 35 | } |
62 | 36 | ||
37 | /** | ||
38 | * tomoyo_check_mount_acl - Check permission for path path path number operation. | ||
39 | * | ||
40 | * @r: Pointer to "struct tomoyo_request_info". | ||
41 | * @ptr: Pointer to "struct tomoyo_acl_info". | ||
42 | * | ||
43 | * Returns true if granted, false otherwise. | ||
44 | */ | ||
63 | static bool tomoyo_check_mount_acl(struct tomoyo_request_info *r, | 45 | static bool tomoyo_check_mount_acl(struct tomoyo_request_info *r, |
64 | const struct tomoyo_acl_info *ptr) | 46 | const struct tomoyo_acl_info *ptr) |
65 | { | 47 | { |
66 | const struct tomoyo_mount_acl *acl = | 48 | const struct tomoyo_mount_acl *acl = |
67 | container_of(ptr, typeof(*acl), head); | 49 | container_of(ptr, typeof(*acl), head); |
68 | return tomoyo_compare_number_union(r->param.mount.flags, &acl->flags) && | 50 | return tomoyo_compare_number_union(r->param.mount.flags, |
69 | tomoyo_compare_name_union(r->param.mount.type, &acl->fs_type) && | 51 | &acl->flags) && |
70 | tomoyo_compare_name_union(r->param.mount.dir, &acl->dir_name) && | 52 | tomoyo_compare_name_union(r->param.mount.type, |
53 | &acl->fs_type) && | ||
54 | tomoyo_compare_name_union(r->param.mount.dir, | ||
55 | &acl->dir_name) && | ||
71 | (!r->param.mount.need_dev || | 56 | (!r->param.mount.need_dev || |
72 | tomoyo_compare_name_union(r->param.mount.dev, &acl->dev_name)); | 57 | tomoyo_compare_name_union(r->param.mount.dev, |
58 | &acl->dev_name)); | ||
73 | } | 59 | } |
74 | 60 | ||
75 | /** | 61 | /** |
76 | * tomoyo_mount_acl - Check permission for mount() operation. | 62 | * tomoyo_mount_acl - Check permission for mount() operation. |
77 | * | 63 | * |
78 | * @r: Pointer to "struct tomoyo_request_info". | 64 | * @r: Pointer to "struct tomoyo_request_info". |
79 | * @dev_name: Name of device file. | 65 | * @dev_name: Name of device file. Maybe NULL. |
80 | * @dir: Pointer to "struct path". | 66 | * @dir: Pointer to "struct path". |
81 | * @type: Name of filesystem type. | 67 | * @type: Name of filesystem type. |
82 | * @flags: Mount options. | 68 | * @flags: Mount options. |
@@ -86,8 +72,10 @@ static bool tomoyo_check_mount_acl(struct tomoyo_request_info *r, | |||
86 | * Caller holds tomoyo_read_lock(). | 72 | * Caller holds tomoyo_read_lock(). |
87 | */ | 73 | */ |
88 | static int tomoyo_mount_acl(struct tomoyo_request_info *r, char *dev_name, | 74 | static int tomoyo_mount_acl(struct tomoyo_request_info *r, char *dev_name, |
89 | struct path *dir, char *type, unsigned long flags) | 75 | struct path *dir, const char *type, |
76 | unsigned long flags) | ||
90 | { | 77 | { |
78 | struct tomoyo_obj_info obj = { }; | ||
91 | struct path path; | 79 | struct path path; |
92 | struct file_system_type *fstype = NULL; | 80 | struct file_system_type *fstype = NULL; |
93 | const char *requested_type = NULL; | 81 | const char *requested_type = NULL; |
@@ -98,6 +86,7 @@ static int tomoyo_mount_acl(struct tomoyo_request_info *r, char *dev_name, | |||
98 | struct tomoyo_path_info rdir; | 86 | struct tomoyo_path_info rdir; |
99 | int need_dev = 0; | 87 | int need_dev = 0; |
100 | int error = -ENOMEM; | 88 | int error = -ENOMEM; |
89 | r->obj = &obj; | ||
101 | 90 | ||
102 | /* Get fstype. */ | 91 | /* Get fstype. */ |
103 | requested_type = tomoyo_encode(type); | 92 | requested_type = tomoyo_encode(type); |
@@ -107,6 +96,7 @@ static int tomoyo_mount_acl(struct tomoyo_request_info *r, char *dev_name, | |||
107 | tomoyo_fill_path_info(&rtype); | 96 | tomoyo_fill_path_info(&rtype); |
108 | 97 | ||
109 | /* Get mount point. */ | 98 | /* Get mount point. */ |
99 | obj.path2 = *dir; | ||
110 | requested_dir_name = tomoyo_realpath_from_path(dir); | 100 | requested_dir_name = tomoyo_realpath_from_path(dir); |
111 | if (!requested_dir_name) { | 101 | if (!requested_dir_name) { |
112 | error = -ENOMEM; | 102 | error = -ENOMEM; |
@@ -116,15 +106,15 @@ static int tomoyo_mount_acl(struct tomoyo_request_info *r, char *dev_name, | |||
116 | tomoyo_fill_path_info(&rdir); | 106 | tomoyo_fill_path_info(&rdir); |
117 | 107 | ||
118 | /* Compare fs name. */ | 108 | /* Compare fs name. */ |
119 | if (!strcmp(type, TOMOYO_MOUNT_REMOUNT_KEYWORD)) { | 109 | if (type == tomoyo_mounts[TOMOYO_MOUNT_REMOUNT]) { |
120 | /* dev_name is ignored. */ | 110 | /* dev_name is ignored. */ |
121 | } else if (!strcmp(type, TOMOYO_MOUNT_MAKE_UNBINDABLE_KEYWORD) || | 111 | } else if (type == tomoyo_mounts[TOMOYO_MOUNT_MAKE_UNBINDABLE] || |
122 | !strcmp(type, TOMOYO_MOUNT_MAKE_PRIVATE_KEYWORD) || | 112 | type == tomoyo_mounts[TOMOYO_MOUNT_MAKE_PRIVATE] || |
123 | !strcmp(type, TOMOYO_MOUNT_MAKE_SLAVE_KEYWORD) || | 113 | type == tomoyo_mounts[TOMOYO_MOUNT_MAKE_SLAVE] || |
124 | !strcmp(type, TOMOYO_MOUNT_MAKE_SHARED_KEYWORD)) { | 114 | type == tomoyo_mounts[TOMOYO_MOUNT_MAKE_SHARED]) { |
125 | /* dev_name is ignored. */ | 115 | /* dev_name is ignored. */ |
126 | } else if (!strcmp(type, TOMOYO_MOUNT_BIND_KEYWORD) || | 116 | } else if (type == tomoyo_mounts[TOMOYO_MOUNT_BIND] || |
127 | !strcmp(type, TOMOYO_MOUNT_MOVE_KEYWORD)) { | 117 | type == tomoyo_mounts[TOMOYO_MOUNT_MOVE]) { |
128 | need_dev = -1; /* dev_name is a directory */ | 118 | need_dev = -1; /* dev_name is a directory */ |
129 | } else { | 119 | } else { |
130 | fstype = get_fs_type(type); | 120 | fstype = get_fs_type(type); |
@@ -142,8 +132,8 @@ static int tomoyo_mount_acl(struct tomoyo_request_info *r, char *dev_name, | |||
142 | error = -ENOENT; | 132 | error = -ENOENT; |
143 | goto out; | 133 | goto out; |
144 | } | 134 | } |
135 | obj.path1 = path; | ||
145 | requested_dev_name = tomoyo_realpath_from_path(&path); | 136 | requested_dev_name = tomoyo_realpath_from_path(&path); |
146 | path_put(&path); | ||
147 | if (!requested_dev_name) { | 137 | if (!requested_dev_name) { |
148 | error = -ENOENT; | 138 | error = -ENOENT; |
149 | goto out; | 139 | goto out; |
@@ -176,22 +166,26 @@ static int tomoyo_mount_acl(struct tomoyo_request_info *r, char *dev_name, | |||
176 | if (fstype) | 166 | if (fstype) |
177 | put_filesystem(fstype); | 167 | put_filesystem(fstype); |
178 | kfree(requested_type); | 168 | kfree(requested_type); |
169 | /* Drop refcount obtained by kern_path(). */ | ||
170 | if (obj.path1.dentry) | ||
171 | path_put(&obj.path1); | ||
179 | return error; | 172 | return error; |
180 | } | 173 | } |
181 | 174 | ||
182 | /** | 175 | /** |
183 | * tomoyo_mount_permission - Check permission for mount() operation. | 176 | * tomoyo_mount_permission - Check permission for mount() operation. |
184 | * | 177 | * |
185 | * @dev_name: Name of device file. | 178 | * @dev_name: Name of device file. Maybe NULL. |
186 | * @path: Pointer to "struct path". | 179 | * @path: Pointer to "struct path". |
187 | * @type: Name of filesystem type. May be NULL. | 180 | * @type: Name of filesystem type. Maybe NULL. |
188 | * @flags: Mount options. | 181 | * @flags: Mount options. |
189 | * @data_page: Optional data. May be NULL. | 182 | * @data_page: Optional data. Maybe NULL. |
190 | * | 183 | * |
191 | * Returns 0 on success, negative value otherwise. | 184 | * Returns 0 on success, negative value otherwise. |
192 | */ | 185 | */ |
193 | int tomoyo_mount_permission(char *dev_name, struct path *path, char *type, | 186 | int tomoyo_mount_permission(char *dev_name, struct path *path, |
194 | unsigned long flags, void *data_page) | 187 | const char *type, unsigned long flags, |
188 | void *data_page) | ||
195 | { | 189 | { |
196 | struct tomoyo_request_info r; | 190 | struct tomoyo_request_info r; |
197 | int error; | 191 | int error; |
@@ -203,31 +197,31 @@ int tomoyo_mount_permission(char *dev_name, struct path *path, char *type, | |||
203 | if ((flags & MS_MGC_MSK) == MS_MGC_VAL) | 197 | if ((flags & MS_MGC_MSK) == MS_MGC_VAL) |
204 | flags &= ~MS_MGC_MSK; | 198 | flags &= ~MS_MGC_MSK; |
205 | if (flags & MS_REMOUNT) { | 199 | if (flags & MS_REMOUNT) { |
206 | type = TOMOYO_MOUNT_REMOUNT_KEYWORD; | 200 | type = tomoyo_mounts[TOMOYO_MOUNT_REMOUNT]; |
207 | flags &= ~MS_REMOUNT; | 201 | flags &= ~MS_REMOUNT; |
208 | } | 202 | } |
209 | if (flags & MS_MOVE) { | 203 | if (flags & MS_MOVE) { |
210 | type = TOMOYO_MOUNT_MOVE_KEYWORD; | 204 | type = tomoyo_mounts[TOMOYO_MOUNT_MOVE]; |
211 | flags &= ~MS_MOVE; | 205 | flags &= ~MS_MOVE; |
212 | } | 206 | } |
213 | if (flags & MS_BIND) { | 207 | if (flags & MS_BIND) { |
214 | type = TOMOYO_MOUNT_BIND_KEYWORD; | 208 | type = tomoyo_mounts[TOMOYO_MOUNT_BIND]; |
215 | flags &= ~MS_BIND; | 209 | flags &= ~MS_BIND; |
216 | } | 210 | } |
217 | if (flags & MS_UNBINDABLE) { | 211 | if (flags & MS_UNBINDABLE) { |
218 | type = TOMOYO_MOUNT_MAKE_UNBINDABLE_KEYWORD; | 212 | type = tomoyo_mounts[TOMOYO_MOUNT_MAKE_UNBINDABLE]; |
219 | flags &= ~MS_UNBINDABLE; | 213 | flags &= ~MS_UNBINDABLE; |
220 | } | 214 | } |
221 | if (flags & MS_PRIVATE) { | 215 | if (flags & MS_PRIVATE) { |
222 | type = TOMOYO_MOUNT_MAKE_PRIVATE_KEYWORD; | 216 | type = tomoyo_mounts[TOMOYO_MOUNT_MAKE_PRIVATE]; |
223 | flags &= ~MS_PRIVATE; | 217 | flags &= ~MS_PRIVATE; |
224 | } | 218 | } |
225 | if (flags & MS_SLAVE) { | 219 | if (flags & MS_SLAVE) { |
226 | type = TOMOYO_MOUNT_MAKE_SLAVE_KEYWORD; | 220 | type = tomoyo_mounts[TOMOYO_MOUNT_MAKE_SLAVE]; |
227 | flags &= ~MS_SLAVE; | 221 | flags &= ~MS_SLAVE; |
228 | } | 222 | } |
229 | if (flags & MS_SHARED) { | 223 | if (flags & MS_SHARED) { |
230 | type = TOMOYO_MOUNT_MAKE_SHARED_KEYWORD; | 224 | type = tomoyo_mounts[TOMOYO_MOUNT_MAKE_SHARED]; |
231 | flags &= ~MS_SHARED; | 225 | flags &= ~MS_SHARED; |
232 | } | 226 | } |
233 | if (!type) | 227 | if (!type) |
@@ -237,49 +231,3 @@ int tomoyo_mount_permission(char *dev_name, struct path *path, char *type, | |||
237 | tomoyo_read_unlock(idx); | 231 | tomoyo_read_unlock(idx); |
238 | return error; | 232 | return error; |
239 | } | 233 | } |
240 | |||
241 | static bool tomoyo_same_mount_acl(const struct tomoyo_acl_info *a, | ||
242 | const struct tomoyo_acl_info *b) | ||
243 | { | ||
244 | const struct tomoyo_mount_acl *p1 = container_of(a, typeof(*p1), head); | ||
245 | const struct tomoyo_mount_acl *p2 = container_of(b, typeof(*p2), head); | ||
246 | return tomoyo_same_acl_head(&p1->head, &p2->head) && | ||
247 | tomoyo_same_name_union(&p1->dev_name, &p2->dev_name) && | ||
248 | tomoyo_same_name_union(&p1->dir_name, &p2->dir_name) && | ||
249 | tomoyo_same_name_union(&p1->fs_type, &p2->fs_type) && | ||
250 | tomoyo_same_number_union(&p1->flags, &p2->flags); | ||
251 | } | ||
252 | |||
253 | /** | ||
254 | * tomoyo_write_mount - Write "struct tomoyo_mount_acl" list. | ||
255 | * | ||
256 | * @data: String to parse. | ||
257 | * @domain: Pointer to "struct tomoyo_domain_info". | ||
258 | * @is_delete: True if it is a delete request. | ||
259 | * | ||
260 | * Returns 0 on success, negative value otherwise. | ||
261 | * | ||
262 | * Caller holds tomoyo_read_lock(). | ||
263 | */ | ||
264 | int tomoyo_write_mount(char *data, struct tomoyo_domain_info *domain, | ||
265 | const bool is_delete) | ||
266 | { | ||
267 | struct tomoyo_mount_acl e = { .head.type = TOMOYO_TYPE_MOUNT_ACL }; | ||
268 | int error = is_delete ? -ENOENT : -ENOMEM; | ||
269 | char *w[4]; | ||
270 | if (!tomoyo_tokenize(data, w, sizeof(w)) || !w[3][0]) | ||
271 | return -EINVAL; | ||
272 | if (!tomoyo_parse_name_union(w[0], &e.dev_name) || | ||
273 | !tomoyo_parse_name_union(w[1], &e.dir_name) || | ||
274 | !tomoyo_parse_name_union(w[2], &e.fs_type) || | ||
275 | !tomoyo_parse_number_union(w[3], &e.flags)) | ||
276 | goto out; | ||
277 | error = tomoyo_update_domain(&e.head, sizeof(e), is_delete, domain, | ||
278 | tomoyo_same_mount_acl, NULL); | ||
279 | out: | ||
280 | tomoyo_put_name_union(&e.dev_name); | ||
281 | tomoyo_put_name_union(&e.dir_name); | ||
282 | tomoyo_put_name_union(&e.fs_type); | ||
283 | tomoyo_put_number_union(&e.flags); | ||
284 | return error; | ||
285 | } | ||