Skip to content

Commit d0a059c

Browse files
committed
KEYS: Search for auth-key by name rather than target key ID
Search for auth-key by name rather than by target key ID as, in a future patch, we'll by searching directly by index key in preference to iteration over all keys. Signed-off-by: David Howells <dhowells@redhat.com>
1 parent 4bdf0bc commit d0a059c

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

security/keys/request_key_auth.c

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <linux/slab.h>
1919
#include <asm/uaccess.h>
2020
#include "internal.h"
21+
#include <keys/user-type.h>
2122

2223
static int request_key_auth_instantiate(struct key *,
2324
struct key_preparsed_payload *);
@@ -221,34 +222,26 @@ struct key *request_key_auth_new(struct key *target, const void *callout_info,
221222
return ERR_PTR(ret);
222223
}
223224

224-
/*
225-
* See if an authorisation key is associated with a particular key.
226-
*/
227-
static int key_get_instantiation_authkey_match(const struct key *key,
228-
const void *_id)
229-
{
230-
struct request_key_auth *rka = key->payload.data;
231-
key_serial_t id = (key_serial_t)(unsigned long) _id;
232-
233-
return rka->target_key->serial == id;
234-
}
235-
236225
/*
237226
* Search the current process's keyrings for the authorisation key for
238227
* instantiation of a key.
239228
*/
240229
struct key *key_get_instantiation_authkey(key_serial_t target_id)
241230
{
231+
char description[16];
242232
struct keyring_search_context ctx = {
243233
.index_key.type = &key_type_request_key_auth,
234+
.index_key.description = description,
244235
.cred = current_cred(),
245-
.match = key_get_instantiation_authkey_match,
246-
.match_data = (void *)(unsigned long)target_id,
236+
.match = user_match,
237+
.match_data = description,
247238
.flags = KEYRING_SEARCH_LOOKUP_DIRECT,
248239
};
249240
struct key *authkey;
250241
key_ref_t authkey_ref;
251242

243+
sprintf(description, "%x", target_id);
244+
252245
authkey_ref = search_process_keyrings(&ctx);
253246

254247
if (IS_ERR(authkey_ref)) {

0 commit comments

Comments
 (0)