diff options
Diffstat (limited to 'security/keys/request_key_auth.c')
| -rw-r--r-- | security/keys/request_key_auth.c | 104 | 
1 files changed, 42 insertions, 62 deletions
diff --git a/security/keys/request_key_auth.c b/security/keys/request_key_auth.c index 86747151ee5..7495a93b4b9 100644 --- a/security/keys/request_key_auth.c +++ b/security/keys/request_key_auth.c @@ -1,4 +1,4 @@ -/* request_key_auth.c: request key authorisation controlling key def +/* Request key authorisation token key definition.   *   * Copyright (C) 2005 Red Hat, Inc. All Rights Reserved.   * Written by David Howells (dhowells@redhat.com) @@ -8,7 +8,7 @@   * as published by the Free Software Foundation; either version   * 2 of the License, or (at your option) any later version.   * - * See Documentation/keys-request-key.txt + * See Documentation/security/keys-request-key.txt   */  #include <linux/module.h> @@ -18,15 +18,17 @@  #include <linux/slab.h>  #include <asm/uaccess.h>  #include "internal.h" +#include <keys/user-type.h> -static int request_key_auth_instantiate(struct key *, const void *, size_t); +static int request_key_auth_instantiate(struct key *, +					struct key_preparsed_payload *);  static void request_key_auth_describe(const struct key *, struct seq_file *);  static void request_key_auth_revoke(struct key *);  static void request_key_auth_destroy(struct key *);  static long request_key_auth_read(const struct key *, char __user *, size_t);  /* - * the request-key authorisation key type definition + * The request-key authorisation key type definition.   */  struct key_type key_type_request_key_auth = {  	.name		= ".request_key_auth", @@ -38,22 +40,18 @@ struct key_type key_type_request_key_auth = {  	.read		= request_key_auth_read,  }; -/*****************************************************************************/  /* - * instantiate a request-key authorisation key + * Instantiate a request-key authorisation key.   */  static int request_key_auth_instantiate(struct key *key, -					const void *data, -					size_t datalen) +					struct key_preparsed_payload *prep)  { -	key->payload.data = (struct request_key_auth *) data; +	key->payload.data = (struct request_key_auth *)prep->data;  	return 0; +} -} /* end request_key_auth_instantiate() */ - -/*****************************************************************************/  /* - * reading a request-key authorisation key retrieves the callout information + * Describe an authorisation token.   */  static void request_key_auth_describe(const struct key *key,  				      struct seq_file *m) @@ -62,13 +60,12 @@ static void request_key_auth_describe(const struct key *key,  	seq_puts(m, "key:");  	seq_puts(m, key->description); -	seq_printf(m, " pid:%d ci:%zu", rka->pid, rka->callout_len); - -} /* end request_key_auth_describe() */ +	if (key_is_instantiated(key)) +		seq_printf(m, " pid:%d ci:%zu", rka->pid, rka->callout_len); +} -/*****************************************************************************/  /* - * read the callout_info data + * Read the callout_info data (retrieves the callout information).   * - the key's semaphore is read-locked   */  static long request_key_auth_read(const struct key *key, @@ -91,13 +88,12 @@ static long request_key_auth_read(const struct key *key,  	}  	return ret; +} -} /* end request_key_auth_read() */ - -/*****************************************************************************/  /* - * handle revocation of an authorisation token key - * - called with the key sem write-locked + * Handle revocation of an authorisation token key. + * + * Called with the key sem write-locked.   */  static void request_key_auth_revoke(struct key *key)  { @@ -109,12 +105,10 @@ static void request_key_auth_revoke(struct key *key)  		put_cred(rka->cred);  		rka->cred = NULL;  	} +} -} /* end request_key_auth_revoke() */ - -/*****************************************************************************/  /* - * destroy an instantiation authorisation token key + * Destroy an instantiation authorisation token key.   */  static void request_key_auth_destroy(struct key *key)  { @@ -131,13 +125,11 @@ static void request_key_auth_destroy(struct key *key)  	key_put(rka->dest_keyring);  	kfree(rka->callout_info);  	kfree(rka); +} -} /* end request_key_auth_destroy() */ - -/*****************************************************************************/  /* - * create an authorisation token for /sbin/request-key or whoever to gain - * access to the caller's security data + * Create an authorisation token for /sbin/request-key or whoever to gain + * access to the caller's security data.   */  struct key *request_key_auth_new(struct key *target, const void *callout_info,  				 size_t callout_len, struct key *dest_keyring) @@ -228,45 +220,34 @@ error_alloc:  	kfree(rka);  	kleave("= %d", ret);  	return ERR_PTR(ret); +} -} /* end request_key_auth_new() */ - -/*****************************************************************************/ -/* - * see if an authorisation key is associated with a particular key - */ -static int key_get_instantiation_authkey_match(const struct key *key, -					       const void *_id) -{ -	struct request_key_auth *rka = key->payload.data; -	key_serial_t id = (key_serial_t)(unsigned long) _id; - -	return rka->target_key->serial == id; - -} /* end key_get_instantiation_authkey_match() */ - -/*****************************************************************************/  /* - * get the authorisation key for instantiation of a specific key if attached to - * the current process's keyrings - * - this key is inserted into a keyring and that is set as /sbin/request-key's - *   session keyring - * - a target_id of zero specifies any valid token + * Search the current process's keyrings for the authorisation key for + * instantiation of a key.   */  struct key *key_get_instantiation_authkey(key_serial_t target_id)  { -	const struct cred *cred = current_cred(); +	char description[16]; +	struct keyring_search_context ctx = { +		.index_key.type		= &key_type_request_key_auth, +		.index_key.description	= description, +		.cred			= current_cred(), +		.match			= user_match, +		.match_data		= description, +		.flags			= KEYRING_SEARCH_LOOKUP_DIRECT, +	};  	struct key *authkey;  	key_ref_t authkey_ref; -	authkey_ref = search_process_keyrings( -		&key_type_request_key_auth, -		(void *) (unsigned long) target_id, -		key_get_instantiation_authkey_match, -		cred); +	sprintf(description, "%x", target_id); + +	authkey_ref = search_process_keyrings(&ctx);  	if (IS_ERR(authkey_ref)) {  		authkey = ERR_CAST(authkey_ref); +		if (authkey == ERR_PTR(-EAGAIN)) +			authkey = ERR_PTR(-ENOKEY);  		goto error;  	} @@ -278,5 +259,4 @@ struct key *key_get_instantiation_authkey(key_serial_t target_id)  error:  	return authkey; - -} /* end key_get_instantiation_authkey() */ +}  | 
