Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

KEYS: Remove key_type::match in favour of overriding default by match_preparse

A previous patch added a ->match_preparse() method to the key type. This is
allowed to override the function called by the iteration algorithm.
Therefore, we can just set a default that simply checks for an exact match of
the key description with the original criterion data and allow match_preparse
to override it as needed.

The key_type::match op is then redundant and can be removed, as can the
user_match() function.

Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>

+31 -45
+3 -3
crypto/asymmetric_keys/asymmetric_type.c
··· 59 59 * "id:<id>" - request a key matching the ID 60 60 * "<subtype>:<id>" - request a key of a subtype 61 61 */ 62 - static int asymmetric_key_match(const struct key *key, 63 - const struct key_match_data *match_data) 62 + static int asymmetric_key_cmp(const struct key *key, 63 + const struct key_match_data *match_data) 64 64 { 65 65 const struct asymmetric_key_subtype *subtype = asymmetric_key_subtype(key); 66 66 const char *description = match_data->raw_data; ··· 110 110 static int asymmetric_key_match_preparse(struct key_match_data *match_data) 111 111 { 112 112 match_data->lookup_type = KEYRING_SEARCH_LOOKUP_ITERATE; 113 + match_data->cmp = asymmetric_key_cmp; 113 114 return 0; 114 115 } 115 116 ··· 225 224 .free_preparse = asymmetric_key_free_preparse, 226 225 .instantiate = generic_key_instantiate, 227 226 .match_preparse = asymmetric_key_match_preparse, 228 - .match = asymmetric_key_match, 229 227 .match_free = asymmetric_key_match_free, 230 228 .destroy = asymmetric_key_destroy, 231 229 .describe = asymmetric_key_describe,
-1
crypto/asymmetric_keys/pkcs7_key_type.c
··· 75 75 .preparse = pkcs7_preparse, 76 76 .free_preparse = user_free_preparse, 77 77 .instantiate = generic_key_instantiate, 78 - .match = user_match, 79 78 .revoke = user_revoke, 80 79 .destroy = user_destroy, 81 80 .describe = user_describe,
-1
fs/cifs/cifs_spnego.c
··· 62 62 struct key_type cifs_spnego_key_type = { 63 63 .name = "cifs.spnego", 64 64 .instantiate = cifs_spnego_key_instantiate, 65 - .match = user_match, 66 65 .destroy = cifs_spnego_key_destroy, 67 66 .describe = user_describe, 68 67 };
-1
fs/cifs/cifsacl.c
··· 84 84 .instantiate = cifs_idmap_key_instantiate, 85 85 .destroy = cifs_idmap_key_destroy, 86 86 .describe = user_describe, 87 - .match = user_match, 88 87 }; 89 88 90 89 static char *
-2
fs/nfs/idmap.c
··· 177 177 .preparse = user_preparse, 178 178 .free_preparse = user_free_preparse, 179 179 .instantiate = generic_key_instantiate, 180 - .match = user_match, 181 180 .revoke = user_revoke, 182 181 .destroy = user_destroy, 183 182 .describe = user_describe, ··· 400 401 .preparse = user_preparse, 401 402 .free_preparse = user_free_preparse, 402 403 .instantiate = generic_key_instantiate, 403 - .match = user_match, 404 404 .revoke = user_revoke, 405 405 .destroy = user_destroy, 406 406 .describe = user_describe,
-3
include/keys/user-type.h
··· 36 36 extern struct key_type key_type_logon; 37 37 38 38 struct key_preparsed_payload; 39 - struct key_match_data; 40 39 41 40 extern int user_preparse(struct key_preparsed_payload *prep); 42 41 extern void user_free_preparse(struct key_preparsed_payload *prep); 43 42 extern int user_update(struct key *key, struct key_preparsed_payload *prep); 44 - extern int user_match(const struct key *key, 45 - const struct key_match_data *match_data); 46 43 extern void user_revoke(struct key *key); 47 44 extern void user_destroy(struct key *key); 48 45 extern void user_describe(const struct key *user, struct seq_file *m);
-4
include/linux/key-type.h
··· 113 113 */ 114 114 int (*match_preparse)(struct key_match_data *match_data); 115 115 116 - /* match a key against a description */ 117 - int (*match)(const struct key *key, 118 - const struct key_match_data *match_data); 119 - 120 116 /* Free preparsed match data (optional). This should be supplied it 121 117 * ->match_preparse() is supplied. */ 122 118 void (*match_free)(struct key_match_data *match_data);
-1
net/ceph/crypto.c
··· 476 476 .preparse = ceph_key_preparse, 477 477 .free_preparse = ceph_key_free_preparse, 478 478 .instantiate = generic_key_instantiate, 479 - .match = user_match, 480 479 .destroy = ceph_key_destroy, 481 480 }; 482 481
+13 -4
net/dns_resolver/dns_key.c
··· 176 176 * The domain name may be a simple name or an absolute domain name (which 177 177 * should end with a period). The domain name is case-independent. 178 178 */ 179 - static int 180 - dns_resolver_match(const struct key *key, 181 - const struct key_match_data *match_data) 179 + static int dns_resolver_cmp(const struct key *key, 180 + const struct key_match_data *match_data) 182 181 { 183 182 int slen, dlen, ret = 0; 184 183 const char *src = key->description, *dsp = match_data->raw_data; ··· 206 207 no_match: 207 208 kleave(" = %d", ret); 208 209 return ret; 210 + } 211 + 212 + /* 213 + * Preparse the match criterion. 214 + */ 215 + static int dns_resolver_match_preparse(struct key_match_data *match_data) 216 + { 217 + match_data->lookup_type = KEYRING_SEARCH_LOOKUP_ITERATE; 218 + match_data->cmp = dns_resolver_cmp; 219 + return 0; 209 220 } 210 221 211 222 /* ··· 252 243 .preparse = dns_resolver_preparse, 253 244 .free_preparse = dns_resolver_free_preparse, 254 245 .instantiate = generic_key_instantiate, 255 - .match = dns_resolver_match, 246 + .match_preparse = dns_resolver_match_preparse, 256 247 .revoke = user_revoke, 257 248 .destroy = user_destroy, 258 249 .describe = dns_resolver_describe,
-2
net/rxrpc/ar-key.c
··· 44 44 .preparse = rxrpc_preparse, 45 45 .free_preparse = rxrpc_free_preparse, 46 46 .instantiate = generic_key_instantiate, 47 - .match = user_match, 48 47 .destroy = rxrpc_destroy, 49 48 .describe = rxrpc_describe, 50 49 .read = rxrpc_read, ··· 60 61 .preparse = rxrpc_preparse_s, 61 62 .free_preparse = rxrpc_free_preparse_s, 62 63 .instantiate = generic_key_instantiate, 63 - .match = user_match, 64 64 .destroy = rxrpc_destroy_s, 65 65 .describe = rxrpc_describe, 66 66 };
-1
security/keys/big_key.c
··· 36 36 .preparse = big_key_preparse, 37 37 .free_preparse = big_key_free_preparse, 38 38 .instantiate = generic_key_instantiate, 39 - .match = user_match, 40 39 .revoke = big_key_revoke, 41 40 .destroy = big_key_destroy, 42 41 .describe = big_key_describe,
-1
security/keys/encrypted-keys/encrypted.c
··· 970 970 .name = "encrypted", 971 971 .instantiate = encrypted_instantiate, 972 972 .update = encrypted_update, 973 - .match = user_match, 974 973 .destroy = encrypted_destroy, 975 974 .describe = user_describe, 976 975 .read = encrypted_read,
+2
security/keys/internal.h
··· 127 127 struct timespec now; 128 128 }; 129 129 130 + extern int key_default_cmp(const struct key *key, 131 + const struct key_match_data *match_data); 130 132 extern key_ref_t keyring_search_aux(key_ref_t keyring_ref, 131 133 struct keyring_search_context *ctx); 132 134
+1 -1
security/keys/key.c
··· 799 799 } 800 800 801 801 key_ref = ERR_PTR(-EINVAL); 802 - if (!index_key.type->match || !index_key.type->instantiate || 802 + if (!index_key.type->instantiate || 803 803 (!index_key.description && !index_key.type->preparse)) 804 804 goto error_put_type; 805 805
+10 -5
security/keys/keyring.c
··· 89 89 .preparse = keyring_preparse, 90 90 .free_preparse = keyring_free_preparse, 91 91 .instantiate = keyring_instantiate, 92 - .match = user_match, 93 92 .revoke = keyring_revoke, 94 93 .destroy = keyring_destroy, 95 94 .describe = keyring_describe, ··· 511 512 EXPORT_SYMBOL(keyring_alloc); 512 513 513 514 /* 515 + * By default, we keys found by getting an exact match on their descriptions. 516 + */ 517 + int key_default_cmp(const struct key *key, 518 + const struct key_match_data *match_data) 519 + { 520 + return strcmp(key->description, match_data->raw_data) == 0; 521 + } 522 + 523 + /* 514 524 * Iteration function to consider each key found. 515 525 */ 516 526 static int keyring_search_iterator(const void *object, void *iterator_data) ··· 892 884 .index_key.type = type, 893 885 .index_key.description = description, 894 886 .cred = current_cred(), 895 - .match_data.cmp = type->match, 887 + .match_data.cmp = key_default_cmp, 896 888 .match_data.raw_data = description, 897 889 .match_data.lookup_type = KEYRING_SEARCH_LOOKUP_DIRECT, 898 890 .flags = KEYRING_SEARCH_DO_STATE_CHECK, 899 891 }; 900 892 key_ref_t key; 901 893 int ret; 902 - 903 - if (!ctx.match_data.cmp) 904 - return ERR_PTR(-ENOKEY); 905 894 906 895 if (type->match_preparse) { 907 896 ret = type->match_preparse(&ctx.match_data);
+1 -1
security/keys/request_key.c
··· 531 531 .index_key.type = type, 532 532 .index_key.description = description, 533 533 .cred = current_cred(), 534 - .match_data.cmp = type->match, 534 + .match_data.cmp = key_default_cmp, 535 535 .match_data.raw_data = description, 536 536 .match_data.lookup_type = KEYRING_SEARCH_LOOKUP_DIRECT, 537 537 };
+1 -1
security/keys/request_key_auth.c
··· 246 246 .index_key.type = &key_type_request_key_auth, 247 247 .index_key.description = description, 248 248 .cred = current_cred(), 249 - .match_data.cmp = user_match, 249 + .match_data.cmp = key_default_cmp, 250 250 .match_data.raw_data = description, 251 251 .match_data.lookup_type = KEYRING_SEARCH_LOOKUP_DIRECT, 252 252 };
-1
security/keys/trusted.c
··· 1096 1096 .name = "trusted", 1097 1097 .instantiate = trusted_instantiate, 1098 1098 .update = trusted_update, 1099 - .match = user_match, 1100 1099 .destroy = trusted_destroy, 1101 1100 .describe = user_describe, 1102 1101 .read = trusted_read,
-12
security/keys/user_defined.c
··· 30 30 .free_preparse = user_free_preparse, 31 31 .instantiate = generic_key_instantiate, 32 32 .update = user_update, 33 - .match = user_match, 34 33 .revoke = user_revoke, 35 34 .destroy = user_destroy, 36 35 .describe = user_describe, ··· 50 51 .free_preparse = user_free_preparse, 51 52 .instantiate = generic_key_instantiate, 52 53 .update = user_update, 53 - .match = user_match, 54 54 .revoke = user_revoke, 55 55 .destroy = user_destroy, 56 56 .describe = user_describe, ··· 133 135 } 134 136 135 137 EXPORT_SYMBOL_GPL(user_update); 136 - 137 - /* 138 - * match users on their name 139 - */ 140 - int user_match(const struct key *key, const struct key_match_data *match_data) 141 - { 142 - return strcmp(key->description, match_data->raw_data) == 0; 143 - } 144 - 145 - EXPORT_SYMBOL_GPL(user_match); 146 138 147 139 /* 148 140 * dispose of the links from a revoked keyring