Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 1 | /* |
| 2 | * security/tomoyo/file.c |
| 3 | * |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 4 | * Pathname restriction functions. |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 5 | * |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 6 | * Copyright (C) 2005-2010 NTT DATA CORPORATION |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include "common.h" |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 10 | #include <linux/slab.h> |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 11 | |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 12 | /* Keyword array for operations with one pathname. */ |
Tetsuo Handa | 71c2823 | 2010-06-16 16:26:38 +0900 | [diff] [blame] | 13 | const char *tomoyo_path_keyword[TOMOYO_MAX_PATH_OPERATION] = { |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 14 | [TOMOYO_TYPE_EXECUTE] = "execute", |
| 15 | [TOMOYO_TYPE_READ] = "read", |
| 16 | [TOMOYO_TYPE_WRITE] = "write", |
Tetsuo Handa | 7c75964 | 2011-06-26 23:15:31 +0900 | [diff] [blame^] | 17 | [TOMOYO_TYPE_APPEND] = "append", |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 18 | [TOMOYO_TYPE_UNLINK] = "unlink", |
Tetsuo Handa | 7c75964 | 2011-06-26 23:15:31 +0900 | [diff] [blame^] | 19 | [TOMOYO_TYPE_GETATTR] = "getattr", |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 20 | [TOMOYO_TYPE_RMDIR] = "rmdir", |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 21 | [TOMOYO_TYPE_TRUNCATE] = "truncate", |
| 22 | [TOMOYO_TYPE_SYMLINK] = "symlink", |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 23 | [TOMOYO_TYPE_CHROOT] = "chroot", |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 24 | [TOMOYO_TYPE_UMOUNT] = "unmount", |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 25 | }; |
| 26 | |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 27 | /* Keyword array for operations with one pathname and three numbers. */ |
Tetsuo Handa | 71c2823 | 2010-06-16 16:26:38 +0900 | [diff] [blame] | 28 | const char *tomoyo_mkdev_keyword[TOMOYO_MAX_MKDEV_OPERATION] = { |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 29 | [TOMOYO_TYPE_MKBLOCK] = "mkblock", |
| 30 | [TOMOYO_TYPE_MKCHAR] = "mkchar", |
| 31 | }; |
| 32 | |
| 33 | /* Keyword array for operations with two pathnames. */ |
Tetsuo Handa | 71c2823 | 2010-06-16 16:26:38 +0900 | [diff] [blame] | 34 | const char *tomoyo_path2_keyword[TOMOYO_MAX_PATH2_OPERATION] = { |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 35 | [TOMOYO_TYPE_LINK] = "link", |
| 36 | [TOMOYO_TYPE_RENAME] = "rename", |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 37 | [TOMOYO_TYPE_PIVOT_ROOT] = "pivot_root", |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 38 | }; |
| 39 | |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 40 | /* Keyword array for operations with one pathname and one number. */ |
Tetsuo Handa | 71c2823 | 2010-06-16 16:26:38 +0900 | [diff] [blame] | 41 | const char *tomoyo_path_number_keyword[TOMOYO_MAX_PATH_NUMBER_OPERATION] = { |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 42 | [TOMOYO_TYPE_CREATE] = "create", |
| 43 | [TOMOYO_TYPE_MKDIR] = "mkdir", |
| 44 | [TOMOYO_TYPE_MKFIFO] = "mkfifo", |
| 45 | [TOMOYO_TYPE_MKSOCK] = "mksock", |
| 46 | [TOMOYO_TYPE_IOCTL] = "ioctl", |
| 47 | [TOMOYO_TYPE_CHMOD] = "chmod", |
| 48 | [TOMOYO_TYPE_CHOWN] = "chown", |
| 49 | [TOMOYO_TYPE_CHGRP] = "chgrp", |
| 50 | }; |
| 51 | |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 52 | static const u8 tomoyo_p2mac[TOMOYO_MAX_PATH_OPERATION] = { |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 53 | [TOMOYO_TYPE_EXECUTE] = TOMOYO_MAC_FILE_EXECUTE, |
| 54 | [TOMOYO_TYPE_READ] = TOMOYO_MAC_FILE_OPEN, |
| 55 | [TOMOYO_TYPE_WRITE] = TOMOYO_MAC_FILE_OPEN, |
Tetsuo Handa | 7c75964 | 2011-06-26 23:15:31 +0900 | [diff] [blame^] | 56 | [TOMOYO_TYPE_APPEND] = TOMOYO_MAC_FILE_OPEN, |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 57 | [TOMOYO_TYPE_UNLINK] = TOMOYO_MAC_FILE_UNLINK, |
Tetsuo Handa | 7c75964 | 2011-06-26 23:15:31 +0900 | [diff] [blame^] | 58 | [TOMOYO_TYPE_GETATTR] = TOMOYO_MAC_FILE_GETATTR, |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 59 | [TOMOYO_TYPE_RMDIR] = TOMOYO_MAC_FILE_RMDIR, |
| 60 | [TOMOYO_TYPE_TRUNCATE] = TOMOYO_MAC_FILE_TRUNCATE, |
| 61 | [TOMOYO_TYPE_SYMLINK] = TOMOYO_MAC_FILE_SYMLINK, |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 62 | [TOMOYO_TYPE_CHROOT] = TOMOYO_MAC_FILE_CHROOT, |
| 63 | [TOMOYO_TYPE_UMOUNT] = TOMOYO_MAC_FILE_UMOUNT, |
| 64 | }; |
| 65 | |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 66 | static const u8 tomoyo_pnnn2mac[TOMOYO_MAX_MKDEV_OPERATION] = { |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 67 | [TOMOYO_TYPE_MKBLOCK] = TOMOYO_MAC_FILE_MKBLOCK, |
| 68 | [TOMOYO_TYPE_MKCHAR] = TOMOYO_MAC_FILE_MKCHAR, |
| 69 | }; |
| 70 | |
| 71 | static const u8 tomoyo_pp2mac[TOMOYO_MAX_PATH2_OPERATION] = { |
| 72 | [TOMOYO_TYPE_LINK] = TOMOYO_MAC_FILE_LINK, |
| 73 | [TOMOYO_TYPE_RENAME] = TOMOYO_MAC_FILE_RENAME, |
| 74 | [TOMOYO_TYPE_PIVOT_ROOT] = TOMOYO_MAC_FILE_PIVOT_ROOT, |
| 75 | }; |
| 76 | |
| 77 | static const u8 tomoyo_pn2mac[TOMOYO_MAX_PATH_NUMBER_OPERATION] = { |
| 78 | [TOMOYO_TYPE_CREATE] = TOMOYO_MAC_FILE_CREATE, |
| 79 | [TOMOYO_TYPE_MKDIR] = TOMOYO_MAC_FILE_MKDIR, |
| 80 | [TOMOYO_TYPE_MKFIFO] = TOMOYO_MAC_FILE_MKFIFO, |
| 81 | [TOMOYO_TYPE_MKSOCK] = TOMOYO_MAC_FILE_MKSOCK, |
| 82 | [TOMOYO_TYPE_IOCTL] = TOMOYO_MAC_FILE_IOCTL, |
| 83 | [TOMOYO_TYPE_CHMOD] = TOMOYO_MAC_FILE_CHMOD, |
| 84 | [TOMOYO_TYPE_CHOWN] = TOMOYO_MAC_FILE_CHOWN, |
| 85 | [TOMOYO_TYPE_CHGRP] = TOMOYO_MAC_FILE_CHGRP, |
| 86 | }; |
| 87 | |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 88 | void tomoyo_put_name_union(struct tomoyo_name_union *ptr) |
| 89 | { |
| 90 | if (!ptr) |
| 91 | return; |
| 92 | if (ptr->is_group) |
Tetsuo Handa | a98aa4d | 2010-06-17 16:52:29 +0900 | [diff] [blame] | 93 | tomoyo_put_group(ptr->group); |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 94 | else |
| 95 | tomoyo_put_name(ptr->filename); |
| 96 | } |
| 97 | |
Tetsuo Handa | 484ca79 | 2010-07-29 14:29:55 +0900 | [diff] [blame] | 98 | const struct tomoyo_path_info * |
| 99 | tomoyo_compare_name_union(const struct tomoyo_path_info *name, |
| 100 | const struct tomoyo_name_union *ptr) |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 101 | { |
| 102 | if (ptr->is_group) |
Tetsuo Handa | 3f62963 | 2010-06-03 20:37:26 +0900 | [diff] [blame] | 103 | return tomoyo_path_matches_group(name, ptr->group); |
Tetsuo Handa | 484ca79 | 2010-07-29 14:29:55 +0900 | [diff] [blame] | 104 | if (tomoyo_path_matches_pattern(name, ptr->filename)) |
| 105 | return ptr->filename; |
| 106 | return NULL; |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 107 | } |
| 108 | |
Tetsuo Handa | 4c3e9e2 | 2010-05-17 10:06:58 +0900 | [diff] [blame] | 109 | void tomoyo_put_number_union(struct tomoyo_number_union *ptr) |
| 110 | { |
| 111 | if (ptr && ptr->is_group) |
Tetsuo Handa | a98aa4d | 2010-06-17 16:52:29 +0900 | [diff] [blame] | 112 | tomoyo_put_group(ptr->group); |
Tetsuo Handa | 4c3e9e2 | 2010-05-17 10:06:58 +0900 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | bool tomoyo_compare_number_union(const unsigned long value, |
| 116 | const struct tomoyo_number_union *ptr) |
| 117 | { |
| 118 | if (ptr->is_group) |
| 119 | return tomoyo_number_matches_group(value, value, ptr->group); |
| 120 | return value >= ptr->values[0] && value <= ptr->values[1]; |
| 121 | } |
| 122 | |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 123 | static void tomoyo_add_slash(struct tomoyo_path_info *buf) |
| 124 | { |
| 125 | if (buf->is_dir) |
| 126 | return; |
| 127 | /* |
| 128 | * This is OK because tomoyo_encode() reserves space for appending "/". |
| 129 | */ |
| 130 | strcat((char *) buf->name, "/"); |
| 131 | tomoyo_fill_path_info(buf); |
| 132 | } |
| 133 | |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 134 | /** |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 135 | * tomoyo_get_realpath - Get realpath. |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 136 | * |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 137 | * @buf: Pointer to "struct tomoyo_path_info". |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 138 | * @path: Pointer to "struct path". |
| 139 | * |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 140 | * Returns true on success, false otherwise. |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 141 | */ |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 142 | static bool tomoyo_get_realpath(struct tomoyo_path_info *buf, struct path *path) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 143 | { |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 144 | buf->name = tomoyo_realpath_from_path(path); |
| 145 | if (buf->name) { |
| 146 | tomoyo_fill_path_info(buf); |
| 147 | return true; |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 148 | } |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 149 | return false; |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 150 | } |
| 151 | |
Tetsuo Handa | 99a8525 | 2010-06-16 16:22:51 +0900 | [diff] [blame] | 152 | /** |
| 153 | * tomoyo_audit_path_log - Audit path request log. |
| 154 | * |
| 155 | * @r: Pointer to "struct tomoyo_request_info". |
| 156 | * |
| 157 | * Returns 0 on success, negative value otherwise. |
| 158 | */ |
| 159 | static int tomoyo_audit_path_log(struct tomoyo_request_info *r) |
| 160 | { |
| 161 | const char *operation = tomoyo_path_keyword[r->param.path.operation]; |
| 162 | const struct tomoyo_path_info *filename = r->param.path.filename; |
| 163 | if (r->granted) |
| 164 | return 0; |
| 165 | tomoyo_warn_log(r, "%s %s", operation, filename->name); |
| 166 | return tomoyo_supervisor(r, "allow_%s %s\n", operation, |
Tetsuo Handa | 7c75964 | 2011-06-26 23:15:31 +0900 | [diff] [blame^] | 167 | filename->name); |
Tetsuo Handa | 99a8525 | 2010-06-16 16:22:51 +0900 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | /** |
| 171 | * tomoyo_audit_path2_log - Audit path/path request log. |
| 172 | * |
| 173 | * @r: Pointer to "struct tomoyo_request_info". |
| 174 | * |
| 175 | * Returns 0 on success, negative value otherwise. |
| 176 | */ |
| 177 | static int tomoyo_audit_path2_log(struct tomoyo_request_info *r) |
| 178 | { |
| 179 | const char *operation = tomoyo_path2_keyword[r->param.path2.operation]; |
| 180 | const struct tomoyo_path_info *filename1 = r->param.path2.filename1; |
| 181 | const struct tomoyo_path_info *filename2 = r->param.path2.filename2; |
| 182 | if (r->granted) |
| 183 | return 0; |
| 184 | tomoyo_warn_log(r, "%s %s %s", operation, filename1->name, |
| 185 | filename2->name); |
| 186 | return tomoyo_supervisor(r, "allow_%s %s %s\n", operation, |
Tetsuo Handa | 7c75964 | 2011-06-26 23:15:31 +0900 | [diff] [blame^] | 187 | filename1->name, filename2->name); |
Tetsuo Handa | 99a8525 | 2010-06-16 16:22:51 +0900 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | /** |
| 191 | * tomoyo_audit_mkdev_log - Audit path/number/number/number request log. |
| 192 | * |
| 193 | * @r: Pointer to "struct tomoyo_request_info". |
| 194 | * |
| 195 | * Returns 0 on success, negative value otherwise. |
| 196 | */ |
| 197 | static int tomoyo_audit_mkdev_log(struct tomoyo_request_info *r) |
| 198 | { |
Tetsuo Handa | 71c2823 | 2010-06-16 16:26:38 +0900 | [diff] [blame] | 199 | const char *operation = tomoyo_mkdev_keyword[r->param.mkdev.operation]; |
Tetsuo Handa | 99a8525 | 2010-06-16 16:22:51 +0900 | [diff] [blame] | 200 | const struct tomoyo_path_info *filename = r->param.mkdev.filename; |
| 201 | const unsigned int major = r->param.mkdev.major; |
| 202 | const unsigned int minor = r->param.mkdev.minor; |
| 203 | const unsigned int mode = r->param.mkdev.mode; |
| 204 | if (r->granted) |
| 205 | return 0; |
| 206 | tomoyo_warn_log(r, "%s %s 0%o %u %u", operation, filename->name, mode, |
| 207 | major, minor); |
| 208 | return tomoyo_supervisor(r, "allow_%s %s 0%o %u %u\n", operation, |
Tetsuo Handa | 7c75964 | 2011-06-26 23:15:31 +0900 | [diff] [blame^] | 209 | filename->name, mode, major, minor); |
Tetsuo Handa | 99a8525 | 2010-06-16 16:22:51 +0900 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | /** |
| 213 | * tomoyo_audit_path_number_log - Audit path/number request log. |
| 214 | * |
| 215 | * @r: Pointer to "struct tomoyo_request_info". |
| 216 | * @error: Error code. |
| 217 | * |
| 218 | * Returns 0 on success, negative value otherwise. |
| 219 | */ |
| 220 | static int tomoyo_audit_path_number_log(struct tomoyo_request_info *r) |
| 221 | { |
| 222 | const u8 type = r->param.path_number.operation; |
| 223 | u8 radix; |
| 224 | const struct tomoyo_path_info *filename = r->param.path_number.filename; |
| 225 | const char *operation = tomoyo_path_number_keyword[type]; |
| 226 | char buffer[64]; |
| 227 | if (r->granted) |
| 228 | return 0; |
| 229 | switch (type) { |
| 230 | case TOMOYO_TYPE_CREATE: |
| 231 | case TOMOYO_TYPE_MKDIR: |
| 232 | case TOMOYO_TYPE_MKFIFO: |
| 233 | case TOMOYO_TYPE_MKSOCK: |
| 234 | case TOMOYO_TYPE_CHMOD: |
| 235 | radix = TOMOYO_VALUE_TYPE_OCTAL; |
| 236 | break; |
| 237 | case TOMOYO_TYPE_IOCTL: |
| 238 | radix = TOMOYO_VALUE_TYPE_HEXADECIMAL; |
| 239 | break; |
| 240 | default: |
| 241 | radix = TOMOYO_VALUE_TYPE_DECIMAL; |
| 242 | break; |
| 243 | } |
| 244 | tomoyo_print_ulong(buffer, sizeof(buffer), r->param.path_number.number, |
| 245 | radix); |
| 246 | tomoyo_warn_log(r, "%s %s %s", operation, filename->name, buffer); |
| 247 | return tomoyo_supervisor(r, "allow_%s %s %s\n", operation, |
Tetsuo Handa | 7c75964 | 2011-06-26 23:15:31 +0900 | [diff] [blame^] | 248 | filename->name, buffer); |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 249 | } |
| 250 | |
Tetsuo Handa | 484ca79 | 2010-07-29 14:29:55 +0900 | [diff] [blame] | 251 | static bool tomoyo_check_path_acl(struct tomoyo_request_info *r, |
Tetsuo Handa | 99a8525 | 2010-06-16 16:22:51 +0900 | [diff] [blame] | 252 | const struct tomoyo_acl_info *ptr) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 253 | { |
Tetsuo Handa | 99a8525 | 2010-06-16 16:22:51 +0900 | [diff] [blame] | 254 | const struct tomoyo_path_acl *acl = container_of(ptr, typeof(*acl), |
| 255 | head); |
Tetsuo Handa | 484ca79 | 2010-07-29 14:29:55 +0900 | [diff] [blame] | 256 | if (acl->perm & (1 << r->param.path.operation)) { |
| 257 | r->param.path.matched_path = |
| 258 | tomoyo_compare_name_union(r->param.path.filename, |
| 259 | &acl->name); |
| 260 | return r->param.path.matched_path != NULL; |
| 261 | } |
| 262 | return false; |
Tetsuo Handa | 99a8525 | 2010-06-16 16:22:51 +0900 | [diff] [blame] | 263 | } |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 264 | |
Tetsuo Handa | 484ca79 | 2010-07-29 14:29:55 +0900 | [diff] [blame] | 265 | static bool tomoyo_check_path_number_acl(struct tomoyo_request_info *r, |
Tetsuo Handa | 99a8525 | 2010-06-16 16:22:51 +0900 | [diff] [blame] | 266 | const struct tomoyo_acl_info *ptr) |
| 267 | { |
| 268 | const struct tomoyo_path_number_acl *acl = |
| 269 | container_of(ptr, typeof(*acl), head); |
| 270 | return (acl->perm & (1 << r->param.path_number.operation)) && |
| 271 | tomoyo_compare_number_union(r->param.path_number.number, |
| 272 | &acl->number) && |
| 273 | tomoyo_compare_name_union(r->param.path_number.filename, |
| 274 | &acl->name); |
| 275 | } |
| 276 | |
Tetsuo Handa | 484ca79 | 2010-07-29 14:29:55 +0900 | [diff] [blame] | 277 | static bool tomoyo_check_path2_acl(struct tomoyo_request_info *r, |
Tetsuo Handa | 99a8525 | 2010-06-16 16:22:51 +0900 | [diff] [blame] | 278 | const struct tomoyo_acl_info *ptr) |
| 279 | { |
| 280 | const struct tomoyo_path2_acl *acl = |
| 281 | container_of(ptr, typeof(*acl), head); |
| 282 | return (acl->perm & (1 << r->param.path2.operation)) && |
| 283 | tomoyo_compare_name_union(r->param.path2.filename1, &acl->name1) |
| 284 | && tomoyo_compare_name_union(r->param.path2.filename2, |
| 285 | &acl->name2); |
| 286 | } |
| 287 | |
Tetsuo Handa | 484ca79 | 2010-07-29 14:29:55 +0900 | [diff] [blame] | 288 | static bool tomoyo_check_mkdev_acl(struct tomoyo_request_info *r, |
Tetsuo Handa | 99a8525 | 2010-06-16 16:22:51 +0900 | [diff] [blame] | 289 | const struct tomoyo_acl_info *ptr) |
| 290 | { |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 291 | const struct tomoyo_mkdev_acl *acl = |
Tetsuo Handa | 99a8525 | 2010-06-16 16:22:51 +0900 | [diff] [blame] | 292 | container_of(ptr, typeof(*acl), head); |
| 293 | return (acl->perm & (1 << r->param.mkdev.operation)) && |
| 294 | tomoyo_compare_number_union(r->param.mkdev.mode, |
| 295 | &acl->mode) && |
| 296 | tomoyo_compare_number_union(r->param.mkdev.major, |
| 297 | &acl->major) && |
| 298 | tomoyo_compare_number_union(r->param.mkdev.minor, |
| 299 | &acl->minor) && |
| 300 | tomoyo_compare_name_union(r->param.mkdev.filename, |
| 301 | &acl->name); |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 302 | } |
| 303 | |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 304 | static bool tomoyo_same_path_acl(const struct tomoyo_acl_info *a, |
| 305 | const struct tomoyo_acl_info *b) |
| 306 | { |
| 307 | const struct tomoyo_path_acl *p1 = container_of(a, typeof(*p1), head); |
| 308 | const struct tomoyo_path_acl *p2 = container_of(b, typeof(*p2), head); |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 309 | return tomoyo_same_acl_head(&p1->head, &p2->head) && |
| 310 | tomoyo_same_name_union(&p1->name, &p2->name); |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 311 | } |
| 312 | |
Tetsuo Handa | 7c75964 | 2011-06-26 23:15:31 +0900 | [diff] [blame^] | 313 | /** |
| 314 | * tomoyo_merge_path_acl - Merge duplicated "struct tomoyo_path_acl" entry. |
| 315 | * |
| 316 | * @a: Pointer to "struct tomoyo_acl_info". |
| 317 | * @b: Pointer to "struct tomoyo_acl_info". |
| 318 | * @is_delete: True for @a &= ~@b, false for @a |= @b. |
| 319 | * |
| 320 | * Returns true if @a is empty, false otherwise. |
| 321 | */ |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 322 | static bool tomoyo_merge_path_acl(struct tomoyo_acl_info *a, |
| 323 | struct tomoyo_acl_info *b, |
| 324 | const bool is_delete) |
| 325 | { |
| 326 | u16 * const a_perm = &container_of(a, struct tomoyo_path_acl, head) |
| 327 | ->perm; |
| 328 | u16 perm = *a_perm; |
| 329 | const u16 b_perm = container_of(b, struct tomoyo_path_acl, head)->perm; |
Tetsuo Handa | 7c75964 | 2011-06-26 23:15:31 +0900 | [diff] [blame^] | 330 | if (is_delete) |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 331 | perm &= ~b_perm; |
Tetsuo Handa | 7c75964 | 2011-06-26 23:15:31 +0900 | [diff] [blame^] | 332 | else |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 333 | perm |= b_perm; |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 334 | *a_perm = perm; |
| 335 | return !perm; |
| 336 | } |
| 337 | |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 338 | /** |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 339 | * tomoyo_update_path_acl - Update "struct tomoyo_path_acl" list. |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 340 | * |
| 341 | * @type: Type of operation. |
| 342 | * @filename: Filename. |
| 343 | * @domain: Pointer to "struct tomoyo_domain_info". |
| 344 | * @is_delete: True if it is a delete request. |
| 345 | * |
| 346 | * Returns 0 on success, negative value otherwise. |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 347 | * |
| 348 | * Caller holds tomoyo_read_lock(). |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 349 | */ |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 350 | static int tomoyo_update_path_acl(const u8 type, const char *filename, |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 351 | struct tomoyo_domain_info * const domain, |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 352 | const bool is_delete) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 353 | { |
Tetsuo Handa | 9e4b50e | 2010-05-06 12:40:02 +0900 | [diff] [blame] | 354 | struct tomoyo_path_acl e = { |
| 355 | .head.type = TOMOYO_TYPE_PATH_ACL, |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 356 | .perm = 1 << type |
Tetsuo Handa | 9e4b50e | 2010-05-06 12:40:02 +0900 | [diff] [blame] | 357 | }; |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 358 | int error; |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 359 | if (!tomoyo_parse_name_union(filename, &e.name)) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 360 | return -EINVAL; |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 361 | error = tomoyo_update_domain(&e.head, sizeof(e), is_delete, domain, |
| 362 | tomoyo_same_path_acl, |
| 363 | tomoyo_merge_path_acl); |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 364 | tomoyo_put_name_union(&e.name); |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 365 | return error; |
| 366 | } |
| 367 | |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 368 | static bool tomoyo_same_mkdev_acl(const struct tomoyo_acl_info *a, |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 369 | const struct tomoyo_acl_info *b) |
| 370 | { |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 371 | const struct tomoyo_mkdev_acl *p1 = container_of(a, typeof(*p1), |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 372 | head); |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 373 | const struct tomoyo_mkdev_acl *p2 = container_of(b, typeof(*p2), |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 374 | head); |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 375 | return tomoyo_same_acl_head(&p1->head, &p2->head) |
| 376 | && tomoyo_same_name_union(&p1->name, &p2->name) |
| 377 | && tomoyo_same_number_union(&p1->mode, &p2->mode) |
| 378 | && tomoyo_same_number_union(&p1->major, &p2->major) |
| 379 | && tomoyo_same_number_union(&p1->minor, &p2->minor); |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 380 | } |
| 381 | |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 382 | static bool tomoyo_merge_mkdev_acl(struct tomoyo_acl_info *a, |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 383 | struct tomoyo_acl_info *b, |
| 384 | const bool is_delete) |
| 385 | { |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 386 | u8 *const a_perm = &container_of(a, struct tomoyo_mkdev_acl, |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 387 | head)->perm; |
| 388 | u8 perm = *a_perm; |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 389 | const u8 b_perm = container_of(b, struct tomoyo_mkdev_acl, head) |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 390 | ->perm; |
| 391 | if (is_delete) |
| 392 | perm &= ~b_perm; |
| 393 | else |
| 394 | perm |= b_perm; |
| 395 | *a_perm = perm; |
| 396 | return !perm; |
| 397 | } |
| 398 | |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 399 | /** |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 400 | * tomoyo_update_mkdev_acl - Update "struct tomoyo_mkdev_acl" list. |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 401 | * |
| 402 | * @type: Type of operation. |
| 403 | * @filename: Filename. |
| 404 | * @mode: Create mode. |
| 405 | * @major: Device major number. |
| 406 | * @minor: Device minor number. |
| 407 | * @domain: Pointer to "struct tomoyo_domain_info". |
| 408 | * @is_delete: True if it is a delete request. |
| 409 | * |
| 410 | * Returns 0 on success, negative value otherwise. |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 411 | * |
| 412 | * Caller holds tomoyo_read_lock(). |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 413 | */ |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 414 | static int tomoyo_update_mkdev_acl(const u8 type, const char *filename, |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 415 | char *mode, char *major, char *minor, |
| 416 | struct tomoyo_domain_info * const |
| 417 | domain, const bool is_delete) |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 418 | { |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 419 | struct tomoyo_mkdev_acl e = { |
| 420 | .head.type = TOMOYO_TYPE_MKDEV_ACL, |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 421 | .perm = 1 << type |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 422 | }; |
| 423 | int error = is_delete ? -ENOENT : -ENOMEM; |
| 424 | if (!tomoyo_parse_name_union(filename, &e.name) || |
| 425 | !tomoyo_parse_number_union(mode, &e.mode) || |
| 426 | !tomoyo_parse_number_union(major, &e.major) || |
| 427 | !tomoyo_parse_number_union(minor, &e.minor)) |
| 428 | goto out; |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 429 | error = tomoyo_update_domain(&e.head, sizeof(e), is_delete, domain, |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 430 | tomoyo_same_mkdev_acl, |
| 431 | tomoyo_merge_mkdev_acl); |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 432 | out: |
| 433 | tomoyo_put_name_union(&e.name); |
| 434 | tomoyo_put_number_union(&e.mode); |
| 435 | tomoyo_put_number_union(&e.major); |
| 436 | tomoyo_put_number_union(&e.minor); |
| 437 | return error; |
| 438 | } |
| 439 | |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 440 | static bool tomoyo_same_path2_acl(const struct tomoyo_acl_info *a, |
| 441 | const struct tomoyo_acl_info *b) |
| 442 | { |
| 443 | const struct tomoyo_path2_acl *p1 = container_of(a, typeof(*p1), head); |
| 444 | const struct tomoyo_path2_acl *p2 = container_of(b, typeof(*p2), head); |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 445 | return tomoyo_same_acl_head(&p1->head, &p2->head) |
| 446 | && tomoyo_same_name_union(&p1->name1, &p2->name1) |
| 447 | && tomoyo_same_name_union(&p1->name2, &p2->name2); |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | static bool tomoyo_merge_path2_acl(struct tomoyo_acl_info *a, |
| 451 | struct tomoyo_acl_info *b, |
| 452 | const bool is_delete) |
| 453 | { |
| 454 | u8 * const a_perm = &container_of(a, struct tomoyo_path2_acl, head) |
| 455 | ->perm; |
| 456 | u8 perm = *a_perm; |
| 457 | const u8 b_perm = container_of(b, struct tomoyo_path2_acl, head)->perm; |
| 458 | if (is_delete) |
| 459 | perm &= ~b_perm; |
| 460 | else |
| 461 | perm |= b_perm; |
| 462 | *a_perm = perm; |
| 463 | return !perm; |
| 464 | } |
| 465 | |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 466 | /** |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 467 | * tomoyo_update_path2_acl - Update "struct tomoyo_path2_acl" list. |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 468 | * |
| 469 | * @type: Type of operation. |
| 470 | * @filename1: First filename. |
| 471 | * @filename2: Second filename. |
| 472 | * @domain: Pointer to "struct tomoyo_domain_info". |
| 473 | * @is_delete: True if it is a delete request. |
| 474 | * |
| 475 | * Returns 0 on success, negative value otherwise. |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 476 | * |
| 477 | * Caller holds tomoyo_read_lock(). |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 478 | */ |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 479 | static int tomoyo_update_path2_acl(const u8 type, const char *filename1, |
| 480 | const char *filename2, |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 481 | struct tomoyo_domain_info * const domain, |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 482 | const bool is_delete) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 483 | { |
Tetsuo Handa | 9e4b50e | 2010-05-06 12:40:02 +0900 | [diff] [blame] | 484 | struct tomoyo_path2_acl e = { |
| 485 | .head.type = TOMOYO_TYPE_PATH2_ACL, |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 486 | .perm = 1 << type |
Tetsuo Handa | 9e4b50e | 2010-05-06 12:40:02 +0900 | [diff] [blame] | 487 | }; |
Tetsuo Handa | 9e4b50e | 2010-05-06 12:40:02 +0900 | [diff] [blame] | 488 | int error = is_delete ? -ENOENT : -ENOMEM; |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 489 | if (!tomoyo_parse_name_union(filename1, &e.name1) || |
| 490 | !tomoyo_parse_name_union(filename2, &e.name2)) |
Tetsuo Handa | ca0b7df | 2010-02-07 20:23:59 +0900 | [diff] [blame] | 491 | goto out; |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 492 | error = tomoyo_update_domain(&e.head, sizeof(e), is_delete, domain, |
| 493 | tomoyo_same_path2_acl, |
| 494 | tomoyo_merge_path2_acl); |
Tetsuo Handa | ca0b7df | 2010-02-07 20:23:59 +0900 | [diff] [blame] | 495 | out: |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 496 | tomoyo_put_name_union(&e.name1); |
| 497 | tomoyo_put_name_union(&e.name2); |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 498 | return error; |
| 499 | } |
| 500 | |
| 501 | /** |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 502 | * tomoyo_path_permission - Check permission for single path operation. |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 503 | * |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 504 | * @r: Pointer to "struct tomoyo_request_info". |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 505 | * @operation: Type of operation. |
| 506 | * @filename: Filename to check. |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 507 | * |
| 508 | * Returns 0 on success, negative value otherwise. |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 509 | * |
| 510 | * Caller holds tomoyo_read_lock(). |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 511 | */ |
Tetsuo Handa | 05336de | 2010-06-16 16:20:24 +0900 | [diff] [blame] | 512 | int tomoyo_path_permission(struct tomoyo_request_info *r, u8 operation, |
| 513 | const struct tomoyo_path_info *filename) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 514 | { |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 515 | int error; |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 516 | |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 517 | r->type = tomoyo_p2mac[operation]; |
| 518 | r->mode = tomoyo_get_mode(r->profile, r->type); |
| 519 | if (r->mode == TOMOYO_CONFIG_DISABLED) |
| 520 | return 0; |
Tetsuo Handa | cf6e9a6 | 2010-06-16 16:21:36 +0900 | [diff] [blame] | 521 | r->param_type = TOMOYO_TYPE_PATH_ACL; |
| 522 | r->param.path.filename = filename; |
| 523 | r->param.path.operation = operation; |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 524 | do { |
Tetsuo Handa | 99a8525 | 2010-06-16 16:22:51 +0900 | [diff] [blame] | 525 | tomoyo_check_acl(r, tomoyo_check_path_acl); |
Tetsuo Handa | 99a8525 | 2010-06-16 16:22:51 +0900 | [diff] [blame] | 526 | error = tomoyo_audit_path_log(r); |
Tetsuo Handa | 05336de | 2010-06-16 16:20:24 +0900 | [diff] [blame] | 527 | /* |
| 528 | * Do not retry for execute request, for alias may have |
| 529 | * changed. |
| 530 | */ |
| 531 | } while (error == TOMOYO_RETRY_REQUEST && |
| 532 | operation != TOMOYO_TYPE_EXECUTE); |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 533 | return error; |
| 534 | } |
| 535 | |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 536 | static bool tomoyo_same_path_number_acl(const struct tomoyo_acl_info *a, |
| 537 | const struct tomoyo_acl_info *b) |
| 538 | { |
| 539 | const struct tomoyo_path_number_acl *p1 = container_of(a, typeof(*p1), |
| 540 | head); |
| 541 | const struct tomoyo_path_number_acl *p2 = container_of(b, typeof(*p2), |
| 542 | head); |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 543 | return tomoyo_same_acl_head(&p1->head, &p2->head) |
| 544 | && tomoyo_same_name_union(&p1->name, &p2->name) |
| 545 | && tomoyo_same_number_union(&p1->number, &p2->number); |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | static bool tomoyo_merge_path_number_acl(struct tomoyo_acl_info *a, |
| 549 | struct tomoyo_acl_info *b, |
| 550 | const bool is_delete) |
| 551 | { |
| 552 | u8 * const a_perm = &container_of(a, struct tomoyo_path_number_acl, |
| 553 | head)->perm; |
| 554 | u8 perm = *a_perm; |
| 555 | const u8 b_perm = container_of(b, struct tomoyo_path_number_acl, head) |
| 556 | ->perm; |
| 557 | if (is_delete) |
| 558 | perm &= ~b_perm; |
| 559 | else |
| 560 | perm |= b_perm; |
| 561 | *a_perm = perm; |
| 562 | return !perm; |
| 563 | } |
| 564 | |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 565 | /** |
| 566 | * tomoyo_update_path_number_acl - Update ioctl/chmod/chown/chgrp ACL. |
| 567 | * |
| 568 | * @type: Type of operation. |
| 569 | * @filename: Filename. |
| 570 | * @number: Number. |
| 571 | * @domain: Pointer to "struct tomoyo_domain_info". |
| 572 | * @is_delete: True if it is a delete request. |
| 573 | * |
| 574 | * Returns 0 on success, negative value otherwise. |
| 575 | */ |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 576 | static int tomoyo_update_path_number_acl(const u8 type, const char *filename, |
| 577 | char *number, |
| 578 | struct tomoyo_domain_info * const |
| 579 | domain, |
| 580 | const bool is_delete) |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 581 | { |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 582 | struct tomoyo_path_number_acl e = { |
| 583 | .head.type = TOMOYO_TYPE_PATH_NUMBER_ACL, |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 584 | .perm = 1 << type |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 585 | }; |
| 586 | int error = is_delete ? -ENOENT : -ENOMEM; |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 587 | if (!tomoyo_parse_name_union(filename, &e.name)) |
| 588 | return -EINVAL; |
| 589 | if (!tomoyo_parse_number_union(number, &e.number)) |
| 590 | goto out; |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 591 | error = tomoyo_update_domain(&e.head, sizeof(e), is_delete, domain, |
| 592 | tomoyo_same_path_number_acl, |
| 593 | tomoyo_merge_path_number_acl); |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 594 | out: |
| 595 | tomoyo_put_name_union(&e.name); |
| 596 | tomoyo_put_number_union(&e.number); |
| 597 | return error; |
| 598 | } |
| 599 | |
| 600 | /** |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 601 | * tomoyo_path_number_perm - Check permission for "create", "mkdir", "mkfifo", "mksock", "ioctl", "chmod", "chown", "chgrp". |
| 602 | * |
| 603 | * @type: Type of operation. |
| 604 | * @path: Pointer to "struct path". |
| 605 | * @number: Number. |
| 606 | * |
| 607 | * Returns 0 on success, negative value otherwise. |
| 608 | */ |
| 609 | int tomoyo_path_number_perm(const u8 type, struct path *path, |
| 610 | unsigned long number) |
| 611 | { |
| 612 | struct tomoyo_request_info r; |
| 613 | int error = -ENOMEM; |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 614 | struct tomoyo_path_info buf; |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 615 | int idx; |
| 616 | |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 617 | if (tomoyo_init_request_info(&r, NULL, tomoyo_pn2mac[type]) |
| 618 | == TOMOYO_CONFIG_DISABLED || !path->mnt || !path->dentry) |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 619 | return 0; |
| 620 | idx = tomoyo_read_lock(); |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 621 | if (!tomoyo_get_realpath(&buf, path)) |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 622 | goto out; |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 623 | if (type == TOMOYO_TYPE_MKDIR) |
| 624 | tomoyo_add_slash(&buf); |
Tetsuo Handa | cb917cf | 2010-06-16 16:28:21 +0900 | [diff] [blame] | 625 | r.param_type = TOMOYO_TYPE_PATH_NUMBER_ACL; |
| 626 | r.param.path_number.operation = type; |
| 627 | r.param.path_number.filename = &buf; |
| 628 | r.param.path_number.number = number; |
| 629 | do { |
| 630 | tomoyo_check_acl(&r, tomoyo_check_path_number_acl); |
| 631 | error = tomoyo_audit_path_number_log(&r); |
| 632 | } while (error == TOMOYO_RETRY_REQUEST); |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 633 | kfree(buf.name); |
Tetsuo Handa | cb917cf | 2010-06-16 16:28:21 +0900 | [diff] [blame] | 634 | out: |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 635 | tomoyo_read_unlock(idx); |
| 636 | if (r.mode != TOMOYO_CONFIG_ENFORCING) |
| 637 | error = 0; |
| 638 | return error; |
| 639 | } |
| 640 | |
| 641 | /** |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 642 | * tomoyo_check_open_permission - Check permission for "read" and "write". |
| 643 | * |
| 644 | * @domain: Pointer to "struct tomoyo_domain_info". |
| 645 | * @path: Pointer to "struct path". |
| 646 | * @flag: Flags for open(). |
| 647 | * |
| 648 | * Returns 0 on success, negative value otherwise. |
| 649 | */ |
| 650 | int tomoyo_check_open_permission(struct tomoyo_domain_info *domain, |
| 651 | struct path *path, const int flag) |
| 652 | { |
| 653 | const u8 acc_mode = ACC_MODE(flag); |
Tetsuo Handa | eae61f3 | 2011-03-02 16:54:24 +0900 | [diff] [blame] | 654 | int error = 0; |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 655 | struct tomoyo_path_info buf; |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 656 | struct tomoyo_request_info r; |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 657 | int idx; |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 658 | |
Tetsuo Handa | 7c75964 | 2011-06-26 23:15:31 +0900 | [diff] [blame^] | 659 | if (!path->mnt) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 660 | return 0; |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 661 | buf.name = NULL; |
| 662 | r.mode = TOMOYO_CONFIG_DISABLED; |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 663 | idx = tomoyo_read_lock(); |
Tetsuo Handa | 7c75964 | 2011-06-26 23:15:31 +0900 | [diff] [blame^] | 664 | if (acc_mode && |
| 665 | tomoyo_init_request_info(&r, domain, TOMOYO_MAC_FILE_OPEN) |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 666 | != TOMOYO_CONFIG_DISABLED) { |
| 667 | if (!tomoyo_get_realpath(&buf, path)) { |
| 668 | error = -ENOMEM; |
| 669 | goto out; |
| 670 | } |
Tetsuo Handa | 7c75964 | 2011-06-26 23:15:31 +0900 | [diff] [blame^] | 671 | if (acc_mode & MAY_READ) |
| 672 | error = tomoyo_path_permission(&r, TOMOYO_TYPE_READ, |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 673 | &buf); |
Tetsuo Handa | 7c75964 | 2011-06-26 23:15:31 +0900 | [diff] [blame^] | 674 | if (!error && (acc_mode & MAY_WRITE)) |
| 675 | error = tomoyo_path_permission(&r, (flag & O_APPEND) ? |
| 676 | TOMOYO_TYPE_APPEND : |
| 677 | TOMOYO_TYPE_WRITE, |
| 678 | &buf); |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 679 | } |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 680 | out: |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 681 | kfree(buf.name); |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 682 | tomoyo_read_unlock(idx); |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 683 | if (r.mode != TOMOYO_CONFIG_ENFORCING) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 684 | error = 0; |
| 685 | return error; |
| 686 | } |
| 687 | |
| 688 | /** |
Tetsuo Handa | 7c75964 | 2011-06-26 23:15:31 +0900 | [diff] [blame^] | 689 | * tomoyo_path_perm - Check permission for "unlink", "rmdir", "truncate", "symlink", "append", "chroot" and "unmount". |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 690 | * |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 691 | * @operation: Type of operation. |
| 692 | * @path: Pointer to "struct path". |
| 693 | * |
| 694 | * Returns 0 on success, negative value otherwise. |
| 695 | */ |
Tetsuo Handa | 97d6931 | 2010-02-16 09:46:15 +0900 | [diff] [blame] | 696 | int tomoyo_path_perm(const u8 operation, struct path *path) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 697 | { |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 698 | struct tomoyo_request_info r; |
Tetsuo Handa | 7c75964 | 2011-06-26 23:15:31 +0900 | [diff] [blame^] | 699 | int error; |
| 700 | struct tomoyo_path_info buf; |
| 701 | bool is_enforce; |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 702 | int idx; |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 703 | |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 704 | if (!path->mnt) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 705 | return 0; |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 706 | if (tomoyo_init_request_info(&r, NULL, tomoyo_p2mac[operation]) |
| 707 | == TOMOYO_CONFIG_DISABLED) |
| 708 | return 0; |
Tetsuo Handa | 7c75964 | 2011-06-26 23:15:31 +0900 | [diff] [blame^] | 709 | is_enforce = (r.mode == TOMOYO_CONFIG_ENFORCING); |
| 710 | error = -ENOMEM; |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 711 | buf.name = NULL; |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 712 | idx = tomoyo_read_lock(); |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 713 | if (!tomoyo_get_realpath(&buf, path)) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 714 | goto out; |
| 715 | switch (operation) { |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 716 | case TOMOYO_TYPE_RMDIR: |
| 717 | case TOMOYO_TYPE_CHROOT: |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 718 | tomoyo_add_slash(&buf); |
| 719 | break; |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 720 | } |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 721 | error = tomoyo_path_permission(&r, operation, &buf); |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 722 | out: |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 723 | kfree(buf.name); |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 724 | tomoyo_read_unlock(idx); |
Tetsuo Handa | 7c75964 | 2011-06-26 23:15:31 +0900 | [diff] [blame^] | 725 | if (!is_enforce) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 726 | error = 0; |
| 727 | return error; |
| 728 | } |
| 729 | |
| 730 | /** |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 731 | * tomoyo_mkdev_perm - Check permission for "mkblock" and "mkchar". |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 732 | * |
| 733 | * @operation: Type of operation. (TOMOYO_TYPE_MKCHAR or TOMOYO_TYPE_MKBLOCK) |
| 734 | * @path: Pointer to "struct path". |
| 735 | * @mode: Create mode. |
| 736 | * @dev: Device number. |
| 737 | * |
| 738 | * Returns 0 on success, negative value otherwise. |
| 739 | */ |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 740 | int tomoyo_mkdev_perm(const u8 operation, struct path *path, |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 741 | const unsigned int mode, unsigned int dev) |
| 742 | { |
| 743 | struct tomoyo_request_info r; |
| 744 | int error = -ENOMEM; |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 745 | struct tomoyo_path_info buf; |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 746 | int idx; |
| 747 | |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 748 | if (!path->mnt || |
| 749 | tomoyo_init_request_info(&r, NULL, tomoyo_pnnn2mac[operation]) |
| 750 | == TOMOYO_CONFIG_DISABLED) |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 751 | return 0; |
| 752 | idx = tomoyo_read_lock(); |
| 753 | error = -ENOMEM; |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 754 | if (tomoyo_get_realpath(&buf, path)) { |
Tetsuo Handa | cf6e9a6 | 2010-06-16 16:21:36 +0900 | [diff] [blame] | 755 | dev = new_decode_dev(dev); |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 756 | r.param_type = TOMOYO_TYPE_MKDEV_ACL; |
Tetsuo Handa | cf6e9a6 | 2010-06-16 16:21:36 +0900 | [diff] [blame] | 757 | r.param.mkdev.filename = &buf; |
| 758 | r.param.mkdev.operation = operation; |
| 759 | r.param.mkdev.mode = mode; |
| 760 | r.param.mkdev.major = MAJOR(dev); |
| 761 | r.param.mkdev.minor = MINOR(dev); |
Tetsuo Handa | 99a8525 | 2010-06-16 16:22:51 +0900 | [diff] [blame] | 762 | tomoyo_check_acl(&r, tomoyo_check_mkdev_acl); |
| 763 | error = tomoyo_audit_mkdev_log(&r); |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 764 | kfree(buf.name); |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 765 | } |
| 766 | tomoyo_read_unlock(idx); |
| 767 | if (r.mode != TOMOYO_CONFIG_ENFORCING) |
| 768 | error = 0; |
| 769 | return error; |
| 770 | } |
| 771 | |
| 772 | /** |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 773 | * tomoyo_path2_perm - Check permission for "rename", "link" and "pivot_root". |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 774 | * |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 775 | * @operation: Type of operation. |
| 776 | * @path1: Pointer to "struct path". |
| 777 | * @path2: Pointer to "struct path". |
| 778 | * |
| 779 | * Returns 0 on success, negative value otherwise. |
| 780 | */ |
Tetsuo Handa | 97d6931 | 2010-02-16 09:46:15 +0900 | [diff] [blame] | 781 | int tomoyo_path2_perm(const u8 operation, struct path *path1, |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 782 | struct path *path2) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 783 | { |
| 784 | int error = -ENOMEM; |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 785 | struct tomoyo_path_info buf1; |
| 786 | struct tomoyo_path_info buf2; |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 787 | struct tomoyo_request_info r; |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 788 | int idx; |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 789 | |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 790 | if (!path1->mnt || !path2->mnt || |
| 791 | tomoyo_init_request_info(&r, NULL, tomoyo_pp2mac[operation]) |
| 792 | == TOMOYO_CONFIG_DISABLED) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 793 | return 0; |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 794 | buf1.name = NULL; |
| 795 | buf2.name = NULL; |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 796 | idx = tomoyo_read_lock(); |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 797 | if (!tomoyo_get_realpath(&buf1, path1) || |
| 798 | !tomoyo_get_realpath(&buf2, path2)) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 799 | goto out; |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 800 | switch (operation) { |
| 801 | struct dentry *dentry; |
| 802 | case TOMOYO_TYPE_RENAME: |
| 803 | case TOMOYO_TYPE_LINK: |
| 804 | dentry = path1->dentry; |
| 805 | if (!dentry->d_inode || !S_ISDIR(dentry->d_inode->i_mode)) |
| 806 | break; |
| 807 | /* fall through */ |
| 808 | case TOMOYO_TYPE_PIVOT_ROOT: |
| 809 | tomoyo_add_slash(&buf1); |
| 810 | tomoyo_add_slash(&buf2); |
| 811 | break; |
| 812 | } |
Tetsuo Handa | cf6e9a6 | 2010-06-16 16:21:36 +0900 | [diff] [blame] | 813 | r.param_type = TOMOYO_TYPE_PATH2_ACL; |
| 814 | r.param.path2.operation = operation; |
| 815 | r.param.path2.filename1 = &buf1; |
| 816 | r.param.path2.filename2 = &buf2; |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 817 | do { |
Tetsuo Handa | 99a8525 | 2010-06-16 16:22:51 +0900 | [diff] [blame] | 818 | tomoyo_check_acl(&r, tomoyo_check_path2_acl); |
| 819 | error = tomoyo_audit_path2_log(&r); |
| 820 | } while (error == TOMOYO_RETRY_REQUEST); |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 821 | out: |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 822 | kfree(buf1.name); |
| 823 | kfree(buf2.name); |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 824 | tomoyo_read_unlock(idx); |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 825 | if (r.mode != TOMOYO_CONFIG_ENFORCING) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 826 | error = 0; |
| 827 | return error; |
| 828 | } |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 829 | |
| 830 | /** |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 831 | * tomoyo_write_file - Update file related list. |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 832 | * |
| 833 | * @data: String to parse. |
| 834 | * @domain: Pointer to "struct tomoyo_domain_info". |
| 835 | * @is_delete: True if it is a delete request. |
| 836 | * |
| 837 | * Returns 0 on success, negative value otherwise. |
| 838 | * |
| 839 | * Caller holds tomoyo_read_lock(). |
| 840 | */ |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 841 | int tomoyo_write_file(char *data, struct tomoyo_domain_info *domain, |
| 842 | const bool is_delete) |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 843 | { |
| 844 | char *w[5]; |
| 845 | u8 type; |
| 846 | if (!tomoyo_tokenize(data, w, sizeof(w)) || !w[1][0]) |
| 847 | return -EINVAL; |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 848 | if (strncmp(w[0], "allow_", 6)) |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 849 | goto out; |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 850 | w[0] += 6; |
| 851 | for (type = 0; type < TOMOYO_MAX_PATH_OPERATION; type++) { |
| 852 | if (strcmp(w[0], tomoyo_path_keyword[type])) |
| 853 | continue; |
| 854 | return tomoyo_update_path_acl(type, w[1], domain, is_delete); |
| 855 | } |
| 856 | if (!w[2][0]) |
| 857 | goto out; |
| 858 | for (type = 0; type < TOMOYO_MAX_PATH2_OPERATION; type++) { |
| 859 | if (strcmp(w[0], tomoyo_path2_keyword[type])) |
| 860 | continue; |
| 861 | return tomoyo_update_path2_acl(type, w[1], w[2], domain, |
| 862 | is_delete); |
| 863 | } |
| 864 | for (type = 0; type < TOMOYO_MAX_PATH_NUMBER_OPERATION; type++) { |
| 865 | if (strcmp(w[0], tomoyo_path_number_keyword[type])) |
| 866 | continue; |
| 867 | return tomoyo_update_path_number_acl(type, w[1], w[2], domain, |
| 868 | is_delete); |
| 869 | } |
| 870 | if (!w[3][0] || !w[4][0]) |
| 871 | goto out; |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 872 | for (type = 0; type < TOMOYO_MAX_MKDEV_OPERATION; type++) { |
| 873 | if (strcmp(w[0], tomoyo_mkdev_keyword[type])) |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 874 | continue; |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 875 | return tomoyo_update_mkdev_acl(type, w[1], w[2], w[3], |
| 876 | w[4], domain, is_delete); |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 877 | } |
| 878 | out: |
| 879 | return -EINVAL; |
| 880 | } |