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 | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 13 | static const char *tomoyo_path_keyword[TOMOYO_MAX_PATH_OPERATION] = { |
| 14 | [TOMOYO_TYPE_READ_WRITE] = "read/write", |
| 15 | [TOMOYO_TYPE_EXECUTE] = "execute", |
| 16 | [TOMOYO_TYPE_READ] = "read", |
| 17 | [TOMOYO_TYPE_WRITE] = "write", |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 18 | [TOMOYO_TYPE_UNLINK] = "unlink", |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 19 | [TOMOYO_TYPE_RMDIR] = "rmdir", |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 20 | [TOMOYO_TYPE_TRUNCATE] = "truncate", |
| 21 | [TOMOYO_TYPE_SYMLINK] = "symlink", |
| 22 | [TOMOYO_TYPE_REWRITE] = "rewrite", |
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. */ |
| 28 | static const char *tomoyo_path_number3_keyword |
| 29 | [TOMOYO_MAX_PATH_NUMBER3_OPERATION] = { |
| 30 | [TOMOYO_TYPE_MKBLOCK] = "mkblock", |
| 31 | [TOMOYO_TYPE_MKCHAR] = "mkchar", |
| 32 | }; |
| 33 | |
| 34 | /* Keyword array for operations with two pathnames. */ |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 35 | static const char *tomoyo_path2_keyword[TOMOYO_MAX_PATH2_OPERATION] = { |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 36 | [TOMOYO_TYPE_LINK] = "link", |
| 37 | [TOMOYO_TYPE_RENAME] = "rename", |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 38 | [TOMOYO_TYPE_PIVOT_ROOT] = "pivot_root", |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 39 | }; |
| 40 | |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 41 | /* Keyword array for operations with one pathname and one number. */ |
| 42 | static const char *tomoyo_path_number_keyword |
| 43 | [TOMOYO_MAX_PATH_NUMBER_OPERATION] = { |
| 44 | [TOMOYO_TYPE_CREATE] = "create", |
| 45 | [TOMOYO_TYPE_MKDIR] = "mkdir", |
| 46 | [TOMOYO_TYPE_MKFIFO] = "mkfifo", |
| 47 | [TOMOYO_TYPE_MKSOCK] = "mksock", |
| 48 | [TOMOYO_TYPE_IOCTL] = "ioctl", |
| 49 | [TOMOYO_TYPE_CHMOD] = "chmod", |
| 50 | [TOMOYO_TYPE_CHOWN] = "chown", |
| 51 | [TOMOYO_TYPE_CHGRP] = "chgrp", |
| 52 | }; |
| 53 | |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 54 | static const u8 tomoyo_p2mac[TOMOYO_MAX_PATH_OPERATION] = { |
| 55 | [TOMOYO_TYPE_READ_WRITE] = TOMOYO_MAC_FILE_OPEN, |
| 56 | [TOMOYO_TYPE_EXECUTE] = TOMOYO_MAC_FILE_EXECUTE, |
| 57 | [TOMOYO_TYPE_READ] = TOMOYO_MAC_FILE_OPEN, |
| 58 | [TOMOYO_TYPE_WRITE] = TOMOYO_MAC_FILE_OPEN, |
| 59 | [TOMOYO_TYPE_UNLINK] = TOMOYO_MAC_FILE_UNLINK, |
| 60 | [TOMOYO_TYPE_RMDIR] = TOMOYO_MAC_FILE_RMDIR, |
| 61 | [TOMOYO_TYPE_TRUNCATE] = TOMOYO_MAC_FILE_TRUNCATE, |
| 62 | [TOMOYO_TYPE_SYMLINK] = TOMOYO_MAC_FILE_SYMLINK, |
| 63 | [TOMOYO_TYPE_REWRITE] = TOMOYO_MAC_FILE_REWRITE, |
| 64 | [TOMOYO_TYPE_CHROOT] = TOMOYO_MAC_FILE_CHROOT, |
| 65 | [TOMOYO_TYPE_UMOUNT] = TOMOYO_MAC_FILE_UMOUNT, |
| 66 | }; |
| 67 | |
| 68 | static const u8 tomoyo_pnnn2mac[TOMOYO_MAX_PATH_NUMBER3_OPERATION] = { |
| 69 | [TOMOYO_TYPE_MKBLOCK] = TOMOYO_MAC_FILE_MKBLOCK, |
| 70 | [TOMOYO_TYPE_MKCHAR] = TOMOYO_MAC_FILE_MKCHAR, |
| 71 | }; |
| 72 | |
| 73 | static const u8 tomoyo_pp2mac[TOMOYO_MAX_PATH2_OPERATION] = { |
| 74 | [TOMOYO_TYPE_LINK] = TOMOYO_MAC_FILE_LINK, |
| 75 | [TOMOYO_TYPE_RENAME] = TOMOYO_MAC_FILE_RENAME, |
| 76 | [TOMOYO_TYPE_PIVOT_ROOT] = TOMOYO_MAC_FILE_PIVOT_ROOT, |
| 77 | }; |
| 78 | |
| 79 | static const u8 tomoyo_pn2mac[TOMOYO_MAX_PATH_NUMBER_OPERATION] = { |
| 80 | [TOMOYO_TYPE_CREATE] = TOMOYO_MAC_FILE_CREATE, |
| 81 | [TOMOYO_TYPE_MKDIR] = TOMOYO_MAC_FILE_MKDIR, |
| 82 | [TOMOYO_TYPE_MKFIFO] = TOMOYO_MAC_FILE_MKFIFO, |
| 83 | [TOMOYO_TYPE_MKSOCK] = TOMOYO_MAC_FILE_MKSOCK, |
| 84 | [TOMOYO_TYPE_IOCTL] = TOMOYO_MAC_FILE_IOCTL, |
| 85 | [TOMOYO_TYPE_CHMOD] = TOMOYO_MAC_FILE_CHMOD, |
| 86 | [TOMOYO_TYPE_CHOWN] = TOMOYO_MAC_FILE_CHOWN, |
| 87 | [TOMOYO_TYPE_CHGRP] = TOMOYO_MAC_FILE_CHGRP, |
| 88 | }; |
| 89 | |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 90 | void tomoyo_put_name_union(struct tomoyo_name_union *ptr) |
| 91 | { |
| 92 | if (!ptr) |
| 93 | return; |
| 94 | if (ptr->is_group) |
| 95 | tomoyo_put_path_group(ptr->group); |
| 96 | else |
| 97 | tomoyo_put_name(ptr->filename); |
| 98 | } |
| 99 | |
| 100 | bool tomoyo_compare_name_union(const struct tomoyo_path_info *name, |
| 101 | const struct tomoyo_name_union *ptr) |
| 102 | { |
| 103 | if (ptr->is_group) |
Tetsuo Handa | 3f62963 | 2010-06-03 20:37:26 +0900 | [diff] [blame] | 104 | return tomoyo_path_matches_group(name, ptr->group); |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 105 | return tomoyo_path_matches_pattern(name, ptr->filename); |
| 106 | } |
| 107 | |
Tetsuo Handa | 4c3e9e2 | 2010-05-17 10:06:58 +0900 | [diff] [blame] | 108 | void tomoyo_put_number_union(struct tomoyo_number_union *ptr) |
| 109 | { |
| 110 | if (ptr && ptr->is_group) |
| 111 | tomoyo_put_number_group(ptr->group); |
| 112 | } |
| 113 | |
| 114 | bool tomoyo_compare_number_union(const unsigned long value, |
| 115 | const struct tomoyo_number_union *ptr) |
| 116 | { |
| 117 | if (ptr->is_group) |
| 118 | return tomoyo_number_matches_group(value, value, ptr->group); |
| 119 | return value >= ptr->values[0] && value <= ptr->values[1]; |
| 120 | } |
| 121 | |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 122 | /** |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 123 | * tomoyo_path2keyword - Get the name of single path operation. |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 124 | * |
| 125 | * @operation: Type of operation. |
| 126 | * |
| 127 | * Returns the name of single path operation. |
| 128 | */ |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 129 | const char *tomoyo_path2keyword(const u8 operation) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 130 | { |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 131 | return (operation < TOMOYO_MAX_PATH_OPERATION) |
| 132 | ? tomoyo_path_keyword[operation] : NULL; |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | /** |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 136 | * tomoyo_path_number32keyword - Get the name of path/number/number/number operations. |
| 137 | * |
| 138 | * @operation: Type of operation. |
| 139 | * |
| 140 | * Returns the name of path/number/number/number operation. |
| 141 | */ |
| 142 | const char *tomoyo_path_number32keyword(const u8 operation) |
| 143 | { |
| 144 | return (operation < TOMOYO_MAX_PATH_NUMBER3_OPERATION) |
| 145 | ? tomoyo_path_number3_keyword[operation] : NULL; |
| 146 | } |
| 147 | |
| 148 | /** |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 149 | * tomoyo_path22keyword - Get the name of double path operation. |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 150 | * |
| 151 | * @operation: Type of operation. |
| 152 | * |
| 153 | * Returns the name of double path operation. |
| 154 | */ |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 155 | const char *tomoyo_path22keyword(const u8 operation) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 156 | { |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 157 | return (operation < TOMOYO_MAX_PATH2_OPERATION) |
| 158 | ? tomoyo_path2_keyword[operation] : NULL; |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | /** |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 162 | * tomoyo_path_number2keyword - Get the name of path/number operations. |
| 163 | * |
| 164 | * @operation: Type of operation. |
| 165 | * |
| 166 | * Returns the name of path/number operation. |
| 167 | */ |
| 168 | const char *tomoyo_path_number2keyword(const u8 operation) |
| 169 | { |
| 170 | return (operation < TOMOYO_MAX_PATH_NUMBER_OPERATION) |
| 171 | ? tomoyo_path_number_keyword[operation] : NULL; |
| 172 | } |
| 173 | |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 174 | static void tomoyo_add_slash(struct tomoyo_path_info *buf) |
| 175 | { |
| 176 | if (buf->is_dir) |
| 177 | return; |
| 178 | /* |
| 179 | * This is OK because tomoyo_encode() reserves space for appending "/". |
| 180 | */ |
| 181 | strcat((char *) buf->name, "/"); |
| 182 | tomoyo_fill_path_info(buf); |
| 183 | } |
| 184 | |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 185 | /** |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 186 | * tomoyo_strendswith - Check whether the token ends with the given token. |
| 187 | * |
| 188 | * @name: The token to check. |
| 189 | * @tail: The token to find. |
| 190 | * |
| 191 | * Returns true if @name ends with @tail, false otherwise. |
| 192 | */ |
| 193 | static bool tomoyo_strendswith(const char *name, const char *tail) |
| 194 | { |
| 195 | int len; |
| 196 | |
| 197 | if (!name || !tail) |
| 198 | return false; |
| 199 | len = strlen(name) - strlen(tail); |
| 200 | return len >= 0 && !strcmp(name + len, tail); |
| 201 | } |
| 202 | |
| 203 | /** |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 204 | * tomoyo_get_realpath - Get realpath. |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 205 | * |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 206 | * @buf: Pointer to "struct tomoyo_path_info". |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 207 | * @path: Pointer to "struct path". |
| 208 | * |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 209 | * Returns true on success, false otherwise. |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 210 | */ |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 211 | 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] | 212 | { |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 213 | buf->name = tomoyo_realpath_from_path(path); |
| 214 | if (buf->name) { |
| 215 | tomoyo_fill_path_info(buf); |
| 216 | return true; |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 217 | } |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 218 | return false; |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 219 | } |
| 220 | |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 221 | static int tomoyo_update_path2_acl(const u8 type, const char *filename1, |
| 222 | const char *filename2, |
| 223 | struct tomoyo_domain_info *const domain, |
| 224 | const bool is_delete); |
| 225 | static int tomoyo_update_path_acl(const u8 type, const char *filename, |
| 226 | struct tomoyo_domain_info *const domain, |
| 227 | const bool is_delete); |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 228 | |
Tetsuo Handa | c3fa109 | 2009-06-08 12:37:39 +0900 | [diff] [blame] | 229 | /* |
| 230 | * tomoyo_globally_readable_list is used for holding list of pathnames which |
| 231 | * are by default allowed to be open()ed for reading by any process. |
| 232 | * |
| 233 | * An entry is added by |
| 234 | * |
| 235 | * # echo 'allow_read /lib/libc-2.5.so' > \ |
| 236 | * /sys/kernel/security/tomoyo/exception_policy |
| 237 | * |
| 238 | * and is deleted by |
| 239 | * |
| 240 | * # echo 'delete allow_read /lib/libc-2.5.so' > \ |
| 241 | * /sys/kernel/security/tomoyo/exception_policy |
| 242 | * |
| 243 | * and all entries are retrieved by |
| 244 | * |
| 245 | * # grep ^allow_read /sys/kernel/security/tomoyo/exception_policy |
| 246 | * |
| 247 | * In the example above, any process is allowed to |
| 248 | * open("/lib/libc-2.5.so", O_RDONLY). |
| 249 | * One exception is, if the domain which current process belongs to is marked |
| 250 | * as "ignore_global_allow_read", current process can't do so unless explicitly |
| 251 | * given "allow_read /lib/libc-2.5.so" to the domain which current process |
| 252 | * belongs to. |
| 253 | */ |
Tetsuo Handa | 847b173 | 2010-02-11 09:43:54 +0900 | [diff] [blame] | 254 | LIST_HEAD(tomoyo_globally_readable_list); |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 255 | |
| 256 | /** |
| 257 | * tomoyo_update_globally_readable_entry - Update "struct tomoyo_globally_readable_file_entry" list. |
| 258 | * |
| 259 | * @filename: Filename unconditionally permitted to open() for reading. |
| 260 | * @is_delete: True if it is a delete request. |
| 261 | * |
| 262 | * Returns 0 on success, negative value otherwise. |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 263 | * |
| 264 | * Caller holds tomoyo_read_lock(). |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 265 | */ |
| 266 | static int tomoyo_update_globally_readable_entry(const char *filename, |
| 267 | const bool is_delete) |
| 268 | { |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 269 | struct tomoyo_globally_readable_file_entry *ptr; |
Tetsuo Handa | 9e4b50e | 2010-05-06 12:40:02 +0900 | [diff] [blame] | 270 | struct tomoyo_globally_readable_file_entry e = { }; |
Tetsuo Handa | ca0b7df | 2010-02-07 20:23:59 +0900 | [diff] [blame] | 271 | int error = is_delete ? -ENOENT : -ENOMEM; |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 272 | |
Tetsuo Handa | 3f62963 | 2010-06-03 20:37:26 +0900 | [diff] [blame] | 273 | if (!tomoyo_is_correct_word(filename)) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 274 | return -EINVAL; |
Tetsuo Handa | 9e4b50e | 2010-05-06 12:40:02 +0900 | [diff] [blame] | 275 | e.filename = tomoyo_get_name(filename); |
| 276 | if (!e.filename) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 277 | return -ENOMEM; |
Tetsuo Handa | 2928238 | 2010-05-06 00:18:15 +0900 | [diff] [blame] | 278 | if (mutex_lock_interruptible(&tomoyo_policy_lock)) |
| 279 | goto out; |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 280 | list_for_each_entry_rcu(ptr, &tomoyo_globally_readable_list, list) { |
Tetsuo Handa | 9e4b50e | 2010-05-06 12:40:02 +0900 | [diff] [blame] | 281 | if (ptr->filename != e.filename) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 282 | continue; |
| 283 | ptr->is_deleted = is_delete; |
| 284 | error = 0; |
Tetsuo Handa | ca0b7df | 2010-02-07 20:23:59 +0900 | [diff] [blame] | 285 | break; |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 286 | } |
Tetsuo Handa | 9e4b50e | 2010-05-06 12:40:02 +0900 | [diff] [blame] | 287 | if (!is_delete && error) { |
| 288 | struct tomoyo_globally_readable_file_entry *entry = |
| 289 | tomoyo_commit_ok(&e, sizeof(e)); |
| 290 | if (entry) { |
| 291 | list_add_tail_rcu(&entry->list, |
| 292 | &tomoyo_globally_readable_list); |
| 293 | error = 0; |
| 294 | } |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 295 | } |
Tetsuo Handa | f737d95 | 2010-01-03 21:16:32 +0900 | [diff] [blame] | 296 | mutex_unlock(&tomoyo_policy_lock); |
Tetsuo Handa | 2928238 | 2010-05-06 00:18:15 +0900 | [diff] [blame] | 297 | out: |
Tetsuo Handa | 9e4b50e | 2010-05-06 12:40:02 +0900 | [diff] [blame] | 298 | tomoyo_put_name(e.filename); |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 299 | return error; |
| 300 | } |
| 301 | |
| 302 | /** |
| 303 | * tomoyo_is_globally_readable_file - Check if the file is unconditionnaly permitted to be open()ed for reading. |
| 304 | * |
| 305 | * @filename: The filename to check. |
| 306 | * |
| 307 | * Returns true if any domain can open @filename for reading, false otherwise. |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 308 | * |
| 309 | * Caller holds tomoyo_read_lock(). |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 310 | */ |
| 311 | static bool tomoyo_is_globally_readable_file(const struct tomoyo_path_info * |
| 312 | filename) |
| 313 | { |
| 314 | struct tomoyo_globally_readable_file_entry *ptr; |
| 315 | bool found = false; |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 316 | |
| 317 | list_for_each_entry_rcu(ptr, &tomoyo_globally_readable_list, list) { |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 318 | if (!ptr->is_deleted && |
| 319 | tomoyo_path_matches_pattern(filename, ptr->filename)) { |
| 320 | found = true; |
| 321 | break; |
| 322 | } |
| 323 | } |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 324 | return found; |
| 325 | } |
| 326 | |
| 327 | /** |
| 328 | * tomoyo_write_globally_readable_policy - Write "struct tomoyo_globally_readable_file_entry" list. |
| 329 | * |
| 330 | * @data: String to parse. |
| 331 | * @is_delete: True if it is a delete request. |
| 332 | * |
| 333 | * Returns 0 on success, negative value otherwise. |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 334 | * |
| 335 | * Caller holds tomoyo_read_lock(). |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 336 | */ |
| 337 | int tomoyo_write_globally_readable_policy(char *data, const bool is_delete) |
| 338 | { |
| 339 | return tomoyo_update_globally_readable_entry(data, is_delete); |
| 340 | } |
| 341 | |
| 342 | /** |
| 343 | * tomoyo_read_globally_readable_policy - Read "struct tomoyo_globally_readable_file_entry" list. |
| 344 | * |
| 345 | * @head: Pointer to "struct tomoyo_io_buffer". |
| 346 | * |
| 347 | * Returns true on success, false otherwise. |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 348 | * |
| 349 | * Caller holds tomoyo_read_lock(). |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 350 | */ |
| 351 | bool tomoyo_read_globally_readable_policy(struct tomoyo_io_buffer *head) |
| 352 | { |
| 353 | struct list_head *pos; |
| 354 | bool done = true; |
| 355 | |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 356 | list_for_each_cookie(pos, head->read_var2, |
| 357 | &tomoyo_globally_readable_list) { |
| 358 | struct tomoyo_globally_readable_file_entry *ptr; |
| 359 | ptr = list_entry(pos, |
| 360 | struct tomoyo_globally_readable_file_entry, |
| 361 | list); |
| 362 | if (ptr->is_deleted) |
| 363 | continue; |
Tetsuo Handa | 7d2948b | 2009-06-02 20:42:24 +0900 | [diff] [blame] | 364 | done = tomoyo_io_printf(head, TOMOYO_KEYWORD_ALLOW_READ "%s\n", |
| 365 | ptr->filename->name); |
| 366 | if (!done) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 367 | break; |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 368 | } |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 369 | return done; |
| 370 | } |
| 371 | |
Tetsuo Handa | c3fa109 | 2009-06-08 12:37:39 +0900 | [diff] [blame] | 372 | /* tomoyo_pattern_list is used for holding list of pathnames which are used for |
| 373 | * converting pathnames to pathname patterns during learning mode. |
| 374 | * |
| 375 | * An entry is added by |
| 376 | * |
| 377 | * # echo 'file_pattern /proc/\$/mounts' > \ |
| 378 | * /sys/kernel/security/tomoyo/exception_policy |
| 379 | * |
| 380 | * and is deleted by |
| 381 | * |
| 382 | * # echo 'delete file_pattern /proc/\$/mounts' > \ |
| 383 | * /sys/kernel/security/tomoyo/exception_policy |
| 384 | * |
| 385 | * and all entries are retrieved by |
| 386 | * |
| 387 | * # grep ^file_pattern /sys/kernel/security/tomoyo/exception_policy |
| 388 | * |
| 389 | * In the example above, if a process which belongs to a domain which is in |
| 390 | * learning mode requested open("/proc/1/mounts", O_RDONLY), |
| 391 | * "allow_read /proc/\$/mounts" is automatically added to the domain which that |
| 392 | * process belongs to. |
| 393 | * |
| 394 | * It is not a desirable behavior that we have to use /proc/\$/ instead of |
| 395 | * /proc/self/ when current process needs to access only current process's |
| 396 | * information. As of now, LSM version of TOMOYO is using __d_path() for |
| 397 | * calculating pathname. Non LSM version of TOMOYO is using its own function |
| 398 | * which pretends as if /proc/self/ is not a symlink; so that we can forbid |
| 399 | * current process from accessing other process's information. |
| 400 | */ |
Tetsuo Handa | 847b173 | 2010-02-11 09:43:54 +0900 | [diff] [blame] | 401 | LIST_HEAD(tomoyo_pattern_list); |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 402 | |
| 403 | /** |
| 404 | * tomoyo_update_file_pattern_entry - Update "struct tomoyo_pattern_entry" list. |
| 405 | * |
| 406 | * @pattern: Pathname pattern. |
| 407 | * @is_delete: True if it is a delete request. |
| 408 | * |
| 409 | * Returns 0 on success, negative value otherwise. |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 410 | * |
| 411 | * Caller holds tomoyo_read_lock(). |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 412 | */ |
| 413 | static int tomoyo_update_file_pattern_entry(const char *pattern, |
| 414 | const bool is_delete) |
| 415 | { |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 416 | struct tomoyo_pattern_entry *ptr; |
Tetsuo Handa | 3f62963 | 2010-06-03 20:37:26 +0900 | [diff] [blame] | 417 | struct tomoyo_pattern_entry e = { }; |
Tetsuo Handa | ca0b7df | 2010-02-07 20:23:59 +0900 | [diff] [blame] | 418 | int error = is_delete ? -ENOENT : -ENOMEM; |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 419 | |
Tetsuo Handa | 3f62963 | 2010-06-03 20:37:26 +0900 | [diff] [blame] | 420 | if (!tomoyo_is_correct_word(pattern)) |
| 421 | return -EINVAL; |
| 422 | e.pattern = tomoyo_get_name(pattern); |
Tetsuo Handa | 9e4b50e | 2010-05-06 12:40:02 +0900 | [diff] [blame] | 423 | if (!e.pattern) |
Tetsuo Handa | ca0b7df | 2010-02-07 20:23:59 +0900 | [diff] [blame] | 424 | return error; |
Tetsuo Handa | 2928238 | 2010-05-06 00:18:15 +0900 | [diff] [blame] | 425 | if (mutex_lock_interruptible(&tomoyo_policy_lock)) |
| 426 | goto out; |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 427 | list_for_each_entry_rcu(ptr, &tomoyo_pattern_list, list) { |
Tetsuo Handa | 9e4b50e | 2010-05-06 12:40:02 +0900 | [diff] [blame] | 428 | if (e.pattern != ptr->pattern) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 429 | continue; |
| 430 | ptr->is_deleted = is_delete; |
| 431 | error = 0; |
Tetsuo Handa | ca0b7df | 2010-02-07 20:23:59 +0900 | [diff] [blame] | 432 | break; |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 433 | } |
Tetsuo Handa | 9e4b50e | 2010-05-06 12:40:02 +0900 | [diff] [blame] | 434 | if (!is_delete && error) { |
| 435 | struct tomoyo_pattern_entry *entry = |
| 436 | tomoyo_commit_ok(&e, sizeof(e)); |
| 437 | if (entry) { |
| 438 | list_add_tail_rcu(&entry->list, &tomoyo_pattern_list); |
| 439 | error = 0; |
| 440 | } |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 441 | } |
Tetsuo Handa | f737d95 | 2010-01-03 21:16:32 +0900 | [diff] [blame] | 442 | mutex_unlock(&tomoyo_policy_lock); |
Tetsuo Handa | ca0b7df | 2010-02-07 20:23:59 +0900 | [diff] [blame] | 443 | out: |
Tetsuo Handa | 9e4b50e | 2010-05-06 12:40:02 +0900 | [diff] [blame] | 444 | tomoyo_put_name(e.pattern); |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 445 | return error; |
| 446 | } |
| 447 | |
| 448 | /** |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 449 | * tomoyo_file_pattern - Get patterned pathname. |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 450 | * |
| 451 | * @filename: The filename to find patterned pathname. |
| 452 | * |
| 453 | * Returns pointer to pathname pattern if matched, @filename otherwise. |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 454 | * |
| 455 | * Caller holds tomoyo_read_lock(). |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 456 | */ |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 457 | const char *tomoyo_file_pattern(const struct tomoyo_path_info *filename) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 458 | { |
| 459 | struct tomoyo_pattern_entry *ptr; |
| 460 | const struct tomoyo_path_info *pattern = NULL; |
| 461 | |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 462 | list_for_each_entry_rcu(ptr, &tomoyo_pattern_list, list) { |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 463 | if (ptr->is_deleted) |
| 464 | continue; |
| 465 | if (!tomoyo_path_matches_pattern(filename, ptr->pattern)) |
| 466 | continue; |
| 467 | pattern = ptr->pattern; |
| 468 | if (tomoyo_strendswith(pattern->name, "/\\*")) { |
| 469 | /* Do nothing. Try to find the better match. */ |
| 470 | } else { |
| 471 | /* This would be the better match. Use this. */ |
| 472 | break; |
| 473 | } |
| 474 | } |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 475 | if (pattern) |
| 476 | filename = pattern; |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 477 | return filename->name; |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | /** |
| 481 | * tomoyo_write_pattern_policy - Write "struct tomoyo_pattern_entry" list. |
| 482 | * |
| 483 | * @data: String to parse. |
| 484 | * @is_delete: True if it is a delete request. |
| 485 | * |
| 486 | * Returns 0 on success, negative value otherwise. |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 487 | * |
| 488 | * Caller holds tomoyo_read_lock(). |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 489 | */ |
| 490 | int tomoyo_write_pattern_policy(char *data, const bool is_delete) |
| 491 | { |
| 492 | return tomoyo_update_file_pattern_entry(data, is_delete); |
| 493 | } |
| 494 | |
| 495 | /** |
| 496 | * tomoyo_read_file_pattern - Read "struct tomoyo_pattern_entry" list. |
| 497 | * |
| 498 | * @head: Pointer to "struct tomoyo_io_buffer". |
| 499 | * |
| 500 | * Returns true on success, false otherwise. |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 501 | * |
| 502 | * Caller holds tomoyo_read_lock(). |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 503 | */ |
| 504 | bool tomoyo_read_file_pattern(struct tomoyo_io_buffer *head) |
| 505 | { |
| 506 | struct list_head *pos; |
| 507 | bool done = true; |
| 508 | |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 509 | list_for_each_cookie(pos, head->read_var2, &tomoyo_pattern_list) { |
| 510 | struct tomoyo_pattern_entry *ptr; |
| 511 | ptr = list_entry(pos, struct tomoyo_pattern_entry, list); |
| 512 | if (ptr->is_deleted) |
| 513 | continue; |
Tetsuo Handa | 7d2948b | 2009-06-02 20:42:24 +0900 | [diff] [blame] | 514 | done = tomoyo_io_printf(head, TOMOYO_KEYWORD_FILE_PATTERN |
| 515 | "%s\n", ptr->pattern->name); |
| 516 | if (!done) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 517 | break; |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 518 | } |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 519 | return done; |
| 520 | } |
| 521 | |
Tetsuo Handa | c3fa109 | 2009-06-08 12:37:39 +0900 | [diff] [blame] | 522 | /* |
| 523 | * tomoyo_no_rewrite_list is used for holding list of pathnames which are by |
| 524 | * default forbidden to modify already written content of a file. |
| 525 | * |
| 526 | * An entry is added by |
| 527 | * |
| 528 | * # echo 'deny_rewrite /var/log/messages' > \ |
| 529 | * /sys/kernel/security/tomoyo/exception_policy |
| 530 | * |
| 531 | * and is deleted by |
| 532 | * |
| 533 | * # echo 'delete deny_rewrite /var/log/messages' > \ |
| 534 | * /sys/kernel/security/tomoyo/exception_policy |
| 535 | * |
| 536 | * and all entries are retrieved by |
| 537 | * |
| 538 | * # grep ^deny_rewrite /sys/kernel/security/tomoyo/exception_policy |
| 539 | * |
| 540 | * In the example above, if a process requested to rewrite /var/log/messages , |
| 541 | * the process can't rewrite unless the domain which that process belongs to |
| 542 | * has "allow_rewrite /var/log/messages" entry. |
| 543 | * |
| 544 | * It is not a desirable behavior that we have to add "\040(deleted)" suffix |
| 545 | * when we want to allow rewriting already unlink()ed file. As of now, |
| 546 | * LSM version of TOMOYO is using __d_path() for calculating pathname. |
| 547 | * Non LSM version of TOMOYO is using its own function which doesn't append |
| 548 | * " (deleted)" suffix if the file is already unlink()ed; so that we don't |
| 549 | * need to worry whether the file is already unlink()ed or not. |
| 550 | */ |
Tetsuo Handa | 847b173 | 2010-02-11 09:43:54 +0900 | [diff] [blame] | 551 | LIST_HEAD(tomoyo_no_rewrite_list); |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 552 | |
| 553 | /** |
| 554 | * tomoyo_update_no_rewrite_entry - Update "struct tomoyo_no_rewrite_entry" list. |
| 555 | * |
| 556 | * @pattern: Pathname pattern that are not rewritable by default. |
| 557 | * @is_delete: True if it is a delete request. |
| 558 | * |
| 559 | * Returns 0 on success, negative value otherwise. |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 560 | * |
| 561 | * Caller holds tomoyo_read_lock(). |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 562 | */ |
| 563 | static int tomoyo_update_no_rewrite_entry(const char *pattern, |
| 564 | const bool is_delete) |
| 565 | { |
Tetsuo Handa | ca0b7df | 2010-02-07 20:23:59 +0900 | [diff] [blame] | 566 | struct tomoyo_no_rewrite_entry *ptr; |
Tetsuo Handa | 9e4b50e | 2010-05-06 12:40:02 +0900 | [diff] [blame] | 567 | struct tomoyo_no_rewrite_entry e = { }; |
Tetsuo Handa | ca0b7df | 2010-02-07 20:23:59 +0900 | [diff] [blame] | 568 | int error = is_delete ? -ENOENT : -ENOMEM; |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 569 | |
Tetsuo Handa | 3f62963 | 2010-06-03 20:37:26 +0900 | [diff] [blame] | 570 | if (!tomoyo_is_correct_word(pattern)) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 571 | return -EINVAL; |
Tetsuo Handa | 9e4b50e | 2010-05-06 12:40:02 +0900 | [diff] [blame] | 572 | e.pattern = tomoyo_get_name(pattern); |
| 573 | if (!e.pattern) |
Tetsuo Handa | ca0b7df | 2010-02-07 20:23:59 +0900 | [diff] [blame] | 574 | return error; |
Tetsuo Handa | 2928238 | 2010-05-06 00:18:15 +0900 | [diff] [blame] | 575 | if (mutex_lock_interruptible(&tomoyo_policy_lock)) |
| 576 | goto out; |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 577 | list_for_each_entry_rcu(ptr, &tomoyo_no_rewrite_list, list) { |
Tetsuo Handa | 9e4b50e | 2010-05-06 12:40:02 +0900 | [diff] [blame] | 578 | if (ptr->pattern != e.pattern) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 579 | continue; |
| 580 | ptr->is_deleted = is_delete; |
| 581 | error = 0; |
Tetsuo Handa | ca0b7df | 2010-02-07 20:23:59 +0900 | [diff] [blame] | 582 | break; |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 583 | } |
Tetsuo Handa | 9e4b50e | 2010-05-06 12:40:02 +0900 | [diff] [blame] | 584 | if (!is_delete && error) { |
| 585 | struct tomoyo_no_rewrite_entry *entry = |
| 586 | tomoyo_commit_ok(&e, sizeof(e)); |
| 587 | if (entry) { |
| 588 | list_add_tail_rcu(&entry->list, |
| 589 | &tomoyo_no_rewrite_list); |
| 590 | error = 0; |
| 591 | } |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 592 | } |
Tetsuo Handa | f737d95 | 2010-01-03 21:16:32 +0900 | [diff] [blame] | 593 | mutex_unlock(&tomoyo_policy_lock); |
Tetsuo Handa | 2928238 | 2010-05-06 00:18:15 +0900 | [diff] [blame] | 594 | out: |
Tetsuo Handa | 9e4b50e | 2010-05-06 12:40:02 +0900 | [diff] [blame] | 595 | tomoyo_put_name(e.pattern); |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 596 | return error; |
| 597 | } |
| 598 | |
| 599 | /** |
| 600 | * tomoyo_is_no_rewrite_file - Check if the given pathname is not permitted to be rewrited. |
| 601 | * |
| 602 | * @filename: Filename to check. |
| 603 | * |
| 604 | * Returns true if @filename is specified by "deny_rewrite" directive, |
| 605 | * false otherwise. |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 606 | * |
| 607 | * Caller holds tomoyo_read_lock(). |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 608 | */ |
| 609 | static bool tomoyo_is_no_rewrite_file(const struct tomoyo_path_info *filename) |
| 610 | { |
| 611 | struct tomoyo_no_rewrite_entry *ptr; |
| 612 | bool found = false; |
| 613 | |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 614 | list_for_each_entry_rcu(ptr, &tomoyo_no_rewrite_list, list) { |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 615 | if (ptr->is_deleted) |
| 616 | continue; |
| 617 | if (!tomoyo_path_matches_pattern(filename, ptr->pattern)) |
| 618 | continue; |
| 619 | found = true; |
| 620 | break; |
| 621 | } |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 622 | return found; |
| 623 | } |
| 624 | |
| 625 | /** |
| 626 | * tomoyo_write_no_rewrite_policy - Write "struct tomoyo_no_rewrite_entry" list. |
| 627 | * |
| 628 | * @data: String to parse. |
| 629 | * @is_delete: True if it is a delete request. |
| 630 | * |
| 631 | * Returns 0 on success, negative value otherwise. |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 632 | * |
| 633 | * Caller holds tomoyo_read_lock(). |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 634 | */ |
| 635 | int tomoyo_write_no_rewrite_policy(char *data, const bool is_delete) |
| 636 | { |
| 637 | return tomoyo_update_no_rewrite_entry(data, is_delete); |
| 638 | } |
| 639 | |
| 640 | /** |
| 641 | * tomoyo_read_no_rewrite_policy - Read "struct tomoyo_no_rewrite_entry" list. |
| 642 | * |
| 643 | * @head: Pointer to "struct tomoyo_io_buffer". |
| 644 | * |
| 645 | * Returns true on success, false otherwise. |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 646 | * |
| 647 | * Caller holds tomoyo_read_lock(). |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 648 | */ |
| 649 | bool tomoyo_read_no_rewrite_policy(struct tomoyo_io_buffer *head) |
| 650 | { |
| 651 | struct list_head *pos; |
| 652 | bool done = true; |
| 653 | |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 654 | list_for_each_cookie(pos, head->read_var2, &tomoyo_no_rewrite_list) { |
| 655 | struct tomoyo_no_rewrite_entry *ptr; |
| 656 | ptr = list_entry(pos, struct tomoyo_no_rewrite_entry, list); |
| 657 | if (ptr->is_deleted) |
| 658 | continue; |
Tetsuo Handa | 7d2948b | 2009-06-02 20:42:24 +0900 | [diff] [blame] | 659 | done = tomoyo_io_printf(head, TOMOYO_KEYWORD_DENY_REWRITE |
| 660 | "%s\n", ptr->pattern->name); |
| 661 | if (!done) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 662 | break; |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 663 | } |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 664 | return done; |
| 665 | } |
| 666 | |
| 667 | /** |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 668 | * tomoyo_path_acl - Check permission for single path operation. |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 669 | * |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 670 | * @r: Pointer to "struct tomoyo_request_info". |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 671 | * @filename: Filename to check. |
| 672 | * @perm: Permission. |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 673 | * |
| 674 | * Returns 0 on success, -EPERM otherwise. |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 675 | * |
| 676 | * Caller holds tomoyo_read_lock(). |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 677 | */ |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 678 | static int tomoyo_path_acl(const struct tomoyo_request_info *r, |
| 679 | const struct tomoyo_path_info *filename, |
Tetsuo Handa | 3f62963 | 2010-06-03 20:37:26 +0900 | [diff] [blame] | 680 | const u32 perm) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 681 | { |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 682 | struct tomoyo_domain_info *domain = r->domain; |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 683 | struct tomoyo_acl_info *ptr; |
| 684 | int error = -EPERM; |
| 685 | |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 686 | list_for_each_entry_rcu(ptr, &domain->acl_info_list, list) { |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 687 | struct tomoyo_path_acl *acl; |
| 688 | if (ptr->type != TOMOYO_TYPE_PATH_ACL) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 689 | continue; |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 690 | acl = container_of(ptr, struct tomoyo_path_acl, head); |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 691 | if (!(acl->perm & perm) || |
Tetsuo Handa | 3f62963 | 2010-06-03 20:37:26 +0900 | [diff] [blame] | 692 | !tomoyo_compare_name_union(filename, &acl->name)) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 693 | continue; |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 694 | error = 0; |
| 695 | break; |
| 696 | } |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 697 | return error; |
| 698 | } |
| 699 | |
| 700 | /** |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 701 | * tomoyo_file_perm - Check permission for opening files. |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 702 | * |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 703 | * @r: Pointer to "struct tomoyo_request_info". |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 704 | * @filename: Filename to check. |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 705 | * @mode: Mode ("read" or "write" or "read/write" or "execute"). |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 706 | * |
| 707 | * Returns 0 on success, negative value otherwise. |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 708 | * |
| 709 | * Caller holds tomoyo_read_lock(). |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 710 | */ |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 711 | static int tomoyo_file_perm(struct tomoyo_request_info *r, |
| 712 | const struct tomoyo_path_info *filename, |
| 713 | const u8 mode) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 714 | { |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 715 | const char *msg = "<unknown>"; |
| 716 | int error = 0; |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 717 | u32 perm = 0; |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 718 | |
| 719 | if (!filename) |
| 720 | return 0; |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 721 | |
| 722 | if (mode == 6) { |
| 723 | msg = tomoyo_path2keyword(TOMOYO_TYPE_READ_WRITE); |
| 724 | perm = 1 << TOMOYO_TYPE_READ_WRITE; |
| 725 | } else if (mode == 4) { |
| 726 | msg = tomoyo_path2keyword(TOMOYO_TYPE_READ); |
| 727 | perm = 1 << TOMOYO_TYPE_READ; |
| 728 | } else if (mode == 2) { |
| 729 | msg = tomoyo_path2keyword(TOMOYO_TYPE_WRITE); |
| 730 | perm = 1 << TOMOYO_TYPE_WRITE; |
| 731 | } else if (mode == 1) { |
| 732 | msg = tomoyo_path2keyword(TOMOYO_TYPE_EXECUTE); |
| 733 | perm = 1 << TOMOYO_TYPE_EXECUTE; |
| 734 | } else |
| 735 | BUG(); |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 736 | do { |
Tetsuo Handa | 3f62963 | 2010-06-03 20:37:26 +0900 | [diff] [blame] | 737 | error = tomoyo_path_acl(r, filename, perm); |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 738 | if (error && mode == 4 && !r->domain->ignore_global_allow_read |
| 739 | && tomoyo_is_globally_readable_file(filename)) |
| 740 | error = 0; |
| 741 | if (!error) |
| 742 | break; |
| 743 | tomoyo_warn_log(r, "%s %s", msg, filename->name); |
| 744 | error = tomoyo_supervisor(r, "allow_%s %s\n", msg, |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 745 | tomoyo_file_pattern(filename)); |
| 746 | /* |
| 747 | * Do not retry for execute request, for alias may have |
| 748 | * changed. |
| 749 | */ |
| 750 | } while (error == TOMOYO_RETRY_REQUEST && mode != 1); |
| 751 | if (r->mode != TOMOYO_CONFIG_ENFORCING) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 752 | error = 0; |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 753 | return error; |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 754 | } |
| 755 | |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame^] | 756 | static bool tomoyo_same_path_acl(const struct tomoyo_acl_info *a, |
| 757 | const struct tomoyo_acl_info *b) |
| 758 | { |
| 759 | const struct tomoyo_path_acl *p1 = container_of(a, typeof(*p1), head); |
| 760 | const struct tomoyo_path_acl *p2 = container_of(b, typeof(*p2), head); |
| 761 | return tomoyo_is_same_acl_head(&p1->head, &p2->head) && |
| 762 | tomoyo_is_same_name_union(&p1->name, &p2->name); |
| 763 | } |
| 764 | |
| 765 | static bool tomoyo_merge_path_acl(struct tomoyo_acl_info *a, |
| 766 | struct tomoyo_acl_info *b, |
| 767 | const bool is_delete) |
| 768 | { |
| 769 | u16 * const a_perm = &container_of(a, struct tomoyo_path_acl, head) |
| 770 | ->perm; |
| 771 | u16 perm = *a_perm; |
| 772 | const u16 b_perm = container_of(b, struct tomoyo_path_acl, head)->perm; |
| 773 | if (is_delete) { |
| 774 | perm &= ~b_perm; |
| 775 | if ((perm & TOMOYO_RW_MASK) != TOMOYO_RW_MASK) |
| 776 | perm &= ~(1 << TOMOYO_TYPE_READ_WRITE); |
| 777 | else if (!(perm & (1 << TOMOYO_TYPE_READ_WRITE))) |
| 778 | perm &= ~TOMOYO_RW_MASK; |
| 779 | } else { |
| 780 | perm |= b_perm; |
| 781 | if ((perm & TOMOYO_RW_MASK) == TOMOYO_RW_MASK) |
| 782 | perm |= (1 << TOMOYO_TYPE_READ_WRITE); |
| 783 | else if (perm & (1 << TOMOYO_TYPE_READ_WRITE)) |
| 784 | perm |= TOMOYO_RW_MASK; |
| 785 | } |
| 786 | *a_perm = perm; |
| 787 | return !perm; |
| 788 | } |
| 789 | |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 790 | /** |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 791 | * tomoyo_update_path_acl - Update "struct tomoyo_path_acl" list. |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 792 | * |
| 793 | * @type: Type of operation. |
| 794 | * @filename: Filename. |
| 795 | * @domain: Pointer to "struct tomoyo_domain_info". |
| 796 | * @is_delete: True if it is a delete request. |
| 797 | * |
| 798 | * Returns 0 on success, negative value otherwise. |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 799 | * |
| 800 | * Caller holds tomoyo_read_lock(). |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 801 | */ |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 802 | static int tomoyo_update_path_acl(const u8 type, const char *filename, |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame^] | 803 | struct tomoyo_domain_info * const domain, |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 804 | const bool is_delete) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 805 | { |
Tetsuo Handa | 9e4b50e | 2010-05-06 12:40:02 +0900 | [diff] [blame] | 806 | struct tomoyo_path_acl e = { |
| 807 | .head.type = TOMOYO_TYPE_PATH_ACL, |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame^] | 808 | .perm = 1 << type |
Tetsuo Handa | 9e4b50e | 2010-05-06 12:40:02 +0900 | [diff] [blame] | 809 | }; |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame^] | 810 | int error; |
| 811 | if (e.perm == (1 << TOMOYO_TYPE_READ_WRITE)) |
| 812 | e.perm |= TOMOYO_RW_MASK; |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 813 | if (!tomoyo_parse_name_union(filename, &e.name)) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 814 | return -EINVAL; |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame^] | 815 | error = tomoyo_update_domain(&e.head, sizeof(e), is_delete, domain, |
| 816 | tomoyo_same_path_acl, |
| 817 | tomoyo_merge_path_acl); |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 818 | tomoyo_put_name_union(&e.name); |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 819 | return error; |
| 820 | } |
| 821 | |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame^] | 822 | static bool tomoyo_same_path_number3_acl(const struct tomoyo_acl_info *a, |
| 823 | const struct tomoyo_acl_info *b) |
| 824 | { |
| 825 | const struct tomoyo_path_number3_acl *p1 = container_of(a, typeof(*p1), |
| 826 | head); |
| 827 | const struct tomoyo_path_number3_acl *p2 = container_of(b, typeof(*p2), |
| 828 | head); |
| 829 | return tomoyo_is_same_acl_head(&p1->head, &p2->head) |
| 830 | && tomoyo_is_same_name_union(&p1->name, &p2->name) |
| 831 | && tomoyo_is_same_number_union(&p1->mode, &p2->mode) |
| 832 | && tomoyo_is_same_number_union(&p1->major, &p2->major) |
| 833 | && tomoyo_is_same_number_union(&p1->minor, &p2->minor); |
| 834 | } |
| 835 | |
| 836 | static bool tomoyo_merge_path_number3_acl(struct tomoyo_acl_info *a, |
| 837 | struct tomoyo_acl_info *b, |
| 838 | const bool is_delete) |
| 839 | { |
| 840 | u8 *const a_perm = &container_of(a, struct tomoyo_path_number3_acl, |
| 841 | head)->perm; |
| 842 | u8 perm = *a_perm; |
| 843 | const u8 b_perm = container_of(b, struct tomoyo_path_number3_acl, head) |
| 844 | ->perm; |
| 845 | if (is_delete) |
| 846 | perm &= ~b_perm; |
| 847 | else |
| 848 | perm |= b_perm; |
| 849 | *a_perm = perm; |
| 850 | return !perm; |
| 851 | } |
| 852 | |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 853 | /** |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 854 | * tomoyo_update_path_number3_acl - Update "struct tomoyo_path_number3_acl" list. |
| 855 | * |
| 856 | * @type: Type of operation. |
| 857 | * @filename: Filename. |
| 858 | * @mode: Create mode. |
| 859 | * @major: Device major number. |
| 860 | * @minor: Device minor number. |
| 861 | * @domain: Pointer to "struct tomoyo_domain_info". |
| 862 | * @is_delete: True if it is a delete request. |
| 863 | * |
| 864 | * Returns 0 on success, negative value otherwise. |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame^] | 865 | * |
| 866 | * Caller holds tomoyo_read_lock(). |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 867 | */ |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame^] | 868 | static int tomoyo_update_path_number3_acl(const u8 type, const char *filename, |
| 869 | char *mode, char *major, char *minor, |
| 870 | struct tomoyo_domain_info * const |
| 871 | domain, const bool is_delete) |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 872 | { |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 873 | struct tomoyo_path_number3_acl e = { |
| 874 | .head.type = TOMOYO_TYPE_PATH_NUMBER3_ACL, |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame^] | 875 | .perm = 1 << type |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 876 | }; |
| 877 | int error = is_delete ? -ENOENT : -ENOMEM; |
| 878 | if (!tomoyo_parse_name_union(filename, &e.name) || |
| 879 | !tomoyo_parse_number_union(mode, &e.mode) || |
| 880 | !tomoyo_parse_number_union(major, &e.major) || |
| 881 | !tomoyo_parse_number_union(minor, &e.minor)) |
| 882 | goto out; |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame^] | 883 | error = tomoyo_update_domain(&e.head, sizeof(e), is_delete, domain, |
| 884 | tomoyo_same_path_number3_acl, |
| 885 | tomoyo_merge_path_number3_acl); |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 886 | out: |
| 887 | tomoyo_put_name_union(&e.name); |
| 888 | tomoyo_put_number_union(&e.mode); |
| 889 | tomoyo_put_number_union(&e.major); |
| 890 | tomoyo_put_number_union(&e.minor); |
| 891 | return error; |
| 892 | } |
| 893 | |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame^] | 894 | static bool tomoyo_same_path2_acl(const struct tomoyo_acl_info *a, |
| 895 | const struct tomoyo_acl_info *b) |
| 896 | { |
| 897 | const struct tomoyo_path2_acl *p1 = container_of(a, typeof(*p1), head); |
| 898 | const struct tomoyo_path2_acl *p2 = container_of(b, typeof(*p2), head); |
| 899 | return tomoyo_is_same_acl_head(&p1->head, &p2->head) |
| 900 | && tomoyo_is_same_name_union(&p1->name1, &p2->name1) |
| 901 | && tomoyo_is_same_name_union(&p1->name2, &p2->name2); |
| 902 | } |
| 903 | |
| 904 | static bool tomoyo_merge_path2_acl(struct tomoyo_acl_info *a, |
| 905 | struct tomoyo_acl_info *b, |
| 906 | const bool is_delete) |
| 907 | { |
| 908 | u8 * const a_perm = &container_of(a, struct tomoyo_path2_acl, head) |
| 909 | ->perm; |
| 910 | u8 perm = *a_perm; |
| 911 | const u8 b_perm = container_of(b, struct tomoyo_path2_acl, head)->perm; |
| 912 | if (is_delete) |
| 913 | perm &= ~b_perm; |
| 914 | else |
| 915 | perm |= b_perm; |
| 916 | *a_perm = perm; |
| 917 | return !perm; |
| 918 | } |
| 919 | |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 920 | /** |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 921 | * tomoyo_update_path2_acl - Update "struct tomoyo_path2_acl" list. |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 922 | * |
| 923 | * @type: Type of operation. |
| 924 | * @filename1: First filename. |
| 925 | * @filename2: Second filename. |
| 926 | * @domain: Pointer to "struct tomoyo_domain_info". |
| 927 | * @is_delete: True if it is a delete request. |
| 928 | * |
| 929 | * Returns 0 on success, negative value otherwise. |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 930 | * |
| 931 | * Caller holds tomoyo_read_lock(). |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 932 | */ |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 933 | static int tomoyo_update_path2_acl(const u8 type, const char *filename1, |
| 934 | const char *filename2, |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame^] | 935 | struct tomoyo_domain_info * const domain, |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 936 | const bool is_delete) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 937 | { |
Tetsuo Handa | 9e4b50e | 2010-05-06 12:40:02 +0900 | [diff] [blame] | 938 | struct tomoyo_path2_acl e = { |
| 939 | .head.type = TOMOYO_TYPE_PATH2_ACL, |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame^] | 940 | .perm = 1 << type |
Tetsuo Handa | 9e4b50e | 2010-05-06 12:40:02 +0900 | [diff] [blame] | 941 | }; |
Tetsuo Handa | 9e4b50e | 2010-05-06 12:40:02 +0900 | [diff] [blame] | 942 | int error = is_delete ? -ENOENT : -ENOMEM; |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 943 | if (!tomoyo_parse_name_union(filename1, &e.name1) || |
| 944 | !tomoyo_parse_name_union(filename2, &e.name2)) |
Tetsuo Handa | ca0b7df | 2010-02-07 20:23:59 +0900 | [diff] [blame] | 945 | goto out; |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame^] | 946 | error = tomoyo_update_domain(&e.head, sizeof(e), is_delete, domain, |
| 947 | tomoyo_same_path2_acl, |
| 948 | tomoyo_merge_path2_acl); |
Tetsuo Handa | ca0b7df | 2010-02-07 20:23:59 +0900 | [diff] [blame] | 949 | out: |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 950 | tomoyo_put_name_union(&e.name1); |
| 951 | tomoyo_put_name_union(&e.name2); |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 952 | return error; |
| 953 | } |
| 954 | |
| 955 | /** |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 956 | * tomoyo_path_number3_acl - Check permission for path/number/number/number operation. |
| 957 | * |
| 958 | * @r: Pointer to "struct tomoyo_request_info". |
| 959 | * @filename: Filename to check. |
| 960 | * @perm: Permission. |
| 961 | * @mode: Create mode. |
| 962 | * @major: Device major number. |
| 963 | * @minor: Device minor number. |
| 964 | * |
| 965 | * Returns 0 on success, -EPERM otherwise. |
| 966 | * |
| 967 | * Caller holds tomoyo_read_lock(). |
| 968 | */ |
| 969 | static int tomoyo_path_number3_acl(struct tomoyo_request_info *r, |
| 970 | const struct tomoyo_path_info *filename, |
| 971 | const u16 perm, const unsigned int mode, |
| 972 | const unsigned int major, |
| 973 | const unsigned int minor) |
| 974 | { |
| 975 | struct tomoyo_domain_info *domain = r->domain; |
| 976 | struct tomoyo_acl_info *ptr; |
| 977 | int error = -EPERM; |
| 978 | list_for_each_entry_rcu(ptr, &domain->acl_info_list, list) { |
| 979 | struct tomoyo_path_number3_acl *acl; |
| 980 | if (ptr->type != TOMOYO_TYPE_PATH_NUMBER3_ACL) |
| 981 | continue; |
| 982 | acl = container_of(ptr, struct tomoyo_path_number3_acl, head); |
| 983 | if (!tomoyo_compare_number_union(mode, &acl->mode)) |
| 984 | continue; |
| 985 | if (!tomoyo_compare_number_union(major, &acl->major)) |
| 986 | continue; |
| 987 | if (!tomoyo_compare_number_union(minor, &acl->minor)) |
| 988 | continue; |
| 989 | if (!(acl->perm & perm)) |
| 990 | continue; |
| 991 | if (!tomoyo_compare_name_union(filename, &acl->name)) |
| 992 | continue; |
| 993 | error = 0; |
| 994 | break; |
| 995 | } |
| 996 | return error; |
| 997 | } |
| 998 | |
| 999 | /** |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 1000 | * tomoyo_path2_acl - Check permission for double path operation. |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 1001 | * |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 1002 | * @r: Pointer to "struct tomoyo_request_info". |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 1003 | * @type: Type of operation. |
| 1004 | * @filename1: First filename to check. |
| 1005 | * @filename2: Second filename to check. |
| 1006 | * |
| 1007 | * Returns 0 on success, -EPERM otherwise. |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 1008 | * |
| 1009 | * Caller holds tomoyo_read_lock(). |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 1010 | */ |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 1011 | static int tomoyo_path2_acl(const struct tomoyo_request_info *r, const u8 type, |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 1012 | const struct tomoyo_path_info *filename1, |
| 1013 | const struct tomoyo_path_info *filename2) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 1014 | { |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 1015 | const struct tomoyo_domain_info *domain = r->domain; |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 1016 | struct tomoyo_acl_info *ptr; |
| 1017 | const u8 perm = 1 << type; |
| 1018 | int error = -EPERM; |
| 1019 | |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 1020 | list_for_each_entry_rcu(ptr, &domain->acl_info_list, list) { |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 1021 | struct tomoyo_path2_acl *acl; |
| 1022 | if (ptr->type != TOMOYO_TYPE_PATH2_ACL) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 1023 | continue; |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 1024 | acl = container_of(ptr, struct tomoyo_path2_acl, head); |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 1025 | if (!(acl->perm & perm)) |
| 1026 | continue; |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 1027 | if (!tomoyo_compare_name_union(filename1, &acl->name1)) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 1028 | continue; |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 1029 | if (!tomoyo_compare_name_union(filename2, &acl->name2)) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 1030 | continue; |
| 1031 | error = 0; |
| 1032 | break; |
| 1033 | } |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 1034 | return error; |
| 1035 | } |
| 1036 | |
| 1037 | /** |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 1038 | * tomoyo_path_permission - Check permission for single path operation. |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 1039 | * |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 1040 | * @r: Pointer to "struct tomoyo_request_info". |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 1041 | * @operation: Type of operation. |
| 1042 | * @filename: Filename to check. |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 1043 | * |
| 1044 | * Returns 0 on success, negative value otherwise. |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 1045 | * |
| 1046 | * Caller holds tomoyo_read_lock(). |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 1047 | */ |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 1048 | static int tomoyo_path_permission(struct tomoyo_request_info *r, u8 operation, |
| 1049 | const struct tomoyo_path_info *filename) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 1050 | { |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1051 | const char *msg; |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 1052 | int error; |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 1053 | |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 1054 | next: |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 1055 | r->type = tomoyo_p2mac[operation]; |
| 1056 | r->mode = tomoyo_get_mode(r->profile, r->type); |
| 1057 | if (r->mode == TOMOYO_CONFIG_DISABLED) |
| 1058 | return 0; |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1059 | do { |
Tetsuo Handa | 3f62963 | 2010-06-03 20:37:26 +0900 | [diff] [blame] | 1060 | error = tomoyo_path_acl(r, filename, 1 << operation); |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1061 | if (!error) |
| 1062 | break; |
| 1063 | msg = tomoyo_path2keyword(operation); |
| 1064 | tomoyo_warn_log(r, "%s %s", msg, filename->name); |
| 1065 | error = tomoyo_supervisor(r, "allow_%s %s\n", msg, |
| 1066 | tomoyo_file_pattern(filename)); |
| 1067 | } while (error == TOMOYO_RETRY_REQUEST); |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 1068 | if (r->mode != TOMOYO_CONFIG_ENFORCING) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 1069 | error = 0; |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 1070 | /* |
| 1071 | * Since "allow_truncate" doesn't imply "allow_rewrite" permission, |
| 1072 | * we need to check "allow_rewrite" permission if the filename is |
| 1073 | * specified by "deny_rewrite" keyword. |
| 1074 | */ |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 1075 | if (!error && operation == TOMOYO_TYPE_TRUNCATE && |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 1076 | tomoyo_is_no_rewrite_file(filename)) { |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 1077 | operation = TOMOYO_TYPE_REWRITE; |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 1078 | goto next; |
| 1079 | } |
| 1080 | return error; |
| 1081 | } |
| 1082 | |
| 1083 | /** |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 1084 | * tomoyo_path_number_acl - Check permission for ioctl/chmod/chown/chgrp operation. |
| 1085 | * |
| 1086 | * @r: Pointer to "struct tomoyo_request_info". |
| 1087 | * @type: Operation. |
| 1088 | * @filename: Filename to check. |
| 1089 | * @number: Number. |
| 1090 | * |
| 1091 | * Returns 0 on success, -EPERM otherwise. |
| 1092 | * |
| 1093 | * Caller holds tomoyo_read_lock(). |
| 1094 | */ |
| 1095 | static int tomoyo_path_number_acl(struct tomoyo_request_info *r, const u8 type, |
| 1096 | const struct tomoyo_path_info *filename, |
| 1097 | const unsigned long number) |
| 1098 | { |
| 1099 | struct tomoyo_domain_info *domain = r->domain; |
| 1100 | struct tomoyo_acl_info *ptr; |
| 1101 | const u8 perm = 1 << type; |
| 1102 | int error = -EPERM; |
| 1103 | list_for_each_entry_rcu(ptr, &domain->acl_info_list, list) { |
| 1104 | struct tomoyo_path_number_acl *acl; |
| 1105 | if (ptr->type != TOMOYO_TYPE_PATH_NUMBER_ACL) |
| 1106 | continue; |
| 1107 | acl = container_of(ptr, struct tomoyo_path_number_acl, |
| 1108 | head); |
| 1109 | if (!(acl->perm & perm) || |
| 1110 | !tomoyo_compare_number_union(number, &acl->number) || |
| 1111 | !tomoyo_compare_name_union(filename, &acl->name)) |
| 1112 | continue; |
| 1113 | error = 0; |
| 1114 | break; |
| 1115 | } |
| 1116 | return error; |
| 1117 | } |
| 1118 | |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame^] | 1119 | static bool tomoyo_same_path_number_acl(const struct tomoyo_acl_info *a, |
| 1120 | const struct tomoyo_acl_info *b) |
| 1121 | { |
| 1122 | const struct tomoyo_path_number_acl *p1 = container_of(a, typeof(*p1), |
| 1123 | head); |
| 1124 | const struct tomoyo_path_number_acl *p2 = container_of(b, typeof(*p2), |
| 1125 | head); |
| 1126 | return tomoyo_is_same_acl_head(&p1->head, &p2->head) |
| 1127 | && tomoyo_is_same_name_union(&p1->name, &p2->name) |
| 1128 | && tomoyo_is_same_number_union(&p1->number, &p2->number); |
| 1129 | } |
| 1130 | |
| 1131 | static bool tomoyo_merge_path_number_acl(struct tomoyo_acl_info *a, |
| 1132 | struct tomoyo_acl_info *b, |
| 1133 | const bool is_delete) |
| 1134 | { |
| 1135 | u8 * const a_perm = &container_of(a, struct tomoyo_path_number_acl, |
| 1136 | head)->perm; |
| 1137 | u8 perm = *a_perm; |
| 1138 | const u8 b_perm = container_of(b, struct tomoyo_path_number_acl, head) |
| 1139 | ->perm; |
| 1140 | if (is_delete) |
| 1141 | perm &= ~b_perm; |
| 1142 | else |
| 1143 | perm |= b_perm; |
| 1144 | *a_perm = perm; |
| 1145 | return !perm; |
| 1146 | } |
| 1147 | |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 1148 | /** |
| 1149 | * tomoyo_update_path_number_acl - Update ioctl/chmod/chown/chgrp ACL. |
| 1150 | * |
| 1151 | * @type: Type of operation. |
| 1152 | * @filename: Filename. |
| 1153 | * @number: Number. |
| 1154 | * @domain: Pointer to "struct tomoyo_domain_info". |
| 1155 | * @is_delete: True if it is a delete request. |
| 1156 | * |
| 1157 | * Returns 0 on success, negative value otherwise. |
| 1158 | */ |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame^] | 1159 | static int tomoyo_update_path_number_acl(const u8 type, const char *filename, |
| 1160 | char *number, |
| 1161 | struct tomoyo_domain_info * const |
| 1162 | domain, |
| 1163 | const bool is_delete) |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 1164 | { |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 1165 | struct tomoyo_path_number_acl e = { |
| 1166 | .head.type = TOMOYO_TYPE_PATH_NUMBER_ACL, |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame^] | 1167 | .perm = 1 << type |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 1168 | }; |
| 1169 | int error = is_delete ? -ENOENT : -ENOMEM; |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 1170 | if (!tomoyo_parse_name_union(filename, &e.name)) |
| 1171 | return -EINVAL; |
| 1172 | if (!tomoyo_parse_number_union(number, &e.number)) |
| 1173 | goto out; |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame^] | 1174 | error = tomoyo_update_domain(&e.head, sizeof(e), is_delete, domain, |
| 1175 | tomoyo_same_path_number_acl, |
| 1176 | tomoyo_merge_path_number_acl); |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 1177 | out: |
| 1178 | tomoyo_put_name_union(&e.name); |
| 1179 | tomoyo_put_number_union(&e.number); |
| 1180 | return error; |
| 1181 | } |
| 1182 | |
| 1183 | /** |
| 1184 | * tomoyo_path_number_perm2 - Check permission for "create", "mkdir", "mkfifo", "mksock", "ioctl", "chmod", "chown", "chgrp". |
| 1185 | * |
| 1186 | * @r: Pointer to "strct tomoyo_request_info". |
| 1187 | * @filename: Filename to check. |
| 1188 | * @number: Number. |
| 1189 | * |
| 1190 | * Returns 0 on success, negative value otherwise. |
| 1191 | * |
| 1192 | * Caller holds tomoyo_read_lock(). |
| 1193 | */ |
| 1194 | static int tomoyo_path_number_perm2(struct tomoyo_request_info *r, |
| 1195 | const u8 type, |
| 1196 | const struct tomoyo_path_info *filename, |
| 1197 | const unsigned long number) |
| 1198 | { |
| 1199 | char buffer[64]; |
| 1200 | int error; |
| 1201 | u8 radix; |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1202 | const char *msg; |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 1203 | |
| 1204 | if (!filename) |
| 1205 | return 0; |
| 1206 | switch (type) { |
| 1207 | case TOMOYO_TYPE_CREATE: |
| 1208 | case TOMOYO_TYPE_MKDIR: |
| 1209 | case TOMOYO_TYPE_MKFIFO: |
| 1210 | case TOMOYO_TYPE_MKSOCK: |
| 1211 | case TOMOYO_TYPE_CHMOD: |
| 1212 | radix = TOMOYO_VALUE_TYPE_OCTAL; |
| 1213 | break; |
| 1214 | case TOMOYO_TYPE_IOCTL: |
| 1215 | radix = TOMOYO_VALUE_TYPE_HEXADECIMAL; |
| 1216 | break; |
| 1217 | default: |
| 1218 | radix = TOMOYO_VALUE_TYPE_DECIMAL; |
| 1219 | break; |
| 1220 | } |
| 1221 | tomoyo_print_ulong(buffer, sizeof(buffer), number, radix); |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1222 | do { |
| 1223 | error = tomoyo_path_number_acl(r, type, filename, number); |
| 1224 | if (!error) |
| 1225 | break; |
| 1226 | msg = tomoyo_path_number2keyword(type); |
| 1227 | tomoyo_warn_log(r, "%s %s %s", msg, filename->name, buffer); |
| 1228 | error = tomoyo_supervisor(r, "allow_%s %s %s\n", msg, |
| 1229 | tomoyo_file_pattern(filename), |
| 1230 | buffer); |
| 1231 | } while (error == TOMOYO_RETRY_REQUEST); |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 1232 | if (r->mode != TOMOYO_CONFIG_ENFORCING) |
| 1233 | error = 0; |
| 1234 | return error; |
| 1235 | } |
| 1236 | |
| 1237 | /** |
| 1238 | * tomoyo_path_number_perm - Check permission for "create", "mkdir", "mkfifo", "mksock", "ioctl", "chmod", "chown", "chgrp". |
| 1239 | * |
| 1240 | * @type: Type of operation. |
| 1241 | * @path: Pointer to "struct path". |
| 1242 | * @number: Number. |
| 1243 | * |
| 1244 | * Returns 0 on success, negative value otherwise. |
| 1245 | */ |
| 1246 | int tomoyo_path_number_perm(const u8 type, struct path *path, |
| 1247 | unsigned long number) |
| 1248 | { |
| 1249 | struct tomoyo_request_info r; |
| 1250 | int error = -ENOMEM; |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 1251 | struct tomoyo_path_info buf; |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 1252 | int idx; |
| 1253 | |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 1254 | if (tomoyo_init_request_info(&r, NULL, tomoyo_pn2mac[type]) |
| 1255 | == TOMOYO_CONFIG_DISABLED || !path->mnt || !path->dentry) |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 1256 | return 0; |
| 1257 | idx = tomoyo_read_lock(); |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 1258 | if (!tomoyo_get_realpath(&buf, path)) |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 1259 | goto out; |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 1260 | if (type == TOMOYO_TYPE_MKDIR) |
| 1261 | tomoyo_add_slash(&buf); |
| 1262 | error = tomoyo_path_number_perm2(&r, type, &buf, number); |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 1263 | out: |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 1264 | kfree(buf.name); |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 1265 | tomoyo_read_unlock(idx); |
| 1266 | if (r.mode != TOMOYO_CONFIG_ENFORCING) |
| 1267 | error = 0; |
| 1268 | return error; |
| 1269 | } |
| 1270 | |
| 1271 | /** |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 1272 | * tomoyo_check_exec_perm - Check permission for "execute". |
| 1273 | * |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 1274 | * @r: Pointer to "struct tomoyo_request_info". |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 1275 | * @filename: Check permission for "execute". |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 1276 | * |
| 1277 | * Returns 0 on success, negativevalue otherwise. |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 1278 | * |
| 1279 | * Caller holds tomoyo_read_lock(). |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 1280 | */ |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 1281 | int tomoyo_check_exec_perm(struct tomoyo_request_info *r, |
Tetsuo Handa | bcb8697 | 2009-06-04 15:14:34 +0900 | [diff] [blame] | 1282 | const struct tomoyo_path_info *filename) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 1283 | { |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 1284 | if (r->mode == TOMOYO_CONFIG_DISABLED) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 1285 | return 0; |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 1286 | return tomoyo_file_perm(r, filename, 1); |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 1287 | } |
| 1288 | |
| 1289 | /** |
| 1290 | * tomoyo_check_open_permission - Check permission for "read" and "write". |
| 1291 | * |
| 1292 | * @domain: Pointer to "struct tomoyo_domain_info". |
| 1293 | * @path: Pointer to "struct path". |
| 1294 | * @flag: Flags for open(). |
| 1295 | * |
| 1296 | * Returns 0 on success, negative value otherwise. |
| 1297 | */ |
| 1298 | int tomoyo_check_open_permission(struct tomoyo_domain_info *domain, |
| 1299 | struct path *path, const int flag) |
| 1300 | { |
| 1301 | const u8 acc_mode = ACC_MODE(flag); |
| 1302 | int error = -ENOMEM; |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 1303 | struct tomoyo_path_info buf; |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 1304 | struct tomoyo_request_info r; |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 1305 | int idx; |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 1306 | |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 1307 | if (!path->mnt || |
| 1308 | (path->dentry->d_inode && S_ISDIR(path->dentry->d_inode->i_mode))) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 1309 | return 0; |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 1310 | buf.name = NULL; |
| 1311 | r.mode = TOMOYO_CONFIG_DISABLED; |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 1312 | idx = tomoyo_read_lock(); |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 1313 | if (!tomoyo_get_realpath(&buf, path)) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 1314 | goto out; |
| 1315 | error = 0; |
| 1316 | /* |
| 1317 | * If the filename is specified by "deny_rewrite" keyword, |
| 1318 | * we need to check "allow_rewrite" permission when the filename is not |
| 1319 | * opened for append mode or the filename is truncated at open time. |
| 1320 | */ |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 1321 | if ((acc_mode & MAY_WRITE) && !(flag & O_APPEND) |
| 1322 | && tomoyo_init_request_info(&r, domain, TOMOYO_MAC_FILE_REWRITE) |
| 1323 | != TOMOYO_CONFIG_DISABLED) { |
| 1324 | if (!tomoyo_get_realpath(&buf, path)) { |
| 1325 | error = -ENOMEM; |
| 1326 | goto out; |
| 1327 | } |
| 1328 | if (tomoyo_is_no_rewrite_file(&buf)) |
| 1329 | error = tomoyo_path_permission(&r, TOMOYO_TYPE_REWRITE, |
| 1330 | &buf); |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 1331 | } |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 1332 | if (!error && acc_mode && |
| 1333 | tomoyo_init_request_info(&r, domain, TOMOYO_MAC_FILE_OPEN) |
| 1334 | != TOMOYO_CONFIG_DISABLED) { |
| 1335 | if (!buf.name && !tomoyo_get_realpath(&buf, path)) { |
| 1336 | error = -ENOMEM; |
| 1337 | goto out; |
| 1338 | } |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 1339 | error = tomoyo_file_perm(&r, &buf, acc_mode); |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 1340 | } |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 1341 | out: |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 1342 | kfree(buf.name); |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 1343 | tomoyo_read_unlock(idx); |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 1344 | if (r.mode != TOMOYO_CONFIG_ENFORCING) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 1345 | error = 0; |
| 1346 | return error; |
| 1347 | } |
| 1348 | |
| 1349 | /** |
Tetsuo Handa | 2106ccd | 2010-05-17 10:10:31 +0900 | [diff] [blame] | 1350 | * tomoyo_path_perm - Check permission for "unlink", "rmdir", "truncate", "symlink", "rewrite", "chroot" and "unmount". |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 1351 | * |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 1352 | * @operation: Type of operation. |
| 1353 | * @path: Pointer to "struct path". |
| 1354 | * |
| 1355 | * Returns 0 on success, negative value otherwise. |
| 1356 | */ |
Tetsuo Handa | 97d6931 | 2010-02-16 09:46:15 +0900 | [diff] [blame] | 1357 | int tomoyo_path_perm(const u8 operation, struct path *path) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 1358 | { |
| 1359 | int error = -ENOMEM; |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 1360 | struct tomoyo_path_info buf; |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 1361 | struct tomoyo_request_info r; |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 1362 | int idx; |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 1363 | |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 1364 | if (!path->mnt) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 1365 | return 0; |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 1366 | if (tomoyo_init_request_info(&r, NULL, tomoyo_p2mac[operation]) |
| 1367 | == TOMOYO_CONFIG_DISABLED) |
| 1368 | return 0; |
| 1369 | buf.name = NULL; |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 1370 | idx = tomoyo_read_lock(); |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 1371 | if (!tomoyo_get_realpath(&buf, path)) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 1372 | goto out; |
| 1373 | switch (operation) { |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 1374 | case TOMOYO_TYPE_REWRITE: |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 1375 | if (!tomoyo_is_no_rewrite_file(&buf)) { |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 1376 | error = 0; |
| 1377 | goto out; |
| 1378 | } |
| 1379 | break; |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 1380 | case TOMOYO_TYPE_RMDIR: |
| 1381 | case TOMOYO_TYPE_CHROOT: |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 1382 | case TOMOYO_TYPE_UMOUNT: |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 1383 | tomoyo_add_slash(&buf); |
| 1384 | break; |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 1385 | } |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 1386 | error = tomoyo_path_permission(&r, operation, &buf); |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 1387 | out: |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 1388 | kfree(buf.name); |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 1389 | tomoyo_read_unlock(idx); |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 1390 | if (r.mode != TOMOYO_CONFIG_ENFORCING) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 1391 | error = 0; |
| 1392 | return error; |
| 1393 | } |
| 1394 | |
| 1395 | /** |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 1396 | * tomoyo_path_number3_perm2 - Check permission for path/number/number/number operation. |
| 1397 | * |
| 1398 | * @r: Pointer to "struct tomoyo_request_info". |
| 1399 | * @operation: Type of operation. |
| 1400 | * @filename: Filename to check. |
| 1401 | * @mode: Create mode. |
| 1402 | * @dev: Device number. |
| 1403 | * |
| 1404 | * Returns 0 on success, negative value otherwise. |
| 1405 | * |
| 1406 | * Caller holds tomoyo_read_lock(). |
| 1407 | */ |
| 1408 | static int tomoyo_path_number3_perm2(struct tomoyo_request_info *r, |
| 1409 | const u8 operation, |
| 1410 | const struct tomoyo_path_info *filename, |
| 1411 | const unsigned int mode, |
| 1412 | const unsigned int dev) |
| 1413 | { |
| 1414 | int error; |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1415 | const char *msg; |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 1416 | const unsigned int major = MAJOR(dev); |
| 1417 | const unsigned int minor = MINOR(dev); |
| 1418 | |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1419 | do { |
| 1420 | error = tomoyo_path_number3_acl(r, filename, 1 << operation, |
| 1421 | mode, major, minor); |
| 1422 | if (!error) |
| 1423 | break; |
| 1424 | msg = tomoyo_path_number32keyword(operation); |
| 1425 | tomoyo_warn_log(r, "%s %s 0%o %u %u", msg, filename->name, |
| 1426 | mode, major, minor); |
| 1427 | error = tomoyo_supervisor(r, "allow_%s %s 0%o %u %u\n", msg, |
| 1428 | tomoyo_file_pattern(filename), mode, |
| 1429 | major, minor); |
| 1430 | } while (error == TOMOYO_RETRY_REQUEST); |
| 1431 | if (r->mode != TOMOYO_CONFIG_ENFORCING) |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 1432 | error = 0; |
| 1433 | return error; |
| 1434 | } |
| 1435 | |
| 1436 | /** |
| 1437 | * tomoyo_path_number3_perm - Check permission for "mkblock" and "mkchar". |
| 1438 | * |
| 1439 | * @operation: Type of operation. (TOMOYO_TYPE_MKCHAR or TOMOYO_TYPE_MKBLOCK) |
| 1440 | * @path: Pointer to "struct path". |
| 1441 | * @mode: Create mode. |
| 1442 | * @dev: Device number. |
| 1443 | * |
| 1444 | * Returns 0 on success, negative value otherwise. |
| 1445 | */ |
| 1446 | int tomoyo_path_number3_perm(const u8 operation, struct path *path, |
| 1447 | const unsigned int mode, unsigned int dev) |
| 1448 | { |
| 1449 | struct tomoyo_request_info r; |
| 1450 | int error = -ENOMEM; |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 1451 | struct tomoyo_path_info buf; |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 1452 | int idx; |
| 1453 | |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 1454 | if (!path->mnt || |
| 1455 | tomoyo_init_request_info(&r, NULL, tomoyo_pnnn2mac[operation]) |
| 1456 | == TOMOYO_CONFIG_DISABLED) |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 1457 | return 0; |
| 1458 | idx = tomoyo_read_lock(); |
| 1459 | error = -ENOMEM; |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 1460 | if (tomoyo_get_realpath(&buf, path)) { |
| 1461 | error = tomoyo_path_number3_perm2(&r, operation, &buf, mode, |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 1462 | new_decode_dev(dev)); |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 1463 | kfree(buf.name); |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 1464 | } |
| 1465 | tomoyo_read_unlock(idx); |
| 1466 | if (r.mode != TOMOYO_CONFIG_ENFORCING) |
| 1467 | error = 0; |
| 1468 | return error; |
| 1469 | } |
| 1470 | |
| 1471 | /** |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 1472 | * tomoyo_path2_perm - Check permission for "rename", "link" and "pivot_root". |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 1473 | * |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 1474 | * @operation: Type of operation. |
| 1475 | * @path1: Pointer to "struct path". |
| 1476 | * @path2: Pointer to "struct path". |
| 1477 | * |
| 1478 | * Returns 0 on success, negative value otherwise. |
| 1479 | */ |
Tetsuo Handa | 97d6931 | 2010-02-16 09:46:15 +0900 | [diff] [blame] | 1480 | int tomoyo_path2_perm(const u8 operation, struct path *path1, |
Tetsuo Handa | 7ef6123 | 2010-02-16 08:03:30 +0900 | [diff] [blame] | 1481 | struct path *path2) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 1482 | { |
| 1483 | int error = -ENOMEM; |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1484 | const char *msg; |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 1485 | struct tomoyo_path_info buf1; |
| 1486 | struct tomoyo_path_info buf2; |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 1487 | struct tomoyo_request_info r; |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 1488 | int idx; |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 1489 | |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 1490 | if (!path1->mnt || !path2->mnt || |
| 1491 | tomoyo_init_request_info(&r, NULL, tomoyo_pp2mac[operation]) |
| 1492 | == TOMOYO_CONFIG_DISABLED) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 1493 | return 0; |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 1494 | buf1.name = NULL; |
| 1495 | buf2.name = NULL; |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 1496 | idx = tomoyo_read_lock(); |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 1497 | if (!tomoyo_get_realpath(&buf1, path1) || |
| 1498 | !tomoyo_get_realpath(&buf2, path2)) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 1499 | goto out; |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 1500 | switch (operation) { |
| 1501 | struct dentry *dentry; |
| 1502 | case TOMOYO_TYPE_RENAME: |
| 1503 | case TOMOYO_TYPE_LINK: |
| 1504 | dentry = path1->dentry; |
| 1505 | if (!dentry->d_inode || !S_ISDIR(dentry->d_inode->i_mode)) |
| 1506 | break; |
| 1507 | /* fall through */ |
| 1508 | case TOMOYO_TYPE_PIVOT_ROOT: |
| 1509 | tomoyo_add_slash(&buf1); |
| 1510 | tomoyo_add_slash(&buf2); |
| 1511 | break; |
| 1512 | } |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1513 | do { |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 1514 | error = tomoyo_path2_acl(&r, operation, &buf1, &buf2); |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1515 | if (!error) |
| 1516 | break; |
| 1517 | msg = tomoyo_path22keyword(operation); |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 1518 | tomoyo_warn_log(&r, "%s %s %s", msg, buf1.name, buf2.name); |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1519 | error = tomoyo_supervisor(&r, "allow_%s %s %s\n", msg, |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 1520 | tomoyo_file_pattern(&buf1), |
| 1521 | tomoyo_file_pattern(&buf2)); |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1522 | } while (error == TOMOYO_RETRY_REQUEST); |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 1523 | out: |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 1524 | kfree(buf1.name); |
| 1525 | kfree(buf2.name); |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 1526 | tomoyo_read_unlock(idx); |
Tetsuo Handa | cb0abe6 | 2010-05-17 10:08:05 +0900 | [diff] [blame] | 1527 | if (r.mode != TOMOYO_CONFIG_ENFORCING) |
Kentaro Takeda | b69a54e | 2009-02-05 17:18:14 +0900 | [diff] [blame] | 1528 | error = 0; |
| 1529 | return error; |
| 1530 | } |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 1531 | |
| 1532 | /** |
| 1533 | * tomoyo_write_file_policy - Update file related list. |
| 1534 | * |
| 1535 | * @data: String to parse. |
| 1536 | * @domain: Pointer to "struct tomoyo_domain_info". |
| 1537 | * @is_delete: True if it is a delete request. |
| 1538 | * |
| 1539 | * Returns 0 on success, negative value otherwise. |
| 1540 | * |
| 1541 | * Caller holds tomoyo_read_lock(). |
| 1542 | */ |
| 1543 | int tomoyo_write_file_policy(char *data, struct tomoyo_domain_info *domain, |
| 1544 | const bool is_delete) |
| 1545 | { |
| 1546 | char *w[5]; |
| 1547 | u8 type; |
| 1548 | if (!tomoyo_tokenize(data, w, sizeof(w)) || !w[1][0]) |
| 1549 | return -EINVAL; |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame^] | 1550 | if (strncmp(w[0], "allow_", 6)) |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 1551 | goto out; |
Tetsuo Handa | a1f9bb6 | 2010-05-17 10:09:15 +0900 | [diff] [blame] | 1552 | w[0] += 6; |
| 1553 | for (type = 0; type < TOMOYO_MAX_PATH_OPERATION; type++) { |
| 1554 | if (strcmp(w[0], tomoyo_path_keyword[type])) |
| 1555 | continue; |
| 1556 | return tomoyo_update_path_acl(type, w[1], domain, is_delete); |
| 1557 | } |
| 1558 | if (!w[2][0]) |
| 1559 | goto out; |
| 1560 | for (type = 0; type < TOMOYO_MAX_PATH2_OPERATION; type++) { |
| 1561 | if (strcmp(w[0], tomoyo_path2_keyword[type])) |
| 1562 | continue; |
| 1563 | return tomoyo_update_path2_acl(type, w[1], w[2], domain, |
| 1564 | is_delete); |
| 1565 | } |
| 1566 | for (type = 0; type < TOMOYO_MAX_PATH_NUMBER_OPERATION; type++) { |
| 1567 | if (strcmp(w[0], tomoyo_path_number_keyword[type])) |
| 1568 | continue; |
| 1569 | return tomoyo_update_path_number_acl(type, w[1], w[2], domain, |
| 1570 | is_delete); |
| 1571 | } |
| 1572 | if (!w[3][0] || !w[4][0]) |
| 1573 | goto out; |
| 1574 | for (type = 0; type < TOMOYO_MAX_PATH_NUMBER3_OPERATION; type++) { |
| 1575 | if (strcmp(w[0], tomoyo_path_number3_keyword[type])) |
| 1576 | continue; |
| 1577 | return tomoyo_update_path_number3_acl(type, w[1], w[2], w[3], |
| 1578 | w[4], domain, is_delete); |
| 1579 | } |
| 1580 | out: |
| 1581 | return -EINVAL; |
| 1582 | } |