Lines Matching full:key

22 #include <linux/key-type.h>
64 static int fscrypt_key_instantiate(struct key *key, in fscrypt_key_instantiate() argument
67 key->payload.data[0] = (struct fscrypt_master_key *)prep->data; in fscrypt_key_instantiate()
71 static void fscrypt_key_destroy(struct key *key) in fscrypt_key_destroy() argument
73 free_master_key(key->payload.data[0]); in fscrypt_key_destroy()
76 static void fscrypt_key_describe(const struct key *key, struct seq_file *m) in fscrypt_key_describe() argument
78 seq_puts(m, key->description); in fscrypt_key_describe()
80 if (key_is_positive(key)) { in fscrypt_key_describe()
81 const struct fscrypt_master_key *mk = key->payload.data[0]; in fscrypt_key_describe()
89 * Type of key in ->s_master_keys. Each key of this type represents a master
90 * key which has been added to the filesystem. Its payload is a
91 * 'struct fscrypt_master_key'. The "." prefix in the key type name prevents
102 static int fscrypt_user_key_instantiate(struct key *key, in fscrypt_user_key_instantiate() argument
106 * We just charge FSCRYPT_MAX_KEY_SIZE bytes to the user's key quota for in fscrypt_user_key_instantiate()
107 * each key, regardless of the exact key size. The amount of memory in fscrypt_user_key_instantiate()
108 * actually used is greater than the size of the raw key anyway. in fscrypt_user_key_instantiate()
110 return key_payload_reserve(key, FSCRYPT_MAX_KEY_SIZE); in fscrypt_user_key_instantiate()
113 static void fscrypt_user_key_describe(const struct key *key, struct seq_file *m) in fscrypt_user_key_describe() argument
115 seq_puts(m, key->description); in fscrypt_user_key_describe()
119 * Type of key in ->mk_users. Each key of this type represents a particular
120 * user who has added a particular master key.
122 * Note that the name of this key type really should be something like
125 * user. And it is expected to be rare that a key is actually added by multiple
135 static struct key *search_fscrypt_keyring(struct key *keyring, in search_fscrypt_keyring()
203 struct key *keyring; in allocate_filesystem_keyring()
232 * Find the specified master key in ->s_master_keys.
235 struct key *fscrypt_find_master_key(struct super_block *sb, in fscrypt_find_master_key()
238 struct key *keyring; in fscrypt_find_master_key()
258 struct key *keyring; in allocate_master_key_users_keyring()
274 * Find the current user's "key" in the master key's ->mk_users.
277 static struct key *find_master_key_user(struct fscrypt_master_key *mk) in find_master_key_user()
287 * Give the current user a "key" in ->mk_users. This charges the user's quota
288 * and marks the master key as added by the current user, so that it cannot be
289 * removed by another user with the key. Either the master key's key->sem must
290 * be held for write, or the master key must be still undergoing initialization.
295 struct key *mk_user; in add_master_key_user()
311 * Remove the current user's "key" from ->mk_users.
312 * The master key's key->sem must be held for write.
318 struct key *mk_user; in remove_master_key_user()
331 * the payload of a new 'struct key' of type fscrypt, and link the 'struct key'
336 struct key *keyring) in add_new_master_key()
340 struct key *key; in add_new_master_key() local
365 * Note that we don't charge this key to anyone's quota, since when in add_new_master_key()
370 key = key_alloc(&key_type_fscrypt, description, in add_new_master_key()
374 if (IS_ERR(key)) { in add_new_master_key()
375 err = PTR_ERR(key); in add_new_master_key()
378 err = key_instantiate_and_link(key, mk, sizeof(*mk), keyring, NULL); in add_new_master_key()
379 key_put(key); in add_new_master_key()
395 struct key *mk_user; in add_existing_master_key()
439 struct key *key; in do_add_master_key() local
444 key = fscrypt_find_master_key(sb, mk_spec); in do_add_master_key()
445 if (IS_ERR(key)) { in do_add_master_key()
446 err = PTR_ERR(key); in do_add_master_key()
449 /* Didn't find the key in ->s_master_keys. Add it. */ in do_add_master_key()
456 * Found the key in ->s_master_keys. Re-add the secret if in do_add_master_key()
459 down_write(&key->sem); in do_add_master_key()
460 err = add_existing_master_key(key->payload.data[0], secret); in do_add_master_key()
461 up_write(&key->sem); in do_add_master_key()
463 /* Key being removed or needs to be removed */ in do_add_master_key()
464 key_invalidate(key); in do_add_master_key()
465 key_put(key); in do_add_master_key()
468 key_put(key); in do_add_master_key()
488 * Now that the HKDF context is initialized, the raw key is no in add_master_key()
493 /* Calculate the key identifier */ in add_master_key()
533 static void fscrypt_provisioning_key_describe(const struct key *key, in fscrypt_provisioning_key_describe() argument
536 seq_puts(m, key->description); in fscrypt_provisioning_key_describe()
537 if (key_is_positive(key)) { in fscrypt_provisioning_key_describe()
539 key->payload.data[0]; in fscrypt_provisioning_key_describe()
541 seq_printf(m, ": %u [%u]", key->datalen, payload->type); in fscrypt_provisioning_key_describe()
545 static void fscrypt_provisioning_key_destroy(struct key *key) in fscrypt_provisioning_key_destroy() argument
547 kfree_sensitive(key->payload.data[0]); in fscrypt_provisioning_key_destroy()
560 * Retrieve the raw key from the Linux keyring key specified by 'key_id', and
563 * The key must be of type "fscrypt-provisioning" and must have the field
566 * 'type'. We don't use the "logon" key type because there's no way to
570 * The ability to specify the key via Linux keyring key is intended for cases
572 * re-mounted. Most users should just provide the raw key directly instead.
578 struct key *key; in get_keyring_key() local
585 key = key_ref_to_ptr(ref); in get_keyring_key()
587 if (key->type != &key_type_fscrypt_provisioning) in get_keyring_key()
589 payload = key->payload.data[0]; in get_keyring_key()
595 secret->size = key->datalen - sizeof(*payload); in get_keyring_key()
608 * Add a master encryption key to the filesystem, causing all files which were
611 * When adding a key for use by v1 encryption policies, this ioctl is
614 * When adding a key for use by v2+ encryption policies, this ioctl is
618 * each key identified by its cryptographically secure hash --- the
620 * cannot add the wrong key for a given identifier. Furthermore, each added key
623 * user from removing a key while other users have added it too, which prevents
624 * a user who knows another user's key from causing a denial-of-service by
625 * removing it at an inopportune time. (We tolerate that a user who knows a key
651 * user could add the wrong key. in fscrypt_ioctl_add_key()
678 /* Return the key identifier to userspace, if applicable */ in fscrypt_ioctl_add_key()
692 * Add the key for '-o test_dummy_encryption' to the filesystem keyring.
694 * Use a per-boot random key to prevent people from misusing this option.
715 * Verify that the current user has added a master key with the given identifier
717 * their files using some other user's key which they don't actually know.
725 * Note that the key may have already removed by the time this returns, but
726 * that's okay; we just care whether the key was there at some point.
728 * Return: 0 if the key is added, -ENOKEY if it isn't, or another -errno code
734 struct key *key, *mk_user; in fscrypt_verify_key_added() local
741 key = fscrypt_find_master_key(sb, &mk_spec); in fscrypt_verify_key_added()
742 if (IS_ERR(key)) { in fscrypt_verify_key_added()
743 err = PTR_ERR(key); in fscrypt_verify_key_added()
746 mk = key->payload.data[0]; in fscrypt_verify_key_added()
754 key_put(key); in fscrypt_verify_key_added()
843 "%s: %zu inode(s) still busy after removing key with %s %*phN%s", in check_for_busy_inodes()
881 * have been evicted due to fscrypt_drop_inode() detecting the key in try_to_lock_encrypted_files()
891 * Try to remove an fscrypt master encryption key.
894 * claim to the key, then removes the key itself if no other users have claims.
896 * key itself.
898 * To "remove the key itself", first we wipe the actual master key secret, so
900 * inodes that had been unlocked with the key.
904 * state (without the actual secret key) where it tracks the list of remaining
906 * alternatively can re-add the secret key again.
916 struct key *key; in do_remove_key() local
939 /* Find the key being removed. */ in do_remove_key()
940 key = fscrypt_find_master_key(sb, &arg.key_spec); in do_remove_key()
941 if (IS_ERR(key)) in do_remove_key()
942 return PTR_ERR(key); in do_remove_key()
943 mk = key->payload.data[0]; in do_remove_key()
945 down_write(&key->sem); in do_remove_key()
947 /* If relevant, remove current user's (or all users) claim to the key */ in do_remove_key()
954 up_write(&key->sem); in do_remove_key()
959 * Other users have still added the key too. We removed in do_remove_key()
960 * the current user's claim to the key, but we still in do_remove_key()
961 * can't remove the key itself. in do_remove_key()
966 up_write(&key->sem); in do_remove_key()
977 up_write(&key->sem); in do_remove_key()
980 * No inodes reference the key, and we wiped the secret, so the in do_remove_key()
981 * key object is free to be removed from the keyring. in do_remove_key()
983 key_invalidate(key); in do_remove_key()
986 /* Some inodes still reference this key; try to evict them. */ in do_remove_key()
996 * key, wiped the secret, or tried locking the files again. Users need in do_remove_key()
997 * to check the informational status flags if they care whether the key in do_remove_key()
1001 key_put(key); in do_remove_key()
1022 * Retrieve the status of an fscrypt master encryption key.
1024 * We set ->status to indicate whether the key is absent, present, or
1025 * incompletely removed. "Incompletely removed" means that the master key
1033 * ->status_flags and ->user_count, whether the key has been added by the
1035 * this, since ordinarily only one user should know a given key. However, if a
1036 * secret key is shared by multiple users, applications may wish to add an
1037 * already-present key to prevent other users from removing it. This ioctl can
1039 * add the key --- which might e.g. require prompting the user for a passphrase.
1048 struct key *key; in fscrypt_ioctl_get_key_status() local
1065 key = fscrypt_find_master_key(sb, &arg.key_spec); in fscrypt_ioctl_get_key_status()
1066 if (IS_ERR(key)) { in fscrypt_ioctl_get_key_status()
1067 if (key != ERR_PTR(-ENOKEY)) in fscrypt_ioctl_get_key_status()
1068 return PTR_ERR(key); in fscrypt_ioctl_get_key_status()
1073 mk = key->payload.data[0]; in fscrypt_ioctl_get_key_status()
1074 down_read(&key->sem); in fscrypt_ioctl_get_key_status()
1084 struct key *mk_user; in fscrypt_ioctl_get_key_status()
1099 up_read(&key->sem); in fscrypt_ioctl_get_key_status()
1100 key_put(key); in fscrypt_ioctl_get_key_status()