Lines Matching full:head
201 * @head: Pointer to "struct tomoyo_io_buffer".
205 static bool tomoyo_flush(struct tomoyo_io_buffer *head) in tomoyo_flush() argument
207 while (head->r.w_pos) { in tomoyo_flush()
208 const char *w = head->r.w[0]; in tomoyo_flush()
212 if (len > head->read_user_buf_avail) in tomoyo_flush()
213 len = head->read_user_buf_avail; in tomoyo_flush()
216 if (copy_to_user(head->read_user_buf, w, len)) in tomoyo_flush()
218 head->read_user_buf_avail -= len; in tomoyo_flush()
219 head->read_user_buf += len; in tomoyo_flush()
222 head->r.w[0] = w; in tomoyo_flush()
226 if (head->poll) { in tomoyo_flush()
227 if (!head->read_user_buf_avail || in tomoyo_flush()
228 copy_to_user(head->read_user_buf, "", 1)) in tomoyo_flush()
230 head->read_user_buf_avail--; in tomoyo_flush()
231 head->read_user_buf++; in tomoyo_flush()
233 head->r.w_pos--; in tomoyo_flush()
234 for (len = 0; len < head->r.w_pos; len++) in tomoyo_flush()
235 head->r.w[len] = head->r.w[len + 1]; in tomoyo_flush()
237 head->r.avail = 0; in tomoyo_flush()
244 * @head: Pointer to "struct tomoyo_io_buffer".
247 * Note that @string has to be kept valid until @head is kfree()d.
251 static void tomoyo_set_string(struct tomoyo_io_buffer *head, const char *string) in tomoyo_set_string() argument
253 if (head->r.w_pos < TOMOYO_MAX_IO_READ_QUEUE) { in tomoyo_set_string()
254 head->r.w[head->r.w_pos++] = string; in tomoyo_set_string()
255 tomoyo_flush(head); in tomoyo_set_string()
260 static void tomoyo_io_printf(struct tomoyo_io_buffer *head, const char *fmt,
266 * @head: Pointer to "struct tomoyo_io_buffer".
269 static void tomoyo_io_printf(struct tomoyo_io_buffer *head, const char *fmt, in tomoyo_io_printf() argument
274 size_t pos = head->r.avail; in tomoyo_io_printf()
275 int size = head->readbuf_size - pos; in tomoyo_io_printf()
280 len = vsnprintf(head->read_buf + pos, size, fmt, args) + 1; in tomoyo_io_printf()
282 if (pos + len >= head->readbuf_size) { in tomoyo_io_printf()
286 head->r.avail += len; in tomoyo_io_printf()
287 tomoyo_set_string(head, head->read_buf + pos); in tomoyo_io_printf()
293 * @head: Pointer to "struct tomoyo_io_buffer".
297 static void tomoyo_set_space(struct tomoyo_io_buffer *head) in tomoyo_set_space() argument
299 tomoyo_set_string(head, " "); in tomoyo_set_space()
305 * @head: Pointer to "struct tomoyo_io_buffer".
309 static bool tomoyo_set_lf(struct tomoyo_io_buffer *head) in tomoyo_set_lf() argument
311 tomoyo_set_string(head, "\n"); in tomoyo_set_lf()
312 return !head->r.w_pos; in tomoyo_set_lf()
318 * @head: Pointer to "struct tomoyo_io_buffer".
322 static void tomoyo_set_slash(struct tomoyo_io_buffer *head) in tomoyo_set_slash() argument
324 tomoyo_set_string(head, "/"); in tomoyo_set_slash()
357 * @head: Pointer to "struct tomoyo_io_buffer".
361 static void tomoyo_print_namespace(struct tomoyo_io_buffer *head) in tomoyo_print_namespace() argument
365 tomoyo_set_string(head, in tomoyo_print_namespace()
366 container_of(head->r.ns, in tomoyo_print_namespace()
369 tomoyo_set_space(head); in tomoyo_print_namespace()
375 * @head: Pointer to "struct tomoyo_io_buffer".
378 static void tomoyo_print_name_union(struct tomoyo_io_buffer *head, in tomoyo_print_name_union() argument
381 tomoyo_set_space(head); in tomoyo_print_name_union()
383 tomoyo_set_string(head, "@"); in tomoyo_print_name_union()
384 tomoyo_set_string(head, ptr->group->group_name->name); in tomoyo_print_name_union()
386 tomoyo_set_string(head, ptr->filename->name); in tomoyo_print_name_union()
393 * @head: Pointer to "struct tomoyo_io_buffer".
398 static void tomoyo_print_name_union_quoted(struct tomoyo_io_buffer *head, in tomoyo_print_name_union_quoted() argument
402 tomoyo_set_string(head, "@"); in tomoyo_print_name_union_quoted()
403 tomoyo_set_string(head, ptr->group->group_name->name); in tomoyo_print_name_union_quoted()
405 tomoyo_set_string(head, "\""); in tomoyo_print_name_union_quoted()
406 tomoyo_set_string(head, ptr->filename->name); in tomoyo_print_name_union_quoted()
407 tomoyo_set_string(head, "\""); in tomoyo_print_name_union_quoted()
414 * @head: Pointer to "struct tomoyo_io_buffer".
420 (struct tomoyo_io_buffer *head, const struct tomoyo_number_union *ptr) in tomoyo_print_number_union_nospace() argument
423 tomoyo_set_string(head, "@"); in tomoyo_print_number_union_nospace()
424 tomoyo_set_string(head, ptr->group->group_name->name); in tomoyo_print_number_union_nospace()
455 tomoyo_io_printf(head, "%s", buffer); in tomoyo_print_number_union_nospace()
462 * @head: Pointer to "struct tomoyo_io_buffer".
467 static void tomoyo_print_number_union(struct tomoyo_io_buffer *head, in tomoyo_print_number_union() argument
470 tomoyo_set_space(head); in tomoyo_print_number_union()
471 tomoyo_print_number_union_nospace(head, ptr); in tomoyo_print_number_union()
662 * @head: Pointer to "struct tomoyo_io_buffer".
666 static int tomoyo_write_profile(struct tomoyo_io_buffer *head) in tomoyo_write_profile() argument
668 char *data = head->write_buf; in tomoyo_write_profile()
673 if (sscanf(data, "PROFILE_VERSION=%u", &head->w.ns->profile_version) in tomoyo_write_profile()
680 profile = tomoyo_assign_profile(head->w.ns, i); in tomoyo_write_profile()
714 * @head: Pointer to "struct tomoyo_io_buffer".
721 static void tomoyo_print_config(struct tomoyo_io_buffer *head, const u8 config) in tomoyo_print_config() argument
723 tomoyo_io_printf(head, "={ mode=%s grant_log=%s reject_log=%s }\n", in tomoyo_print_config()
732 * @head: Pointer to "struct tomoyo_io_buffer".
736 static void tomoyo_read_profile(struct tomoyo_io_buffer *head) in tomoyo_read_profile() argument
740 container_of(head->r.ns, typeof(*ns), namespace_list); in tomoyo_read_profile()
743 if (head->r.eof) in tomoyo_read_profile()
746 index = head->r.index; in tomoyo_read_profile()
748 switch (head->r.step) { in tomoyo_read_profile()
750 tomoyo_print_namespace(head); in tomoyo_read_profile()
751 tomoyo_io_printf(head, "PROFILE_VERSION=%u\n", in tomoyo_read_profile()
753 head->r.step++; in tomoyo_read_profile()
756 for ( ; head->r.index < TOMOYO_MAX_PROFILES; in tomoyo_read_profile()
757 head->r.index++) in tomoyo_read_profile()
758 if (ns->profile_ptr[head->r.index]) in tomoyo_read_profile()
760 if (head->r.index == TOMOYO_MAX_PROFILES) { in tomoyo_read_profile()
761 head->r.eof = true; in tomoyo_read_profile()
764 head->r.step++; in tomoyo_read_profile()
772 tomoyo_print_namespace(head); in tomoyo_read_profile()
773 tomoyo_io_printf(head, "%u-COMMENT=", index); in tomoyo_read_profile()
774 tomoyo_set_string(head, comment ? comment->name : ""); in tomoyo_read_profile()
775 tomoyo_set_lf(head); in tomoyo_read_profile()
776 tomoyo_print_namespace(head); in tomoyo_read_profile()
777 tomoyo_io_printf(head, "%u-PREFERENCE={ ", index); in tomoyo_read_profile()
779 tomoyo_io_printf(head, "%s=%u ", in tomoyo_read_profile()
782 tomoyo_set_string(head, "}\n"); in tomoyo_read_profile()
783 head->r.step++; in tomoyo_read_profile()
788 tomoyo_print_namespace(head); in tomoyo_read_profile()
789 tomoyo_io_printf(head, "%u-%s", index, "CONFIG"); in tomoyo_read_profile()
790 tomoyo_print_config(head, profile->default_config); in tomoyo_read_profile()
791 head->r.bit = 0; in tomoyo_read_profile()
792 head->r.step++; in tomoyo_read_profile()
796 for ( ; head->r.bit < TOMOYO_MAX_MAC_INDEX in tomoyo_read_profile()
797 + TOMOYO_MAX_MAC_CATEGORY_INDEX; head->r.bit++) { in tomoyo_read_profile()
798 const u8 i = head->r.bit; in tomoyo_read_profile()
803 tomoyo_print_namespace(head); in tomoyo_read_profile()
805 tomoyo_io_printf(head, "%u-CONFIG::%s::%s", in tomoyo_read_profile()
811 tomoyo_io_printf(head, "%u-CONFIG::%s", index, in tomoyo_read_profile()
813 tomoyo_print_config(head, config); in tomoyo_read_profile()
814 head->r.bit++; in tomoyo_read_profile()
817 if (head->r.bit == TOMOYO_MAX_MAC_INDEX in tomoyo_read_profile()
819 head->r.index++; in tomoyo_read_profile()
820 head->r.step = 1; in tomoyo_read_profile()
824 if (tomoyo_flush(head)) in tomoyo_read_profile()
839 return container_of(a, struct tomoyo_manager, head)->manager == in tomoyo_same_manager()
840 container_of(b, struct tomoyo_manager, head)->manager; in tomoyo_same_manager()
869 error = tomoyo_update_policy(&e.head, sizeof(e), ¶m, in tomoyo_update_manager_entry()
879 * @head: Pointer to "struct tomoyo_io_buffer".
885 static int tomoyo_write_manager(struct tomoyo_io_buffer *head) in tomoyo_write_manager() argument
887 char *data = head->write_buf; in tomoyo_write_manager()
890 tomoyo_manage_by_non_root = !head->w.is_delete; in tomoyo_write_manager()
893 return tomoyo_update_manager_entry(data, head->w.is_delete); in tomoyo_write_manager()
899 * @head: Pointer to "struct tomoyo_io_buffer".
903 static void tomoyo_read_manager(struct tomoyo_io_buffer *head) in tomoyo_read_manager() argument
905 if (head->r.eof) in tomoyo_read_manager()
907 list_for_each_cookie(head->r.acl, &tomoyo_kernel_namespace.policy_list[TOMOYO_ID_MANAGER]) { in tomoyo_read_manager()
909 list_entry(head->r.acl, typeof(*ptr), head.list); in tomoyo_read_manager()
911 if (ptr->head.is_deleted) in tomoyo_read_manager()
913 if (!tomoyo_flush(head)) in tomoyo_read_manager()
915 tomoyo_set_string(head, ptr->manager->name); in tomoyo_read_manager()
916 tomoyo_set_lf(head); in tomoyo_read_manager()
918 head->r.eof = true; in tomoyo_read_manager()
946 list_for_each_entry_rcu(ptr, &tomoyo_kernel_namespace.policy_list[TOMOYO_ID_MANAGER], head.list, in tomoyo_manager()
948 if (!ptr->head.is_deleted && in tomoyo_manager()
975 * @head: Pointer to "struct tomoyo_io_buffer".
982 static bool tomoyo_select_domain(struct tomoyo_io_buffer *head, in tomoyo_select_domain() argument
1011 head->w.domain = domain; in tomoyo_select_domain()
1012 /* Accessing read_buf is safe because head->io_sem is held. */ in tomoyo_select_domain()
1013 if (!head->read_buf) in tomoyo_select_domain()
1015 memset(&head->r, 0, sizeof(head->r)); in tomoyo_select_domain()
1016 head->r.print_this_domain_only = true; in tomoyo_select_domain()
1018 head->r.domain = &domain->list; in tomoyo_select_domain()
1020 head->r.eof = true; in tomoyo_select_domain()
1021 tomoyo_io_printf(head, "# select %s\n", data); in tomoyo_select_domain()
1023 tomoyo_io_printf(head, "# This is a deleted domain.\n"); in tomoyo_select_domain()
1038 const struct tomoyo_task_acl *p1 = container_of(a, typeof(*p1), head); in tomoyo_same_task_acl()
1039 const struct tomoyo_task_acl *p2 = container_of(b, typeof(*p2), head); in tomoyo_same_task_acl()
1059 .head.type = TOMOYO_TYPE_MANUAL_TASK_ACL, in tomoyo_write_task()
1064 error = tomoyo_update_domain(&e.head, sizeof(e), param, in tomoyo_write_task()
1158 * @head: Pointer to "struct tomoyo_io_buffer".
1164 static int tomoyo_write_domain(struct tomoyo_io_buffer *head) in tomoyo_write_domain() argument
1166 char *data = head->write_buf; in tomoyo_write_domain()
1168 struct tomoyo_domain_info *domain = head->w.domain; in tomoyo_write_domain()
1169 const bool is_delete = head->w.is_delete; in tomoyo_write_domain()
1183 head->w.domain = domain; in tomoyo_write_domain()
1219 * @head: Pointer to "struct tomoyo_io_buffer".
1224 static bool tomoyo_print_condition(struct tomoyo_io_buffer *head, in tomoyo_print_condition() argument
1227 switch (head->r.cond_step) { in tomoyo_print_condition()
1229 head->r.cond_index = 0; in tomoyo_print_condition()
1230 head->r.cond_step++; in tomoyo_print_condition()
1232 tomoyo_set_space(head); in tomoyo_print_condition()
1233 tomoyo_set_string(head, cond->transit->name); in tomoyo_print_condition()
1252 for (skip = 0; skip < head->r.cond_index; skip++) { in tomoyo_print_condition()
1277 while (head->r.cond_index < condc) { in tomoyo_print_condition()
1282 if (!tomoyo_flush(head)) in tomoyo_print_condition()
1285 head->r.cond_index++; in tomoyo_print_condition()
1286 tomoyo_set_space(head); in tomoyo_print_condition()
1289 tomoyo_io_printf(head, in tomoyo_print_condition()
1292 tomoyo_set_string(head, in tomoyo_print_condition()
1294 tomoyo_set_string(head, "\""); in tomoyo_print_condition()
1298 tomoyo_set_string(head, in tomoyo_print_condition()
1300 tomoyo_set_string(head, in tomoyo_print_condition()
1302 tomoyo_io_printf(head, "\"]%s=", envp->is_not ? "!" : ""); in tomoyo_print_condition()
1304 tomoyo_set_string(head, "\""); in tomoyo_print_condition()
1305 tomoyo_set_string(head, envp->value->name); in tomoyo_print_condition()
1306 tomoyo_set_string(head, "\""); in tomoyo_print_condition()
1308 tomoyo_set_string(head, in tomoyo_print_condition()
1315 (head, numbers_p++); in tomoyo_print_condition()
1318 tomoyo_set_string(head, in tomoyo_print_condition()
1322 tomoyo_set_string(head, match ? "=" : "!="); in tomoyo_print_condition()
1326 (head, names_p++); in tomoyo_print_condition()
1330 (head, numbers_p++); in tomoyo_print_condition()
1333 tomoyo_set_string(head, in tomoyo_print_condition()
1339 head->r.cond_step++; in tomoyo_print_condition()
1342 if (!tomoyo_flush(head)) in tomoyo_print_condition()
1344 head->r.cond_step++; in tomoyo_print_condition()
1348 tomoyo_io_printf(head, " grant_log=%s", in tomoyo_print_condition()
1351 tomoyo_set_lf(head); in tomoyo_print_condition()
1360 * @head: Pointer to "struct tomoyo_io_buffer".
1365 static void tomoyo_set_group(struct tomoyo_io_buffer *head, in tomoyo_set_group() argument
1368 if (head->type == TOMOYO_EXCEPTIONPOLICY) { in tomoyo_set_group()
1369 tomoyo_print_namespace(head); in tomoyo_set_group()
1370 tomoyo_io_printf(head, "acl_group %u ", in tomoyo_set_group()
1371 head->r.acl_group_index); in tomoyo_set_group()
1373 tomoyo_set_string(head, category); in tomoyo_set_group()
1379 * @head: Pointer to "struct tomoyo_io_buffer".
1384 static bool tomoyo_print_entry(struct tomoyo_io_buffer *head, in tomoyo_print_entry() argument
1391 if (head->r.print_cond_part) in tomoyo_print_entry()
1395 if (!tomoyo_flush(head)) in tomoyo_print_entry()
1399 container_of(acl, typeof(*ptr), head); in tomoyo_print_entry()
1405 if (head->r.print_transition_related_only && in tomoyo_print_entry()
1409 tomoyo_set_group(head, "file "); in tomoyo_print_entry()
1412 tomoyo_set_slash(head); in tomoyo_print_entry()
1414 tomoyo_set_string(head, tomoyo_path_keyword[bit]); in tomoyo_print_entry()
1418 tomoyo_print_name_union(head, &ptr->name); in tomoyo_print_entry()
1421 container_of(acl, typeof(*ptr), head); in tomoyo_print_entry()
1423 tomoyo_set_group(head, "task "); in tomoyo_print_entry()
1424 tomoyo_set_string(head, "manual_domain_transition "); in tomoyo_print_entry()
1425 tomoyo_set_string(head, ptr->domainname->name); in tomoyo_print_entry()
1426 } else if (head->r.print_transition_related_only) { in tomoyo_print_entry()
1430 container_of(acl, typeof(*ptr), head); in tomoyo_print_entry()
1437 tomoyo_set_group(head, "file "); in tomoyo_print_entry()
1440 tomoyo_set_slash(head); in tomoyo_print_entry()
1442 tomoyo_set_string(head, tomoyo_mac_keywords in tomoyo_print_entry()
1447 tomoyo_print_name_union(head, &ptr->name1); in tomoyo_print_entry()
1448 tomoyo_print_name_union(head, &ptr->name2); in tomoyo_print_entry()
1451 container_of(acl, typeof(*ptr), head); in tomoyo_print_entry()
1458 tomoyo_set_group(head, "file "); in tomoyo_print_entry()
1461 tomoyo_set_slash(head); in tomoyo_print_entry()
1463 tomoyo_set_string(head, tomoyo_mac_keywords in tomoyo_print_entry()
1468 tomoyo_print_name_union(head, &ptr->name); in tomoyo_print_entry()
1469 tomoyo_print_number_union(head, &ptr->number); in tomoyo_print_entry()
1472 container_of(acl, typeof(*ptr), head); in tomoyo_print_entry()
1479 tomoyo_set_group(head, "file "); in tomoyo_print_entry()
1482 tomoyo_set_slash(head); in tomoyo_print_entry()
1484 tomoyo_set_string(head, tomoyo_mac_keywords in tomoyo_print_entry()
1489 tomoyo_print_name_union(head, &ptr->name); in tomoyo_print_entry()
1490 tomoyo_print_number_union(head, &ptr->mode); in tomoyo_print_entry()
1491 tomoyo_print_number_union(head, &ptr->major); in tomoyo_print_entry()
1492 tomoyo_print_number_union(head, &ptr->minor); in tomoyo_print_entry()
1495 container_of(acl, typeof(*ptr), head); in tomoyo_print_entry()
1502 tomoyo_set_group(head, "network inet "); in tomoyo_print_entry()
1503 tomoyo_set_string(head, tomoyo_proto_keyword in tomoyo_print_entry()
1505 tomoyo_set_space(head); in tomoyo_print_entry()
1508 tomoyo_set_slash(head); in tomoyo_print_entry()
1510 tomoyo_set_string(head, tomoyo_socket_keyword[bit]); in tomoyo_print_entry()
1514 tomoyo_set_space(head); in tomoyo_print_entry()
1516 tomoyo_set_string(head, "@"); in tomoyo_print_entry()
1517 tomoyo_set_string(head, ptr->address.group->group_name in tomoyo_print_entry()
1523 tomoyo_io_printf(head, "%s", buf); in tomoyo_print_entry()
1525 tomoyo_print_number_union(head, &ptr->port); in tomoyo_print_entry()
1528 container_of(acl, typeof(*ptr), head); in tomoyo_print_entry()
1535 tomoyo_set_group(head, "network unix "); in tomoyo_print_entry()
1536 tomoyo_set_string(head, tomoyo_proto_keyword in tomoyo_print_entry()
1538 tomoyo_set_space(head); in tomoyo_print_entry()
1541 tomoyo_set_slash(head); in tomoyo_print_entry()
1543 tomoyo_set_string(head, tomoyo_socket_keyword[bit]); in tomoyo_print_entry()
1547 tomoyo_print_name_union(head, &ptr->name); in tomoyo_print_entry()
1550 container_of(acl, typeof(*ptr), head); in tomoyo_print_entry()
1552 tomoyo_set_group(head, "file mount"); in tomoyo_print_entry()
1553 tomoyo_print_name_union(head, &ptr->dev_name); in tomoyo_print_entry()
1554 tomoyo_print_name_union(head, &ptr->dir_name); in tomoyo_print_entry()
1555 tomoyo_print_name_union(head, &ptr->fs_type); in tomoyo_print_entry()
1556 tomoyo_print_number_union(head, &ptr->flags); in tomoyo_print_entry()
1559 container_of(acl, typeof(*ptr), head); in tomoyo_print_entry()
1561 tomoyo_set_group(head, "misc env "); in tomoyo_print_entry()
1562 tomoyo_set_string(head, ptr->env->name); in tomoyo_print_entry()
1565 head->r.print_cond_part = true; in tomoyo_print_entry()
1566 head->r.cond_step = 0; in tomoyo_print_entry()
1567 if (!tomoyo_flush(head)) in tomoyo_print_entry()
1570 if (!tomoyo_print_condition(head, acl->cond)) in tomoyo_print_entry()
1572 head->r.print_cond_part = false; in tomoyo_print_entry()
1574 tomoyo_set_lf(head); in tomoyo_print_entry()
1582 * @head: Pointer to "struct tomoyo_io_buffer".
1589 static bool tomoyo_read_domain2(struct tomoyo_io_buffer *head, in tomoyo_read_domain2() argument
1592 list_for_each_cookie(head->r.acl, list) { in tomoyo_read_domain2()
1594 list_entry(head->r.acl, typeof(*ptr), list); in tomoyo_read_domain2()
1596 if (!tomoyo_print_entry(head, ptr)) in tomoyo_read_domain2()
1599 head->r.acl = NULL; in tomoyo_read_domain2()
1606 * @head: Pointer to "struct tomoyo_io_buffer".
1610 static void tomoyo_read_domain(struct tomoyo_io_buffer *head) in tomoyo_read_domain() argument
1612 if (head->r.eof) in tomoyo_read_domain()
1614 list_for_each_cookie(head->r.domain, &tomoyo_domain_list) { in tomoyo_read_domain()
1616 list_entry(head->r.domain, typeof(*domain), list); in tomoyo_read_domain()
1619 switch (head->r.step) { in tomoyo_read_domain()
1622 !head->r.print_this_domain_only) in tomoyo_read_domain()
1625 tomoyo_set_string(head, domain->domainname->name); in tomoyo_read_domain()
1626 tomoyo_set_lf(head); in tomoyo_read_domain()
1627 tomoyo_io_printf(head, "use_profile %u\n", in tomoyo_read_domain()
1631 tomoyo_set_string(head, tomoyo_dif[i]); in tomoyo_read_domain()
1632 head->r.index = 0; in tomoyo_read_domain()
1633 head->r.step++; in tomoyo_read_domain()
1636 while (head->r.index < TOMOYO_MAX_ACL_GROUPS) { in tomoyo_read_domain()
1637 i = head->r.index++; in tomoyo_read_domain()
1640 tomoyo_io_printf(head, "use_group %u\n", i); in tomoyo_read_domain()
1641 if (!tomoyo_flush(head)) in tomoyo_read_domain()
1644 head->r.index = 0; in tomoyo_read_domain()
1645 head->r.step++; in tomoyo_read_domain()
1646 tomoyo_set_lf(head); in tomoyo_read_domain()
1649 if (!tomoyo_read_domain2(head, &domain->acl_info_list)) in tomoyo_read_domain()
1651 head->r.step++; in tomoyo_read_domain()
1652 if (!tomoyo_set_lf(head)) in tomoyo_read_domain()
1656 head->r.step = 0; in tomoyo_read_domain()
1657 if (head->r.print_this_domain_only) in tomoyo_read_domain()
1662 head->r.eof = true; in tomoyo_read_domain()
1668 * @head: Pointer to "struct tomoyo_io_buffer".
1672 static int tomoyo_write_pid(struct tomoyo_io_buffer *head) in tomoyo_write_pid() argument
1674 head->r.eof = false; in tomoyo_write_pid()
1681 * @head: Pointer to "struct tomoyo_io_buffer".
1688 static void tomoyo_read_pid(struct tomoyo_io_buffer *head) in tomoyo_read_pid() argument
1690 char *buf = head->write_buf; in tomoyo_read_pid()
1696 /* Accessing write_buf is safe because head->io_sem is held. */ in tomoyo_read_pid()
1698 head->r.eof = true; in tomoyo_read_pid()
1701 if (head->r.w_pos || head->r.eof) in tomoyo_read_pid()
1703 head->r.eof = true; in tomoyo_read_pid()
1718 tomoyo_io_printf(head, "%u %u ", pid, domain->profile); in tomoyo_read_pid()
1719 tomoyo_set_string(head, domain->domainname->name); in tomoyo_read_pid()
1742 * @head: Pointer to "struct tomoyo_io_buffer".
1748 static int tomoyo_write_exception(struct tomoyo_io_buffer *head) in tomoyo_write_exception() argument
1750 const bool is_delete = head->w.is_delete; in tomoyo_write_exception()
1752 .ns = head->w.ns, in tomoyo_write_exception()
1754 .data = head->write_buf, in tomoyo_write_exception()
1773 (head->w.ns, &head->w.ns->acl_group[group], in tomoyo_write_exception()
1782 * @head: Pointer to "struct tomoyo_io_buffer".
1789 static bool tomoyo_read_group(struct tomoyo_io_buffer *head, const int idx) in tomoyo_read_group() argument
1792 container_of(head->r.ns, typeof(*ns), namespace_list); in tomoyo_read_group()
1795 list_for_each_cookie(head->r.group, list) { in tomoyo_read_group()
1797 list_entry(head->r.group, typeof(*group), head.list); in tomoyo_read_group()
1799 list_for_each_cookie(head->r.acl, &group->member_list) { in tomoyo_read_group()
1801 list_entry(head->r.acl, typeof(*ptr), list); in tomoyo_read_group()
1805 if (!tomoyo_flush(head)) in tomoyo_read_group()
1807 tomoyo_print_namespace(head); in tomoyo_read_group()
1808 tomoyo_set_string(head, tomoyo_group_name[idx]); in tomoyo_read_group()
1809 tomoyo_set_string(head, group->group_name->name); in tomoyo_read_group()
1811 tomoyo_set_space(head); in tomoyo_read_group()
1812 tomoyo_set_string(head, container_of in tomoyo_read_group()
1814 head)->member_name->name); in tomoyo_read_group()
1816 tomoyo_print_number_union(head, &container_of in tomoyo_read_group()
1819 head)->number); in tomoyo_read_group()
1824 head); in tomoyo_read_group()
1828 tomoyo_io_printf(head, " %s", buffer); in tomoyo_read_group()
1830 tomoyo_set_lf(head); in tomoyo_read_group()
1832 head->r.acl = NULL; in tomoyo_read_group()
1834 head->r.group = NULL; in tomoyo_read_group()
1841 * @head: Pointer to "struct tomoyo_io_buffer".
1848 static bool tomoyo_read_policy(struct tomoyo_io_buffer *head, const int idx) in tomoyo_read_policy() argument
1851 container_of(head->r.ns, typeof(*ns), namespace_list); in tomoyo_read_policy()
1854 list_for_each_cookie(head->r.acl, list) { in tomoyo_read_policy()
1856 container_of(head->r.acl, typeof(*acl), list); in tomoyo_read_policy()
1859 if (!tomoyo_flush(head)) in tomoyo_read_policy()
1865 container_of(acl, typeof(*ptr), head); in tomoyo_read_policy()
1867 tomoyo_print_namespace(head); in tomoyo_read_policy()
1868 tomoyo_set_string(head, tomoyo_transition_type in tomoyo_read_policy()
1870 tomoyo_set_string(head, ptr->program ? in tomoyo_read_policy()
1872 tomoyo_set_string(head, " from "); in tomoyo_read_policy()
1873 tomoyo_set_string(head, ptr->domainname ? in tomoyo_read_policy()
1881 container_of(acl, typeof(*ptr), head); in tomoyo_read_policy()
1883 tomoyo_print_namespace(head); in tomoyo_read_policy()
1884 tomoyo_set_string(head, "aggregator "); in tomoyo_read_policy()
1885 tomoyo_set_string(head, in tomoyo_read_policy()
1887 tomoyo_set_space(head); in tomoyo_read_policy()
1888 tomoyo_set_string(head, in tomoyo_read_policy()
1895 tomoyo_set_lf(head); in tomoyo_read_policy()
1897 head->r.acl = NULL; in tomoyo_read_policy()
1904 * @head: Pointer to "struct tomoyo_io_buffer".
1908 static void tomoyo_read_exception(struct tomoyo_io_buffer *head) in tomoyo_read_exception() argument
1911 container_of(head->r.ns, typeof(*ns), namespace_list); in tomoyo_read_exception()
1913 if (head->r.eof) in tomoyo_read_exception()
1915 while (head->r.step < TOMOYO_MAX_POLICY && in tomoyo_read_exception()
1916 tomoyo_read_policy(head, head->r.step)) in tomoyo_read_exception()
1917 head->r.step++; in tomoyo_read_exception()
1918 if (head->r.step < TOMOYO_MAX_POLICY) in tomoyo_read_exception()
1920 while (head->r.step < TOMOYO_MAX_POLICY + TOMOYO_MAX_GROUP && in tomoyo_read_exception()
1921 tomoyo_read_group(head, head->r.step - TOMOYO_MAX_POLICY)) in tomoyo_read_exception()
1922 head->r.step++; in tomoyo_read_exception()
1923 if (head->r.step < TOMOYO_MAX_POLICY + TOMOYO_MAX_GROUP) in tomoyo_read_exception()
1925 while (head->r.step < TOMOYO_MAX_POLICY + TOMOYO_MAX_GROUP in tomoyo_read_exception()
1927 head->r.acl_group_index = head->r.step - TOMOYO_MAX_POLICY in tomoyo_read_exception()
1929 if (!tomoyo_read_domain2(head, &ns->acl_group in tomoyo_read_exception()
1930 [head->r.acl_group_index])) in tomoyo_read_exception()
1932 head->r.step++; in tomoyo_read_exception()
1934 head->r.eof = true; in tomoyo_read_exception()
2192 * @head: Pointer to "struct tomoyo_io_buffer".
2194 static void tomoyo_read_query(struct tomoyo_io_buffer *head) in tomoyo_read_query() argument
2201 if (head->r.w_pos) in tomoyo_read_query()
2203 kfree(head->read_buf); in tomoyo_read_query()
2204 head->read_buf = NULL; in tomoyo_read_query()
2209 if (pos++ != head->r.query_index) in tomoyo_read_query()
2216 head->r.query_index = 0; in tomoyo_read_query()
2227 if (pos++ != head->r.query_index) in tomoyo_read_query()
2240 head->read_buf = buf; in tomoyo_read_query()
2241 head->r.w[head->r.w_pos++] = buf; in tomoyo_read_query()
2242 head->r.query_index++; in tomoyo_read_query()
2251 * @head: Pointer to "struct tomoyo_io_buffer".
2255 static int tomoyo_write_answer(struct tomoyo_io_buffer *head) in tomoyo_write_answer() argument
2257 char *data = head->write_buf; in tomoyo_write_answer()
2290 * @head: Pointer to "struct tomoyo_io_buffer".
2294 static void tomoyo_read_version(struct tomoyo_io_buffer *head) in tomoyo_read_version() argument
2296 if (!head->r.eof) { in tomoyo_read_version()
2297 tomoyo_io_printf(head, "2.6.0"); in tomoyo_read_version()
2298 head->r.eof = true; in tomoyo_read_version()
2338 * @head: Pointer to "struct tomoyo_io_buffer".
2342 static void tomoyo_read_stat(struct tomoyo_io_buffer *head) in tomoyo_read_stat() argument
2347 if (head->r.eof) in tomoyo_read_stat()
2350 tomoyo_io_printf(head, "Policy %-30s %10u", in tomoyo_read_stat()
2357 tomoyo_io_printf(head, " (Last: %04u/%02u/%02u %02u:%02u:%02u)", in tomoyo_read_stat()
2361 tomoyo_set_lf(head); in tomoyo_read_stat()
2367 tomoyo_io_printf(head, "Memory used by %-22s %10u", in tomoyo_read_stat()
2371 tomoyo_io_printf(head, " (Quota: %10u)", used); in tomoyo_read_stat()
2372 tomoyo_set_lf(head); in tomoyo_read_stat()
2374 tomoyo_io_printf(head, "Total memory used: %10u\n", in tomoyo_read_stat()
2376 head->r.eof = true; in tomoyo_read_stat()
2382 * @head: Pointer to "struct tomoyo_io_buffer".
2386 static int tomoyo_write_stat(struct tomoyo_io_buffer *head) in tomoyo_write_stat() argument
2388 char *data = head->write_buf; in tomoyo_write_stat()
2408 struct tomoyo_io_buffer *head = kzalloc(sizeof(*head), GFP_NOFS); in tomoyo_open_control() local
2410 if (!head) in tomoyo_open_control()
2412 mutex_init(&head->io_sem); in tomoyo_open_control()
2413 head->type = type; in tomoyo_open_control()
2417 head->write = tomoyo_write_domain; in tomoyo_open_control()
2418 head->read = tomoyo_read_domain; in tomoyo_open_control()
2422 head->write = tomoyo_write_exception; in tomoyo_open_control()
2423 head->read = tomoyo_read_exception; in tomoyo_open_control()
2427 head->poll = tomoyo_poll_log; in tomoyo_open_control()
2428 head->read = tomoyo_read_log; in tomoyo_open_control()
2432 head->write = tomoyo_write_pid; in tomoyo_open_control()
2433 head->read = tomoyo_read_pid; in tomoyo_open_control()
2437 head->read = tomoyo_read_version; in tomoyo_open_control()
2438 head->readbuf_size = 128; in tomoyo_open_control()
2442 head->write = tomoyo_write_stat; in tomoyo_open_control()
2443 head->read = tomoyo_read_stat; in tomoyo_open_control()
2444 head->readbuf_size = 1024; in tomoyo_open_control()
2448 head->write = tomoyo_write_profile; in tomoyo_open_control()
2449 head->read = tomoyo_read_profile; in tomoyo_open_control()
2452 head->poll = tomoyo_poll_query; in tomoyo_open_control()
2453 head->write = tomoyo_write_answer; in tomoyo_open_control()
2454 head->read = tomoyo_read_query; in tomoyo_open_control()
2458 head->write = tomoyo_write_manager; in tomoyo_open_control()
2459 head->read = tomoyo_read_manager; in tomoyo_open_control()
2467 head->read = NULL; in tomoyo_open_control()
2468 head->poll = NULL; in tomoyo_open_control()
2469 } else if (!head->poll) { in tomoyo_open_control()
2471 if (!head->readbuf_size) in tomoyo_open_control()
2472 head->readbuf_size = 4096 * 2; in tomoyo_open_control()
2473 head->read_buf = kzalloc(head->readbuf_size, GFP_NOFS); in tomoyo_open_control()
2474 if (!head->read_buf) { in tomoyo_open_control()
2475 kfree(head); in tomoyo_open_control()
2484 head->write = NULL; in tomoyo_open_control()
2485 } else if (head->write) { in tomoyo_open_control()
2486 head->writebuf_size = 4096 * 2; in tomoyo_open_control()
2487 head->write_buf = kzalloc(head->writebuf_size, GFP_NOFS); in tomoyo_open_control()
2488 if (!head->write_buf) { in tomoyo_open_control()
2489 kfree(head->read_buf); in tomoyo_open_control()
2490 kfree(head); in tomoyo_open_control()
2502 file->private_data = head; in tomoyo_open_control()
2503 tomoyo_notify_gc(head, true); in tomoyo_open_control()
2518 struct tomoyo_io_buffer *head = file->private_data; in tomoyo_poll_control() local
2520 if (head->poll) in tomoyo_poll_control()
2521 return head->poll(file, wait) | EPOLLOUT | EPOLLWRNORM; in tomoyo_poll_control()
2528 * @head: Pointer to "struct tomoyo_io_buffer".
2532 static inline void tomoyo_set_namespace_cursor(struct tomoyo_io_buffer *head) in tomoyo_set_namespace_cursor() argument
2536 if (head->type != TOMOYO_EXCEPTIONPOLICY && in tomoyo_set_namespace_cursor()
2537 head->type != TOMOYO_PROFILE) in tomoyo_set_namespace_cursor()
2543 ns = head->r.ns; in tomoyo_set_namespace_cursor()
2544 if (!ns || (head->r.eof && ns->next != &tomoyo_namespace_list)) { in tomoyo_set_namespace_cursor()
2546 memset(&head->r, 0, sizeof(head->r)); in tomoyo_set_namespace_cursor()
2547 head->r.ns = ns ? ns->next : tomoyo_namespace_list.next; in tomoyo_set_namespace_cursor()
2554 * @head: Pointer to "struct tomoyo_io_buffer".
2558 static inline bool tomoyo_has_more_namespace(struct tomoyo_io_buffer *head) in tomoyo_has_more_namespace() argument
2560 return (head->type == TOMOYO_EXCEPTIONPOLICY || in tomoyo_has_more_namespace()
2561 head->type == TOMOYO_PROFILE) && head->r.eof && in tomoyo_has_more_namespace()
2562 head->r.ns->next != &tomoyo_namespace_list; in tomoyo_has_more_namespace()
2568 * @head: Pointer to "struct tomoyo_io_buffer".
2574 ssize_t tomoyo_read_control(struct tomoyo_io_buffer *head, char __user *buffer, in tomoyo_read_control() argument
2580 if (!head->read) in tomoyo_read_control()
2582 if (mutex_lock_interruptible(&head->io_sem)) in tomoyo_read_control()
2584 head->read_user_buf = buffer; in tomoyo_read_control()
2585 head->read_user_buf_avail = buffer_len; in tomoyo_read_control()
2587 if (tomoyo_flush(head)) in tomoyo_read_control()
2590 tomoyo_set_namespace_cursor(head); in tomoyo_read_control()
2591 head->read(head); in tomoyo_read_control()
2592 } while (tomoyo_flush(head) && in tomoyo_read_control()
2593 tomoyo_has_more_namespace(head)); in tomoyo_read_control()
2595 len = head->read_user_buf - buffer; in tomoyo_read_control()
2596 mutex_unlock(&head->io_sem); in tomoyo_read_control()
2603 * @head: Pointer to "struct tomoyo_io_buffer".
2610 static int tomoyo_parse_policy(struct tomoyo_io_buffer *head, char *line) in tomoyo_parse_policy() argument
2613 head->w.is_delete = !strncmp(line, "delete ", 7); in tomoyo_parse_policy()
2614 if (head->w.is_delete) in tomoyo_parse_policy()
2617 if (head->type == TOMOYO_EXCEPTIONPOLICY || in tomoyo_parse_policy()
2618 head->type == TOMOYO_PROFILE) { in tomoyo_parse_policy()
2624 head->w.ns = tomoyo_assign_namespace(line); in tomoyo_parse_policy()
2627 head->w.ns = NULL; in tomoyo_parse_policy()
2629 head->w.ns = &tomoyo_kernel_namespace; in tomoyo_parse_policy()
2631 if (!head->w.ns) in tomoyo_parse_policy()
2635 return head->write(head); in tomoyo_parse_policy()
2641 * @head: Pointer to "struct tomoyo_io_buffer".
2647 ssize_t tomoyo_write_control(struct tomoyo_io_buffer *head, in tomoyo_write_control() argument
2652 char *cp0 = head->write_buf; in tomoyo_write_control()
2655 if (!head->write) in tomoyo_write_control()
2657 if (mutex_lock_interruptible(&head->io_sem)) in tomoyo_write_control()
2659 head->read_user_buf_avail = 0; in tomoyo_write_control()
2665 if (head->w.avail >= head->writebuf_size - 1) { in tomoyo_write_control()
2666 const int len = head->writebuf_size * 2; in tomoyo_write_control()
2673 memmove(cp, cp0, head->w.avail); in tomoyo_write_control()
2675 head->write_buf = cp; in tomoyo_write_control()
2677 head->writebuf_size = len; in tomoyo_write_control()
2685 cp0[head->w.avail++] = c; in tomoyo_write_control()
2688 cp0[head->w.avail - 1] = '\0'; in tomoyo_write_control()
2689 head->w.avail = 0; in tomoyo_write_control()
2692 head->w.ns = &tomoyo_kernel_namespace; in tomoyo_write_control()
2693 head->w.domain = NULL; in tomoyo_write_control()
2694 memset(&head->r, 0, sizeof(head->r)); in tomoyo_write_control()
2698 switch (head->type) { in tomoyo_write_control()
2703 if (tomoyo_select_domain(head, cp0)) in tomoyo_write_control()
2708 head->r.print_transition_related_only = true; in tomoyo_write_control()
2718 switch (tomoyo_parse_policy(head, cp0)) { in tomoyo_write_control()
2723 switch (head->type) { in tomoyo_write_control()
2739 mutex_unlock(&head->io_sem); in tomoyo_write_control()
2746 * @head: Pointer to "struct tomoyo_io_buffer".
2748 void tomoyo_close_control(struct tomoyo_io_buffer *head) in tomoyo_close_control() argument
2754 if (head->type == TOMOYO_QUERY && in tomoyo_close_control()
2757 tomoyo_notify_gc(head, false); in tomoyo_close_control()
2825 struct tomoyo_io_buffer head = { }; in tomoyo_load_builtin_policy() local
2831 head.type = TOMOYO_PROFILE; in tomoyo_load_builtin_policy()
2832 head.write = tomoyo_write_profile; in tomoyo_load_builtin_policy()
2836 head.type = TOMOYO_EXCEPTIONPOLICY; in tomoyo_load_builtin_policy()
2837 head.write = tomoyo_write_exception; in tomoyo_load_builtin_policy()
2841 head.type = TOMOYO_DOMAINPOLICY; in tomoyo_load_builtin_policy()
2842 head.write = tomoyo_write_domain; in tomoyo_load_builtin_policy()
2846 head.type = TOMOYO_MANAGER; in tomoyo_load_builtin_policy()
2847 head.write = tomoyo_write_manager; in tomoyo_load_builtin_policy()
2851 head.type = TOMOYO_STAT; in tomoyo_load_builtin_policy()
2852 head.write = tomoyo_write_stat; in tomoyo_load_builtin_policy()
2862 head.write_buf = start; in tomoyo_load_builtin_policy()
2863 tomoyo_parse_policy(&head, start); in tomoyo_load_builtin_policy()