diff options
author | David Howells <dhowells@redhat.com> | 2014-07-18 13:56:34 -0400 |
---|---|---|
committer | David Howells <dhowells@redhat.com> | 2014-07-18 13:56:34 -0400 |
commit | 6a09d17bb66a533c165be81e8a4c3557f68e1a3b (patch) | |
tree | d56b7ce27813ea9ab20ae1f22236af76b5390d6a /security | |
parent | 32c2e6752ff0f48fe03b9e1c7c64bde580a840d2 (diff) |
KEYS: Provide a generic instantiation function
Provide a generic instantiation function for key types that use the preparse
hook. This makes it easier to prereserve key quota before keyrings get locked
to retain the new key.
Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: Steve Dickson <steved@redhat.com>
Acked-by: Jeff Layton <jlayton@primarydata.com>
Reviewed-by: Sage Weil <sage@redhat.com>
Diffstat (limited to 'security')
-rw-r--r-- | security/keys/key.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/security/keys/key.c b/security/keys/key.c index 2048a110e7f1..7c9acbf106b6 100644 --- a/security/keys/key.c +++ b/security/keys/key.c | |||
@@ -1024,6 +1024,36 @@ void key_invalidate(struct key *key) | |||
1024 | EXPORT_SYMBOL(key_invalidate); | 1024 | EXPORT_SYMBOL(key_invalidate); |
1025 | 1025 | ||
1026 | /** | 1026 | /** |
1027 | * generic_key_instantiate - Simple instantiation of a key from preparsed data | ||
1028 | * @key: The key to be instantiated | ||
1029 | * @prep: The preparsed data to load. | ||
1030 | * | ||
1031 | * Instantiate a key from preparsed data. We assume we can just copy the data | ||
1032 | * in directly and clear the old pointers. | ||
1033 | * | ||
1034 | * This can be pointed to directly by the key type instantiate op pointer. | ||
1035 | */ | ||
1036 | int generic_key_instantiate(struct key *key, struct key_preparsed_payload *prep) | ||
1037 | { | ||
1038 | int ret; | ||
1039 | |||
1040 | pr_devel("==>%s()\n", __func__); | ||
1041 | |||
1042 | ret = key_payload_reserve(key, prep->quotalen); | ||
1043 | if (ret == 0) { | ||
1044 | key->type_data.p[0] = prep->type_data[0]; | ||
1045 | key->type_data.p[1] = prep->type_data[1]; | ||
1046 | rcu_assign_keypointer(key, prep->payload); | ||
1047 | prep->type_data[0] = NULL; | ||
1048 | prep->type_data[1] = NULL; | ||
1049 | prep->payload = NULL; | ||
1050 | } | ||
1051 | pr_devel("<==%s() = %d\n", __func__, ret); | ||
1052 | return ret; | ||
1053 | } | ||
1054 | EXPORT_SYMBOL(generic_key_instantiate); | ||
1055 | |||
1056 | /** | ||
1027 | * register_key_type - Register a type of key. | 1057 | * register_key_type - Register a type of key. |
1028 | * @ktype: The new key type. | 1058 | * @ktype: The new key type. |
1029 | * | 1059 | * |