Lines Matching full:key
25 * When plumbing the depths of the key tree, this sets a hard limit
40 static inline struct key *keyring_ptr_to_key(const struct assoc_array_ptr *x) in keyring_ptr_to_key()
43 return (struct key *)((unsigned long)object & ~KEYRING_PTR_SUBTYPE); in keyring_ptr_to_key()
45 static inline void *keyring_key_to_ptr(struct key *key) in keyring_key_to_ptr() argument
47 if (key->type == &key_type_keyring) in keyring_key_to_ptr()
48 return (void *)((unsigned long)key | KEYRING_PTR_SUBTYPE); in keyring_key_to_ptr()
49 return key; in keyring_key_to_ptr()
70 * The keyring key type definition. Keyrings are simply keys of this type and
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()
129 * Free a preparse of a user defined key payload
140 static int keyring_instantiate(struct key *keyring, in keyring_instantiate()
161 * Hash a key type and description.
211 * Finalise an index key to include a part of the description actually in the
212 * index key, to set the domain tag and to calculate the hash.
249 * key_remove_domain - Kill off a key domain and gc its keys
264 * Build the next index key chunk.
305 const struct key *key = keyring_ptr_to_key(object); in keyring_get_object_key_chunk() local
306 return keyring_get_key_chunk(&key->index_key, level); in keyring_get_object_key_chunk()
312 const struct key *key = keyring_ptr_to_key(object); in keyring_compare_object() local
314 return key->index_key.type == index_key->type && in keyring_compare_object()
315 key->index_key.domain_tag == index_key->domain_tag && in keyring_compare_object()
316 key->index_key.desc_len == index_key->desc_len && in keyring_compare_object()
317 memcmp(key->index_key.description, index_key->description, in keyring_compare_object()
327 const struct key *key_a = keyring_ptr_to_key(object); in keyring_diff_objects()
412 static void keyring_destroy(struct key *keyring) in keyring_destroy()
427 key_put(keyres->key); in keyring_destroy()
437 static void keyring_describe(const struct key *keyring, struct seq_file *m) in keyring_describe()
461 const struct key *key = keyring_ptr_to_key(object); in keyring_read_iterator() local
464 key->type->name, key->serial, ctx->count, ctx->buflen); in keyring_read_iterator()
469 *ctx->buffer++ = key->serial; in keyring_read_iterator()
470 ctx->count += sizeof(key->serial); in keyring_read_iterator()
475 * Read a list of key IDs from the keyring's contents in binary form
478 * from modifying it under us - which could cause us to read key IDs multiple
481 static long keyring_read(const struct key *keyring, in keyring_read()
492 /* Copy as many key IDs as fit into the buffer */ in keyring_read()
517 struct key *keyring_alloc(const char *description, kuid_t uid, kgid_t gid, in keyring_alloc()
521 struct key *dest) in keyring_alloc()
523 struct key *keyring; in keyring_alloc()
543 * @type: The type of key being added.
544 * @payload: The payload of the key intended to be added.
549 * adding a key to a keyring.
554 int restrict_link_reject(struct key *keyring, in restrict_link_reject()
557 struct key *restriction_key) in restrict_link_reject()
565 bool key_default_cmp(const struct key *key, in key_default_cmp() argument
568 return strcmp(key->description, match_data->raw_data) == 0; in key_default_cmp()
572 * Iteration function to consider each key found.
577 const struct key *key = keyring_ptr_to_key(object); in keyring_search_iterator() local
578 unsigned long kflags = READ_ONCE(key->flags); in keyring_search_iterator()
579 short state = READ_ONCE(key->state); in keyring_search_iterator()
581 kenter("{%d}", key->serial); in keyring_search_iterator()
584 if (key->type != ctx->index_key.type) { in keyring_search_iterator()
591 time64_t expiry = READ_ONCE(key->expiry); in keyring_search_iterator()
609 if (!ctx->match_data.cmp(key, &ctx->match_data)) { in keyring_search_iterator()
614 /* key must have search permissions */ in keyring_search_iterator()
616 key_task_permission(make_key_ref(key, ctx->possessed), in keyring_search_iterator()
624 /* we set a different error code if we pass a negative key */ in keyring_search_iterator()
633 ctx->result = make_key_ref(key, ctx->possessed); in keyring_search_iterator()
642 * Search inside a keyring for a key. We can search by walking to it
643 * directly based on its index-key or we can iterate over the entire
646 static int search_keyring(struct key *keyring, struct keyring_search_context *ctx) in search_keyring()
663 static bool search_nested_keyrings(struct key *keyring, in search_nested_keyrings()
667 struct key *keyring; in search_nested_keyrings()
675 struct key *key; in search_nested_keyrings() local
781 key = keyring_ptr_to_key(ptr); in search_nested_keyrings()
793 key_task_permission(make_key_ref(key, ctx->possessed), in search_nested_keyrings()
804 keyring = key; in search_nested_keyrings()
834 * matching key. in search_nested_keyrings()
853 key = key_ref_to_ptr(ctx->result); in search_nested_keyrings()
854 key_check(key); in search_nested_keyrings()
856 key->last_used_at = ctx->now; in search_nested_keyrings()
866 * keyring_search_rcu - Search a keyring tree for a matching key under RCU
870 * Search the supplied keyring tree for a key that matches the criteria given.
875 * addition, the LSM gets to forbid keyring searches and key matches.
884 * match function may use any attributes of a key that it wishes to
885 * determine the match. Normally the match function from the key type would be
888 * RCU can be used to prevent the keyring key lists from disappearing without
891 * Returns a pointer to the found key and increments the key usage count if
897 * @keyring_ref is propagated to the returned key reference.
902 struct key *keyring; in keyring_search_rcu()
928 * keyring_search - Search the supplied keyring tree for a matching key
952 key_ref_t key; in keyring_search() local
964 key = keyring_search_rcu(keyring, &ctx); in keyring_search()
969 return key; in keyring_search()
989 * cycles through restriction key pointers.
997 static bool keyring_detect_restriction_cycle(const struct key *dest_keyring, in keyring_detect_restriction_cycle()
1000 while (keyres && keyres->key && in keyring_detect_restriction_cycle()
1001 keyres->key->type == &key_type_keyring) { in keyring_detect_restriction_cycle()
1002 if (keyres->key == dest_keyring) in keyring_detect_restriction_cycle()
1005 keyres = keyres->key->restrict_link; in keyring_detect_restriction_cycle()
1014 * @type: The key type that will provide the restriction checker.
1018 * by the specific key type, but can be configured by the options specified in
1024 struct key *keyring; in keyring_restrict()
1072 key_put(restrict_link->key); in keyring_restrict()
1085 * Search the given keyring for a key that might be updated.
1091 * Returns a pointer to the found key with usage count incremented if
1096 * to the returned key reference.
1101 struct key *keyring, *key; in find_key_to_update() local
1119 key = keyring_ptr_to_key(object); in find_key_to_update()
1120 if (key->flags & ((1 << KEY_FLAG_INVALIDATED) | in find_key_to_update()
1125 __key_get(key); in find_key_to_update()
1126 kleave(" = {%d}", key->serial); in find_key_to_update()
1127 return make_key_ref(key, is_key_possessed(keyring_ref)); in find_key_to_update()
1139 * incremented on success. -ENOKEY is returned if a key could not be found.
1141 struct key *find_keyring_by_name(const char *name, bool uid_keyring) in find_keyring_by_name()
1144 struct key *keyring; in find_keyring_by_name()
1193 const struct key *key = keyring_ptr_to_key(object); in keyring_detect_cycle_iterator() local
1195 kenter("{%d}", key->serial); in keyring_detect_cycle_iterator()
1197 /* We might get a keyring with matching index-key that is nonetheless a in keyring_detect_cycle_iterator()
1199 if (key != ctx->match_data.raw_data) in keyring_detect_cycle_iterator()
1213 static int keyring_detect_cycle(struct key *A, struct key *B) in keyring_detect_cycle()
1236 int __key_link_lock(struct key *keyring, in __key_link_lock()
1258 int __key_move_lock(struct key *l_keyring, struct key *u_keyring, in __key_move_lock()
1290 * Preallocate memory so that a key can be linked into to a keyring.
1292 int __key_link_begin(struct key *keyring, in __key_link_begin()
1311 /* Create an edit script that will insert/replace the key in the in __key_link_begin()
1350 int __key_link_check_live_key(struct key *keyring, struct key *key) in __key_link_check_live_key() argument
1352 if (key->type == &key_type_keyring) in __key_link_check_live_key()
1355 return keyring_detect_cycle(keyring, key); in __key_link_check_live_key()
1360 * Link a key into to a keyring.
1363 * already extant link to matching key if there is one, so that each keyring
1364 * holds at most one link to any given key of a particular type+description
1367 void __key_link(struct key *keyring, struct key *key, in __key_link() argument
1370 __key_get(key); in __key_link()
1371 assoc_array_insert_set_object(*_edit, keyring_key_to_ptr(key)); in __key_link()
1374 notify_key(keyring, NOTIFY_KEY_LINKED, key_serial(key)); in __key_link()
1378 * Finish linking a key into to a keyring.
1382 void __key_link_end(struct key *keyring, in __key_link_end()
1407 static int __key_link_check_restriction(struct key *keyring, struct key *key) in __key_link_check_restriction() argument
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()
1416 * key_link - Link a key to a keyring
1418 * @key: The key to link to.
1420 * Make a link in a keyring to a key, such that the keyring holds a reference
1421 * on that key and the key can potentially be found by searching that keyring.
1424 * of the user's key data quota to hold the link.
1428 * full, -EDQUOT if there is insufficient key data quota remaining to add
1432 * be made (the keyring should have Write permission and the key Link
1435 int key_link(struct key *keyring, struct key *key) in key_link() argument
1443 key_check(key); 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()
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()
1471 static int __key_unlink_lock(struct key *keyring) in __key_unlink_lock()
1482 * Begin the process of unlinking a key from a keyring.
1484 static int __key_unlink_begin(struct key *keyring, struct key *key, in __key_unlink_begin() argument
1492 &key->index_key); 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()
1516 * Finish unlinking a key from to a keyring.
1518 static void __key_unlink_end(struct key *keyring, in __key_unlink_end() argument
1519 struct key *key, in __key_unlink_end()
1529 * key_unlink - Unlink the first link to a key from a keyring.
1531 * @key: The key the link is to.
1533 * Remove a link from a keyring to a key.
1538 * the key isn't linked to by the keyring or -ENOMEM if there's insufficient
1543 * required on the key).
1545 int key_unlink(struct key *keyring, struct key *key) in key_unlink() argument
1551 key_check(key); 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()
1566 * key_move - Move a key from one keyring to another
1567 * @key: The key to move
1572 * Make a link in @to_keyring to a key, such that the keyring holds a reference
1573 * on that key and the key can potentially be found by searching that keyring
1574 * whilst simultaneously removing a link to the key from @from_keyring.
1577 * some of the user's key data quota to hold the link on @to_keyring.
1581 * keyring is full, -EDQUOT if there is insufficient key data quota remaining
1584 * matching key in @to_keyring.
1587 * be made (the keyring should have Write permission and the key Link
1590 int key_move(struct key *key, in key_move() argument
1591 struct key *from_keyring, in key_move()
1592 struct key *to_keyring, in key_move()
1598 kenter("%d,%d,%d", key->serial, from_keyring->serial, to_keyring->serial); in key_move()
1603 key_check(key); in key_move()
1607 ret = __key_move_lock(from_keyring, to_keyring, &key->index_key); in key_move()
1610 ret = __key_unlink_begin(from_keyring, key, &from_edit); in key_move()
1613 ret = __key_link_begin(to_keyring, &key->index_key, &to_edit); in key_move()
1621 ret = __key_link_check_restriction(to_keyring, key); in key_move()
1624 ret = __key_link_check_live_key(to_keyring, key); in key_move()
1628 __key_unlink(from_keyring, key, &from_edit); in key_move()
1629 __key_link(to_keyring, key, &to_edit); in key_move()
1631 __key_link_end(to_keyring, &key->index_key, to_edit); in key_move()
1632 __key_unlink_end(from_keyring, key, from_edit); in key_move()
1647 int keyring_clear(struct key *keyring) in keyring_clear()
1676 * This is called with the key sem write-locked.
1678 static void keyring_revoke(struct key *keyring) in keyring_revoke()
1692 struct key *key = keyring_ptr_to_key(object); in keyring_gc_select_iterator() local
1695 if (key_is_dead(key, *limit)) in keyring_gc_select_iterator()
1697 key_get(key); in keyring_gc_select_iterator()
1703 const struct key *key = keyring_ptr_to_key(object); in keyring_gc_check_iterator() local
1706 key_check(key); in keyring_gc_check_iterator()
1707 return key_is_dead(key, *limit); in keyring_gc_check_iterator()
1713 * Not called with any locks held. The keyring's key struct will not be
1716 void keyring_gc(struct key *keyring, time64_t limit) in keyring_gc()
1749 * Keyring restrictions are associated with a key type, and must be cleaned
1750 * up if the key type is unregistered. The restriction is altered to always
1752 * a key type.
1754 * Not called with any keyring locks held. The keyring's key struct will not
1761 void keyring_restriction_gc(struct key *keyring, struct key_type *dead_type) in keyring_restriction_gc()
1768 * keyring->restrict_link is only assigned at key allocation time in keyring_restriction_gc()
1769 * or with the key type locked, so the only values that could be in keyring_restriction_gc()
1770 * concurrently assigned to keyring->restrict_link are for key in keyring_restriction_gc()
1772 * the key type before acquiring keyring->sem. in keyring_restriction_gc()
1787 key_put(keyres->key); in keyring_restriction_gc()
1788 keyres->key = NULL; in keyring_restriction_gc()