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 | * |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame^] | 215 | * @r: Pointer to "struct tomoyo_request_info". |
Tetsuo Handa | 99a8525 | 2010-06-16 16:22:51 +0900 | [diff] [blame] | 216 | * |
| 217 | * Returns 0 on success, negative value otherwise. |
| 218 | */ |
| 219 | static int tomoyo_audit_path_number_log(struct tomoyo_request_info *r) |
| 220 | { |
| 221 | const u8 type = r->param.path_number.operation; |
| 222 | u8 radix; |
| 223 | const struct tomoyo_path_info *filename = r->param.path_number.filename; |
| 224 | const char *operation = tomoyo_path_number_keyword[type]; |
| 225 | char buffer[64]; |
| 226 | if (r->granted) |
| 227 | return 0; |
| 228 | switch (type) { |
| 229 | case TOMOYO_TYPE_CREATE: |
| 230 | case TOMOYO_TYPE_MKDIR: |
| 231 | case TOMOYO_TYPE_MKFIFO: |
| 232 | case TOMOYO_TYPE_MKSOCK: |
| 233 | case TOMOYO_TYPE_CHMOD: |
| 234 | radix = TOMOYO_VALUE_TYPE_OCTAL; |
| 235 | break; |
| 236 | case TOMOYO_TYPE_IOCTL: |
| 237 | radix = TOMOYO_VALUE_TYPE_HEXADECIMAL; |
| 238 | break; |
| 239 | default: |
| 240 | radix = TOMOYO_VALUE_TYPE_DECIMAL; |
| 241 | break; |
| 242 | } |
| 243 | tomoyo_print_ulong(buffer, sizeof(buffer), r->param.path_number.number, |
| 244 | radix); |
| 245 | tomoyo_warn_log(r, "%s %s %s", operation, filename->name, buffer); |
| 246 | return tomoyo_supervisor(r, "allow_%s %s %s\n", operation, |
Tetsuo Handa | 7c75964 | 2011-06-26 23:15:31 +0900 | [diff] [blame] | 247 | filename->name, buffer); |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 248 | } |
| 249 | |
Tetsuo Handa | 484ca79 | 2010-07-29 14:29:55 +0900 | [diff] [blame] | 250 | static bool tomoyo_check_path_acl(struct tomoyo_request_info *r, |
Tetsuo Handa | 99a8525 | 2010-06-16 16:22:51 +0900 | [diff] [blame] | 251 | const struct tomoyo_acl_info *ptr) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 252 | { |
Tetsuo Handa | 99a8525 | 2010-06-16 16:22:51 +0900 | [diff] [blame] | 253 | const struct tomoyo_path_acl *acl = container_of(ptr, typeof(*acl), |
| 254 | head); |
Tetsuo Handa | 484ca79 | 2010-07-29 14:29:55 +0900 | [diff] [blame] | 255 | if (acl->perm & (1 << r->param.path.operation)) { |
| 256 | r->param.path.matched_path = |
| 257 | tomoyo_compare_name_union(r->param.path.filename, |
| 258 | &acl->name); |
| 259 | return r->param.path.matched_path != NULL; |
| 260 | } |
| 261 | return false; |
Tetsuo Handa | 99a8525 | 2010-06-16 16:22:51 +0900 | [diff] [blame] | 262 | } |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 263 | |
Tetsuo Handa | 484ca79 | 2010-07-29 14:29:55 +0900 | [diff] [blame] | 264 | static bool tomoyo_check_path_number_acl(struct tomoyo_request_info *r, |
Tetsuo Handa | 99a8525 | 2010-06-16 16:22:51 +0900 | [diff] [blame] | 265 | const struct tomoyo_acl_info *ptr) |
| 266 | { |
| 267 | const struct tomoyo_path_number_acl *acl = |
| 268 | container_of(ptr, typeof(*acl), head); |
| 269 | return (acl->perm & (1 << r->param.path_number.operation)) && |
| 270 | tomoyo_compare_number_union(r->param.path_number.number, |
| 271 | &acl->number) && |
| 272 | tomoyo_compare_name_union(r->param.path_number.filename, |
| 273 | &acl->name); |
| 274 | } |
| 275 | |
Tetsuo Handa | 484ca79 | 2010-07-29 14:29:55 +0900 | [diff] [blame] | 276 | static bool tomoyo_check_path2_acl(struct tomoyo_request_info *r, |
Tetsuo Handa | 99a8525 | 2010-06-16 16:22:51 +0900 | [diff] [blame] | 277 | const struct tomoyo_acl_info *ptr) |
| 278 | { |
| 279 | const struct tomoyo_path2_acl *acl = |
| 280 | container_of(ptr, typeof(*acl), head); |
| 281 | return (acl->perm & (1 << r->param.path2.operation)) && |
| 282 | tomoyo_compare_name_union(r->param.path2.filename1, &acl->name1) |
| 283 | && tomoyo_compare_name_union(r->param.path2.filename2, |
| 284 | &acl->name2); |
| 285 | } |
| 286 | |
Tetsuo Handa | 484ca79 | 2010-07-29 14:29:55 +0900 | [diff] [blame] | 287 | static bool tomoyo_check_mkdev_acl(struct tomoyo_request_info *r, |
Tetsuo Handa | 99a8525 | 2010-06-16 16:22:51 +0900 | [diff] [blame] | 288 | const struct tomoyo_acl_info *ptr) |
| 289 | { |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 290 | const struct tomoyo_mkdev_acl *acl = |
Tetsuo Handa | 99a8525 | 2010-06-16 16:22:51 +0900 | [diff] [blame] | 291 | container_of(ptr, typeof(*acl), head); |
| 292 | return (acl->perm & (1 << r->param.mkdev.operation)) && |
| 293 | tomoyo_compare_number_union(r->param.mkdev.mode, |
| 294 | &acl->mode) && |
| 295 | tomoyo_compare_number_union(r->param.mkdev.major, |
| 296 | &acl->major) && |
| 297 | tomoyo_compare_number_union(r->param.mkdev.minor, |
| 298 | &acl->minor) && |
| 299 | tomoyo_compare_name_union(r->param.mkdev.filename, |
| 300 | &acl->name); |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 301 | } |
| 302 | |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 303 | static bool tomoyo_same_path_acl(const struct tomoyo_acl_info *a, |
| 304 | const struct tomoyo_acl_info *b) |
| 305 | { |
| 306 | const struct tomoyo_path_acl *p1 = container_of(a, typeof(*p1), head); |
| 307 | const struct tomoyo_path_acl *p2 = container_of(b, typeof(*p2), head); |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 308 | return tomoyo_same_acl_head(&p1->head, &p2->head) && |
| 309 | tomoyo_same_name_union(&p1->name, &p2->name); |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 310 | } |
| 311 | |
Tetsuo Handa | 7c75964 | 2011-06-26 23:15:31 +0900 | [diff] [blame] | 312 | /** |
| 313 | * tomoyo_merge_path_acl - Merge duplicated "struct tomoyo_path_acl" entry. |
| 314 | * |
| 315 | * @a: Pointer to "struct tomoyo_acl_info". |
| 316 | * @b: Pointer to "struct tomoyo_acl_info". |
| 317 | * @is_delete: True for @a &= ~@b, false for @a |= @b. |
| 318 | * |
| 319 | * Returns true if @a is empty, false otherwise. |
| 320 | */ |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 321 | static bool tomoyo_merge_path_acl(struct tomoyo_acl_info *a, |
| 322 | struct tomoyo_acl_info *b, |
| 323 | const bool is_delete) |
| 324 | { |
| 325 | u16 * const a_perm = &container_of(a, struct tomoyo_path_acl, head) |
| 326 | ->perm; |
| 327 | u16 perm = *a_perm; |
| 328 | 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] | 329 | if (is_delete) |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 330 | perm &= ~b_perm; |
Tetsuo Handa | 7c75964 | 2011-06-26 23:15:31 +0900 | [diff] [blame] | 331 | else |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 332 | perm |= b_perm; |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 333 | *a_perm = perm; |
| 334 | return !perm; |
| 335 | } |
| 336 | |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 337 | /** |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 338 | * tomoyo_update_path_acl - Update "struct tomoyo_path_acl" list. |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 339 | * |
| 340 | * @type: Type of operation. |
| 341 | * @filename: Filename. |
| 342 | * @domain: Pointer to "struct tomoyo_domain_info". |
| 343 | * @is_delete: True if it is a delete request. |
| 344 | * |
| 345 | * Returns 0 on success, negative value otherwise. |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 346 | * |
| 347 | * Caller holds tomoyo_read_lock(). |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 348 | */ |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 349 | static int tomoyo_update_path_acl(const u8 type, const char *filename, |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 350 | struct tomoyo_domain_info * const domain, |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 351 | const bool is_delete) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 352 | { |
Tetsuo Handa | 9e4b50e | 2010-05-06 12:40:02 +0900 | [diff] [blame] | 353 | struct tomoyo_path_acl e = { |
| 354 | .head.type = TOMOYO_TYPE_PATH_ACL, |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 355 | .perm = 1 << type |
Tetsuo Handa | 9e4b50e | 2010-05-06 12:40:02 +0900 | [diff] [blame] | 356 | }; |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 357 | int error; |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 358 | if (!tomoyo_parse_name_union(filename, &e.name)) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 359 | return -EINVAL; |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 360 | error = tomoyo_update_domain(&e.head, sizeof(e), is_delete, domain, |
| 361 | tomoyo_same_path_acl, |
| 362 | tomoyo_merge_path_acl); |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 363 | tomoyo_put_name_union(&e.name); |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 364 | return error; |
| 365 | } |
| 366 | |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 367 | static bool tomoyo_same_mkdev_acl(const struct tomoyo_acl_info *a, |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 368 | const struct tomoyo_acl_info *b) |
| 369 | { |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 370 | const struct tomoyo_mkdev_acl *p1 = container_of(a, typeof(*p1), |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 371 | head); |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 372 | const struct tomoyo_mkdev_acl *p2 = container_of(b, typeof(*p2), |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 373 | head); |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 374 | return tomoyo_same_acl_head(&p1->head, &p2->head) |
| 375 | && tomoyo_same_name_union(&p1->name, &p2->name) |
| 376 | && tomoyo_same_number_union(&p1->mode, &p2->mode) |
| 377 | && tomoyo_same_number_union(&p1->major, &p2->major) |
| 378 | && tomoyo_same_number_union(&p1->minor, &p2->minor); |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 379 | } |
| 380 | |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 381 | static bool tomoyo_merge_mkdev_acl(struct tomoyo_acl_info *a, |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 382 | struct tomoyo_acl_info *b, |
| 383 | const bool is_delete) |
| 384 | { |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 385 | u8 *const a_perm = &container_of(a, struct tomoyo_mkdev_acl, |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 386 | head)->perm; |
| 387 | u8 perm = *a_perm; |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 388 | const u8 b_perm = container_of(b, struct tomoyo_mkdev_acl, head) |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 389 | ->perm; |
| 390 | if (is_delete) |
| 391 | perm &= ~b_perm; |
| 392 | else |
| 393 | perm |= b_perm; |
| 394 | *a_perm = perm; |
| 395 | return !perm; |
| 396 | } |
| 397 | |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 398 | /** |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 399 | * tomoyo_update_mkdev_acl - Update "struct tomoyo_mkdev_acl" list. |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 400 | * |
| 401 | * @type: Type of operation. |
| 402 | * @filename: Filename. |
| 403 | * @mode: Create mode. |
| 404 | * @major: Device major number. |
| 405 | * @minor: Device minor number. |
| 406 | * @domain: Pointer to "struct tomoyo_domain_info". |
| 407 | * @is_delete: True if it is a delete request. |
| 408 | * |
| 409 | * Returns 0 on success, negative value otherwise. |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 410 | * |
| 411 | * Caller holds tomoyo_read_lock(). |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 412 | */ |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 413 | static int tomoyo_update_mkdev_acl(const u8 type, const char *filename, |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 414 | char *mode, char *major, char *minor, |
| 415 | struct tomoyo_domain_info * const |
| 416 | domain, const bool is_delete) |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 417 | { |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 418 | struct tomoyo_mkdev_acl e = { |
| 419 | .head.type = TOMOYO_TYPE_MKDEV_ACL, |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 420 | .perm = 1 << type |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 421 | }; |
| 422 | int error = is_delete ? -ENOENT : -ENOMEM; |
| 423 | if (!tomoyo_parse_name_union(filename, &e.name) || |
| 424 | !tomoyo_parse_number_union(mode, &e.mode) || |
| 425 | !tomoyo_parse_number_union(major, &e.major) || |
| 426 | !tomoyo_parse_number_union(minor, &e.minor)) |
| 427 | goto out; |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 428 | error = tomoyo_update_domain(&e.head, sizeof(e), is_delete, domain, |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 429 | tomoyo_same_mkdev_acl, |
| 430 | tomoyo_merge_mkdev_acl); |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 431 | out: |
| 432 | tomoyo_put_name_union(&e.name); |
| 433 | tomoyo_put_number_union(&e.mode); |
| 434 | tomoyo_put_number_union(&e.major); |
| 435 | tomoyo_put_number_union(&e.minor); |
| 436 | return error; |
| 437 | } |
| 438 | |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 439 | static bool tomoyo_same_path2_acl(const struct tomoyo_acl_info *a, |
| 440 | const struct tomoyo_acl_info *b) |
| 441 | { |
| 442 | const struct tomoyo_path2_acl *p1 = container_of(a, typeof(*p1), head); |
| 443 | const struct tomoyo_path2_acl *p2 = container_of(b, typeof(*p2), head); |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 444 | return tomoyo_same_acl_head(&p1->head, &p2->head) |
| 445 | && tomoyo_same_name_union(&p1->name1, &p2->name1) |
| 446 | && tomoyo_same_name_union(&p1->name2, &p2->name2); |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | static bool tomoyo_merge_path2_acl(struct tomoyo_acl_info *a, |
| 450 | struct tomoyo_acl_info *b, |
| 451 | const bool is_delete) |
| 452 | { |
| 453 | u8 * const a_perm = &container_of(a, struct tomoyo_path2_acl, head) |
| 454 | ->perm; |
| 455 | u8 perm = *a_perm; |
| 456 | const u8 b_perm = container_of(b, struct tomoyo_path2_acl, head)->perm; |
| 457 | if (is_delete) |
| 458 | perm &= ~b_perm; |
| 459 | else |
| 460 | perm |= b_perm; |
| 461 | *a_perm = perm; |
| 462 | return !perm; |
| 463 | } |
| 464 | |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 465 | /** |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 466 | * tomoyo_update_path2_acl - Update "struct tomoyo_path2_acl" list. |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 467 | * |
| 468 | * @type: Type of operation. |
| 469 | * @filename1: First filename. |
| 470 | * @filename2: Second filename. |
| 471 | * @domain: Pointer to "struct tomoyo_domain_info". |
| 472 | * @is_delete: True if it is a delete request. |
| 473 | * |
| 474 | * Returns 0 on success, negative value otherwise. |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 475 | * |
| 476 | * Caller holds tomoyo_read_lock(). |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 477 | */ |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 478 | static int tomoyo_update_path2_acl(const u8 type, const char *filename1, |
| 479 | const char *filename2, |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 480 | struct tomoyo_domain_info * const domain, |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 481 | const bool is_delete) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 482 | { |
Tetsuo Handa | 9e4b50e | 2010-05-06 12:40:02 +0900 | [diff] [blame] | 483 | struct tomoyo_path2_acl e = { |
| 484 | .head.type = TOMOYO_TYPE_PATH2_ACL, |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 485 | .perm = 1 << type |
Tetsuo Handa | 9e4b50e | 2010-05-06 12:40:02 +0900 | [diff] [blame] | 486 | }; |
Tetsuo Handa | 9e4b50e | 2010-05-06 12:40:02 +0900 | [diff] [blame] | 487 | int error = is_delete ? -ENOENT : -ENOMEM; |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 488 | if (!tomoyo_parse_name_union(filename1, &e.name1) || |
| 489 | !tomoyo_parse_name_union(filename2, &e.name2)) |
Tetsuo Handa | ca0b7df | 2010-02-07 20:23:59 +0900 | [diff] [blame] | 490 | goto out; |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 491 | error = tomoyo_update_domain(&e.head, sizeof(e), is_delete, domain, |
| 492 | tomoyo_same_path2_acl, |
| 493 | tomoyo_merge_path2_acl); |
Tetsuo Handa | ca0b7df | 2010-02-07 20:23:59 +0900 | [diff] [blame] | 494 | out: |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 495 | tomoyo_put_name_union(&e.name1); |
| 496 | tomoyo_put_name_union(&e.name2); |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 497 | return error; |
| 498 | } |
| 499 | |
| 500 | /** |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 501 | * tomoyo_path_permission - Check permission for single path operation. |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 502 | * |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 503 | * @r: Pointer to "struct tomoyo_request_info". |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 504 | * @operation: Type of operation. |
| 505 | * @filename: Filename to check. |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 506 | * |
| 507 | * Returns 0 on success, negative value otherwise. |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 508 | * |
| 509 | * Caller holds tomoyo_read_lock(). |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 510 | */ |
Tetsuo Handa | 05336de | 2010-06-16 16:20:24 +0900 | [diff] [blame] | 511 | int tomoyo_path_permission(struct tomoyo_request_info *r, u8 operation, |
| 512 | const struct tomoyo_path_info *filename) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 513 | { |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 514 | int error; |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 515 | |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 516 | r->type = tomoyo_p2mac[operation]; |
| 517 | r->mode = tomoyo_get_mode(r->profile, r->type); |
| 518 | if (r->mode == TOMOYO_CONFIG_DISABLED) |
| 519 | return 0; |
Tetsuo Handa | cf6e9a6 | 2010-06-16 16:21:36 +0900 | [diff] [blame] | 520 | r->param_type = TOMOYO_TYPE_PATH_ACL; |
| 521 | r->param.path.filename = filename; |
| 522 | r->param.path.operation = operation; |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 523 | do { |
Tetsuo Handa | 99a8525 | 2010-06-16 16:22:51 +0900 | [diff] [blame] | 524 | tomoyo_check_acl(r, tomoyo_check_path_acl); |
Tetsuo Handa | 99a8525 | 2010-06-16 16:22:51 +0900 | [diff] [blame] | 525 | error = tomoyo_audit_path_log(r); |
Tetsuo Handa | 05336de | 2010-06-16 16:20:24 +0900 | [diff] [blame] | 526 | /* |
| 527 | * Do not retry for execute request, for alias may have |
| 528 | * changed. |
| 529 | */ |
| 530 | } while (error == TOMOYO_RETRY_REQUEST && |
| 531 | operation != TOMOYO_TYPE_EXECUTE); |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 532 | return error; |
| 533 | } |
| 534 | |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 535 | static bool tomoyo_same_path_number_acl(const struct tomoyo_acl_info *a, |
| 536 | const struct tomoyo_acl_info *b) |
| 537 | { |
| 538 | const struct tomoyo_path_number_acl *p1 = container_of(a, typeof(*p1), |
| 539 | head); |
| 540 | const struct tomoyo_path_number_acl *p2 = container_of(b, typeof(*p2), |
| 541 | head); |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 542 | return tomoyo_same_acl_head(&p1->head, &p2->head) |
| 543 | && tomoyo_same_name_union(&p1->name, &p2->name) |
| 544 | && tomoyo_same_number_union(&p1->number, &p2->number); |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | static bool tomoyo_merge_path_number_acl(struct tomoyo_acl_info *a, |
| 548 | struct tomoyo_acl_info *b, |
| 549 | const bool is_delete) |
| 550 | { |
| 551 | u8 * const a_perm = &container_of(a, struct tomoyo_path_number_acl, |
| 552 | head)->perm; |
| 553 | u8 perm = *a_perm; |
| 554 | const u8 b_perm = container_of(b, struct tomoyo_path_number_acl, head) |
| 555 | ->perm; |
| 556 | if (is_delete) |
| 557 | perm &= ~b_perm; |
| 558 | else |
| 559 | perm |= b_perm; |
| 560 | *a_perm = perm; |
| 561 | return !perm; |
| 562 | } |
| 563 | |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 564 | /** |
| 565 | * tomoyo_update_path_number_acl - Update ioctl/chmod/chown/chgrp ACL. |
| 566 | * |
| 567 | * @type: Type of operation. |
| 568 | * @filename: Filename. |
| 569 | * @number: Number. |
| 570 | * @domain: Pointer to "struct tomoyo_domain_info". |
| 571 | * @is_delete: True if it is a delete request. |
| 572 | * |
| 573 | * Returns 0 on success, negative value otherwise. |
| 574 | */ |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 575 | static int tomoyo_update_path_number_acl(const u8 type, const char *filename, |
| 576 | char *number, |
| 577 | struct tomoyo_domain_info * const |
| 578 | domain, |
| 579 | const bool is_delete) |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 580 | { |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 581 | struct tomoyo_path_number_acl e = { |
| 582 | .head.type = TOMOYO_TYPE_PATH_NUMBER_ACL, |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 583 | .perm = 1 << type |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 584 | }; |
| 585 | int error = is_delete ? -ENOENT : -ENOMEM; |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 586 | if (!tomoyo_parse_name_union(filename, &e.name)) |
| 587 | return -EINVAL; |
| 588 | if (!tomoyo_parse_number_union(number, &e.number)) |
| 589 | goto out; |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 590 | error = tomoyo_update_domain(&e.head, sizeof(e), is_delete, domain, |
| 591 | tomoyo_same_path_number_acl, |
| 592 | tomoyo_merge_path_number_acl); |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 593 | out: |
| 594 | tomoyo_put_name_union(&e.name); |
| 595 | tomoyo_put_number_union(&e.number); |
| 596 | return error; |
| 597 | } |
| 598 | |
| 599 | /** |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 600 | * tomoyo_path_number_perm - Check permission for "create", "mkdir", "mkfifo", "mksock", "ioctl", "chmod", "chown", "chgrp". |
| 601 | * |
| 602 | * @type: Type of operation. |
| 603 | * @path: Pointer to "struct path". |
| 604 | * @number: Number. |
| 605 | * |
| 606 | * Returns 0 on success, negative value otherwise. |
| 607 | */ |
| 608 | int tomoyo_path_number_perm(const u8 type, struct path *path, |
| 609 | unsigned long number) |
| 610 | { |
| 611 | struct tomoyo_request_info r; |
| 612 | int error = -ENOMEM; |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 613 | struct tomoyo_path_info buf; |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 614 | int idx; |
| 615 | |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 616 | if (tomoyo_init_request_info(&r, NULL, tomoyo_pn2mac[type]) |
| 617 | == TOMOYO_CONFIG_DISABLED || !path->mnt || !path->dentry) |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 618 | return 0; |
| 619 | idx = tomoyo_read_lock(); |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 620 | if (!tomoyo_get_realpath(&buf, path)) |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 621 | goto out; |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 622 | if (type == TOMOYO_TYPE_MKDIR) |
| 623 | tomoyo_add_slash(&buf); |
Tetsuo Handa | cb917cf | 2010-06-16 16:28:21 +0900 | [diff] [blame] | 624 | r.param_type = TOMOYO_TYPE_PATH_NUMBER_ACL; |
| 625 | r.param.path_number.operation = type; |
| 626 | r.param.path_number.filename = &buf; |
| 627 | r.param.path_number.number = number; |
| 628 | do { |
| 629 | tomoyo_check_acl(&r, tomoyo_check_path_number_acl); |
| 630 | error = tomoyo_audit_path_number_log(&r); |
| 631 | } while (error == TOMOYO_RETRY_REQUEST); |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 632 | kfree(buf.name); |
Tetsuo Handa | cb917cf | 2010-06-16 16:28:21 +0900 | [diff] [blame] | 633 | out: |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 634 | tomoyo_read_unlock(idx); |
| 635 | if (r.mode != TOMOYO_CONFIG_ENFORCING) |
| 636 | error = 0; |
| 637 | return error; |
| 638 | } |
| 639 | |
| 640 | /** |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 641 | * tomoyo_check_open_permission - Check permission for "read" and "write". |
| 642 | * |
| 643 | * @domain: Pointer to "struct tomoyo_domain_info". |
| 644 | * @path: Pointer to "struct path". |
| 645 | * @flag: Flags for open(). |
| 646 | * |
| 647 | * Returns 0 on success, negative value otherwise. |
| 648 | */ |
| 649 | int tomoyo_check_open_permission(struct tomoyo_domain_info *domain, |
| 650 | struct path *path, const int flag) |
| 651 | { |
| 652 | const u8 acc_mode = ACC_MODE(flag); |
Tetsuo Handa | eae61f3 | 2011-03-02 16:54:24 +0900 | [diff] [blame] | 653 | int error = 0; |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 654 | struct tomoyo_path_info buf; |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 655 | struct tomoyo_request_info r; |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 656 | int idx; |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 657 | |
Tetsuo Handa | 7c75964 | 2011-06-26 23:15:31 +0900 | [diff] [blame] | 658 | if (!path->mnt) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 659 | return 0; |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 660 | buf.name = NULL; |
| 661 | r.mode = TOMOYO_CONFIG_DISABLED; |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 662 | idx = tomoyo_read_lock(); |
Tetsuo Handa | 7c75964 | 2011-06-26 23:15:31 +0900 | [diff] [blame] | 663 | if (acc_mode && |
| 664 | tomoyo_init_request_info(&r, domain, TOMOYO_MAC_FILE_OPEN) |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 665 | != TOMOYO_CONFIG_DISABLED) { |
| 666 | if (!tomoyo_get_realpath(&buf, path)) { |
| 667 | error = -ENOMEM; |
| 668 | goto out; |
| 669 | } |
Tetsuo Handa | 7c75964 | 2011-06-26 23:15:31 +0900 | [diff] [blame] | 670 | if (acc_mode & MAY_READ) |
| 671 | error = tomoyo_path_permission(&r, TOMOYO_TYPE_READ, |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 672 | &buf); |
Tetsuo Handa | 7c75964 | 2011-06-26 23:15:31 +0900 | [diff] [blame] | 673 | if (!error && (acc_mode & MAY_WRITE)) |
| 674 | error = tomoyo_path_permission(&r, (flag & O_APPEND) ? |
| 675 | TOMOYO_TYPE_APPEND : |
| 676 | TOMOYO_TYPE_WRITE, |
| 677 | &buf); |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 678 | } |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 679 | out: |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 680 | kfree(buf.name); |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 681 | tomoyo_read_unlock(idx); |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 682 | if (r.mode != TOMOYO_CONFIG_ENFORCING) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 683 | error = 0; |
| 684 | return error; |
| 685 | } |
| 686 | |
| 687 | /** |
Tetsuo Handa | 7c75964 | 2011-06-26 23:15:31 +0900 | [diff] [blame] | 688 | * 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] | 689 | * |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 690 | * @operation: Type of operation. |
| 691 | * @path: Pointer to "struct path". |
| 692 | * |
| 693 | * Returns 0 on success, negative value otherwise. |
| 694 | */ |
Tetsuo Handa | 97d6931 | 2010-02-16 09:46:15 +0900 | [diff] [blame] | 695 | int tomoyo_path_perm(const u8 operation, struct path *path) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 696 | { |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 697 | struct tomoyo_request_info r; |
Tetsuo Handa | 7c75964 | 2011-06-26 23:15:31 +0900 | [diff] [blame] | 698 | int error; |
| 699 | struct tomoyo_path_info buf; |
| 700 | bool is_enforce; |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 701 | int idx; |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 702 | |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 703 | if (!path->mnt) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 704 | return 0; |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 705 | if (tomoyo_init_request_info(&r, NULL, tomoyo_p2mac[operation]) |
| 706 | == TOMOYO_CONFIG_DISABLED) |
| 707 | return 0; |
Tetsuo Handa | 7c75964 | 2011-06-26 23:15:31 +0900 | [diff] [blame] | 708 | is_enforce = (r.mode == TOMOYO_CONFIG_ENFORCING); |
| 709 | error = -ENOMEM; |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 710 | buf.name = NULL; |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 711 | idx = tomoyo_read_lock(); |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 712 | if (!tomoyo_get_realpath(&buf, path)) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 713 | goto out; |
| 714 | switch (operation) { |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 715 | case TOMOYO_TYPE_RMDIR: |
| 716 | case TOMOYO_TYPE_CHROOT: |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 717 | tomoyo_add_slash(&buf); |
| 718 | break; |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 719 | } |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 720 | error = tomoyo_path_permission(&r, operation, &buf); |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 721 | out: |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 722 | kfree(buf.name); |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 723 | tomoyo_read_unlock(idx); |
Tetsuo Handa | 7c75964 | 2011-06-26 23:15:31 +0900 | [diff] [blame] | 724 | if (!is_enforce) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 725 | error = 0; |
| 726 | return error; |
| 727 | } |
| 728 | |
| 729 | /** |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 730 | * tomoyo_mkdev_perm - Check permission for "mkblock" and "mkchar". |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 731 | * |
| 732 | * @operation: Type of operation. (TOMOYO_TYPE_MKCHAR or TOMOYO_TYPE_MKBLOCK) |
| 733 | * @path: Pointer to "struct path". |
| 734 | * @mode: Create mode. |
| 735 | * @dev: Device number. |
| 736 | * |
| 737 | * Returns 0 on success, negative value otherwise. |
| 738 | */ |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 739 | int tomoyo_mkdev_perm(const u8 operation, struct path *path, |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 740 | const unsigned int mode, unsigned int dev) |
| 741 | { |
| 742 | struct tomoyo_request_info r; |
| 743 | int error = -ENOMEM; |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 744 | struct tomoyo_path_info buf; |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 745 | int idx; |
| 746 | |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 747 | if (!path->mnt || |
| 748 | tomoyo_init_request_info(&r, NULL, tomoyo_pnnn2mac[operation]) |
| 749 | == TOMOYO_CONFIG_DISABLED) |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 750 | return 0; |
| 751 | idx = tomoyo_read_lock(); |
| 752 | error = -ENOMEM; |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 753 | if (tomoyo_get_realpath(&buf, path)) { |
Tetsuo Handa | cf6e9a6 | 2010-06-16 16:21:36 +0900 | [diff] [blame] | 754 | dev = new_decode_dev(dev); |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 755 | r.param_type = TOMOYO_TYPE_MKDEV_ACL; |
Tetsuo Handa | cf6e9a6 | 2010-06-16 16:21:36 +0900 | [diff] [blame] | 756 | r.param.mkdev.filename = &buf; |
| 757 | r.param.mkdev.operation = operation; |
| 758 | r.param.mkdev.mode = mode; |
| 759 | r.param.mkdev.major = MAJOR(dev); |
| 760 | r.param.mkdev.minor = MINOR(dev); |
Tetsuo Handa | 99a8525 | 2010-06-16 16:22:51 +0900 | [diff] [blame] | 761 | tomoyo_check_acl(&r, tomoyo_check_mkdev_acl); |
| 762 | error = tomoyo_audit_mkdev_log(&r); |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 763 | kfree(buf.name); |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 764 | } |
| 765 | tomoyo_read_unlock(idx); |
| 766 | if (r.mode != TOMOYO_CONFIG_ENFORCING) |
| 767 | error = 0; |
| 768 | return error; |
| 769 | } |
| 770 | |
| 771 | /** |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 772 | * tomoyo_path2_perm - Check permission for "rename", "link" and "pivot_root". |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 773 | * |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 774 | * @operation: Type of operation. |
| 775 | * @path1: Pointer to "struct path". |
| 776 | * @path2: Pointer to "struct path". |
| 777 | * |
| 778 | * Returns 0 on success, negative value otherwise. |
| 779 | */ |
Tetsuo Handa | 97d6931 | 2010-02-16 09:46:15 +0900 | [diff] [blame] | 780 | int tomoyo_path2_perm(const u8 operation, struct path *path1, |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 781 | struct path *path2) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 782 | { |
| 783 | int error = -ENOMEM; |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 784 | struct tomoyo_path_info buf1; |
| 785 | struct tomoyo_path_info buf2; |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 786 | struct tomoyo_request_info r; |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 787 | int idx; |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 788 | |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 789 | if (!path1->mnt || !path2->mnt || |
| 790 | tomoyo_init_request_info(&r, NULL, tomoyo_pp2mac[operation]) |
| 791 | == TOMOYO_CONFIG_DISABLED) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 792 | return 0; |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 793 | buf1.name = NULL; |
| 794 | buf2.name = NULL; |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 795 | idx = tomoyo_read_lock(); |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 796 | if (!tomoyo_get_realpath(&buf1, path1) || |
| 797 | !tomoyo_get_realpath(&buf2, path2)) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 798 | goto out; |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 799 | switch (operation) { |
| 800 | struct dentry *dentry; |
| 801 | case TOMOYO_TYPE_RENAME: |
| 802 | case TOMOYO_TYPE_LINK: |
| 803 | dentry = path1->dentry; |
| 804 | if (!dentry->d_inode || !S_ISDIR(dentry->d_inode->i_mode)) |
| 805 | break; |
| 806 | /* fall through */ |
| 807 | case TOMOYO_TYPE_PIVOT_ROOT: |
| 808 | tomoyo_add_slash(&buf1); |
| 809 | tomoyo_add_slash(&buf2); |
| 810 | break; |
| 811 | } |
Tetsuo Handa | cf6e9a6 | 2010-06-16 16:21:36 +0900 | [diff] [blame] | 812 | r.param_type = TOMOYO_TYPE_PATH2_ACL; |
| 813 | r.param.path2.operation = operation; |
| 814 | r.param.path2.filename1 = &buf1; |
| 815 | r.param.path2.filename2 = &buf2; |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 816 | do { |
Tetsuo Handa | 99a8525 | 2010-06-16 16:22:51 +0900 | [diff] [blame] | 817 | tomoyo_check_acl(&r, tomoyo_check_path2_acl); |
| 818 | error = tomoyo_audit_path2_log(&r); |
| 819 | } while (error == TOMOYO_RETRY_REQUEST); |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 820 | out: |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 821 | kfree(buf1.name); |
| 822 | kfree(buf2.name); |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 823 | tomoyo_read_unlock(idx); |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 824 | if (r.mode != TOMOYO_CONFIG_ENFORCING) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 825 | error = 0; |
| 826 | return error; |
| 827 | } |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 828 | |
| 829 | /** |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 830 | * tomoyo_write_file - Update file related list. |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 831 | * |
| 832 | * @data: String to parse. |
| 833 | * @domain: Pointer to "struct tomoyo_domain_info". |
| 834 | * @is_delete: True if it is a delete request. |
| 835 | * |
| 836 | * Returns 0 on success, negative value otherwise. |
| 837 | * |
| 838 | * Caller holds tomoyo_read_lock(). |
| 839 | */ |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 840 | int tomoyo_write_file(char *data, struct tomoyo_domain_info *domain, |
| 841 | const bool is_delete) |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 842 | { |
| 843 | char *w[5]; |
| 844 | u8 type; |
| 845 | if (!tomoyo_tokenize(data, w, sizeof(w)) || !w[1][0]) |
| 846 | return -EINVAL; |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 847 | if (strncmp(w[0], "allow_", 6)) |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 848 | goto out; |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 849 | w[0] += 6; |
| 850 | for (type = 0; type < TOMOYO_MAX_PATH_OPERATION; type++) { |
| 851 | if (strcmp(w[0], tomoyo_path_keyword[type])) |
| 852 | continue; |
| 853 | return tomoyo_update_path_acl(type, w[1], domain, is_delete); |
| 854 | } |
| 855 | if (!w[2][0]) |
| 856 | goto out; |
| 857 | for (type = 0; type < TOMOYO_MAX_PATH2_OPERATION; type++) { |
| 858 | if (strcmp(w[0], tomoyo_path2_keyword[type])) |
| 859 | continue; |
| 860 | return tomoyo_update_path2_acl(type, w[1], w[2], domain, |
| 861 | is_delete); |
| 862 | } |
| 863 | for (type = 0; type < TOMOYO_MAX_PATH_NUMBER_OPERATION; type++) { |
| 864 | if (strcmp(w[0], tomoyo_path_number_keyword[type])) |
| 865 | continue; |
| 866 | return tomoyo_update_path_number_acl(type, w[1], w[2], domain, |
| 867 | is_delete); |
| 868 | } |
| 869 | if (!w[3][0] || !w[4][0]) |
| 870 | goto out; |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 871 | for (type = 0; type < TOMOYO_MAX_MKDEV_OPERATION; type++) { |
| 872 | if (strcmp(w[0], tomoyo_mkdev_keyword[type])) |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 873 | continue; |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 874 | return tomoyo_update_mkdev_acl(type, w[1], w[2], w[3], |
| 875 | w[4], domain, is_delete); |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 876 | } |
| 877 | out: |
| 878 | return -EINVAL; |
| 879 | } |