Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1 | /* |
| 2 | * security/tomoyo/common.c |
| 3 | * |
| 4 | * Common functions for TOMOYO. |
| 5 | * |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 6 | * Copyright (C) 2005-2010 NTT DATA CORPORATION |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <linux/uaccess.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 10 | #include <linux/slab.h> |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 11 | #include <linux/security.h> |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 12 | #include "common.h" |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 13 | |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 14 | /* String table for operation mode. */ |
| 15 | const char * const tomoyo_mode[TOMOYO_CONFIG_MAX_MODE] = { |
| 16 | [TOMOYO_CONFIG_DISABLED] = "disabled", |
| 17 | [TOMOYO_CONFIG_LEARNING] = "learning", |
| 18 | [TOMOYO_CONFIG_PERMISSIVE] = "permissive", |
| 19 | [TOMOYO_CONFIG_ENFORCING] = "enforcing" |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 20 | }; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 21 | |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 22 | /* String table for /sys/kernel/security/tomoyo/profile */ |
Tetsuo Handa | 2c47ab9 | 2011-06-26 23:21:19 +0900 | [diff] [blame] | 23 | const char * const tomoyo_mac_keywords[TOMOYO_MAX_MAC_INDEX |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 24 | + TOMOYO_MAX_MAC_CATEGORY_INDEX] = { |
Tetsuo Handa | 2c47ab9 | 2011-06-26 23:21:19 +0900 | [diff] [blame] | 25 | [TOMOYO_MAC_FILE_EXECUTE] = "execute", |
| 26 | [TOMOYO_MAC_FILE_OPEN] = "open", |
| 27 | [TOMOYO_MAC_FILE_CREATE] = "create", |
| 28 | [TOMOYO_MAC_FILE_UNLINK] = "unlink", |
| 29 | [TOMOYO_MAC_FILE_GETATTR] = "getattr", |
| 30 | [TOMOYO_MAC_FILE_MKDIR] = "mkdir", |
| 31 | [TOMOYO_MAC_FILE_RMDIR] = "rmdir", |
| 32 | [TOMOYO_MAC_FILE_MKFIFO] = "mkfifo", |
| 33 | [TOMOYO_MAC_FILE_MKSOCK] = "mksock", |
| 34 | [TOMOYO_MAC_FILE_TRUNCATE] = "truncate", |
| 35 | [TOMOYO_MAC_FILE_SYMLINK] = "symlink", |
| 36 | [TOMOYO_MAC_FILE_MKBLOCK] = "mkblock", |
| 37 | [TOMOYO_MAC_FILE_MKCHAR] = "mkchar", |
| 38 | [TOMOYO_MAC_FILE_LINK] = "link", |
| 39 | [TOMOYO_MAC_FILE_RENAME] = "rename", |
| 40 | [TOMOYO_MAC_FILE_CHMOD] = "chmod", |
| 41 | [TOMOYO_MAC_FILE_CHOWN] = "chown", |
| 42 | [TOMOYO_MAC_FILE_CHGRP] = "chgrp", |
| 43 | [TOMOYO_MAC_FILE_IOCTL] = "ioctl", |
| 44 | [TOMOYO_MAC_FILE_CHROOT] = "chroot", |
| 45 | [TOMOYO_MAC_FILE_MOUNT] = "mount", |
| 46 | [TOMOYO_MAC_FILE_UMOUNT] = "unmount", |
| 47 | [TOMOYO_MAC_FILE_PIVOT_ROOT] = "pivot_root", |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 48 | [TOMOYO_MAX_MAC_INDEX + TOMOYO_MAC_CATEGORY_FILE] = "file", |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 49 | }; |
| 50 | |
Tetsuo Handa | 2066a36 | 2011-07-08 13:21:37 +0900 | [diff] [blame] | 51 | /* String table for conditions. */ |
| 52 | const char * const tomoyo_condition_keyword[TOMOYO_MAX_CONDITION_KEYWORD] = { |
| 53 | [TOMOYO_TASK_UID] = "task.uid", |
| 54 | [TOMOYO_TASK_EUID] = "task.euid", |
| 55 | [TOMOYO_TASK_SUID] = "task.suid", |
| 56 | [TOMOYO_TASK_FSUID] = "task.fsuid", |
| 57 | [TOMOYO_TASK_GID] = "task.gid", |
| 58 | [TOMOYO_TASK_EGID] = "task.egid", |
| 59 | [TOMOYO_TASK_SGID] = "task.sgid", |
| 60 | [TOMOYO_TASK_FSGID] = "task.fsgid", |
| 61 | [TOMOYO_TASK_PID] = "task.pid", |
| 62 | [TOMOYO_TASK_PPID] = "task.ppid", |
Tetsuo Handa | 8761afd | 2011-07-08 13:22:41 +0900 | [diff] [blame^] | 63 | [TOMOYO_TYPE_IS_SOCKET] = "socket", |
| 64 | [TOMOYO_TYPE_IS_SYMLINK] = "symlink", |
| 65 | [TOMOYO_TYPE_IS_FILE] = "file", |
| 66 | [TOMOYO_TYPE_IS_BLOCK_DEV] = "block", |
| 67 | [TOMOYO_TYPE_IS_DIRECTORY] = "directory", |
| 68 | [TOMOYO_TYPE_IS_CHAR_DEV] = "char", |
| 69 | [TOMOYO_TYPE_IS_FIFO] = "fifo", |
| 70 | [TOMOYO_MODE_SETUID] = "setuid", |
| 71 | [TOMOYO_MODE_SETGID] = "setgid", |
| 72 | [TOMOYO_MODE_STICKY] = "sticky", |
| 73 | [TOMOYO_MODE_OWNER_READ] = "owner_read", |
| 74 | [TOMOYO_MODE_OWNER_WRITE] = "owner_write", |
| 75 | [TOMOYO_MODE_OWNER_EXECUTE] = "owner_execute", |
| 76 | [TOMOYO_MODE_GROUP_READ] = "group_read", |
| 77 | [TOMOYO_MODE_GROUP_WRITE] = "group_write", |
| 78 | [TOMOYO_MODE_GROUP_EXECUTE] = "group_execute", |
| 79 | [TOMOYO_MODE_OTHERS_READ] = "others_read", |
| 80 | [TOMOYO_MODE_OTHERS_WRITE] = "others_write", |
| 81 | [TOMOYO_MODE_OTHERS_EXECUTE] = "others_execute", |
| 82 | [TOMOYO_PATH1_UID] = "path1.uid", |
| 83 | [TOMOYO_PATH1_GID] = "path1.gid", |
| 84 | [TOMOYO_PATH1_INO] = "path1.ino", |
| 85 | [TOMOYO_PATH1_MAJOR] = "path1.major", |
| 86 | [TOMOYO_PATH1_MINOR] = "path1.minor", |
| 87 | [TOMOYO_PATH1_PERM] = "path1.perm", |
| 88 | [TOMOYO_PATH1_TYPE] = "path1.type", |
| 89 | [TOMOYO_PATH1_DEV_MAJOR] = "path1.dev_major", |
| 90 | [TOMOYO_PATH1_DEV_MINOR] = "path1.dev_minor", |
| 91 | [TOMOYO_PATH2_UID] = "path2.uid", |
| 92 | [TOMOYO_PATH2_GID] = "path2.gid", |
| 93 | [TOMOYO_PATH2_INO] = "path2.ino", |
| 94 | [TOMOYO_PATH2_MAJOR] = "path2.major", |
| 95 | [TOMOYO_PATH2_MINOR] = "path2.minor", |
| 96 | [TOMOYO_PATH2_PERM] = "path2.perm", |
| 97 | [TOMOYO_PATH2_TYPE] = "path2.type", |
| 98 | [TOMOYO_PATH2_DEV_MAJOR] = "path2.dev_major", |
| 99 | [TOMOYO_PATH2_DEV_MINOR] = "path2.dev_minor", |
| 100 | [TOMOYO_PATH1_PARENT_UID] = "path1.parent.uid", |
| 101 | [TOMOYO_PATH1_PARENT_GID] = "path1.parent.gid", |
| 102 | [TOMOYO_PATH1_PARENT_INO] = "path1.parent.ino", |
| 103 | [TOMOYO_PATH1_PARENT_PERM] = "path1.parent.perm", |
| 104 | [TOMOYO_PATH2_PARENT_UID] = "path2.parent.uid", |
| 105 | [TOMOYO_PATH2_PARENT_GID] = "path2.parent.gid", |
| 106 | [TOMOYO_PATH2_PARENT_INO] = "path2.parent.ino", |
| 107 | [TOMOYO_PATH2_PARENT_PERM] = "path2.parent.perm", |
Tetsuo Handa | 2066a36 | 2011-07-08 13:21:37 +0900 | [diff] [blame] | 108 | }; |
| 109 | |
Tetsuo Handa | d5ca172 | 2011-06-26 23:18:21 +0900 | [diff] [blame] | 110 | /* String table for PREFERENCE keyword. */ |
| 111 | static const char * const tomoyo_pref_keywords[TOMOYO_MAX_PREF] = { |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 112 | [TOMOYO_PREF_MAX_AUDIT_LOG] = "max_audit_log", |
Tetsuo Handa | d5ca172 | 2011-06-26 23:18:21 +0900 | [diff] [blame] | 113 | [TOMOYO_PREF_MAX_LEARNING_ENTRY] = "max_learning_entry", |
| 114 | }; |
| 115 | |
Tetsuo Handa | 2c47ab9 | 2011-06-26 23:21:19 +0900 | [diff] [blame] | 116 | /* String table for path operation. */ |
| 117 | const char * const tomoyo_path_keyword[TOMOYO_MAX_PATH_OPERATION] = { |
| 118 | [TOMOYO_TYPE_EXECUTE] = "execute", |
| 119 | [TOMOYO_TYPE_READ] = "read", |
| 120 | [TOMOYO_TYPE_WRITE] = "write", |
| 121 | [TOMOYO_TYPE_APPEND] = "append", |
| 122 | [TOMOYO_TYPE_UNLINK] = "unlink", |
| 123 | [TOMOYO_TYPE_GETATTR] = "getattr", |
| 124 | [TOMOYO_TYPE_RMDIR] = "rmdir", |
| 125 | [TOMOYO_TYPE_TRUNCATE] = "truncate", |
| 126 | [TOMOYO_TYPE_SYMLINK] = "symlink", |
| 127 | [TOMOYO_TYPE_CHROOT] = "chroot", |
| 128 | [TOMOYO_TYPE_UMOUNT] = "unmount", |
| 129 | }; |
| 130 | |
| 131 | /* String table for categories. */ |
| 132 | static const char * const tomoyo_category_keywords |
| 133 | [TOMOYO_MAX_MAC_CATEGORY_INDEX] = { |
| 134 | [TOMOYO_MAC_CATEGORY_FILE] = "file", |
| 135 | }; |
| 136 | |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 137 | /* Permit policy management by non-root user? */ |
| 138 | static bool tomoyo_manage_by_non_root; |
| 139 | |
| 140 | /* Utility functions. */ |
| 141 | |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 142 | /** |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 143 | * tomoyo_yesno - Return "yes" or "no". |
| 144 | * |
| 145 | * @value: Bool value. |
| 146 | */ |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 147 | const char *tomoyo_yesno(const unsigned int value) |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 148 | { |
| 149 | return value ? "yes" : "no"; |
| 150 | } |
| 151 | |
Tetsuo Handa | d5ca172 | 2011-06-26 23:18:21 +0900 | [diff] [blame] | 152 | /** |
| 153 | * tomoyo_addprintf - strncat()-like-snprintf(). |
| 154 | * |
| 155 | * @buffer: Buffer to write to. Must be '\0'-terminated. |
| 156 | * @len: Size of @buffer. |
| 157 | * @fmt: The printf()'s format string, followed by parameters. |
| 158 | * |
| 159 | * Returns nothing. |
| 160 | */ |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 161 | static void tomoyo_addprintf(char *buffer, int len, const char *fmt, ...) |
| 162 | { |
| 163 | va_list args; |
| 164 | const int pos = strlen(buffer); |
| 165 | va_start(args, fmt); |
| 166 | vsnprintf(buffer + pos, len - pos - 1, fmt, args); |
| 167 | va_end(args); |
| 168 | } |
| 169 | |
| 170 | /** |
| 171 | * tomoyo_flush - Flush queued string to userspace's buffer. |
| 172 | * |
| 173 | * @head: Pointer to "struct tomoyo_io_buffer". |
| 174 | * |
| 175 | * Returns true if all data was flushed, false otherwise. |
| 176 | */ |
| 177 | static bool tomoyo_flush(struct tomoyo_io_buffer *head) |
| 178 | { |
| 179 | while (head->r.w_pos) { |
| 180 | const char *w = head->r.w[0]; |
Tetsuo Handa | 2c47ab9 | 2011-06-26 23:21:19 +0900 | [diff] [blame] | 181 | size_t len = strlen(w); |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 182 | if (len) { |
| 183 | if (len > head->read_user_buf_avail) |
| 184 | len = head->read_user_buf_avail; |
| 185 | if (!len) |
| 186 | return false; |
| 187 | if (copy_to_user(head->read_user_buf, w, len)) |
| 188 | return false; |
| 189 | head->read_user_buf_avail -= len; |
| 190 | head->read_user_buf += len; |
| 191 | w += len; |
| 192 | } |
Tetsuo Handa | c0fa797 | 2011-04-03 00:12:54 +0900 | [diff] [blame] | 193 | head->r.w[0] = w; |
| 194 | if (*w) |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 195 | return false; |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 196 | /* Add '\0' for audit logs and query. */ |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 197 | if (head->poll) { |
| 198 | if (!head->read_user_buf_avail || |
| 199 | copy_to_user(head->read_user_buf, "", 1)) |
| 200 | return false; |
| 201 | head->read_user_buf_avail--; |
| 202 | head->read_user_buf++; |
| 203 | } |
| 204 | head->r.w_pos--; |
| 205 | for (len = 0; len < head->r.w_pos; len++) |
| 206 | head->r.w[len] = head->r.w[len + 1]; |
| 207 | } |
| 208 | head->r.avail = 0; |
| 209 | return true; |
| 210 | } |
| 211 | |
| 212 | /** |
| 213 | * tomoyo_set_string - Queue string to "struct tomoyo_io_buffer" structure. |
| 214 | * |
| 215 | * @head: Pointer to "struct tomoyo_io_buffer". |
| 216 | * @string: String to print. |
| 217 | * |
| 218 | * Note that @string has to be kept valid until @head is kfree()d. |
| 219 | * This means that char[] allocated on stack memory cannot be passed to |
| 220 | * this function. Use tomoyo_io_printf() for char[] allocated on stack memory. |
| 221 | */ |
| 222 | static void tomoyo_set_string(struct tomoyo_io_buffer *head, const char *string) |
| 223 | { |
| 224 | if (head->r.w_pos < TOMOYO_MAX_IO_READ_QUEUE) { |
| 225 | head->r.w[head->r.w_pos++] = string; |
| 226 | tomoyo_flush(head); |
| 227 | } else |
| 228 | WARN_ON(1); |
| 229 | } |
| 230 | |
| 231 | /** |
| 232 | * tomoyo_io_printf - printf() to "struct tomoyo_io_buffer" structure. |
| 233 | * |
| 234 | * @head: Pointer to "struct tomoyo_io_buffer". |
| 235 | * @fmt: The printf()'s format string, followed by parameters. |
| 236 | */ |
| 237 | void tomoyo_io_printf(struct tomoyo_io_buffer *head, const char *fmt, ...) |
| 238 | { |
| 239 | va_list args; |
Tetsuo Handa | 2c47ab9 | 2011-06-26 23:21:19 +0900 | [diff] [blame] | 240 | size_t len; |
| 241 | size_t pos = head->r.avail; |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 242 | int size = head->readbuf_size - pos; |
| 243 | if (size <= 0) |
| 244 | return; |
| 245 | va_start(args, fmt); |
| 246 | len = vsnprintf(head->read_buf + pos, size, fmt, args) + 1; |
| 247 | va_end(args); |
| 248 | if (pos + len >= head->readbuf_size) { |
| 249 | WARN_ON(1); |
| 250 | return; |
| 251 | } |
| 252 | head->r.avail += len; |
| 253 | tomoyo_set_string(head, head->read_buf + pos); |
| 254 | } |
| 255 | |
Tetsuo Handa | 0d2171d | 2011-06-26 23:17:46 +0900 | [diff] [blame] | 256 | /** |
| 257 | * tomoyo_set_space - Put a space to "struct tomoyo_io_buffer" structure. |
| 258 | * |
| 259 | * @head: Pointer to "struct tomoyo_io_buffer". |
| 260 | * |
| 261 | * Returns nothing. |
| 262 | */ |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 263 | static void tomoyo_set_space(struct tomoyo_io_buffer *head) |
| 264 | { |
| 265 | tomoyo_set_string(head, " "); |
| 266 | } |
| 267 | |
Tetsuo Handa | 0d2171d | 2011-06-26 23:17:46 +0900 | [diff] [blame] | 268 | /** |
| 269 | * tomoyo_set_lf - Put a line feed to "struct tomoyo_io_buffer" structure. |
| 270 | * |
| 271 | * @head: Pointer to "struct tomoyo_io_buffer". |
| 272 | * |
| 273 | * Returns nothing. |
| 274 | */ |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 275 | static bool tomoyo_set_lf(struct tomoyo_io_buffer *head) |
| 276 | { |
| 277 | tomoyo_set_string(head, "\n"); |
| 278 | return !head->r.w_pos; |
| 279 | } |
| 280 | |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 281 | /** |
Tetsuo Handa | 0d2171d | 2011-06-26 23:17:46 +0900 | [diff] [blame] | 282 | * tomoyo_set_slash - Put a shash to "struct tomoyo_io_buffer" structure. |
| 283 | * |
| 284 | * @head: Pointer to "struct tomoyo_io_buffer". |
| 285 | * |
| 286 | * Returns nothing. |
| 287 | */ |
| 288 | static void tomoyo_set_slash(struct tomoyo_io_buffer *head) |
| 289 | { |
| 290 | tomoyo_set_string(head, "/"); |
| 291 | } |
| 292 | |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 293 | /* List of namespaces. */ |
| 294 | LIST_HEAD(tomoyo_namespace_list); |
| 295 | /* True if namespace other than tomoyo_kernel_namespace is defined. */ |
| 296 | static bool tomoyo_namespace_enabled; |
| 297 | |
| 298 | /** |
| 299 | * tomoyo_init_policy_namespace - Initialize namespace. |
| 300 | * |
| 301 | * @ns: Pointer to "struct tomoyo_policy_namespace". |
| 302 | * |
| 303 | * Returns nothing. |
| 304 | */ |
| 305 | void tomoyo_init_policy_namespace(struct tomoyo_policy_namespace *ns) |
| 306 | { |
| 307 | unsigned int idx; |
| 308 | for (idx = 0; idx < TOMOYO_MAX_ACL_GROUPS; idx++) |
| 309 | INIT_LIST_HEAD(&ns->acl_group[idx]); |
| 310 | for (idx = 0; idx < TOMOYO_MAX_GROUP; idx++) |
| 311 | INIT_LIST_HEAD(&ns->group_list[idx]); |
| 312 | for (idx = 0; idx < TOMOYO_MAX_POLICY; idx++) |
| 313 | INIT_LIST_HEAD(&ns->policy_list[idx]); |
| 314 | ns->profile_version = 20100903; |
| 315 | tomoyo_namespace_enabled = !list_empty(&tomoyo_namespace_list); |
| 316 | list_add_tail_rcu(&ns->namespace_list, &tomoyo_namespace_list); |
| 317 | } |
| 318 | |
| 319 | /** |
| 320 | * tomoyo_print_namespace - Print namespace header. |
| 321 | * |
| 322 | * @head: Pointer to "struct tomoyo_io_buffer". |
| 323 | * |
| 324 | * Returns nothing. |
| 325 | */ |
| 326 | static void tomoyo_print_namespace(struct tomoyo_io_buffer *head) |
| 327 | { |
| 328 | if (!tomoyo_namespace_enabled) |
| 329 | return; |
| 330 | tomoyo_set_string(head, |
| 331 | container_of(head->r.ns, |
| 332 | struct tomoyo_policy_namespace, |
| 333 | namespace_list)->name); |
| 334 | tomoyo_set_space(head); |
| 335 | } |
| 336 | |
Tetsuo Handa | 0d2171d | 2011-06-26 23:17:46 +0900 | [diff] [blame] | 337 | /** |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 338 | * tomoyo_print_name_union - Print a tomoyo_name_union. |
| 339 | * |
| 340 | * @head: Pointer to "struct tomoyo_io_buffer". |
| 341 | * @ptr: Pointer to "struct tomoyo_name_union". |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 342 | */ |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 343 | static void tomoyo_print_name_union(struct tomoyo_io_buffer *head, |
| 344 | const struct tomoyo_name_union *ptr) |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 345 | { |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 346 | tomoyo_set_space(head); |
Tetsuo Handa | 0df7e8b | 2011-06-26 23:16:36 +0900 | [diff] [blame] | 347 | if (ptr->group) { |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 348 | tomoyo_set_string(head, "@"); |
| 349 | tomoyo_set_string(head, ptr->group->group_name->name); |
| 350 | } else { |
| 351 | tomoyo_set_string(head, ptr->filename->name); |
| 352 | } |
Tetsuo Handa | 7762fbf | 2010-05-10 17:30:26 +0900 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | /** |
Tetsuo Handa | 2066a36 | 2011-07-08 13:21:37 +0900 | [diff] [blame] | 356 | * tomoyo_print_number_union_nospace - Print a tomoyo_number_union without a space. |
Tetsuo Handa | 4c3e9e2 | 2010-05-17 10:06:58 +0900 | [diff] [blame] | 357 | * |
Tetsuo Handa | 2066a36 | 2011-07-08 13:21:37 +0900 | [diff] [blame] | 358 | * @head: Pointer to "struct tomoyo_io_buffer". |
| 359 | * @ptr: Pointer to "struct tomoyo_number_union". |
| 360 | * |
| 361 | * Returns nothing. |
Tetsuo Handa | 4c3e9e2 | 2010-05-17 10:06:58 +0900 | [diff] [blame] | 362 | */ |
Tetsuo Handa | 2066a36 | 2011-07-08 13:21:37 +0900 | [diff] [blame] | 363 | static void tomoyo_print_number_union_nospace |
| 364 | (struct tomoyo_io_buffer *head, const struct tomoyo_number_union *ptr) |
Tetsuo Handa | 4c3e9e2 | 2010-05-17 10:06:58 +0900 | [diff] [blame] | 365 | { |
Tetsuo Handa | 0df7e8b | 2011-06-26 23:16:36 +0900 | [diff] [blame] | 366 | if (ptr->group) { |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 367 | tomoyo_set_string(head, "@"); |
| 368 | tomoyo_set_string(head, ptr->group->group_name->name); |
| 369 | } else { |
| 370 | int i; |
| 371 | unsigned long min = ptr->values[0]; |
| 372 | const unsigned long max = ptr->values[1]; |
Tetsuo Handa | 0df7e8b | 2011-06-26 23:16:36 +0900 | [diff] [blame] | 373 | u8 min_type = ptr->value_type[0]; |
| 374 | const u8 max_type = ptr->value_type[1]; |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 375 | char buffer[128]; |
| 376 | buffer[0] = '\0'; |
| 377 | for (i = 0; i < 2; i++) { |
| 378 | switch (min_type) { |
| 379 | case TOMOYO_VALUE_TYPE_HEXADECIMAL: |
| 380 | tomoyo_addprintf(buffer, sizeof(buffer), |
| 381 | "0x%lX", min); |
| 382 | break; |
| 383 | case TOMOYO_VALUE_TYPE_OCTAL: |
| 384 | tomoyo_addprintf(buffer, sizeof(buffer), |
| 385 | "0%lo", min); |
| 386 | break; |
| 387 | default: |
Tetsuo Handa | 2066a36 | 2011-07-08 13:21:37 +0900 | [diff] [blame] | 388 | tomoyo_addprintf(buffer, sizeof(buffer), "%lu", |
| 389 | min); |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 390 | break; |
| 391 | } |
| 392 | if (min == max && min_type == max_type) |
| 393 | break; |
| 394 | tomoyo_addprintf(buffer, sizeof(buffer), "-"); |
| 395 | min_type = max_type; |
| 396 | min = max; |
| 397 | } |
| 398 | tomoyo_io_printf(head, "%s", buffer); |
Tetsuo Handa | 4c3e9e2 | 2010-05-17 10:06:58 +0900 | [diff] [blame] | 399 | } |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | /** |
Tetsuo Handa | 2066a36 | 2011-07-08 13:21:37 +0900 | [diff] [blame] | 403 | * tomoyo_print_number_union - Print a tomoyo_number_union. |
| 404 | * |
| 405 | * @head: Pointer to "struct tomoyo_io_buffer". |
| 406 | * @ptr: Pointer to "struct tomoyo_number_union". |
| 407 | * |
| 408 | * Returns nothing. |
| 409 | */ |
| 410 | static void tomoyo_print_number_union(struct tomoyo_io_buffer *head, |
| 411 | const struct tomoyo_number_union *ptr) |
| 412 | { |
| 413 | tomoyo_set_space(head); |
| 414 | tomoyo_print_number_union_nospace(head, ptr); |
| 415 | } |
| 416 | |
| 417 | /** |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 418 | * tomoyo_assign_profile - Create a new profile. |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 419 | * |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 420 | * @ns: Pointer to "struct tomoyo_policy_namespace". |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 421 | * @profile: Profile number to create. |
| 422 | * |
| 423 | * Returns pointer to "struct tomoyo_profile" on success, NULL otherwise. |
| 424 | */ |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 425 | static struct tomoyo_profile *tomoyo_assign_profile |
| 426 | (struct tomoyo_policy_namespace *ns, const unsigned int profile) |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 427 | { |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 428 | struct tomoyo_profile *ptr; |
| 429 | struct tomoyo_profile *entry; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 430 | if (profile >= TOMOYO_MAX_PROFILES) |
| 431 | return NULL; |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 432 | ptr = ns->profile_ptr[profile]; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 433 | if (ptr) |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 434 | return ptr; |
| 435 | entry = kzalloc(sizeof(*entry), GFP_NOFS); |
| 436 | if (mutex_lock_interruptible(&tomoyo_policy_lock)) |
| 437 | goto out; |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 438 | ptr = ns->profile_ptr[profile]; |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 439 | if (!ptr && tomoyo_memory_ok(entry)) { |
| 440 | ptr = entry; |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 441 | ptr->default_config = TOMOYO_CONFIG_DISABLED | |
| 442 | TOMOYO_CONFIG_WANT_GRANT_LOG | |
| 443 | TOMOYO_CONFIG_WANT_REJECT_LOG; |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 444 | memset(ptr->config, TOMOYO_CONFIG_USE_DEFAULT, |
| 445 | sizeof(ptr->config)); |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 446 | ptr->pref[TOMOYO_PREF_MAX_AUDIT_LOG] = 1024; |
Tetsuo Handa | d5ca172 | 2011-06-26 23:18:21 +0900 | [diff] [blame] | 447 | ptr->pref[TOMOYO_PREF_MAX_LEARNING_ENTRY] = 2048; |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 448 | mb(); /* Avoid out-of-order execution. */ |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 449 | ns->profile_ptr[profile] = ptr; |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 450 | entry = NULL; |
Tetsuo Handa | cd7bec6 | 2010-01-05 06:39:37 +0900 | [diff] [blame] | 451 | } |
Tetsuo Handa | 2928238 | 2010-05-06 00:18:15 +0900 | [diff] [blame] | 452 | mutex_unlock(&tomoyo_policy_lock); |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 453 | out: |
| 454 | kfree(entry); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 455 | return ptr; |
| 456 | } |
| 457 | |
| 458 | /** |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 459 | * tomoyo_profile - Find a profile. |
| 460 | * |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 461 | * @ns: Pointer to "struct tomoyo_policy_namespace". |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 462 | * @profile: Profile number to find. |
| 463 | * |
| 464 | * Returns pointer to "struct tomoyo_profile". |
| 465 | */ |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 466 | struct tomoyo_profile *tomoyo_profile(const struct tomoyo_policy_namespace *ns, |
| 467 | const u8 profile) |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 468 | { |
Tetsuo Handa | d5ca172 | 2011-06-26 23:18:21 +0900 | [diff] [blame] | 469 | static struct tomoyo_profile tomoyo_null_profile; |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 470 | struct tomoyo_profile *ptr = ns->profile_ptr[profile]; |
Tetsuo Handa | d5ca172 | 2011-06-26 23:18:21 +0900 | [diff] [blame] | 471 | if (!ptr) |
| 472 | ptr = &tomoyo_null_profile; |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 473 | return ptr; |
| 474 | } |
| 475 | |
Tetsuo Handa | d5ca172 | 2011-06-26 23:18:21 +0900 | [diff] [blame] | 476 | /** |
| 477 | * tomoyo_find_yesno - Find values for specified keyword. |
| 478 | * |
| 479 | * @string: String to check. |
| 480 | * @find: Name of keyword. |
| 481 | * |
| 482 | * Returns 1 if "@find=yes" was found, 0 if "@find=no" was found, -1 otherwise. |
| 483 | */ |
Tetsuo Handa | 8e56868 | 2010-06-25 09:30:09 +0900 | [diff] [blame] | 484 | static s8 tomoyo_find_yesno(const char *string, const char *find) |
| 485 | { |
| 486 | const char *cp = strstr(string, find); |
| 487 | if (cp) { |
| 488 | cp += strlen(find); |
| 489 | if (!strncmp(cp, "=yes", 4)) |
| 490 | return 1; |
| 491 | else if (!strncmp(cp, "=no", 3)) |
| 492 | return 0; |
| 493 | } |
| 494 | return -1; |
| 495 | } |
| 496 | |
Tetsuo Handa | d5ca172 | 2011-06-26 23:18:21 +0900 | [diff] [blame] | 497 | /** |
| 498 | * tomoyo_set_uint - Set value for specified preference. |
| 499 | * |
| 500 | * @i: Pointer to "unsigned int". |
| 501 | * @string: String to check. |
| 502 | * @find: Name of keyword. |
| 503 | * |
| 504 | * Returns nothing. |
| 505 | */ |
Tetsuo Handa | 8e56868 | 2010-06-25 09:30:09 +0900 | [diff] [blame] | 506 | static void tomoyo_set_uint(unsigned int *i, const char *string, |
| 507 | const char *find) |
| 508 | { |
| 509 | const char *cp = strstr(string, find); |
| 510 | if (cp) |
| 511 | sscanf(cp + strlen(find), "=%u", i); |
| 512 | } |
| 513 | |
Tetsuo Handa | d5ca172 | 2011-06-26 23:18:21 +0900 | [diff] [blame] | 514 | /** |
| 515 | * tomoyo_set_mode - Set mode for specified profile. |
| 516 | * |
| 517 | * @name: Name of functionality. |
| 518 | * @value: Mode for @name. |
| 519 | * @profile: Pointer to "struct tomoyo_profile". |
| 520 | * |
| 521 | * Returns 0 on success, negative value otherwise. |
| 522 | */ |
Tetsuo Handa | 8e56868 | 2010-06-25 09:30:09 +0900 | [diff] [blame] | 523 | static int tomoyo_set_mode(char *name, const char *value, |
Tetsuo Handa | 8e56868 | 2010-06-25 09:30:09 +0900 | [diff] [blame] | 524 | struct tomoyo_profile *profile) |
| 525 | { |
| 526 | u8 i; |
| 527 | u8 config; |
| 528 | if (!strcmp(name, "CONFIG")) { |
| 529 | i = TOMOYO_MAX_MAC_INDEX + TOMOYO_MAX_MAC_CATEGORY_INDEX; |
| 530 | config = profile->default_config; |
| 531 | } else if (tomoyo_str_starts(&name, "CONFIG::")) { |
| 532 | config = 0; |
| 533 | for (i = 0; i < TOMOYO_MAX_MAC_INDEX |
| 534 | + TOMOYO_MAX_MAC_CATEGORY_INDEX; i++) { |
Tetsuo Handa | 2c47ab9 | 2011-06-26 23:21:19 +0900 | [diff] [blame] | 535 | int len = 0; |
| 536 | if (i < TOMOYO_MAX_MAC_INDEX) { |
| 537 | const u8 c = tomoyo_index2category[i]; |
| 538 | const char *category = |
| 539 | tomoyo_category_keywords[c]; |
| 540 | len = strlen(category); |
| 541 | if (strncmp(name, category, len) || |
| 542 | name[len++] != ':' || name[len++] != ':') |
| 543 | continue; |
| 544 | } |
| 545 | if (strcmp(name + len, tomoyo_mac_keywords[i])) |
Tetsuo Handa | 8e56868 | 2010-06-25 09:30:09 +0900 | [diff] [blame] | 546 | continue; |
| 547 | config = profile->config[i]; |
| 548 | break; |
| 549 | } |
| 550 | if (i == TOMOYO_MAX_MAC_INDEX + TOMOYO_MAX_MAC_CATEGORY_INDEX) |
| 551 | return -EINVAL; |
| 552 | } else { |
| 553 | return -EINVAL; |
| 554 | } |
Tetsuo Handa | d5ca172 | 2011-06-26 23:18:21 +0900 | [diff] [blame] | 555 | if (strstr(value, "use_default")) { |
Tetsuo Handa | 8e56868 | 2010-06-25 09:30:09 +0900 | [diff] [blame] | 556 | config = TOMOYO_CONFIG_USE_DEFAULT; |
| 557 | } else { |
| 558 | u8 mode; |
| 559 | for (mode = 0; mode < 4; mode++) |
| 560 | if (strstr(value, tomoyo_mode[mode])) |
| 561 | /* |
| 562 | * Update lower 3 bits in order to distinguish |
| 563 | * 'config' from 'TOMOYO_CONFIG_USE_DEAFULT'. |
| 564 | */ |
| 565 | config = (config & ~7) | mode; |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 566 | if (config != TOMOYO_CONFIG_USE_DEFAULT) { |
| 567 | switch (tomoyo_find_yesno(value, "grant_log")) { |
| 568 | case 1: |
| 569 | config |= TOMOYO_CONFIG_WANT_GRANT_LOG; |
| 570 | break; |
| 571 | case 0: |
| 572 | config &= ~TOMOYO_CONFIG_WANT_GRANT_LOG; |
| 573 | break; |
| 574 | } |
| 575 | switch (tomoyo_find_yesno(value, "reject_log")) { |
| 576 | case 1: |
| 577 | config |= TOMOYO_CONFIG_WANT_REJECT_LOG; |
| 578 | break; |
| 579 | case 0: |
| 580 | config &= ~TOMOYO_CONFIG_WANT_REJECT_LOG; |
| 581 | break; |
| 582 | } |
| 583 | } |
Tetsuo Handa | 8e56868 | 2010-06-25 09:30:09 +0900 | [diff] [blame] | 584 | } |
| 585 | if (i < TOMOYO_MAX_MAC_INDEX + TOMOYO_MAX_MAC_CATEGORY_INDEX) |
| 586 | profile->config[i] = config; |
| 587 | else if (config != TOMOYO_CONFIG_USE_DEFAULT) |
| 588 | profile->default_config = config; |
| 589 | return 0; |
| 590 | } |
| 591 | |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 592 | /** |
| 593 | * tomoyo_write_profile - Write profile table. |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 594 | * |
| 595 | * @head: Pointer to "struct tomoyo_io_buffer". |
| 596 | * |
| 597 | * Returns 0 on success, negative value otherwise. |
| 598 | */ |
| 599 | static int tomoyo_write_profile(struct tomoyo_io_buffer *head) |
| 600 | { |
| 601 | char *data = head->write_buf; |
| 602 | unsigned int i; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 603 | char *cp; |
| 604 | struct tomoyo_profile *profile; |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 605 | if (sscanf(data, "PROFILE_VERSION=%u", &head->w.ns->profile_version) |
| 606 | == 1) |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 607 | return 0; |
| 608 | i = simple_strtoul(data, &cp, 10); |
Tetsuo Handa | d5ca172 | 2011-06-26 23:18:21 +0900 | [diff] [blame] | 609 | if (*cp != '-') |
| 610 | return -EINVAL; |
| 611 | data = cp + 1; |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 612 | profile = tomoyo_assign_profile(head->w.ns, i); |
Tetsuo Handa | d5ca172 | 2011-06-26 23:18:21 +0900 | [diff] [blame] | 613 | if (!profile) |
| 614 | return -EINVAL; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 615 | cp = strchr(data, '='); |
| 616 | if (!cp) |
| 617 | return -EINVAL; |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 618 | *cp++ = '\0'; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 619 | if (!strcmp(data, "COMMENT")) { |
Tetsuo Handa | 2a086e5 | 2011-04-03 00:09:26 +0900 | [diff] [blame] | 620 | static DEFINE_SPINLOCK(lock); |
| 621 | const struct tomoyo_path_info *new_comment |
| 622 | = tomoyo_get_name(cp); |
| 623 | const struct tomoyo_path_info *old_comment; |
| 624 | if (!new_comment) |
| 625 | return -ENOMEM; |
| 626 | spin_lock(&lock); |
| 627 | old_comment = profile->comment; |
| 628 | profile->comment = new_comment; |
| 629 | spin_unlock(&lock); |
Tetsuo Handa | bf24fb0 | 2010-02-11 09:41:58 +0900 | [diff] [blame] | 630 | tomoyo_put_name(old_comment); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 631 | return 0; |
| 632 | } |
Tetsuo Handa | d5ca172 | 2011-06-26 23:18:21 +0900 | [diff] [blame] | 633 | if (!strcmp(data, "PREFERENCE")) { |
| 634 | for (i = 0; i < TOMOYO_MAX_PREF; i++) |
| 635 | tomoyo_set_uint(&profile->pref[i], cp, |
| 636 | tomoyo_pref_keywords[i]); |
| 637 | return 0; |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 638 | } |
Tetsuo Handa | d5ca172 | 2011-06-26 23:18:21 +0900 | [diff] [blame] | 639 | return tomoyo_set_mode(data, cp, profile); |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 640 | } |
| 641 | |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 642 | /** |
| 643 | * tomoyo_print_config - Print mode for specified functionality. |
| 644 | * |
| 645 | * @head: Pointer to "struct tomoyo_io_buffer". |
| 646 | * @config: Mode for that functionality. |
| 647 | * |
| 648 | * Returns nothing. |
| 649 | * |
| 650 | * Caller prints functionality's name. |
| 651 | */ |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 652 | static void tomoyo_print_config(struct tomoyo_io_buffer *head, const u8 config) |
| 653 | { |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 654 | tomoyo_io_printf(head, "={ mode=%s grant_log=%s reject_log=%s }\n", |
| 655 | tomoyo_mode[config & 3], |
| 656 | tomoyo_yesno(config & TOMOYO_CONFIG_WANT_GRANT_LOG), |
| 657 | tomoyo_yesno(config & TOMOYO_CONFIG_WANT_REJECT_LOG)); |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 658 | } |
| 659 | |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 660 | /** |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 661 | * tomoyo_read_profile - Read profile table. |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 662 | * |
| 663 | * @head: Pointer to "struct tomoyo_io_buffer". |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 664 | * |
| 665 | * Returns nothing. |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 666 | */ |
Tetsuo Handa | 8fbe71f | 2010-06-16 16:29:59 +0900 | [diff] [blame] | 667 | static void tomoyo_read_profile(struct tomoyo_io_buffer *head) |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 668 | { |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 669 | u8 index; |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 670 | struct tomoyo_policy_namespace *ns = |
| 671 | container_of(head->r.ns, typeof(*ns), namespace_list); |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 672 | const struct tomoyo_profile *profile; |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 673 | if (head->r.eof) |
| 674 | return; |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 675 | next: |
| 676 | index = head->r.index; |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 677 | profile = ns->profile_ptr[index]; |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 678 | switch (head->r.step) { |
| 679 | case 0: |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 680 | tomoyo_print_namespace(head); |
| 681 | tomoyo_io_printf(head, "PROFILE_VERSION=%u\n", |
| 682 | ns->profile_version); |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 683 | head->r.step++; |
| 684 | break; |
| 685 | case 1: |
| 686 | for ( ; head->r.index < TOMOYO_MAX_PROFILES; |
| 687 | head->r.index++) |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 688 | if (ns->profile_ptr[head->r.index]) |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 689 | break; |
| 690 | if (head->r.index == TOMOYO_MAX_PROFILES) |
| 691 | return; |
| 692 | head->r.step++; |
| 693 | break; |
| 694 | case 2: |
| 695 | { |
Tetsuo Handa | d5ca172 | 2011-06-26 23:18:21 +0900 | [diff] [blame] | 696 | u8 i; |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 697 | const struct tomoyo_path_info *comment = |
| 698 | profile->comment; |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 699 | tomoyo_print_namespace(head); |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 700 | tomoyo_io_printf(head, "%u-COMMENT=", index); |
| 701 | tomoyo_set_string(head, comment ? comment->name : ""); |
| 702 | tomoyo_set_lf(head); |
Tetsuo Handa | d5ca172 | 2011-06-26 23:18:21 +0900 | [diff] [blame] | 703 | tomoyo_io_printf(head, "%u-PREFERENCE={ ", index); |
| 704 | for (i = 0; i < TOMOYO_MAX_PREF; i++) |
| 705 | tomoyo_io_printf(head, "%s=%u ", |
| 706 | tomoyo_pref_keywords[i], |
| 707 | profile->pref[i]); |
| 708 | tomoyo_set_string(head, "}\n"); |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 709 | head->r.step++; |
| 710 | } |
| 711 | break; |
| 712 | case 3: |
| 713 | { |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 714 | tomoyo_print_namespace(head); |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 715 | tomoyo_io_printf(head, "%u-%s", index, "CONFIG"); |
| 716 | tomoyo_print_config(head, profile->default_config); |
| 717 | head->r.bit = 0; |
| 718 | head->r.step++; |
| 719 | } |
| 720 | break; |
| 721 | case 4: |
| 722 | for ( ; head->r.bit < TOMOYO_MAX_MAC_INDEX |
| 723 | + TOMOYO_MAX_MAC_CATEGORY_INDEX; head->r.bit++) { |
| 724 | const u8 i = head->r.bit; |
| 725 | const u8 config = profile->config[i]; |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 726 | if (config == TOMOYO_CONFIG_USE_DEFAULT) |
| 727 | continue; |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 728 | tomoyo_print_namespace(head); |
Tetsuo Handa | 2c47ab9 | 2011-06-26 23:21:19 +0900 | [diff] [blame] | 729 | if (i < TOMOYO_MAX_MAC_INDEX) |
| 730 | tomoyo_io_printf(head, "%u-CONFIG::%s::%s", |
| 731 | index, |
| 732 | tomoyo_category_keywords |
| 733 | [tomoyo_index2category[i]], |
| 734 | tomoyo_mac_keywords[i]); |
| 735 | else |
| 736 | tomoyo_io_printf(head, "%u-CONFIG::%s", index, |
| 737 | tomoyo_mac_keywords[i]); |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 738 | tomoyo_print_config(head, config); |
| 739 | head->r.bit++; |
| 740 | break; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 741 | } |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 742 | if (head->r.bit == TOMOYO_MAX_MAC_INDEX |
| 743 | + TOMOYO_MAX_MAC_CATEGORY_INDEX) { |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 744 | head->r.index++; |
| 745 | head->r.step = 1; |
| 746 | } |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 747 | break; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 748 | } |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 749 | if (tomoyo_flush(head)) |
| 750 | goto next; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 751 | } |
| 752 | |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 753 | static bool tomoyo_same_manager(const struct tomoyo_acl_head *a, |
| 754 | const struct tomoyo_acl_head *b) |
Tetsuo Handa | 36f5e1f | 2010-06-15 09:23:26 +0900 | [diff] [blame] | 755 | { |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 756 | return container_of(a, struct tomoyo_manager, head)->manager == |
| 757 | container_of(b, struct tomoyo_manager, head)->manager; |
Tetsuo Handa | 36f5e1f | 2010-06-15 09:23:26 +0900 | [diff] [blame] | 758 | } |
| 759 | |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 760 | /** |
| 761 | * tomoyo_update_manager_entry - Add a manager entry. |
| 762 | * |
| 763 | * @manager: The path to manager or the domainnamme. |
| 764 | * @is_delete: True if it is a delete request. |
| 765 | * |
| 766 | * Returns 0 on success, negative value otherwise. |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 767 | * |
| 768 | * Caller holds tomoyo_read_lock(). |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 769 | */ |
| 770 | static int tomoyo_update_manager_entry(const char *manager, |
| 771 | const bool is_delete) |
| 772 | { |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 773 | struct tomoyo_manager e = { }; |
Tetsuo Handa | a238cf5 | 2011-06-26 23:17:10 +0900 | [diff] [blame] | 774 | struct tomoyo_acl_param param = { |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 775 | /* .ns = &tomoyo_kernel_namespace, */ |
Tetsuo Handa | a238cf5 | 2011-06-26 23:17:10 +0900 | [diff] [blame] | 776 | .is_delete = is_delete, |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 777 | .list = &tomoyo_kernel_namespace. |
| 778 | policy_list[TOMOYO_ID_MANAGER], |
Tetsuo Handa | a238cf5 | 2011-06-26 23:17:10 +0900 | [diff] [blame] | 779 | }; |
| 780 | int error = is_delete ? -ENOENT : -ENOMEM; |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 781 | if (tomoyo_domain_def(manager)) { |
| 782 | if (!tomoyo_correct_domain(manager)) |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 783 | return -EINVAL; |
Tetsuo Handa | 9e4b50e | 2010-05-06 12:40:02 +0900 | [diff] [blame] | 784 | e.is_domain = true; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 785 | } else { |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 786 | if (!tomoyo_correct_path(manager)) |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 787 | return -EINVAL; |
| 788 | } |
Tetsuo Handa | 9e4b50e | 2010-05-06 12:40:02 +0900 | [diff] [blame] | 789 | e.manager = tomoyo_get_name(manager); |
Tetsuo Handa | a238cf5 | 2011-06-26 23:17:10 +0900 | [diff] [blame] | 790 | if (e.manager) { |
| 791 | error = tomoyo_update_policy(&e.head, sizeof(e), ¶m, |
| 792 | tomoyo_same_manager); |
| 793 | tomoyo_put_name(e.manager); |
| 794 | } |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 795 | return error; |
| 796 | } |
| 797 | |
| 798 | /** |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 799 | * tomoyo_write_manager - Write manager policy. |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 800 | * |
| 801 | * @head: Pointer to "struct tomoyo_io_buffer". |
| 802 | * |
| 803 | * Returns 0 on success, negative value otherwise. |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 804 | * |
| 805 | * Caller holds tomoyo_read_lock(). |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 806 | */ |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 807 | static int tomoyo_write_manager(struct tomoyo_io_buffer *head) |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 808 | { |
| 809 | char *data = head->write_buf; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 810 | |
| 811 | if (!strcmp(data, "manage_by_non_root")) { |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 812 | tomoyo_manage_by_non_root = !head->w.is_delete; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 813 | return 0; |
| 814 | } |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 815 | return tomoyo_update_manager_entry(data, head->w.is_delete); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 816 | } |
| 817 | |
| 818 | /** |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 819 | * tomoyo_read_manager - Read manager policy. |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 820 | * |
| 821 | * @head: Pointer to "struct tomoyo_io_buffer". |
| 822 | * |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 823 | * Caller holds tomoyo_read_lock(). |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 824 | */ |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 825 | static void tomoyo_read_manager(struct tomoyo_io_buffer *head) |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 826 | { |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 827 | if (head->r.eof) |
Tetsuo Handa | 8fbe71f | 2010-06-16 16:29:59 +0900 | [diff] [blame] | 828 | return; |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 829 | list_for_each_cookie(head->r.acl, &tomoyo_kernel_namespace. |
| 830 | policy_list[TOMOYO_ID_MANAGER]) { |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 831 | struct tomoyo_manager *ptr = |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 832 | list_entry(head->r.acl, typeof(*ptr), head.list); |
Tetsuo Handa | 82e0f00 | 2010-06-15 09:22:42 +0900 | [diff] [blame] | 833 | if (ptr->head.is_deleted) |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 834 | continue; |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 835 | if (!tomoyo_flush(head)) |
| 836 | return; |
| 837 | tomoyo_set_string(head, ptr->manager->name); |
| 838 | tomoyo_set_lf(head); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 839 | } |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 840 | head->r.eof = true; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 841 | } |
| 842 | |
| 843 | /** |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 844 | * tomoyo_manager - Check whether the current process is a policy manager. |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 845 | * |
| 846 | * Returns true if the current process is permitted to modify policy |
| 847 | * via /sys/kernel/security/tomoyo/ interface. |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 848 | * |
| 849 | * Caller holds tomoyo_read_lock(). |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 850 | */ |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 851 | static bool tomoyo_manager(void) |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 852 | { |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 853 | struct tomoyo_manager *ptr; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 854 | const char *exe; |
| 855 | const struct task_struct *task = current; |
| 856 | const struct tomoyo_path_info *domainname = tomoyo_domain()->domainname; |
| 857 | bool found = false; |
| 858 | |
| 859 | if (!tomoyo_policy_loaded) |
| 860 | return true; |
| 861 | if (!tomoyo_manage_by_non_root && (task->cred->uid || task->cred->euid)) |
| 862 | return false; |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 863 | list_for_each_entry_rcu(ptr, &tomoyo_kernel_namespace. |
| 864 | policy_list[TOMOYO_ID_MANAGER], head.list) { |
Tetsuo Handa | 82e0f00 | 2010-06-15 09:22:42 +0900 | [diff] [blame] | 865 | if (!ptr->head.is_deleted && ptr->is_domain |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 866 | && !tomoyo_pathcmp(domainname, ptr->manager)) { |
| 867 | found = true; |
| 868 | break; |
| 869 | } |
| 870 | } |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 871 | if (found) |
| 872 | return true; |
| 873 | exe = tomoyo_get_exe(); |
| 874 | if (!exe) |
| 875 | return false; |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 876 | list_for_each_entry_rcu(ptr, &tomoyo_kernel_namespace. |
| 877 | policy_list[TOMOYO_ID_MANAGER], head.list) { |
Tetsuo Handa | 82e0f00 | 2010-06-15 09:22:42 +0900 | [diff] [blame] | 878 | if (!ptr->head.is_deleted && !ptr->is_domain |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 879 | && !strcmp(exe, ptr->manager->name)) { |
| 880 | found = true; |
| 881 | break; |
| 882 | } |
| 883 | } |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 884 | if (!found) { /* Reduce error messages. */ |
| 885 | static pid_t last_pid; |
| 886 | const pid_t pid = current->pid; |
| 887 | if (last_pid != pid) { |
| 888 | printk(KERN_WARNING "%s ( %s ) is not permitted to " |
| 889 | "update policies.\n", domainname->name, exe); |
| 890 | last_pid = pid; |
| 891 | } |
| 892 | } |
Tetsuo Handa | 8e2d39a | 2010-01-26 20:45:27 +0900 | [diff] [blame] | 893 | kfree(exe); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 894 | return found; |
| 895 | } |
| 896 | |
| 897 | /** |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 898 | * tomoyo_select_domain - Parse select command. |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 899 | * |
| 900 | * @head: Pointer to "struct tomoyo_io_buffer". |
| 901 | * @data: String to parse. |
| 902 | * |
| 903 | * Returns true on success, false otherwise. |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 904 | * |
| 905 | * Caller holds tomoyo_read_lock(). |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 906 | */ |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 907 | static bool tomoyo_select_domain(struct tomoyo_io_buffer *head, |
| 908 | const char *data) |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 909 | { |
| 910 | unsigned int pid; |
| 911 | struct tomoyo_domain_info *domain = NULL; |
Tetsuo Handa | 9b24437 | 2010-06-03 20:35:53 +0900 | [diff] [blame] | 912 | bool global_pid = false; |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 913 | if (strncmp(data, "select ", 7)) |
| 914 | return false; |
| 915 | data += 7; |
Tetsuo Handa | 9b24437 | 2010-06-03 20:35:53 +0900 | [diff] [blame] | 916 | if (sscanf(data, "pid=%u", &pid) == 1 || |
| 917 | (global_pid = true, sscanf(data, "global-pid=%u", &pid) == 1)) { |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 918 | struct task_struct *p; |
Tetsuo Handa | 1fcdc7c | 2010-02-25 17:19:25 +0900 | [diff] [blame] | 919 | rcu_read_lock(); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 920 | read_lock(&tasklist_lock); |
Tetsuo Handa | 9b24437 | 2010-06-03 20:35:53 +0900 | [diff] [blame] | 921 | if (global_pid) |
| 922 | p = find_task_by_pid_ns(pid, &init_pid_ns); |
| 923 | else |
| 924 | p = find_task_by_vpid(pid); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 925 | if (p) |
| 926 | domain = tomoyo_real_domain(p); |
| 927 | read_unlock(&tasklist_lock); |
Tetsuo Handa | 1fcdc7c | 2010-02-25 17:19:25 +0900 | [diff] [blame] | 928 | rcu_read_unlock(); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 929 | } else if (!strncmp(data, "domain=", 7)) { |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 930 | if (tomoyo_domain_def(data + 7)) |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 931 | domain = tomoyo_find_domain(data + 7); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 932 | } else |
| 933 | return false; |
Tetsuo Handa | 0df7e8b | 2011-06-26 23:16:36 +0900 | [diff] [blame] | 934 | head->w.domain = domain; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 935 | /* Accessing read_buf is safe because head->io_sem is held. */ |
| 936 | if (!head->read_buf) |
| 937 | return true; /* Do nothing if open(O_WRONLY). */ |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 938 | memset(&head->r, 0, sizeof(head->r)); |
| 939 | head->r.print_this_domain_only = true; |
Dan Carpenter | 68eda8f | 2010-08-08 00:17:51 +0200 | [diff] [blame] | 940 | if (domain) |
| 941 | head->r.domain = &domain->list; |
| 942 | else |
| 943 | head->r.eof = 1; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 944 | tomoyo_io_printf(head, "# select %s\n", data); |
Tetsuo Handa | 475e6fa | 2010-06-24 11:28:14 +0900 | [diff] [blame] | 945 | if (domain && domain->is_deleted) |
| 946 | tomoyo_io_printf(head, "# This is a deleted domain.\n"); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 947 | return true; |
| 948 | } |
| 949 | |
| 950 | /** |
Tetsuo Handa | ccf135f | 2009-06-19 10:29:34 +0900 | [diff] [blame] | 951 | * tomoyo_delete_domain - Delete a domain. |
| 952 | * |
| 953 | * @domainname: The name of domain. |
| 954 | * |
| 955 | * Returns 0. |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 956 | * |
| 957 | * Caller holds tomoyo_read_lock(). |
Tetsuo Handa | ccf135f | 2009-06-19 10:29:34 +0900 | [diff] [blame] | 958 | */ |
| 959 | static int tomoyo_delete_domain(char *domainname) |
| 960 | { |
| 961 | struct tomoyo_domain_info *domain; |
| 962 | struct tomoyo_path_info name; |
| 963 | |
| 964 | name.name = domainname; |
| 965 | tomoyo_fill_path_info(&name); |
Tetsuo Handa | 2928238 | 2010-05-06 00:18:15 +0900 | [diff] [blame] | 966 | if (mutex_lock_interruptible(&tomoyo_policy_lock)) |
| 967 | return 0; |
Tetsuo Handa | ccf135f | 2009-06-19 10:29:34 +0900 | [diff] [blame] | 968 | /* Is there an active domain? */ |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 969 | list_for_each_entry_rcu(domain, &tomoyo_domain_list, list) { |
Tetsuo Handa | ccf135f | 2009-06-19 10:29:34 +0900 | [diff] [blame] | 970 | /* Never delete tomoyo_kernel_domain */ |
| 971 | if (domain == &tomoyo_kernel_domain) |
| 972 | continue; |
| 973 | if (domain->is_deleted || |
| 974 | tomoyo_pathcmp(domain->domainname, &name)) |
| 975 | continue; |
| 976 | domain->is_deleted = true; |
| 977 | break; |
| 978 | } |
Tetsuo Handa | f737d95 | 2010-01-03 21:16:32 +0900 | [diff] [blame] | 979 | mutex_unlock(&tomoyo_policy_lock); |
Tetsuo Handa | ccf135f | 2009-06-19 10:29:34 +0900 | [diff] [blame] | 980 | return 0; |
| 981 | } |
| 982 | |
| 983 | /** |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 984 | * tomoyo_write_domain2 - Write domain policy. |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 985 | * |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 986 | * @ns: Pointer to "struct tomoyo_policy_namespace". |
Tetsuo Handa | a238cf5 | 2011-06-26 23:17:10 +0900 | [diff] [blame] | 987 | * @list: Pointer to "struct list_head". |
| 988 | * @data: Policy to be interpreted. |
| 989 | * @is_delete: True if it is a delete request. |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 990 | * |
| 991 | * Returns 0 on success, negative value otherwise. |
| 992 | * |
| 993 | * Caller holds tomoyo_read_lock(). |
| 994 | */ |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 995 | static int tomoyo_write_domain2(struct tomoyo_policy_namespace *ns, |
| 996 | struct list_head *list, char *data, |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 997 | const bool is_delete) |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 998 | { |
Tetsuo Handa | a238cf5 | 2011-06-26 23:17:10 +0900 | [diff] [blame] | 999 | struct tomoyo_acl_param param = { |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 1000 | .ns = ns, |
Tetsuo Handa | a238cf5 | 2011-06-26 23:17:10 +0900 | [diff] [blame] | 1001 | .list = list, |
| 1002 | .data = data, |
| 1003 | .is_delete = is_delete, |
| 1004 | }; |
| 1005 | static const struct { |
| 1006 | const char *keyword; |
| 1007 | int (*write) (struct tomoyo_acl_param *); |
| 1008 | } tomoyo_callback[1] = { |
| 1009 | { "file ", tomoyo_write_file }, |
| 1010 | }; |
| 1011 | u8 i; |
| 1012 | for (i = 0; i < 1; i++) { |
| 1013 | if (!tomoyo_str_starts(¶m.data, |
| 1014 | tomoyo_callback[i].keyword)) |
| 1015 | continue; |
| 1016 | return tomoyo_callback[i].write(¶m); |
| 1017 | } |
| 1018 | return -EINVAL; |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1019 | } |
| 1020 | |
Tetsuo Handa | 2c47ab9 | 2011-06-26 23:21:19 +0900 | [diff] [blame] | 1021 | /* String table for domain flags. */ |
| 1022 | const char * const tomoyo_dif[TOMOYO_MAX_DOMAIN_INFO_FLAGS] = { |
| 1023 | [TOMOYO_DIF_QUOTA_WARNED] = "quota_exceeded\n", |
| 1024 | [TOMOYO_DIF_TRANSITION_FAILED] = "transition_failed\n", |
| 1025 | }; |
| 1026 | |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1027 | /** |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 1028 | * tomoyo_write_domain - Write domain policy. |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1029 | * |
| 1030 | * @head: Pointer to "struct tomoyo_io_buffer". |
| 1031 | * |
| 1032 | * Returns 0 on success, negative value otherwise. |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 1033 | * |
| 1034 | * Caller holds tomoyo_read_lock(). |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1035 | */ |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 1036 | static int tomoyo_write_domain(struct tomoyo_io_buffer *head) |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1037 | { |
| 1038 | char *data = head->write_buf; |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 1039 | struct tomoyo_policy_namespace *ns; |
Tetsuo Handa | 0df7e8b | 2011-06-26 23:16:36 +0900 | [diff] [blame] | 1040 | struct tomoyo_domain_info *domain = head->w.domain; |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 1041 | const bool is_delete = head->w.is_delete; |
| 1042 | bool is_select = !is_delete && tomoyo_str_starts(&data, "select "); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1043 | unsigned int profile; |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 1044 | if (*data == '<') { |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1045 | domain = NULL; |
| 1046 | if (is_delete) |
| 1047 | tomoyo_delete_domain(data); |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 1048 | else if (is_select) |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1049 | domain = tomoyo_find_domain(data); |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 1050 | else |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 1051 | domain = tomoyo_assign_domain(data, false); |
Tetsuo Handa | 0df7e8b | 2011-06-26 23:16:36 +0900 | [diff] [blame] | 1052 | head->w.domain = domain; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1053 | return 0; |
| 1054 | } |
| 1055 | if (!domain) |
| 1056 | return -EINVAL; |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 1057 | ns = domain->ns; |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 1058 | if (sscanf(data, "use_profile %u", &profile) == 1 |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1059 | && profile < TOMOYO_MAX_PROFILES) { |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 1060 | if (!tomoyo_policy_loaded || ns->profile_ptr[profile]) |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1061 | domain->profile = (u8) profile; |
| 1062 | return 0; |
| 1063 | } |
Tetsuo Handa | 3299714 | 2011-06-26 23:19:28 +0900 | [diff] [blame] | 1064 | if (sscanf(data, "use_group %u\n", &profile) == 1 |
| 1065 | && profile < TOMOYO_MAX_ACL_GROUPS) { |
| 1066 | if (!is_delete) |
| 1067 | domain->group = (u8) profile; |
| 1068 | return 0; |
| 1069 | } |
Tetsuo Handa | 2c47ab9 | 2011-06-26 23:21:19 +0900 | [diff] [blame] | 1070 | for (profile = 0; profile < TOMOYO_MAX_DOMAIN_INFO_FLAGS; profile++) { |
| 1071 | const char *cp = tomoyo_dif[profile]; |
| 1072 | if (strncmp(data, cp, strlen(cp) - 1)) |
| 1073 | continue; |
| 1074 | domain->flags[profile] = !is_delete; |
Tetsuo Handa | 9b24437 | 2010-06-03 20:35:53 +0900 | [diff] [blame] | 1075 | return 0; |
| 1076 | } |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 1077 | return tomoyo_write_domain2(ns, &domain->acl_info_list, data, |
| 1078 | is_delete); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1079 | } |
| 1080 | |
| 1081 | /** |
Tetsuo Handa | 2066a36 | 2011-07-08 13:21:37 +0900 | [diff] [blame] | 1082 | * tomoyo_print_condition - Print condition part. |
| 1083 | * |
| 1084 | * @head: Pointer to "struct tomoyo_io_buffer". |
| 1085 | * @cond: Pointer to "struct tomoyo_condition". |
| 1086 | * |
| 1087 | * Returns true on success, false otherwise. |
| 1088 | */ |
| 1089 | static bool tomoyo_print_condition(struct tomoyo_io_buffer *head, |
| 1090 | const struct tomoyo_condition *cond) |
| 1091 | { |
| 1092 | switch (head->r.cond_step) { |
| 1093 | case 0: |
| 1094 | head->r.cond_index = 0; |
| 1095 | head->r.cond_step++; |
| 1096 | /* fall through */ |
| 1097 | case 1: |
| 1098 | { |
| 1099 | const u16 condc = cond->condc; |
| 1100 | const struct tomoyo_condition_element *condp = |
| 1101 | (typeof(condp)) (cond + 1); |
| 1102 | const struct tomoyo_number_union *numbers_p = |
| 1103 | (typeof(numbers_p)) (condp + condc); |
| 1104 | u16 skip; |
| 1105 | for (skip = 0; skip < head->r.cond_index; skip++) { |
| 1106 | const u8 left = condp->left; |
| 1107 | const u8 right = condp->right; |
| 1108 | condp++; |
| 1109 | switch (left) { |
| 1110 | case TOMOYO_NUMBER_UNION: |
| 1111 | numbers_p++; |
| 1112 | break; |
| 1113 | } |
| 1114 | switch (right) { |
| 1115 | case TOMOYO_NUMBER_UNION: |
| 1116 | numbers_p++; |
| 1117 | break; |
| 1118 | } |
| 1119 | } |
| 1120 | while (head->r.cond_index < condc) { |
| 1121 | const u8 match = condp->equals; |
| 1122 | const u8 left = condp->left; |
| 1123 | const u8 right = condp->right; |
| 1124 | if (!tomoyo_flush(head)) |
| 1125 | return false; |
| 1126 | condp++; |
| 1127 | head->r.cond_index++; |
| 1128 | tomoyo_set_space(head); |
| 1129 | switch (left) { |
| 1130 | case TOMOYO_NUMBER_UNION: |
| 1131 | tomoyo_print_number_union_nospace |
| 1132 | (head, numbers_p++); |
| 1133 | break; |
| 1134 | default: |
| 1135 | tomoyo_set_string(head, |
| 1136 | tomoyo_condition_keyword[left]); |
| 1137 | break; |
| 1138 | } |
| 1139 | tomoyo_set_string(head, match ? "=" : "!="); |
| 1140 | switch (right) { |
| 1141 | case TOMOYO_NUMBER_UNION: |
| 1142 | tomoyo_print_number_union_nospace |
| 1143 | (head, numbers_p++); |
| 1144 | break; |
| 1145 | default: |
| 1146 | tomoyo_set_string(head, |
| 1147 | tomoyo_condition_keyword[right]); |
| 1148 | break; |
| 1149 | } |
| 1150 | } |
| 1151 | } |
| 1152 | head->r.cond_step++; |
| 1153 | /* fall through */ |
| 1154 | case 2: |
| 1155 | if (!tomoyo_flush(head)) |
| 1156 | break; |
| 1157 | head->r.cond_step++; |
| 1158 | /* fall through */ |
| 1159 | case 3: |
| 1160 | tomoyo_set_lf(head); |
| 1161 | return true; |
| 1162 | } |
| 1163 | return false; |
| 1164 | } |
| 1165 | |
| 1166 | /** |
Tetsuo Handa | 3299714 | 2011-06-26 23:19:28 +0900 | [diff] [blame] | 1167 | * tomoyo_set_group - Print "acl_group " header keyword and category name. |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1168 | * |
Tetsuo Handa | 0d2171d | 2011-06-26 23:17:46 +0900 | [diff] [blame] | 1169 | * @head: Pointer to "struct tomoyo_io_buffer". |
| 1170 | * @category: Category name. |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1171 | * |
Tetsuo Handa | 0d2171d | 2011-06-26 23:17:46 +0900 | [diff] [blame] | 1172 | * Returns nothing. |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1173 | */ |
Tetsuo Handa | 0d2171d | 2011-06-26 23:17:46 +0900 | [diff] [blame] | 1174 | static void tomoyo_set_group(struct tomoyo_io_buffer *head, |
| 1175 | const char *category) |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1176 | { |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 1177 | if (head->type == TOMOYO_EXCEPTIONPOLICY) { |
| 1178 | tomoyo_print_namespace(head); |
Tetsuo Handa | 3299714 | 2011-06-26 23:19:28 +0900 | [diff] [blame] | 1179 | tomoyo_io_printf(head, "acl_group %u ", |
| 1180 | head->r.acl_group_index); |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 1181 | } |
Tetsuo Handa | 0d2171d | 2011-06-26 23:17:46 +0900 | [diff] [blame] | 1182 | tomoyo_set_string(head, category); |
Tetsuo Handa | 2106ccd | 2010-05-17 10:10:31 +0900 | [diff] [blame] | 1183 | } |
| 1184 | |
| 1185 | /** |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1186 | * tomoyo_print_entry - Print an ACL entry. |
| 1187 | * |
| 1188 | * @head: Pointer to "struct tomoyo_io_buffer". |
Tetsuo Handa | 5db5a39 | 2010-06-24 12:24:19 +0900 | [diff] [blame] | 1189 | * @acl: Pointer to an ACL entry. |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1190 | * |
| 1191 | * Returns true on success, false otherwise. |
| 1192 | */ |
| 1193 | static bool tomoyo_print_entry(struct tomoyo_io_buffer *head, |
Tetsuo Handa | 5db5a39 | 2010-06-24 12:24:19 +0900 | [diff] [blame] | 1194 | struct tomoyo_acl_info *acl) |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1195 | { |
Tetsuo Handa | 5db5a39 | 2010-06-24 12:24:19 +0900 | [diff] [blame] | 1196 | const u8 acl_type = acl->type; |
Tetsuo Handa | 0d2171d | 2011-06-26 23:17:46 +0900 | [diff] [blame] | 1197 | bool first = true; |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 1198 | u8 bit; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1199 | |
Tetsuo Handa | 2066a36 | 2011-07-08 13:21:37 +0900 | [diff] [blame] | 1200 | if (head->r.print_cond_part) |
| 1201 | goto print_cond_part; |
Tetsuo Handa | 5db5a39 | 2010-06-24 12:24:19 +0900 | [diff] [blame] | 1202 | if (acl->is_deleted) |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 1203 | return true; |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 1204 | if (!tomoyo_flush(head)) |
| 1205 | return false; |
| 1206 | else if (acl_type == TOMOYO_TYPE_PATH_ACL) { |
Tetsuo Handa | 5db5a39 | 2010-06-24 12:24:19 +0900 | [diff] [blame] | 1207 | struct tomoyo_path_acl *ptr = |
| 1208 | container_of(acl, typeof(*ptr), head); |
| 1209 | const u16 perm = ptr->perm; |
Tetsuo Handa | 0d2171d | 2011-06-26 23:17:46 +0900 | [diff] [blame] | 1210 | for (bit = 0; bit < TOMOYO_MAX_PATH_OPERATION; bit++) { |
Tetsuo Handa | 5db5a39 | 2010-06-24 12:24:19 +0900 | [diff] [blame] | 1211 | if (!(perm & (1 << bit))) |
| 1212 | continue; |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 1213 | if (head->r.print_transition_related_only && |
Tetsuo Handa | 5db5a39 | 2010-06-24 12:24:19 +0900 | [diff] [blame] | 1214 | bit != TOMOYO_TYPE_EXECUTE) |
| 1215 | continue; |
Tetsuo Handa | 0d2171d | 2011-06-26 23:17:46 +0900 | [diff] [blame] | 1216 | if (first) { |
| 1217 | tomoyo_set_group(head, "file "); |
| 1218 | first = false; |
| 1219 | } else { |
| 1220 | tomoyo_set_slash(head); |
| 1221 | } |
| 1222 | tomoyo_set_string(head, tomoyo_path_keyword[bit]); |
Tetsuo Handa | 5db5a39 | 2010-06-24 12:24:19 +0900 | [diff] [blame] | 1223 | } |
Tetsuo Handa | 0d2171d | 2011-06-26 23:17:46 +0900 | [diff] [blame] | 1224 | if (first) |
| 1225 | return true; |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 1226 | tomoyo_print_name_union(head, &ptr->name); |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 1227 | } else if (head->r.print_transition_related_only) { |
Tetsuo Handa | 063821c | 2010-06-24 12:00:25 +0900 | [diff] [blame] | 1228 | return true; |
Tetsuo Handa | 5db5a39 | 2010-06-24 12:24:19 +0900 | [diff] [blame] | 1229 | } else if (acl_type == TOMOYO_TYPE_PATH2_ACL) { |
| 1230 | struct tomoyo_path2_acl *ptr = |
| 1231 | container_of(acl, typeof(*ptr), head); |
Tetsuo Handa | 0d2171d | 2011-06-26 23:17:46 +0900 | [diff] [blame] | 1232 | const u8 perm = ptr->perm; |
| 1233 | for (bit = 0; bit < TOMOYO_MAX_PATH2_OPERATION; bit++) { |
| 1234 | if (!(perm & (1 << bit))) |
| 1235 | continue; |
| 1236 | if (first) { |
| 1237 | tomoyo_set_group(head, "file "); |
| 1238 | first = false; |
| 1239 | } else { |
| 1240 | tomoyo_set_slash(head); |
| 1241 | } |
| 1242 | tomoyo_set_string(head, tomoyo_mac_keywords |
| 1243 | [tomoyo_pp2mac[bit]]); |
| 1244 | } |
| 1245 | if (first) |
| 1246 | return true; |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 1247 | tomoyo_print_name_union(head, &ptr->name1); |
| 1248 | tomoyo_print_name_union(head, &ptr->name2); |
Tetsuo Handa | 5db5a39 | 2010-06-24 12:24:19 +0900 | [diff] [blame] | 1249 | } else if (acl_type == TOMOYO_TYPE_PATH_NUMBER_ACL) { |
| 1250 | struct tomoyo_path_number_acl *ptr = |
| 1251 | container_of(acl, typeof(*ptr), head); |
Tetsuo Handa | 0d2171d | 2011-06-26 23:17:46 +0900 | [diff] [blame] | 1252 | const u8 perm = ptr->perm; |
| 1253 | for (bit = 0; bit < TOMOYO_MAX_PATH_NUMBER_OPERATION; bit++) { |
| 1254 | if (!(perm & (1 << bit))) |
| 1255 | continue; |
| 1256 | if (first) { |
| 1257 | tomoyo_set_group(head, "file "); |
| 1258 | first = false; |
| 1259 | } else { |
| 1260 | tomoyo_set_slash(head); |
| 1261 | } |
| 1262 | tomoyo_set_string(head, tomoyo_mac_keywords |
| 1263 | [tomoyo_pn2mac[bit]]); |
| 1264 | } |
| 1265 | if (first) |
| 1266 | return true; |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 1267 | tomoyo_print_name_union(head, &ptr->name); |
| 1268 | tomoyo_print_number_union(head, &ptr->number); |
Tetsuo Handa | 5db5a39 | 2010-06-24 12:24:19 +0900 | [diff] [blame] | 1269 | } else if (acl_type == TOMOYO_TYPE_MKDEV_ACL) { |
| 1270 | struct tomoyo_mkdev_acl *ptr = |
| 1271 | container_of(acl, typeof(*ptr), head); |
Tetsuo Handa | 0d2171d | 2011-06-26 23:17:46 +0900 | [diff] [blame] | 1272 | const u8 perm = ptr->perm; |
| 1273 | for (bit = 0; bit < TOMOYO_MAX_MKDEV_OPERATION; bit++) { |
| 1274 | if (!(perm & (1 << bit))) |
| 1275 | continue; |
| 1276 | if (first) { |
| 1277 | tomoyo_set_group(head, "file "); |
| 1278 | first = false; |
| 1279 | } else { |
| 1280 | tomoyo_set_slash(head); |
| 1281 | } |
| 1282 | tomoyo_set_string(head, tomoyo_mac_keywords |
| 1283 | [tomoyo_pnnn2mac[bit]]); |
| 1284 | } |
| 1285 | if (first) |
| 1286 | return true; |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 1287 | tomoyo_print_name_union(head, &ptr->name); |
| 1288 | tomoyo_print_number_union(head, &ptr->mode); |
| 1289 | tomoyo_print_number_union(head, &ptr->major); |
| 1290 | tomoyo_print_number_union(head, &ptr->minor); |
Tetsuo Handa | 5db5a39 | 2010-06-24 12:24:19 +0900 | [diff] [blame] | 1291 | } else if (acl_type == TOMOYO_TYPE_MOUNT_ACL) { |
| 1292 | struct tomoyo_mount_acl *ptr = |
| 1293 | container_of(acl, typeof(*ptr), head); |
Tetsuo Handa | 0d2171d | 2011-06-26 23:17:46 +0900 | [diff] [blame] | 1294 | tomoyo_set_group(head, "file mount"); |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 1295 | tomoyo_print_name_union(head, &ptr->dev_name); |
| 1296 | tomoyo_print_name_union(head, &ptr->dir_name); |
| 1297 | tomoyo_print_name_union(head, &ptr->fs_type); |
| 1298 | tomoyo_print_number_union(head, &ptr->flags); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1299 | } |
Tetsuo Handa | 2066a36 | 2011-07-08 13:21:37 +0900 | [diff] [blame] | 1300 | if (acl->cond) { |
| 1301 | head->r.print_cond_part = true; |
| 1302 | head->r.cond_step = 0; |
| 1303 | if (!tomoyo_flush(head)) |
| 1304 | return false; |
| 1305 | print_cond_part: |
| 1306 | if (!tomoyo_print_condition(head, acl->cond)) |
| 1307 | return false; |
| 1308 | head->r.print_cond_part = false; |
| 1309 | } else { |
| 1310 | tomoyo_set_lf(head); |
| 1311 | } |
Tetsuo Handa | 5db5a39 | 2010-06-24 12:24:19 +0900 | [diff] [blame] | 1312 | return true; |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 1313 | } |
| 1314 | |
| 1315 | /** |
| 1316 | * tomoyo_read_domain2 - Read domain policy. |
| 1317 | * |
Tetsuo Handa | 3299714 | 2011-06-26 23:19:28 +0900 | [diff] [blame] | 1318 | * @head: Pointer to "struct tomoyo_io_buffer". |
| 1319 | * @list: Pointer to "struct list_head". |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 1320 | * |
| 1321 | * Caller holds tomoyo_read_lock(). |
| 1322 | * |
| 1323 | * Returns true on success, false otherwise. |
| 1324 | */ |
| 1325 | static bool tomoyo_read_domain2(struct tomoyo_io_buffer *head, |
Tetsuo Handa | 3299714 | 2011-06-26 23:19:28 +0900 | [diff] [blame] | 1326 | struct list_head *list) |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 1327 | { |
Tetsuo Handa | 3299714 | 2011-06-26 23:19:28 +0900 | [diff] [blame] | 1328 | list_for_each_cookie(head->r.acl, list) { |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 1329 | struct tomoyo_acl_info *ptr = |
| 1330 | list_entry(head->r.acl, typeof(*ptr), list); |
| 1331 | if (!tomoyo_print_entry(head, ptr)) |
| 1332 | return false; |
| 1333 | } |
| 1334 | head->r.acl = NULL; |
| 1335 | return true; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1336 | } |
| 1337 | |
| 1338 | /** |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 1339 | * tomoyo_read_domain - Read domain policy. |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1340 | * |
| 1341 | * @head: Pointer to "struct tomoyo_io_buffer". |
| 1342 | * |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 1343 | * Caller holds tomoyo_read_lock(). |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1344 | */ |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 1345 | static void tomoyo_read_domain(struct tomoyo_io_buffer *head) |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1346 | { |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 1347 | if (head->r.eof) |
Tetsuo Handa | 8fbe71f | 2010-06-16 16:29:59 +0900 | [diff] [blame] | 1348 | return; |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 1349 | list_for_each_cookie(head->r.domain, &tomoyo_domain_list) { |
Tetsuo Handa | 475e6fa | 2010-06-24 11:28:14 +0900 | [diff] [blame] | 1350 | struct tomoyo_domain_info *domain = |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 1351 | list_entry(head->r.domain, typeof(*domain), list); |
| 1352 | switch (head->r.step) { |
Tetsuo Handa | 2c47ab9 | 2011-06-26 23:21:19 +0900 | [diff] [blame] | 1353 | u8 i; |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 1354 | case 0: |
| 1355 | if (domain->is_deleted && |
| 1356 | !head->r.print_this_domain_only) |
| 1357 | continue; |
| 1358 | /* Print domainname and flags. */ |
| 1359 | tomoyo_set_string(head, domain->domainname->name); |
| 1360 | tomoyo_set_lf(head); |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 1361 | tomoyo_io_printf(head, "use_profile %u\n", |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 1362 | domain->profile); |
Tetsuo Handa | 3299714 | 2011-06-26 23:19:28 +0900 | [diff] [blame] | 1363 | tomoyo_io_printf(head, "use_group %u\n", |
| 1364 | domain->group); |
Tetsuo Handa | 2c47ab9 | 2011-06-26 23:21:19 +0900 | [diff] [blame] | 1365 | for (i = 0; i < TOMOYO_MAX_DOMAIN_INFO_FLAGS; i++) |
| 1366 | if (domain->flags[i]) |
| 1367 | tomoyo_set_string(head, tomoyo_dif[i]); |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 1368 | head->r.step++; |
| 1369 | tomoyo_set_lf(head); |
| 1370 | /* fall through */ |
| 1371 | case 1: |
Tetsuo Handa | 3299714 | 2011-06-26 23:19:28 +0900 | [diff] [blame] | 1372 | if (!tomoyo_read_domain2(head, &domain->acl_info_list)) |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 1373 | return; |
| 1374 | head->r.step++; |
| 1375 | if (!tomoyo_set_lf(head)) |
| 1376 | return; |
| 1377 | /* fall through */ |
| 1378 | case 2: |
| 1379 | head->r.step = 0; |
| 1380 | if (head->r.print_this_domain_only) |
| 1381 | goto done; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1382 | } |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1383 | } |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 1384 | done: |
| 1385 | head->r.eof = true; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1386 | } |
| 1387 | |
| 1388 | /** |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1389 | * tomoyo_write_pid: Specify PID to obtain domainname. |
| 1390 | * |
| 1391 | * @head: Pointer to "struct tomoyo_io_buffer". |
| 1392 | * |
| 1393 | * Returns 0. |
| 1394 | */ |
| 1395 | static int tomoyo_write_pid(struct tomoyo_io_buffer *head) |
| 1396 | { |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 1397 | head->r.eof = false; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1398 | return 0; |
| 1399 | } |
| 1400 | |
| 1401 | /** |
| 1402 | * tomoyo_read_pid - Get domainname of the specified PID. |
| 1403 | * |
| 1404 | * @head: Pointer to "struct tomoyo_io_buffer". |
| 1405 | * |
| 1406 | * Returns the domainname which the specified PID is in on success, |
| 1407 | * empty string otherwise. |
| 1408 | * The PID is specified by tomoyo_write_pid() so that the user can obtain |
| 1409 | * using read()/write() interface rather than sysctl() interface. |
| 1410 | */ |
Tetsuo Handa | 8fbe71f | 2010-06-16 16:29:59 +0900 | [diff] [blame] | 1411 | static void tomoyo_read_pid(struct tomoyo_io_buffer *head) |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1412 | { |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 1413 | char *buf = head->write_buf; |
| 1414 | bool global_pid = false; |
| 1415 | unsigned int pid; |
| 1416 | struct task_struct *p; |
| 1417 | struct tomoyo_domain_info *domain = NULL; |
| 1418 | |
| 1419 | /* Accessing write_buf is safe because head->io_sem is held. */ |
| 1420 | if (!buf) { |
| 1421 | head->r.eof = true; |
| 1422 | return; /* Do nothing if open(O_RDONLY). */ |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1423 | } |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 1424 | if (head->r.w_pos || head->r.eof) |
| 1425 | return; |
| 1426 | head->r.eof = true; |
| 1427 | if (tomoyo_str_starts(&buf, "global-pid ")) |
| 1428 | global_pid = true; |
| 1429 | pid = (unsigned int) simple_strtoul(buf, NULL, 10); |
| 1430 | rcu_read_lock(); |
| 1431 | read_lock(&tasklist_lock); |
| 1432 | if (global_pid) |
| 1433 | p = find_task_by_pid_ns(pid, &init_pid_ns); |
| 1434 | else |
| 1435 | p = find_task_by_vpid(pid); |
| 1436 | if (p) |
| 1437 | domain = tomoyo_real_domain(p); |
| 1438 | read_unlock(&tasklist_lock); |
| 1439 | rcu_read_unlock(); |
| 1440 | if (!domain) |
| 1441 | return; |
| 1442 | tomoyo_io_printf(head, "%u %u ", pid, domain->profile); |
| 1443 | tomoyo_set_string(head, domain->domainname->name); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1444 | } |
| 1445 | |
Tetsuo Handa | 5448ec4 | 2010-06-21 11:14:39 +0900 | [diff] [blame] | 1446 | static const char *tomoyo_transition_type[TOMOYO_MAX_TRANSITION_TYPE] = { |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 1447 | [TOMOYO_TRANSITION_CONTROL_NO_RESET] = "no_reset_domain ", |
| 1448 | [TOMOYO_TRANSITION_CONTROL_RESET] = "reset_domain ", |
| 1449 | [TOMOYO_TRANSITION_CONTROL_NO_INITIALIZE] = "no_initialize_domain ", |
| 1450 | [TOMOYO_TRANSITION_CONTROL_INITIALIZE] = "initialize_domain ", |
| 1451 | [TOMOYO_TRANSITION_CONTROL_NO_KEEP] = "no_keep_domain ", |
| 1452 | [TOMOYO_TRANSITION_CONTROL_KEEP] = "keep_domain ", |
Tetsuo Handa | 5448ec4 | 2010-06-21 11:14:39 +0900 | [diff] [blame] | 1453 | }; |
| 1454 | |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 1455 | static const char *tomoyo_group_name[TOMOYO_MAX_GROUP] = { |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 1456 | [TOMOYO_PATH_GROUP] = "path_group ", |
| 1457 | [TOMOYO_NUMBER_GROUP] = "number_group ", |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 1458 | }; |
| 1459 | |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1460 | /** |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 1461 | * tomoyo_write_exception - Write exception policy. |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1462 | * |
| 1463 | * @head: Pointer to "struct tomoyo_io_buffer". |
| 1464 | * |
| 1465 | * Returns 0 on success, negative value otherwise. |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 1466 | * |
| 1467 | * Caller holds tomoyo_read_lock(). |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1468 | */ |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 1469 | static int tomoyo_write_exception(struct tomoyo_io_buffer *head) |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1470 | { |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 1471 | const bool is_delete = head->w.is_delete; |
Tetsuo Handa | a238cf5 | 2011-06-26 23:17:10 +0900 | [diff] [blame] | 1472 | struct tomoyo_acl_param param = { |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 1473 | .ns = head->w.ns, |
| 1474 | .is_delete = is_delete, |
Tetsuo Handa | a238cf5 | 2011-06-26 23:17:10 +0900 | [diff] [blame] | 1475 | .data = head->write_buf, |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 1476 | }; |
Tetsuo Handa | a238cf5 | 2011-06-26 23:17:10 +0900 | [diff] [blame] | 1477 | u8 i; |
Tetsuo Handa | a238cf5 | 2011-06-26 23:17:10 +0900 | [diff] [blame] | 1478 | if (tomoyo_str_starts(¶m.data, "aggregator ")) |
| 1479 | return tomoyo_write_aggregator(¶m); |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 1480 | for (i = 0; i < TOMOYO_MAX_TRANSITION_TYPE; i++) |
Tetsuo Handa | a238cf5 | 2011-06-26 23:17:10 +0900 | [diff] [blame] | 1481 | if (tomoyo_str_starts(¶m.data, tomoyo_transition_type[i])) |
| 1482 | return tomoyo_write_transition_control(¶m, i); |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 1483 | for (i = 0; i < TOMOYO_MAX_GROUP; i++) |
Tetsuo Handa | a238cf5 | 2011-06-26 23:17:10 +0900 | [diff] [blame] | 1484 | if (tomoyo_str_starts(¶m.data, tomoyo_group_name[i])) |
| 1485 | return tomoyo_write_group(¶m, i); |
Tetsuo Handa | 3299714 | 2011-06-26 23:19:28 +0900 | [diff] [blame] | 1486 | if (tomoyo_str_starts(¶m.data, "acl_group ")) { |
| 1487 | unsigned int group; |
| 1488 | char *data; |
| 1489 | group = simple_strtoul(param.data, &data, 10); |
| 1490 | if (group < TOMOYO_MAX_ACL_GROUPS && *data++ == ' ') |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 1491 | return tomoyo_write_domain2 |
| 1492 | (head->w.ns, &head->w.ns->acl_group[group], |
| 1493 | data, is_delete); |
Tetsuo Handa | 3299714 | 2011-06-26 23:19:28 +0900 | [diff] [blame] | 1494 | } |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1495 | return -EINVAL; |
| 1496 | } |
| 1497 | |
Tetsuo Handa | 31845e8 | 2010-06-17 16:54:33 +0900 | [diff] [blame] | 1498 | /** |
| 1499 | * tomoyo_read_group - Read "struct tomoyo_path_group"/"struct tomoyo_number_group" list. |
| 1500 | * |
| 1501 | * @head: Pointer to "struct tomoyo_io_buffer". |
| 1502 | * @idx: Index number. |
| 1503 | * |
| 1504 | * Returns true on success, false otherwise. |
| 1505 | * |
| 1506 | * Caller holds tomoyo_read_lock(). |
| 1507 | */ |
| 1508 | static bool tomoyo_read_group(struct tomoyo_io_buffer *head, const int idx) |
| 1509 | { |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 1510 | struct tomoyo_policy_namespace *ns = |
| 1511 | container_of(head->r.ns, typeof(*ns), namespace_list); |
| 1512 | struct list_head *list = &ns->group_list[idx]; |
| 1513 | list_for_each_cookie(head->r.group, list) { |
Tetsuo Handa | 31845e8 | 2010-06-17 16:54:33 +0900 | [diff] [blame] | 1514 | struct tomoyo_group *group = |
Tetsuo Handa | 0df7e8b | 2011-06-26 23:16:36 +0900 | [diff] [blame] | 1515 | list_entry(head->r.group, typeof(*group), head.list); |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 1516 | list_for_each_cookie(head->r.acl, &group->member_list) { |
Tetsuo Handa | 31845e8 | 2010-06-17 16:54:33 +0900 | [diff] [blame] | 1517 | struct tomoyo_acl_head *ptr = |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 1518 | list_entry(head->r.acl, typeof(*ptr), list); |
Tetsuo Handa | 31845e8 | 2010-06-17 16:54:33 +0900 | [diff] [blame] | 1519 | if (ptr->is_deleted) |
| 1520 | continue; |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 1521 | if (!tomoyo_flush(head)) |
Tetsuo Handa | 31845e8 | 2010-06-17 16:54:33 +0900 | [diff] [blame] | 1522 | return false; |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 1523 | tomoyo_print_namespace(head); |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 1524 | tomoyo_set_string(head, tomoyo_group_name[idx]); |
| 1525 | tomoyo_set_string(head, group->group_name->name); |
| 1526 | if (idx == TOMOYO_PATH_GROUP) { |
| 1527 | tomoyo_set_space(head); |
| 1528 | tomoyo_set_string(head, container_of |
| 1529 | (ptr, struct tomoyo_path_group, |
| 1530 | head)->member_name->name); |
| 1531 | } else if (idx == TOMOYO_NUMBER_GROUP) { |
| 1532 | tomoyo_print_number_union(head, &container_of |
| 1533 | (ptr, |
| 1534 | struct tomoyo_number_group, |
| 1535 | head)->number); |
| 1536 | } |
| 1537 | tomoyo_set_lf(head); |
Tetsuo Handa | 31845e8 | 2010-06-17 16:54:33 +0900 | [diff] [blame] | 1538 | } |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 1539 | head->r.acl = NULL; |
Tetsuo Handa | 31845e8 | 2010-06-17 16:54:33 +0900 | [diff] [blame] | 1540 | } |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 1541 | head->r.group = NULL; |
Tetsuo Handa | 31845e8 | 2010-06-17 16:54:33 +0900 | [diff] [blame] | 1542 | return true; |
| 1543 | } |
| 1544 | |
| 1545 | /** |
| 1546 | * tomoyo_read_policy - Read "struct tomoyo_..._entry" list. |
| 1547 | * |
| 1548 | * @head: Pointer to "struct tomoyo_io_buffer". |
| 1549 | * @idx: Index number. |
| 1550 | * |
| 1551 | * Returns true on success, false otherwise. |
| 1552 | * |
| 1553 | * Caller holds tomoyo_read_lock(). |
| 1554 | */ |
| 1555 | static bool tomoyo_read_policy(struct tomoyo_io_buffer *head, const int idx) |
| 1556 | { |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 1557 | struct tomoyo_policy_namespace *ns = |
| 1558 | container_of(head->r.ns, typeof(*ns), namespace_list); |
| 1559 | struct list_head *list = &ns->policy_list[idx]; |
| 1560 | list_for_each_cookie(head->r.acl, list) { |
Tetsuo Handa | 475e6fa | 2010-06-24 11:28:14 +0900 | [diff] [blame] | 1561 | struct tomoyo_acl_head *acl = |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 1562 | container_of(head->r.acl, typeof(*acl), list); |
Tetsuo Handa | 31845e8 | 2010-06-17 16:54:33 +0900 | [diff] [blame] | 1563 | if (acl->is_deleted) |
| 1564 | continue; |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 1565 | if (!tomoyo_flush(head)) |
| 1566 | return false; |
Tetsuo Handa | 31845e8 | 2010-06-17 16:54:33 +0900 | [diff] [blame] | 1567 | switch (idx) { |
Tetsuo Handa | 5448ec4 | 2010-06-21 11:14:39 +0900 | [diff] [blame] | 1568 | case TOMOYO_ID_TRANSITION_CONTROL: |
Tetsuo Handa | 31845e8 | 2010-06-17 16:54:33 +0900 | [diff] [blame] | 1569 | { |
Tetsuo Handa | 5448ec4 | 2010-06-21 11:14:39 +0900 | [diff] [blame] | 1570 | struct tomoyo_transition_control *ptr = |
Tetsuo Handa | 31845e8 | 2010-06-17 16:54:33 +0900 | [diff] [blame] | 1571 | container_of(acl, typeof(*ptr), head); |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 1572 | tomoyo_print_namespace(head); |
Tetsuo Handa | 0d2171d | 2011-06-26 23:17:46 +0900 | [diff] [blame] | 1573 | tomoyo_set_string(head, tomoyo_transition_type |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 1574 | [ptr->type]); |
Tetsuo Handa | 0d2171d | 2011-06-26 23:17:46 +0900 | [diff] [blame] | 1575 | tomoyo_set_string(head, ptr->program ? |
| 1576 | ptr->program->name : "any"); |
| 1577 | tomoyo_set_string(head, " from "); |
| 1578 | tomoyo_set_string(head, ptr->domainname ? |
| 1579 | ptr->domainname->name : |
| 1580 | "any"); |
Tetsuo Handa | 31845e8 | 2010-06-17 16:54:33 +0900 | [diff] [blame] | 1581 | } |
| 1582 | break; |
Tetsuo Handa | 31845e8 | 2010-06-17 16:54:33 +0900 | [diff] [blame] | 1583 | case TOMOYO_ID_AGGREGATOR: |
| 1584 | { |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 1585 | struct tomoyo_aggregator *ptr = |
Tetsuo Handa | 31845e8 | 2010-06-17 16:54:33 +0900 | [diff] [blame] | 1586 | container_of(acl, typeof(*ptr), head); |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 1587 | tomoyo_print_namespace(head); |
Tetsuo Handa | b5bc60b | 2011-06-26 23:16:03 +0900 | [diff] [blame] | 1588 | tomoyo_set_string(head, "aggregator "); |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 1589 | tomoyo_set_string(head, |
| 1590 | ptr->original_name->name); |
| 1591 | tomoyo_set_space(head); |
| 1592 | tomoyo_set_string(head, |
| 1593 | ptr->aggregated_name->name); |
Tetsuo Handa | 31845e8 | 2010-06-17 16:54:33 +0900 | [diff] [blame] | 1594 | } |
| 1595 | break; |
Tetsuo Handa | 31845e8 | 2010-06-17 16:54:33 +0900 | [diff] [blame] | 1596 | default: |
| 1597 | continue; |
| 1598 | } |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 1599 | tomoyo_set_lf(head); |
Tetsuo Handa | 31845e8 | 2010-06-17 16:54:33 +0900 | [diff] [blame] | 1600 | } |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 1601 | head->r.acl = NULL; |
Tetsuo Handa | 31845e8 | 2010-06-17 16:54:33 +0900 | [diff] [blame] | 1602 | return true; |
| 1603 | } |
| 1604 | |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1605 | /** |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 1606 | * tomoyo_read_exception - Read exception policy. |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1607 | * |
| 1608 | * @head: Pointer to "struct tomoyo_io_buffer". |
| 1609 | * |
Tetsuo Handa | fdb8ebb | 2009-12-08 09:34:43 +0900 | [diff] [blame] | 1610 | * Caller holds tomoyo_read_lock(). |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1611 | */ |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 1612 | static void tomoyo_read_exception(struct tomoyo_io_buffer *head) |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1613 | { |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 1614 | struct tomoyo_policy_namespace *ns = |
| 1615 | container_of(head->r.ns, typeof(*ns), namespace_list); |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 1616 | if (head->r.eof) |
Tetsuo Handa | 31845e8 | 2010-06-17 16:54:33 +0900 | [diff] [blame] | 1617 | return; |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 1618 | while (head->r.step < TOMOYO_MAX_POLICY && |
| 1619 | tomoyo_read_policy(head, head->r.step)) |
| 1620 | head->r.step++; |
| 1621 | if (head->r.step < TOMOYO_MAX_POLICY) |
Tetsuo Handa | 31845e8 | 2010-06-17 16:54:33 +0900 | [diff] [blame] | 1622 | return; |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 1623 | while (head->r.step < TOMOYO_MAX_POLICY + TOMOYO_MAX_GROUP && |
| 1624 | tomoyo_read_group(head, head->r.step - TOMOYO_MAX_POLICY)) |
| 1625 | head->r.step++; |
| 1626 | if (head->r.step < TOMOYO_MAX_POLICY + TOMOYO_MAX_GROUP) |
Tetsuo Handa | 31845e8 | 2010-06-17 16:54:33 +0900 | [diff] [blame] | 1627 | return; |
Tetsuo Handa | 3299714 | 2011-06-26 23:19:28 +0900 | [diff] [blame] | 1628 | while (head->r.step < TOMOYO_MAX_POLICY + TOMOYO_MAX_GROUP |
| 1629 | + TOMOYO_MAX_ACL_GROUPS) { |
| 1630 | head->r.acl_group_index = head->r.step - TOMOYO_MAX_POLICY |
| 1631 | - TOMOYO_MAX_GROUP; |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 1632 | if (!tomoyo_read_domain2(head, &ns->acl_group |
Tetsuo Handa | 3299714 | 2011-06-26 23:19:28 +0900 | [diff] [blame] | 1633 | [head->r.acl_group_index])) |
| 1634 | return; |
| 1635 | head->r.step++; |
| 1636 | } |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 1637 | head->r.eof = true; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1638 | } |
| 1639 | |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 1640 | /* Wait queue for kernel -> userspace notification. */ |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1641 | static DECLARE_WAIT_QUEUE_HEAD(tomoyo_query_wait); |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 1642 | /* Wait queue for userspace -> kernel notification. */ |
| 1643 | static DECLARE_WAIT_QUEUE_HEAD(tomoyo_answer_wait); |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1644 | |
| 1645 | /* Structure for query. */ |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 1646 | struct tomoyo_query { |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1647 | struct list_head list; |
| 1648 | char *query; |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 1649 | size_t query_len; |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1650 | unsigned int serial; |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 1651 | u8 timer; |
| 1652 | u8 answer; |
| 1653 | u8 retry; |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1654 | }; |
| 1655 | |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 1656 | /* The list for "struct tomoyo_query". */ |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1657 | static LIST_HEAD(tomoyo_query_list); |
| 1658 | |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 1659 | /* Lock for manipulating tomoyo_query_list. */ |
| 1660 | static DEFINE_SPINLOCK(tomoyo_query_list_lock); |
| 1661 | |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1662 | /* |
| 1663 | * Number of "struct file" referring /sys/kernel/security/tomoyo/query |
| 1664 | * interface. |
| 1665 | */ |
| 1666 | static atomic_t tomoyo_query_observers = ATOMIC_INIT(0); |
| 1667 | |
| 1668 | /** |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 1669 | * tomoyo_add_entry - Add an ACL to current thread's domain. Used by learning mode. |
| 1670 | * |
| 1671 | * @domain: Pointer to "struct tomoyo_domain_info". |
| 1672 | * @header: Lines containing ACL. |
| 1673 | * |
| 1674 | * Returns nothing. |
| 1675 | */ |
| 1676 | static void tomoyo_add_entry(struct tomoyo_domain_info *domain, char *header) |
| 1677 | { |
| 1678 | char *buffer; |
| 1679 | char *cp = strchr(header, '\n'); |
| 1680 | int len; |
| 1681 | if (!cp) |
| 1682 | return; |
| 1683 | cp = strchr(cp + 1, '\n'); |
| 1684 | if (!cp) |
| 1685 | return; |
| 1686 | *cp++ = '\0'; |
| 1687 | len = strlen(cp) + 1; |
| 1688 | buffer = kmalloc(len, GFP_NOFS); |
| 1689 | if (!buffer) |
| 1690 | return; |
| 1691 | snprintf(buffer, len - 1, "%s", cp); |
| 1692 | tomoyo_normalize_line(buffer); |
Tetsuo Handa | b22b8b9 | 2011-06-26 23:21:50 +0900 | [diff] [blame] | 1693 | if (!tomoyo_write_domain2(domain->ns, &domain->acl_info_list, buffer, |
| 1694 | false)) |
| 1695 | tomoyo_update_stat(TOMOYO_STAT_POLICY_UPDATES); |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 1696 | kfree(buffer); |
| 1697 | } |
| 1698 | |
| 1699 | /** |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1700 | * tomoyo_supervisor - Ask for the supervisor's decision. |
| 1701 | * |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 1702 | * @r: Pointer to "struct tomoyo_request_info". |
| 1703 | * @fmt: The printf()'s format string, followed by parameters. |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1704 | * |
| 1705 | * Returns 0 if the supervisor decided to permit the access request which |
| 1706 | * violated the policy in enforcing mode, TOMOYO_RETRY_REQUEST if the |
| 1707 | * supervisor decided to retry the access request which violated the policy in |
| 1708 | * enforcing mode, 0 if it is not in enforcing mode, -EPERM otherwise. |
| 1709 | */ |
| 1710 | int tomoyo_supervisor(struct tomoyo_request_info *r, const char *fmt, ...) |
| 1711 | { |
| 1712 | va_list args; |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 1713 | int error; |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1714 | int len; |
| 1715 | static unsigned int tomoyo_serial; |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 1716 | struct tomoyo_query entry = { }; |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1717 | bool quota_exceeded = false; |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 1718 | va_start(args, fmt); |
| 1719 | len = vsnprintf((char *) &len, 1, fmt, args) + 1; |
| 1720 | va_end(args); |
| 1721 | /* Write /sys/kernel/security/tomoyo/audit. */ |
| 1722 | va_start(args, fmt); |
| 1723 | tomoyo_write_log2(r, len, fmt, args); |
| 1724 | va_end(args); |
| 1725 | /* Nothing more to do if granted. */ |
| 1726 | if (r->granted) |
| 1727 | return 0; |
Tetsuo Handa | b22b8b9 | 2011-06-26 23:21:50 +0900 | [diff] [blame] | 1728 | if (r->mode) |
| 1729 | tomoyo_update_stat(r->mode); |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1730 | switch (r->mode) { |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 1731 | case TOMOYO_CONFIG_ENFORCING: |
| 1732 | error = -EPERM; |
| 1733 | if (atomic_read(&tomoyo_query_observers)) |
| 1734 | break; |
| 1735 | goto out; |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1736 | case TOMOYO_CONFIG_LEARNING: |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 1737 | error = 0; |
| 1738 | /* Check max_learning_entry parameter. */ |
| 1739 | if (tomoyo_domain_quota_is_ok(r)) |
| 1740 | break; |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1741 | /* fall through */ |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 1742 | default: |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1743 | return 0; |
| 1744 | } |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 1745 | /* Get message. */ |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1746 | va_start(args, fmt); |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 1747 | entry.query = tomoyo_init_log(r, len, fmt, args); |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1748 | va_end(args); |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 1749 | if (!entry.query) |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1750 | goto out; |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 1751 | entry.query_len = strlen(entry.query) + 1; |
| 1752 | if (!error) { |
| 1753 | tomoyo_add_entry(r->domain, entry.query); |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1754 | goto out; |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 1755 | } |
| 1756 | len = tomoyo_round2(entry.query_len); |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1757 | spin_lock(&tomoyo_query_list_lock); |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 1758 | if (tomoyo_memory_quota[TOMOYO_MEMORY_QUERY] && |
| 1759 | tomoyo_memory_used[TOMOYO_MEMORY_QUERY] + len |
| 1760 | >= tomoyo_memory_quota[TOMOYO_MEMORY_QUERY]) { |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1761 | quota_exceeded = true; |
| 1762 | } else { |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 1763 | entry.serial = tomoyo_serial++; |
| 1764 | entry.retry = r->retry; |
| 1765 | tomoyo_memory_used[TOMOYO_MEMORY_QUERY] += len; |
| 1766 | list_add_tail(&entry.list, &tomoyo_query_list); |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1767 | } |
| 1768 | spin_unlock(&tomoyo_query_list_lock); |
| 1769 | if (quota_exceeded) |
| 1770 | goto out; |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1771 | /* Give 10 seconds for supervisor's opinion. */ |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 1772 | while (entry.timer < 10) { |
| 1773 | wake_up_all(&tomoyo_query_wait); |
| 1774 | if (wait_event_interruptible_timeout |
| 1775 | (tomoyo_answer_wait, entry.answer || |
| 1776 | !atomic_read(&tomoyo_query_observers), HZ)) |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1777 | break; |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 1778 | else |
| 1779 | entry.timer++; |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1780 | } |
| 1781 | spin_lock(&tomoyo_query_list_lock); |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 1782 | list_del(&entry.list); |
| 1783 | tomoyo_memory_used[TOMOYO_MEMORY_QUERY] -= len; |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1784 | spin_unlock(&tomoyo_query_list_lock); |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 1785 | switch (entry.answer) { |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1786 | case 3: /* Asked to retry by administrator. */ |
| 1787 | error = TOMOYO_RETRY_REQUEST; |
| 1788 | r->retry++; |
| 1789 | break; |
| 1790 | case 1: |
| 1791 | /* Granted by administrator. */ |
| 1792 | error = 0; |
| 1793 | break; |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1794 | default: |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 1795 | /* Timed out or rejected by administrator. */ |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1796 | break; |
| 1797 | } |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 1798 | out: |
| 1799 | kfree(entry.query); |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1800 | return error; |
| 1801 | } |
| 1802 | |
| 1803 | /** |
| 1804 | * tomoyo_poll_query - poll() for /sys/kernel/security/tomoyo/query. |
| 1805 | * |
| 1806 | * @file: Pointer to "struct file". |
| 1807 | * @wait: Pointer to "poll_table". |
| 1808 | * |
| 1809 | * Returns POLLIN | POLLRDNORM when ready to read, 0 otherwise. |
| 1810 | * |
| 1811 | * Waits for access requests which violated policy in enforcing mode. |
| 1812 | */ |
| 1813 | static int tomoyo_poll_query(struct file *file, poll_table *wait) |
| 1814 | { |
| 1815 | struct list_head *tmp; |
| 1816 | bool found = false; |
| 1817 | u8 i; |
| 1818 | for (i = 0; i < 2; i++) { |
| 1819 | spin_lock(&tomoyo_query_list_lock); |
| 1820 | list_for_each(tmp, &tomoyo_query_list) { |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 1821 | struct tomoyo_query *ptr = |
| 1822 | list_entry(tmp, typeof(*ptr), list); |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1823 | if (ptr->answer) |
| 1824 | continue; |
| 1825 | found = true; |
| 1826 | break; |
| 1827 | } |
| 1828 | spin_unlock(&tomoyo_query_list_lock); |
| 1829 | if (found) |
| 1830 | return POLLIN | POLLRDNORM; |
| 1831 | if (i) |
| 1832 | break; |
| 1833 | poll_wait(file, &tomoyo_query_wait, wait); |
| 1834 | } |
| 1835 | return 0; |
| 1836 | } |
| 1837 | |
| 1838 | /** |
| 1839 | * tomoyo_read_query - Read access requests which violated policy in enforcing mode. |
| 1840 | * |
| 1841 | * @head: Pointer to "struct tomoyo_io_buffer". |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1842 | */ |
Tetsuo Handa | 8fbe71f | 2010-06-16 16:29:59 +0900 | [diff] [blame] | 1843 | static void tomoyo_read_query(struct tomoyo_io_buffer *head) |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1844 | { |
| 1845 | struct list_head *tmp; |
Tetsuo Handa | 2c47ab9 | 2011-06-26 23:21:19 +0900 | [diff] [blame] | 1846 | unsigned int pos = 0; |
| 1847 | size_t len = 0; |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1848 | char *buf; |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 1849 | if (head->r.w_pos) |
Tetsuo Handa | 8fbe71f | 2010-06-16 16:29:59 +0900 | [diff] [blame] | 1850 | return; |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1851 | if (head->read_buf) { |
| 1852 | kfree(head->read_buf); |
| 1853 | head->read_buf = NULL; |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1854 | } |
| 1855 | spin_lock(&tomoyo_query_list_lock); |
| 1856 | list_for_each(tmp, &tomoyo_query_list) { |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 1857 | struct tomoyo_query *ptr = list_entry(tmp, typeof(*ptr), list); |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1858 | if (ptr->answer) |
| 1859 | continue; |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 1860 | if (pos++ != head->r.query_index) |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1861 | continue; |
| 1862 | len = ptr->query_len; |
| 1863 | break; |
| 1864 | } |
| 1865 | spin_unlock(&tomoyo_query_list_lock); |
| 1866 | if (!len) { |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 1867 | head->r.query_index = 0; |
Tetsuo Handa | 8fbe71f | 2010-06-16 16:29:59 +0900 | [diff] [blame] | 1868 | return; |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1869 | } |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 1870 | buf = kzalloc(len + 32, GFP_NOFS); |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1871 | if (!buf) |
Tetsuo Handa | 8fbe71f | 2010-06-16 16:29:59 +0900 | [diff] [blame] | 1872 | return; |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1873 | pos = 0; |
| 1874 | spin_lock(&tomoyo_query_list_lock); |
| 1875 | list_for_each(tmp, &tomoyo_query_list) { |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 1876 | struct tomoyo_query *ptr = list_entry(tmp, typeof(*ptr), list); |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1877 | if (ptr->answer) |
| 1878 | continue; |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 1879 | if (pos++ != head->r.query_index) |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1880 | continue; |
| 1881 | /* |
| 1882 | * Some query can be skipped because tomoyo_query_list |
| 1883 | * can change, but I don't care. |
| 1884 | */ |
| 1885 | if (len == ptr->query_len) |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 1886 | snprintf(buf, len + 31, "Q%u-%hu\n%s", ptr->serial, |
| 1887 | ptr->retry, ptr->query); |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1888 | break; |
| 1889 | } |
| 1890 | spin_unlock(&tomoyo_query_list_lock); |
| 1891 | if (buf[0]) { |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1892 | head->read_buf = buf; |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 1893 | head->r.w[head->r.w_pos++] = buf; |
| 1894 | head->r.query_index++; |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1895 | } else { |
| 1896 | kfree(buf); |
| 1897 | } |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1898 | } |
| 1899 | |
| 1900 | /** |
| 1901 | * tomoyo_write_answer - Write the supervisor's decision. |
| 1902 | * |
| 1903 | * @head: Pointer to "struct tomoyo_io_buffer". |
| 1904 | * |
| 1905 | * Returns 0 on success, -EINVAL otherwise. |
| 1906 | */ |
| 1907 | static int tomoyo_write_answer(struct tomoyo_io_buffer *head) |
| 1908 | { |
| 1909 | char *data = head->write_buf; |
| 1910 | struct list_head *tmp; |
| 1911 | unsigned int serial; |
| 1912 | unsigned int answer; |
| 1913 | spin_lock(&tomoyo_query_list_lock); |
| 1914 | list_for_each(tmp, &tomoyo_query_list) { |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 1915 | struct tomoyo_query *ptr = list_entry(tmp, typeof(*ptr), list); |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1916 | ptr->timer = 0; |
| 1917 | } |
| 1918 | spin_unlock(&tomoyo_query_list_lock); |
| 1919 | if (sscanf(data, "A%u=%u", &serial, &answer) != 2) |
| 1920 | return -EINVAL; |
| 1921 | spin_lock(&tomoyo_query_list_lock); |
| 1922 | list_for_each(tmp, &tomoyo_query_list) { |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 1923 | struct tomoyo_query *ptr = list_entry(tmp, typeof(*ptr), list); |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 1924 | if (ptr->serial != serial) |
| 1925 | continue; |
| 1926 | if (!ptr->answer) |
| 1927 | ptr->answer = answer; |
| 1928 | break; |
| 1929 | } |
| 1930 | spin_unlock(&tomoyo_query_list_lock); |
| 1931 | return 0; |
| 1932 | } |
| 1933 | |
| 1934 | /** |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1935 | * tomoyo_read_version: Get version. |
| 1936 | * |
| 1937 | * @head: Pointer to "struct tomoyo_io_buffer". |
| 1938 | * |
| 1939 | * Returns version information. |
| 1940 | */ |
Tetsuo Handa | 8fbe71f | 2010-06-16 16:29:59 +0900 | [diff] [blame] | 1941 | static void tomoyo_read_version(struct tomoyo_io_buffer *head) |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1942 | { |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 1943 | if (!head->r.eof) { |
Tetsuo Handa | d5ca172 | 2011-06-26 23:18:21 +0900 | [diff] [blame] | 1944 | tomoyo_io_printf(head, "2.4.0"); |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 1945 | head->r.eof = true; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1946 | } |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1947 | } |
| 1948 | |
| 1949 | /** |
| 1950 | * tomoyo_read_self_domain - Get the current process's domainname. |
| 1951 | * |
| 1952 | * @head: Pointer to "struct tomoyo_io_buffer". |
| 1953 | * |
| 1954 | * Returns the current process's domainname. |
| 1955 | */ |
Tetsuo Handa | 8fbe71f | 2010-06-16 16:29:59 +0900 | [diff] [blame] | 1956 | static void tomoyo_read_self_domain(struct tomoyo_io_buffer *head) |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1957 | { |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 1958 | if (!head->r.eof) { |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1959 | /* |
| 1960 | * tomoyo_domain()->domainname != NULL |
| 1961 | * because every process belongs to a domain and |
| 1962 | * the domain's name cannot be NULL. |
| 1963 | */ |
| 1964 | tomoyo_io_printf(head, "%s", tomoyo_domain()->domainname->name); |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 1965 | head->r.eof = true; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1966 | } |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 1967 | } |
| 1968 | |
Tetsuo Handa | b22b8b9 | 2011-06-26 23:21:50 +0900 | [diff] [blame] | 1969 | /* String table for /sys/kernel/security/tomoyo/stat interface. */ |
| 1970 | static const char * const tomoyo_policy_headers[TOMOYO_MAX_POLICY_STAT] = { |
| 1971 | [TOMOYO_STAT_POLICY_UPDATES] = "update:", |
| 1972 | [TOMOYO_STAT_POLICY_LEARNING] = "violation in learning mode:", |
| 1973 | [TOMOYO_STAT_POLICY_PERMISSIVE] = "violation in permissive mode:", |
| 1974 | [TOMOYO_STAT_POLICY_ENFORCING] = "violation in enforcing mode:", |
| 1975 | }; |
| 1976 | |
| 1977 | /* String table for /sys/kernel/security/tomoyo/stat interface. */ |
| 1978 | static const char * const tomoyo_memory_headers[TOMOYO_MAX_MEMORY_STAT] = { |
| 1979 | [TOMOYO_MEMORY_POLICY] = "policy:", |
| 1980 | [TOMOYO_MEMORY_AUDIT] = "audit log:", |
| 1981 | [TOMOYO_MEMORY_QUERY] = "query message:", |
| 1982 | }; |
| 1983 | |
| 1984 | /* Timestamp counter for last updated. */ |
| 1985 | static unsigned int tomoyo_stat_updated[TOMOYO_MAX_POLICY_STAT]; |
| 1986 | /* Counter for number of updates. */ |
| 1987 | static unsigned int tomoyo_stat_modified[TOMOYO_MAX_POLICY_STAT]; |
| 1988 | |
| 1989 | /** |
| 1990 | * tomoyo_update_stat - Update statistic counters. |
| 1991 | * |
| 1992 | * @index: Index for policy type. |
| 1993 | * |
| 1994 | * Returns nothing. |
| 1995 | */ |
| 1996 | void tomoyo_update_stat(const u8 index) |
| 1997 | { |
| 1998 | struct timeval tv; |
| 1999 | do_gettimeofday(&tv); |
| 2000 | /* |
| 2001 | * I don't use atomic operations because race condition is not fatal. |
| 2002 | */ |
| 2003 | tomoyo_stat_updated[index]++; |
| 2004 | tomoyo_stat_modified[index] = tv.tv_sec; |
| 2005 | } |
| 2006 | |
| 2007 | /** |
| 2008 | * tomoyo_read_stat - Read statistic data. |
| 2009 | * |
| 2010 | * @head: Pointer to "struct tomoyo_io_buffer". |
| 2011 | * |
| 2012 | * Returns nothing. |
| 2013 | */ |
| 2014 | static void tomoyo_read_stat(struct tomoyo_io_buffer *head) |
| 2015 | { |
| 2016 | u8 i; |
| 2017 | unsigned int total = 0; |
| 2018 | if (head->r.eof) |
| 2019 | return; |
| 2020 | for (i = 0; i < TOMOYO_MAX_POLICY_STAT; i++) { |
| 2021 | tomoyo_io_printf(head, "Policy %-30s %10u", |
| 2022 | tomoyo_policy_headers[i], |
| 2023 | tomoyo_stat_updated[i]); |
| 2024 | if (tomoyo_stat_modified[i]) { |
| 2025 | struct tomoyo_time stamp; |
| 2026 | tomoyo_convert_time(tomoyo_stat_modified[i], &stamp); |
| 2027 | tomoyo_io_printf(head, " (Last: %04u/%02u/%02u " |
| 2028 | "%02u:%02u:%02u)", |
| 2029 | stamp.year, stamp.month, stamp.day, |
| 2030 | stamp.hour, stamp.min, stamp.sec); |
| 2031 | } |
| 2032 | tomoyo_set_lf(head); |
| 2033 | } |
| 2034 | for (i = 0; i < TOMOYO_MAX_MEMORY_STAT; i++) { |
| 2035 | unsigned int used = tomoyo_memory_used[i]; |
| 2036 | total += used; |
| 2037 | tomoyo_io_printf(head, "Memory used by %-22s %10u", |
| 2038 | tomoyo_memory_headers[i], used); |
| 2039 | used = tomoyo_memory_quota[i]; |
| 2040 | if (used) |
| 2041 | tomoyo_io_printf(head, " (Quota: %10u)", used); |
| 2042 | tomoyo_set_lf(head); |
| 2043 | } |
| 2044 | tomoyo_io_printf(head, "Total memory used: %10u\n", |
| 2045 | total); |
| 2046 | head->r.eof = true; |
| 2047 | } |
| 2048 | |
| 2049 | /** |
| 2050 | * tomoyo_write_stat - Set memory quota. |
| 2051 | * |
| 2052 | * @head: Pointer to "struct tomoyo_io_buffer". |
| 2053 | * |
| 2054 | * Returns 0. |
| 2055 | */ |
| 2056 | static int tomoyo_write_stat(struct tomoyo_io_buffer *head) |
| 2057 | { |
| 2058 | char *data = head->write_buf; |
| 2059 | u8 i; |
| 2060 | if (tomoyo_str_starts(&data, "Memory used by ")) |
| 2061 | for (i = 0; i < TOMOYO_MAX_MEMORY_STAT; i++) |
| 2062 | if (tomoyo_str_starts(&data, tomoyo_memory_headers[i])) |
| 2063 | sscanf(data, "%u", &tomoyo_memory_quota[i]); |
| 2064 | return 0; |
| 2065 | } |
| 2066 | |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 2067 | /** |
| 2068 | * tomoyo_open_control - open() for /sys/kernel/security/tomoyo/ interface. |
| 2069 | * |
| 2070 | * @type: Type of interface. |
| 2071 | * @file: Pointer to "struct file". |
| 2072 | * |
Tetsuo Handa | 2e503bb | 2011-06-26 23:20:55 +0900 | [diff] [blame] | 2073 | * Returns 0 on success, negative value otherwise. |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 2074 | */ |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 2075 | int tomoyo_open_control(const u8 type, struct file *file) |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 2076 | { |
Tetsuo Handa | 4e5d6f7 | 2010-04-28 14:17:42 +0900 | [diff] [blame] | 2077 | struct tomoyo_io_buffer *head = kzalloc(sizeof(*head), GFP_NOFS); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 2078 | |
| 2079 | if (!head) |
| 2080 | return -ENOMEM; |
| 2081 | mutex_init(&head->io_sem); |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 2082 | head->type = type; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 2083 | switch (type) { |
| 2084 | case TOMOYO_DOMAINPOLICY: |
| 2085 | /* /sys/kernel/security/tomoyo/domain_policy */ |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 2086 | head->write = tomoyo_write_domain; |
| 2087 | head->read = tomoyo_read_domain; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 2088 | break; |
| 2089 | case TOMOYO_EXCEPTIONPOLICY: |
| 2090 | /* /sys/kernel/security/tomoyo/exception_policy */ |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 2091 | head->write = tomoyo_write_exception; |
| 2092 | head->read = tomoyo_read_exception; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 2093 | break; |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 2094 | case TOMOYO_AUDIT: |
| 2095 | /* /sys/kernel/security/tomoyo/audit */ |
| 2096 | head->poll = tomoyo_poll_log; |
| 2097 | head->read = tomoyo_read_log; |
| 2098 | break; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 2099 | case TOMOYO_SELFDOMAIN: |
| 2100 | /* /sys/kernel/security/tomoyo/self_domain */ |
| 2101 | head->read = tomoyo_read_self_domain; |
| 2102 | break; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 2103 | case TOMOYO_PROCESS_STATUS: |
| 2104 | /* /sys/kernel/security/tomoyo/.process_status */ |
| 2105 | head->write = tomoyo_write_pid; |
| 2106 | head->read = tomoyo_read_pid; |
| 2107 | break; |
| 2108 | case TOMOYO_VERSION: |
| 2109 | /* /sys/kernel/security/tomoyo/version */ |
| 2110 | head->read = tomoyo_read_version; |
| 2111 | head->readbuf_size = 128; |
| 2112 | break; |
Tetsuo Handa | b22b8b9 | 2011-06-26 23:21:50 +0900 | [diff] [blame] | 2113 | case TOMOYO_STAT: |
| 2114 | /* /sys/kernel/security/tomoyo/stat */ |
| 2115 | head->write = tomoyo_write_stat; |
| 2116 | head->read = tomoyo_read_stat; |
| 2117 | head->readbuf_size = 1024; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 2118 | break; |
| 2119 | case TOMOYO_PROFILE: |
| 2120 | /* /sys/kernel/security/tomoyo/profile */ |
| 2121 | head->write = tomoyo_write_profile; |
| 2122 | head->read = tomoyo_read_profile; |
| 2123 | break; |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 2124 | case TOMOYO_QUERY: /* /sys/kernel/security/tomoyo/query */ |
| 2125 | head->poll = tomoyo_poll_query; |
| 2126 | head->write = tomoyo_write_answer; |
| 2127 | head->read = tomoyo_read_query; |
| 2128 | break; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 2129 | case TOMOYO_MANAGER: |
| 2130 | /* /sys/kernel/security/tomoyo/manager */ |
Tetsuo Handa | e2bf690 | 2010-06-25 11:16:00 +0900 | [diff] [blame] | 2131 | head->write = tomoyo_write_manager; |
| 2132 | head->read = tomoyo_read_manager; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 2133 | break; |
| 2134 | } |
| 2135 | if (!(file->f_mode & FMODE_READ)) { |
| 2136 | /* |
| 2137 | * No need to allocate read_buf since it is not opened |
| 2138 | * for reading. |
| 2139 | */ |
| 2140 | head->read = NULL; |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 2141 | head->poll = NULL; |
| 2142 | } else if (!head->poll) { |
| 2143 | /* Don't allocate read_buf for poll() access. */ |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 2144 | if (!head->readbuf_size) |
| 2145 | head->readbuf_size = 4096 * 2; |
Tetsuo Handa | 4e5d6f7 | 2010-04-28 14:17:42 +0900 | [diff] [blame] | 2146 | head->read_buf = kzalloc(head->readbuf_size, GFP_NOFS); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 2147 | if (!head->read_buf) { |
Tetsuo Handa | 8e2d39a | 2010-01-26 20:45:27 +0900 | [diff] [blame] | 2148 | kfree(head); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 2149 | return -ENOMEM; |
| 2150 | } |
| 2151 | } |
| 2152 | if (!(file->f_mode & FMODE_WRITE)) { |
| 2153 | /* |
| 2154 | * No need to allocate write_buf since it is not opened |
| 2155 | * for writing. |
| 2156 | */ |
| 2157 | head->write = NULL; |
| 2158 | } else if (head->write) { |
| 2159 | head->writebuf_size = 4096 * 2; |
Tetsuo Handa | 4e5d6f7 | 2010-04-28 14:17:42 +0900 | [diff] [blame] | 2160 | head->write_buf = kzalloc(head->writebuf_size, GFP_NOFS); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 2161 | if (!head->write_buf) { |
Tetsuo Handa | 8e2d39a | 2010-01-26 20:45:27 +0900 | [diff] [blame] | 2162 | kfree(head->read_buf); |
| 2163 | kfree(head); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 2164 | return -ENOMEM; |
| 2165 | } |
| 2166 | } |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 2167 | /* |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 2168 | * If the file is /sys/kernel/security/tomoyo/query , increment the |
| 2169 | * observer counter. |
| 2170 | * The obserber counter is used by tomoyo_supervisor() to see if |
| 2171 | * there is some process monitoring /sys/kernel/security/tomoyo/query. |
| 2172 | */ |
Tetsuo Handa | 7c75964 | 2011-06-26 23:15:31 +0900 | [diff] [blame] | 2173 | if (type == TOMOYO_QUERY) |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 2174 | atomic_inc(&tomoyo_query_observers); |
Tetsuo Handa | 2e503bb | 2011-06-26 23:20:55 +0900 | [diff] [blame] | 2175 | file->private_data = head; |
| 2176 | tomoyo_notify_gc(head, true); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 2177 | return 0; |
| 2178 | } |
| 2179 | |
| 2180 | /** |
Tetsuo Handa | 0849e3b | 2010-06-25 12:22:09 +0900 | [diff] [blame] | 2181 | * tomoyo_poll_control - poll() for /sys/kernel/security/tomoyo/ interface. |
| 2182 | * |
| 2183 | * @file: Pointer to "struct file". |
| 2184 | * @wait: Pointer to "poll_table". |
| 2185 | * |
| 2186 | * Waits for read readiness. |
Tetsuo Handa | eadd99c | 2011-06-26 23:18:58 +0900 | [diff] [blame] | 2187 | * /sys/kernel/security/tomoyo/query is handled by /usr/sbin/tomoyo-queryd and |
| 2188 | * /sys/kernel/security/tomoyo/audit is handled by /usr/sbin/tomoyo-auditd. |
Tetsuo Handa | 0849e3b | 2010-06-25 12:22:09 +0900 | [diff] [blame] | 2189 | */ |
| 2190 | int tomoyo_poll_control(struct file *file, poll_table *wait) |
| 2191 | { |
| 2192 | struct tomoyo_io_buffer *head = file->private_data; |
| 2193 | if (!head->poll) |
| 2194 | return -ENOSYS; |
| 2195 | return head->poll(file, wait); |
| 2196 | } |
| 2197 | |
| 2198 | /** |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 2199 | * tomoyo_set_namespace_cursor - Set namespace to read. |
| 2200 | * |
| 2201 | * @head: Pointer to "struct tomoyo_io_buffer". |
| 2202 | * |
| 2203 | * Returns nothing. |
| 2204 | */ |
| 2205 | static inline void tomoyo_set_namespace_cursor(struct tomoyo_io_buffer *head) |
| 2206 | { |
| 2207 | struct list_head *ns; |
| 2208 | if (head->type != TOMOYO_EXCEPTIONPOLICY && |
| 2209 | head->type != TOMOYO_PROFILE) |
| 2210 | return; |
| 2211 | /* |
| 2212 | * If this is the first read, or reading previous namespace finished |
| 2213 | * and has more namespaces to read, update the namespace cursor. |
| 2214 | */ |
| 2215 | ns = head->r.ns; |
| 2216 | if (!ns || (head->r.eof && ns->next != &tomoyo_namespace_list)) { |
| 2217 | /* Clearing is OK because tomoyo_flush() returned true. */ |
| 2218 | memset(&head->r, 0, sizeof(head->r)); |
| 2219 | head->r.ns = ns ? ns->next : tomoyo_namespace_list.next; |
| 2220 | } |
| 2221 | } |
| 2222 | |
| 2223 | /** |
| 2224 | * tomoyo_has_more_namespace - Check for unread namespaces. |
| 2225 | * |
| 2226 | * @head: Pointer to "struct tomoyo_io_buffer". |
| 2227 | * |
| 2228 | * Returns true if we have more entries to print, false otherwise. |
| 2229 | */ |
| 2230 | static inline bool tomoyo_has_more_namespace(struct tomoyo_io_buffer *head) |
| 2231 | { |
| 2232 | return (head->type == TOMOYO_EXCEPTIONPOLICY || |
| 2233 | head->type == TOMOYO_PROFILE) && head->r.eof && |
| 2234 | head->r.ns->next != &tomoyo_namespace_list; |
| 2235 | } |
| 2236 | |
| 2237 | /** |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 2238 | * tomoyo_read_control - read() for /sys/kernel/security/tomoyo/ interface. |
| 2239 | * |
Tetsuo Handa | 0df7e8b | 2011-06-26 23:16:36 +0900 | [diff] [blame] | 2240 | * @head: Pointer to "struct tomoyo_io_buffer". |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 2241 | * @buffer: Poiner to buffer to write to. |
| 2242 | * @buffer_len: Size of @buffer. |
| 2243 | * |
| 2244 | * Returns bytes read on success, negative value otherwise. |
| 2245 | */ |
Tetsuo Handa | 2c47ab9 | 2011-06-26 23:21:19 +0900 | [diff] [blame] | 2246 | ssize_t tomoyo_read_control(struct tomoyo_io_buffer *head, char __user *buffer, |
| 2247 | const int buffer_len) |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 2248 | { |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 2249 | int len; |
Tetsuo Handa | 2e503bb | 2011-06-26 23:20:55 +0900 | [diff] [blame] | 2250 | int idx; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 2251 | |
| 2252 | if (!head->read) |
| 2253 | return -ENOSYS; |
| 2254 | if (mutex_lock_interruptible(&head->io_sem)) |
| 2255 | return -EINTR; |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 2256 | head->read_user_buf = buffer; |
| 2257 | head->read_user_buf_avail = buffer_len; |
Tetsuo Handa | 2e503bb | 2011-06-26 23:20:55 +0900 | [diff] [blame] | 2258 | idx = tomoyo_read_lock(); |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 2259 | if (tomoyo_flush(head)) |
| 2260 | /* Call the policy handler. */ |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 2261 | do { |
| 2262 | tomoyo_set_namespace_cursor(head); |
| 2263 | head->read(head); |
| 2264 | } while (tomoyo_flush(head) && |
| 2265 | tomoyo_has_more_namespace(head)); |
Tetsuo Handa | 2e503bb | 2011-06-26 23:20:55 +0900 | [diff] [blame] | 2266 | tomoyo_read_unlock(idx); |
Tetsuo Handa | f23571e | 2010-06-24 14:57:16 +0900 | [diff] [blame] | 2267 | len = head->read_user_buf - buffer; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 2268 | mutex_unlock(&head->io_sem); |
| 2269 | return len; |
| 2270 | } |
| 2271 | |
| 2272 | /** |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 2273 | * tomoyo_parse_policy - Parse a policy line. |
| 2274 | * |
| 2275 | * @head: Poiter to "struct tomoyo_io_buffer". |
| 2276 | * @line: Line to parse. |
| 2277 | * |
| 2278 | * Returns 0 on success, negative value otherwise. |
| 2279 | * |
| 2280 | * Caller holds tomoyo_read_lock(). |
| 2281 | */ |
| 2282 | static int tomoyo_parse_policy(struct tomoyo_io_buffer *head, char *line) |
| 2283 | { |
| 2284 | /* Delete request? */ |
| 2285 | head->w.is_delete = !strncmp(line, "delete ", 7); |
| 2286 | if (head->w.is_delete) |
| 2287 | memmove(line, line + 7, strlen(line + 7) + 1); |
| 2288 | /* Selecting namespace to update. */ |
| 2289 | if (head->type == TOMOYO_EXCEPTIONPOLICY || |
| 2290 | head->type == TOMOYO_PROFILE) { |
| 2291 | if (*line == '<') { |
| 2292 | char *cp = strchr(line, ' '); |
| 2293 | if (cp) { |
| 2294 | *cp++ = '\0'; |
| 2295 | head->w.ns = tomoyo_assign_namespace(line); |
| 2296 | memmove(line, cp, strlen(cp) + 1); |
| 2297 | } else |
| 2298 | head->w.ns = NULL; |
| 2299 | } else |
| 2300 | head->w.ns = &tomoyo_kernel_namespace; |
| 2301 | /* Don't allow updating if namespace is invalid. */ |
| 2302 | if (!head->w.ns) |
| 2303 | return -ENOENT; |
| 2304 | } |
| 2305 | /* Do the update. */ |
| 2306 | return head->write(head); |
| 2307 | } |
| 2308 | |
| 2309 | /** |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 2310 | * tomoyo_write_control - write() for /sys/kernel/security/tomoyo/ interface. |
| 2311 | * |
Tetsuo Handa | 0df7e8b | 2011-06-26 23:16:36 +0900 | [diff] [blame] | 2312 | * @head: Pointer to "struct tomoyo_io_buffer". |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 2313 | * @buffer: Pointer to buffer to read from. |
| 2314 | * @buffer_len: Size of @buffer. |
| 2315 | * |
| 2316 | * Returns @buffer_len on success, negative value otherwise. |
| 2317 | */ |
Tetsuo Handa | 2c47ab9 | 2011-06-26 23:21:19 +0900 | [diff] [blame] | 2318 | ssize_t tomoyo_write_control(struct tomoyo_io_buffer *head, |
| 2319 | const char __user *buffer, const int buffer_len) |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 2320 | { |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 2321 | int error = buffer_len; |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 2322 | size_t avail_len = buffer_len; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 2323 | char *cp0 = head->write_buf; |
Tetsuo Handa | 2e503bb | 2011-06-26 23:20:55 +0900 | [diff] [blame] | 2324 | int idx; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 2325 | if (!head->write) |
| 2326 | return -ENOSYS; |
| 2327 | if (!access_ok(VERIFY_READ, buffer, buffer_len)) |
| 2328 | return -EFAULT; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 2329 | if (mutex_lock_interruptible(&head->io_sem)) |
| 2330 | return -EINTR; |
Tetsuo Handa | 2e503bb | 2011-06-26 23:20:55 +0900 | [diff] [blame] | 2331 | idx = tomoyo_read_lock(); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 2332 | /* Read a line and dispatch it to the policy handler. */ |
| 2333 | while (avail_len > 0) { |
| 2334 | char c; |
Tetsuo Handa | 0df7e8b | 2011-06-26 23:16:36 +0900 | [diff] [blame] | 2335 | if (head->w.avail >= head->writebuf_size - 1) { |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 2336 | const int len = head->writebuf_size * 2; |
| 2337 | char *cp = kzalloc(len, GFP_NOFS); |
| 2338 | if (!cp) { |
| 2339 | error = -ENOMEM; |
| 2340 | break; |
| 2341 | } |
| 2342 | memmove(cp, cp0, head->w.avail); |
| 2343 | kfree(cp0); |
| 2344 | head->write_buf = cp; |
| 2345 | cp0 = cp; |
| 2346 | head->writebuf_size = len; |
| 2347 | } |
| 2348 | if (get_user(c, buffer)) { |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 2349 | error = -EFAULT; |
| 2350 | break; |
| 2351 | } |
| 2352 | buffer++; |
| 2353 | avail_len--; |
Tetsuo Handa | 0df7e8b | 2011-06-26 23:16:36 +0900 | [diff] [blame] | 2354 | cp0[head->w.avail++] = c; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 2355 | if (c != '\n') |
| 2356 | continue; |
Tetsuo Handa | 0df7e8b | 2011-06-26 23:16:36 +0900 | [diff] [blame] | 2357 | cp0[head->w.avail - 1] = '\0'; |
| 2358 | head->w.avail = 0; |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 2359 | tomoyo_normalize_line(cp0); |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 2360 | if (!strcmp(cp0, "reset")) { |
| 2361 | head->w.ns = &tomoyo_kernel_namespace; |
| 2362 | head->w.domain = NULL; |
| 2363 | memset(&head->r, 0, sizeof(head->r)); |
| 2364 | continue; |
| 2365 | } |
| 2366 | /* Don't allow updating policies by non manager programs. */ |
| 2367 | switch (head->type) { |
| 2368 | case TOMOYO_PROCESS_STATUS: |
| 2369 | /* This does not write anything. */ |
| 2370 | break; |
| 2371 | case TOMOYO_DOMAINPOLICY: |
| 2372 | if (tomoyo_select_domain(head, cp0)) |
| 2373 | continue; |
| 2374 | /* fall through */ |
| 2375 | case TOMOYO_EXCEPTIONPOLICY: |
| 2376 | if (!strcmp(cp0, "select transition_only")) { |
| 2377 | head->r.print_transition_related_only = true; |
| 2378 | continue; |
| 2379 | } |
| 2380 | /* fall through */ |
| 2381 | default: |
| 2382 | if (!tomoyo_manager()) { |
| 2383 | error = -EPERM; |
| 2384 | goto out; |
| 2385 | } |
| 2386 | } |
| 2387 | switch (tomoyo_parse_policy(head, cp0)) { |
| 2388 | case -EPERM: |
| 2389 | error = -EPERM; |
| 2390 | goto out; |
Tetsuo Handa | b22b8b9 | 2011-06-26 23:21:50 +0900 | [diff] [blame] | 2391 | case 0: |
| 2392 | switch (head->type) { |
| 2393 | case TOMOYO_DOMAINPOLICY: |
| 2394 | case TOMOYO_EXCEPTIONPOLICY: |
Tetsuo Handa | b22b8b9 | 2011-06-26 23:21:50 +0900 | [diff] [blame] | 2395 | case TOMOYO_STAT: |
| 2396 | case TOMOYO_PROFILE: |
| 2397 | case TOMOYO_MANAGER: |
| 2398 | tomoyo_update_stat(TOMOYO_STAT_POLICY_UPDATES); |
| 2399 | break; |
| 2400 | default: |
| 2401 | break; |
| 2402 | } |
| 2403 | break; |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 2404 | } |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 2405 | } |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 2406 | out: |
Tetsuo Handa | 2e503bb | 2011-06-26 23:20:55 +0900 | [diff] [blame] | 2407 | tomoyo_read_unlock(idx); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 2408 | mutex_unlock(&head->io_sem); |
| 2409 | return error; |
| 2410 | } |
| 2411 | |
| 2412 | /** |
| 2413 | * tomoyo_close_control - close() for /sys/kernel/security/tomoyo/ interface. |
| 2414 | * |
Tetsuo Handa | 0df7e8b | 2011-06-26 23:16:36 +0900 | [diff] [blame] | 2415 | * @head: Pointer to "struct tomoyo_io_buffer". |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 2416 | * |
Tetsuo Handa | 2e503bb | 2011-06-26 23:20:55 +0900 | [diff] [blame] | 2417 | * Returns 0. |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 2418 | */ |
Tetsuo Handa | 0df7e8b | 2011-06-26 23:16:36 +0900 | [diff] [blame] | 2419 | int tomoyo_close_control(struct tomoyo_io_buffer *head) |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 2420 | { |
Tetsuo Handa | 17fcfbd | 2010-05-17 10:11:36 +0900 | [diff] [blame] | 2421 | /* |
| 2422 | * If the file is /sys/kernel/security/tomoyo/query , decrement the |
| 2423 | * observer counter. |
| 2424 | */ |
Tetsuo Handa | 2e503bb | 2011-06-26 23:20:55 +0900 | [diff] [blame] | 2425 | if (head->type == TOMOYO_QUERY && |
| 2426 | atomic_dec_and_test(&tomoyo_query_observers)) |
| 2427 | wake_up_all(&tomoyo_answer_wait); |
| 2428 | tomoyo_notify_gc(head, false); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 2429 | return 0; |
| 2430 | } |
| 2431 | |
| 2432 | /** |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 2433 | * tomoyo_check_profile - Check all profiles currently assigned to domains are defined. |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 2434 | */ |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 2435 | void tomoyo_check_profile(void) |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 2436 | { |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 2437 | struct tomoyo_domain_info *domain; |
| 2438 | const int idx = tomoyo_read_lock(); |
| 2439 | tomoyo_policy_loaded = true; |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 2440 | printk(KERN_INFO "TOMOYO: 2.4.0\n"); |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 2441 | list_for_each_entry_rcu(domain, &tomoyo_domain_list, list) { |
| 2442 | const u8 profile = domain->profile; |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 2443 | const struct tomoyo_policy_namespace *ns = domain->ns; |
| 2444 | if (ns->profile_version != 20100903) |
| 2445 | printk(KERN_ERR |
| 2446 | "Profile version %u is not supported.\n", |
| 2447 | ns->profile_version); |
| 2448 | else if (!ns->profile_ptr[profile]) |
| 2449 | printk(KERN_ERR |
| 2450 | "Profile %u (used by '%s') is not defined.\n", |
| 2451 | profile, domain->domainname->name); |
| 2452 | else |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 2453 | continue; |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 2454 | printk(KERN_ERR |
| 2455 | "Userland tools for TOMOYO 2.4 must be installed and " |
| 2456 | "policy must be initialized.\n"); |
| 2457 | printk(KERN_ERR "Please see http://tomoyo.sourceforge.jp/2.4/ " |
Tetsuo Handa | 9f1c1d4 | 2010-10-08 14:43:22 +0900 | [diff] [blame] | 2458 | "for more information.\n"); |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 2459 | panic("STOP!"); |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 2460 | } |
| 2461 | tomoyo_read_unlock(idx); |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 2462 | printk(KERN_INFO "Mandatory Access Control activated.\n"); |
Kentaro Takeda | 9590837 | 2009-02-05 17:18:13 +0900 | [diff] [blame] | 2463 | } |
Tetsuo Handa | efe836a | 2011-06-26 23:22:18 +0900 | [diff] [blame] | 2464 | |
| 2465 | /** |
| 2466 | * tomoyo_load_builtin_policy - Load built-in policy. |
| 2467 | * |
| 2468 | * Returns nothing. |
| 2469 | */ |
| 2470 | void __init tomoyo_load_builtin_policy(void) |
| 2471 | { |
| 2472 | /* |
| 2473 | * This include file is manually created and contains built-in policy |
| 2474 | * named "tomoyo_builtin_profile", "tomoyo_builtin_exception_policy", |
| 2475 | * "tomoyo_builtin_domain_policy", "tomoyo_builtin_manager", |
| 2476 | * "tomoyo_builtin_stat" in the form of "static char [] __initdata". |
| 2477 | */ |
| 2478 | #include "builtin-policy.h" |
| 2479 | u8 i; |
| 2480 | const int idx = tomoyo_read_lock(); |
| 2481 | for (i = 0; i < 5; i++) { |
| 2482 | struct tomoyo_io_buffer head = { }; |
| 2483 | char *start = ""; |
| 2484 | switch (i) { |
| 2485 | case 0: |
| 2486 | start = tomoyo_builtin_profile; |
| 2487 | head.type = TOMOYO_PROFILE; |
| 2488 | head.write = tomoyo_write_profile; |
| 2489 | break; |
| 2490 | case 1: |
| 2491 | start = tomoyo_builtin_exception_policy; |
| 2492 | head.type = TOMOYO_EXCEPTIONPOLICY; |
| 2493 | head.write = tomoyo_write_exception; |
| 2494 | break; |
| 2495 | case 2: |
| 2496 | start = tomoyo_builtin_domain_policy; |
| 2497 | head.type = TOMOYO_DOMAINPOLICY; |
| 2498 | head.write = tomoyo_write_domain; |
| 2499 | break; |
| 2500 | case 3: |
| 2501 | start = tomoyo_builtin_manager; |
| 2502 | head.type = TOMOYO_MANAGER; |
| 2503 | head.write = tomoyo_write_manager; |
| 2504 | break; |
| 2505 | case 4: |
| 2506 | start = tomoyo_builtin_stat; |
| 2507 | head.type = TOMOYO_STAT; |
| 2508 | head.write = tomoyo_write_stat; |
| 2509 | break; |
| 2510 | } |
| 2511 | while (1) { |
| 2512 | char *end = strchr(start, '\n'); |
| 2513 | if (!end) |
| 2514 | break; |
| 2515 | *end = '\0'; |
| 2516 | tomoyo_normalize_line(start); |
| 2517 | head.write_buf = start; |
| 2518 | tomoyo_parse_policy(&head, start); |
| 2519 | start = end + 1; |
| 2520 | } |
| 2521 | } |
| 2522 | tomoyo_read_unlock(idx); |
Tetsuo Handa | 0e4ae0e | 2011-06-26 23:22:59 +0900 | [diff] [blame] | 2523 | #ifdef CONFIG_SECURITY_TOMOYO_OMIT_USERSPACE_LOADER |
| 2524 | tomoyo_check_profile(); |
| 2525 | #endif |
Tetsuo Handa | efe836a | 2011-06-26 23:22:18 +0900 | [diff] [blame] | 2526 | } |