Lookup the key type by name and protect ecryptfs from encrypted_keys.ko module load failures, and cleanup the configuration dependencies on the definition of the ecryptfs_get_encrypted_key() helper. Cc: Tyler Hicks <tyhicks@xxxxxxxxxxxxx> Cc: <ecryptfs@xxxxxxxxxxxxxxx> Signed-off-by: Dan Williams <dan.j.williams@xxxxxxxxx> --- fs/ecryptfs/ecryptfs_kernel.h | 22 +--------------------- fs/ecryptfs/keystore.c | 12 ++++++++++++ 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/fs/ecryptfs/ecryptfs_kernel.h b/fs/ecryptfs/ecryptfs_kernel.h index e74cb2a0b299..3106d23d95f0 100644 --- a/fs/ecryptfs/ecryptfs_kernel.h +++ b/fs/ecryptfs/ecryptfs_kernel.h @@ -87,13 +87,12 @@ struct ecryptfs_page_crypt_context { } param; }; -#if defined(CONFIG_ENCRYPTED_KEYS) || defined(CONFIG_ENCRYPTED_KEYS_MODULE) static inline struct ecryptfs_auth_tok * ecryptfs_get_encrypted_key_payload_data(struct key *key) { struct encrypted_key_payload *payload; - if (key->type != &key_type_encrypted) + if (strcmp(key->type->name, "encrypted") != 0) return NULL; payload = key->payload.data[0]; @@ -103,25 +102,6 @@ ecryptfs_get_encrypted_key_payload_data(struct key *key) return (struct ecryptfs_auth_tok *)payload->payload_data; } -static inline struct key *ecryptfs_get_encrypted_key(char *sig) -{ - return request_key(&key_type_encrypted, sig, NULL); -} - -#else -static inline struct ecryptfs_auth_tok * -ecryptfs_get_encrypted_key_payload_data(struct key *key) -{ - return NULL; -} - -static inline struct key *ecryptfs_get_encrypted_key(char *sig) -{ - return ERR_PTR(-ENOKEY); -} - -#endif /* CONFIG_ENCRYPTED_KEYS */ - static inline struct ecryptfs_auth_tok * ecryptfs_get_key_payload_data(struct key *key) { diff --git a/fs/ecryptfs/keystore.c b/fs/ecryptfs/keystore.c index e74fe84d0886..52a01dd57f4a 100644 --- a/fs/ecryptfs/keystore.c +++ b/fs/ecryptfs/keystore.c @@ -1619,6 +1619,17 @@ parse_tag_11_packet(unsigned char *data, unsigned char *contents, return rc; } +static struct key *ecryptfs_get_encrypted_key(char *sig) +{ + struct key_type *type; + struct key *key; + + type = key_type_lookup("encrypted"); + if (IS_ERR(type)) + return (struct key *) type; + return request_key(type, sig, NULL); +} + int ecryptfs_keyring_auth_tok_for_sig(struct key **auth_tok_key, struct ecryptfs_auth_tok **auth_tok, char *sig) @@ -2542,3 +2553,4 @@ ecryptfs_add_global_auth_tok(struct ecryptfs_mount_crypt_stat *mount_crypt_stat, return 0; } +MODULE_SOFTDEP("pre: encrypted_keys");