Lines Matching refs:keyring

76 static int keyring_instantiate(struct key *keyring,
78 static void keyring_revoke(struct key *keyring);
79 static void keyring_destroy(struct key *keyring);
80 static void keyring_describe(const struct key *keyring, struct seq_file *m);
81 static long keyring_read(const struct key *keyring,
107 static void keyring_publish_name(struct key *keyring) in keyring_publish_name() argument
111 if (keyring->description && in keyring_publish_name()
112 keyring->description[0] && in keyring_publish_name()
113 keyring->description[0] != '.') { in keyring_publish_name()
115 list_add_tail(&keyring->name_link, &ns->keyring_name_list); in keyring_publish_name()
140 static int keyring_instantiate(struct key *keyring, in keyring_instantiate() argument
143 assoc_array_init(&keyring->keys); in keyring_instantiate()
145 keyring_publish_name(keyring); in keyring_instantiate()
412 static void keyring_destroy(struct key *keyring) in keyring_destroy() argument
414 if (keyring->description) { in keyring_destroy()
417 if (keyring->name_link.next != NULL && in keyring_destroy()
418 !list_empty(&keyring->name_link)) in keyring_destroy()
419 list_del(&keyring->name_link); in keyring_destroy()
424 if (keyring->restrict_link) { in keyring_destroy()
425 struct key_restriction *keyres = keyring->restrict_link; in keyring_destroy()
431 assoc_array_destroy(&keyring->keys, &keyring_assoc_array_ops); in keyring_destroy()
437 static void keyring_describe(const struct key *keyring, struct seq_file *m) in keyring_describe() argument
439 if (keyring->description) in keyring_describe()
440 seq_puts(m, keyring->description); in keyring_describe()
444 if (key_is_positive(keyring)) { in keyring_describe()
445 if (keyring->keys.nr_leaves_on_tree != 0) in keyring_describe()
446 seq_printf(m, ": %lu", keyring->keys.nr_leaves_on_tree); in keyring_describe()
481 static long keyring_read(const struct key *keyring, in keyring_read() argument
487 kenter("{%d},,%zu", key_serial(keyring), buflen); in keyring_read()
497 ret = assoc_array_iterate(&keyring->keys, in keyring_read()
506 ret = keyring->keys.nr_leaves_on_tree * sizeof(key_serial_t); in keyring_read()
523 struct key *keyring; in keyring_alloc() local
526 keyring = key_alloc(&key_type_keyring, description, in keyring_alloc()
528 if (!IS_ERR(keyring)) { in keyring_alloc()
529 ret = key_instantiate_and_link(keyring, NULL, 0, dest, NULL); in keyring_alloc()
531 key_put(keyring); in keyring_alloc()
532 keyring = ERR_PTR(ret); in keyring_alloc()
536 return keyring; in keyring_alloc()
554 int restrict_link_reject(struct key *keyring, in restrict_link_reject() argument
646 static int search_keyring(struct key *keyring, struct keyring_search_context *ctx) in search_keyring() argument
651 object = assoc_array_find(&keyring->keys, in search_keyring()
656 return assoc_array_iterate(&keyring->keys, ctx->iterator, ctx); in search_keyring()
663 static bool search_nested_keyrings(struct key *keyring, in search_nested_keyrings() argument
667 struct key *keyring; in search_nested_keyrings() member
679 keyring->serial, in search_nested_keyrings()
694 keyring_compare_object(keyring, &ctx->index_key)) { in search_nested_keyrings()
696 switch (ctx->iterator(keyring_key_to_ptr(keyring), ctx)) { in search_nested_keyrings()
710 kdebug("descend to %d", keyring->serial); in search_nested_keyrings()
711 if (keyring->flags & ((1 << KEY_FLAG_INVALIDATED) | in search_nested_keyrings()
718 if (search_keyring(keyring, ctx)) in search_nested_keyrings()
732 ptr = READ_ONCE(keyring->keys.root); in search_nested_keyrings()
798 stack[sp].keyring = keyring; in search_nested_keyrings()
804 keyring = key; in search_nested_keyrings()
845 keyring = stack[sp].keyring; in search_nested_keyrings()
848 kdebug("ascend to %d [%d]", keyring->serial, slot); in search_nested_keyrings()
857 keyring->last_used_at = ctx->now; in search_nested_keyrings()
859 stack[--sp].keyring->last_used_at = ctx->now; in search_nested_keyrings()
902 struct key *keyring; in keyring_search_rcu() local
909 keyring = key_ref_to_ptr(keyring_ref); in keyring_search_rcu()
910 key_check(keyring); in keyring_search_rcu()
912 if (keyring->type != &key_type_keyring) in keyring_search_rcu()
922 if (search_nested_keyrings(keyring, ctx)) in keyring_search_rcu()
937 key_ref_t keyring_search(key_ref_t keyring, in keyring_search() argument
964 key = keyring_search_rcu(keyring, &ctx); in keyring_search()
1024 struct key *keyring; in keyring_restrict() local
1029 keyring = key_ref_to_ptr(keyring_ref); in keyring_restrict()
1030 key_check(keyring); in keyring_restrict()
1032 if (keyring->type != &key_type_keyring) in keyring_restrict()
1056 down_write(&keyring->sem); in keyring_restrict()
1059 if (keyring->restrict_link) { in keyring_restrict()
1061 } else if (keyring_detect_restriction_cycle(keyring, restrict_link)) { in keyring_restrict()
1064 keyring->restrict_link = restrict_link; in keyring_restrict()
1065 notify_key(keyring, NOTIFY_KEY_SETATTR, 0); in keyring_restrict()
1069 up_write(&keyring->sem); in keyring_restrict()
1101 struct key *keyring, *key; in find_key_to_update() local
1104 keyring = key_ref_to_ptr(keyring_ref); in find_key_to_update()
1107 keyring->serial, index_key->type->name, index_key->description); in find_key_to_update()
1109 object = assoc_array_find(&keyring->keys, &keyring_assoc_array_ops, in find_key_to_update()
1144 struct key *keyring; in find_keyring_by_name() local
1154 list_for_each_entry(keyring, &ns->keyring_name_list, name_link) { in find_keyring_by_name()
1155 if (!kuid_has_mapping(ns, keyring->user->uid)) in find_keyring_by_name()
1158 if (test_bit(KEY_FLAG_REVOKED, &keyring->flags)) in find_keyring_by_name()
1161 if (strcmp(keyring->description, name) != 0) in find_keyring_by_name()
1166 &keyring->flags)) in find_keyring_by_name()
1169 if (key_permission(make_key_ref(keyring, 0), in find_keyring_by_name()
1177 if (!refcount_inc_not_zero(&keyring->usage)) in find_keyring_by_name()
1179 keyring->last_used_at = ktime_get_real_seconds(); in find_keyring_by_name()
1183 keyring = ERR_PTR(-ENOKEY); in find_keyring_by_name()
1186 return keyring; in find_keyring_by_name()
1236 int __key_link_lock(struct key *keyring, in __key_link_lock() argument
1238 __acquires(&keyring->sem) in __key_link_lock()
1241 if (keyring->type != &key_type_keyring) in __key_link_lock()
1244 down_write(&keyring->sem); in __key_link_lock()
1292 int __key_link_begin(struct key *keyring, in __key_link_begin() argument
1300 keyring->serial, index_key->type->name, index_key->description); in __key_link_begin()
1308 if (test_bit(KEY_FLAG_REVOKED, &keyring->flags)) in __key_link_begin()
1314 edit = assoc_array_insert(&keyring->keys, in __key_link_begin()
1327 ret = key_payload_reserve(keyring, in __key_link_begin()
1328 keyring->datalen + KEYQUOTA_LINK_BYTES); in __key_link_begin()
1350 int __key_link_check_live_key(struct key *keyring, struct key *key) in __key_link_check_live_key() argument
1355 return keyring_detect_cycle(keyring, key); in __key_link_check_live_key()
1367 void __key_link(struct key *keyring, struct key *key, in __key_link() argument
1374 notify_key(keyring, NOTIFY_KEY_LINKED, key_serial(key)); in __key_link()
1382 void __key_link_end(struct key *keyring, in __key_link_end() argument
1385 __releases(&keyring->sem) in __key_link_end()
1389 kenter("%d,%s,", keyring->serial, index_key->type->name); in __key_link_end()
1393 key_payload_reserve(keyring, in __key_link_end()
1394 keyring->datalen - KEYQUOTA_LINK_BYTES); in __key_link_end()
1398 up_write(&keyring->sem); in __key_link_end()
1407 static int __key_link_check_restriction(struct key *keyring, struct key *key) in __key_link_check_restriction() argument
1409 if (!keyring->restrict_link || !keyring->restrict_link->check) in __key_link_check_restriction()
1411 return keyring->restrict_link->check(keyring, key->type, &key->payload, in __key_link_check_restriction()
1412 keyring->restrict_link->key); in __key_link_check_restriction()
1435 int key_link(struct key *keyring, struct key *key) in key_link() argument
1440 kenter("{%d,%d}", keyring->serial, refcount_read(&keyring->usage)); in key_link()
1442 key_check(keyring); in key_link()
1445 ret = __key_link_lock(keyring, &key->index_key); in key_link()
1449 ret = __key_link_begin(keyring, &key->index_key, &edit); in key_link()
1453 kdebug("begun {%d,%d}", keyring->serial, refcount_read(&keyring->usage)); in key_link()
1454 ret = __key_link_check_restriction(keyring, key); in key_link()
1456 ret = __key_link_check_live_key(keyring, key); in key_link()
1458 __key_link(keyring, key, &edit); in key_link()
1461 __key_link_end(keyring, &key->index_key, edit); in key_link()
1463 kleave(" = %d {%d,%d}", ret, keyring->serial, refcount_read(&keyring->usage)); in key_link()
1471 static int __key_unlink_lock(struct key *keyring) in __key_unlink_lock() argument
1472 __acquires(&keyring->sem) in __key_unlink_lock()
1474 if (keyring->type != &key_type_keyring) in __key_unlink_lock()
1477 down_write(&keyring->sem); in __key_unlink_lock()
1484 static int __key_unlink_begin(struct key *keyring, struct key *key, in __key_unlink_begin() argument
1491 edit = assoc_array_delete(&keyring->keys, &keyring_assoc_array_ops, in __key_unlink_begin()
1506 static void __key_unlink(struct key *keyring, struct key *key, in __key_unlink() argument
1510 notify_key(keyring, NOTIFY_KEY_UNLINKED, key_serial(key)); in __key_unlink()
1512 key_payload_reserve(keyring, keyring->datalen - KEYQUOTA_LINK_BYTES); in __key_unlink()
1518 static void __key_unlink_end(struct key *keyring, in __key_unlink_end() argument
1521 __releases(&keyring->sem) in __key_unlink_end()
1525 up_write(&keyring->sem); in __key_unlink_end()
1545 int key_unlink(struct key *keyring, struct key *key) in key_unlink() argument
1550 key_check(keyring); in key_unlink()
1553 ret = __key_unlink_lock(keyring); in key_unlink()
1557 ret = __key_unlink_begin(keyring, key, &edit); in key_unlink()
1559 __key_unlink(keyring, key, &edit); in key_unlink()
1560 __key_unlink_end(keyring, key, edit); in key_unlink()
1647 int keyring_clear(struct key *keyring) in keyring_clear() argument
1652 if (keyring->type != &key_type_keyring) in keyring_clear()
1655 down_write(&keyring->sem); in keyring_clear()
1657 edit = assoc_array_clear(&keyring->keys, &keyring_assoc_array_ops); in keyring_clear()
1663 notify_key(keyring, NOTIFY_KEY_CLEARED, 0); in keyring_clear()
1664 key_payload_reserve(keyring, 0); in keyring_clear()
1668 up_write(&keyring->sem); in keyring_clear()
1678 static void keyring_revoke(struct key *keyring) in keyring_revoke() argument
1682 edit = assoc_array_clear(&keyring->keys, &keyring_assoc_array_ops); in keyring_revoke()
1686 key_payload_reserve(keyring, 0); in keyring_revoke()
1716 void keyring_gc(struct key *keyring, time64_t limit) in keyring_gc() argument
1720 kenter("%x{%s}", keyring->serial, keyring->description ?: ""); in keyring_gc()
1722 if (keyring->flags & ((1 << KEY_FLAG_INVALIDATED) | in keyring_gc()
1728 result = assoc_array_iterate(&keyring->keys, in keyring_gc()
1739 down_write(&keyring->sem); in keyring_gc()
1740 assoc_array_gc(&keyring->keys, &keyring_assoc_array_ops, in keyring_gc()
1742 up_write(&keyring->sem); in keyring_gc()
1761 void keyring_restriction_gc(struct key *keyring, struct key_type *dead_type) in keyring_restriction_gc() argument
1765 kenter("%x{%s}", keyring->serial, keyring->description ?: ""); in keyring_restriction_gc()
1774 if (!dead_type || !keyring->restrict_link || in keyring_restriction_gc()
1775 keyring->restrict_link->keytype != dead_type) { in keyring_restriction_gc()
1781 down_write(&keyring->sem); in keyring_restriction_gc()
1783 keyres = keyring->restrict_link; in keyring_restriction_gc()
1791 up_write(&keyring->sem); in keyring_restriction_gc()