mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-24 09:50:04 +00:00
![David Howells](/assets/img/avatar_default.png)
Give the key type the opportunity to preparse the payload prior to the instantiation and update routines being called. This is done with the provision of two new key type operations: int (*preparse)(struct key_preparsed_payload *prep); void (*free_preparse)(struct key_preparsed_payload *prep); If the first operation is present, then it is called before key creation (in the add/update case) or before the key semaphore is taken (in the update and instantiate cases). The second operation is called to clean up if the first was called. preparse() is given the opportunity to fill in the following structure: struct key_preparsed_payload { char *description; void *type_data[2]; void *payload; const void *data; size_t datalen; size_t quotalen; }; Before the preparser is called, the first three fields will have been cleared, the payload pointer and size will be stored in data and datalen and the default quota size from the key_type struct will be stored into quotalen. The preparser may parse the payload in any way it likes and may store data in the type_data[] and payload fields for use by the instantiate() and update() ops. The preparser may also propose a description for the key by attaching it as a string to the description field. This can be used by passing a NULL or "" description to the add_key() system call or the key_create_or_update() function. This cannot work with request_key() as that required the description to tell the upcall about the key to be created. This, for example permits keys that store PGP public keys to generate their own name from the user ID and public key fingerprint in the key. The instantiate() and update() operations are then modified to look like this: int (*instantiate)(struct key *key, struct key_preparsed_payload *prep); int (*update)(struct key *key, struct key_preparsed_payload *prep); and the new payload data is passed in *prep, whether or not it was preparsed. Signed-off-by: David Howells <dhowells@redhat.com> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
157 lines
5.1 KiB
C
157 lines
5.1 KiB
C
/* Definitions for key type implementations
|
|
*
|
|
* Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
|
|
* Written by David Howells (dhowells@redhat.com)
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public Licence
|
|
* as published by the Free Software Foundation; either version
|
|
* 2 of the Licence, or (at your option) any later version.
|
|
*/
|
|
|
|
#ifndef _LINUX_KEY_TYPE_H
|
|
#define _LINUX_KEY_TYPE_H
|
|
|
|
#include <linux/key.h>
|
|
#include <linux/errno.h>
|
|
|
|
#ifdef CONFIG_KEYS
|
|
|
|
/*
|
|
* key under-construction record
|
|
* - passed to the request_key actor if supplied
|
|
*/
|
|
struct key_construction {
|
|
struct key *key; /* key being constructed */
|
|
struct key *authkey;/* authorisation for key being constructed */
|
|
};
|
|
|
|
/*
|
|
* Pre-parsed payload, used by key add, update and instantiate.
|
|
*
|
|
* This struct will be cleared and data and datalen will be set with the data
|
|
* and length parameters from the caller and quotalen will be set from
|
|
* def_datalen from the key type. Then if the preparse() op is provided by the
|
|
* key type, that will be called. Then the struct will be passed to the
|
|
* instantiate() or the update() op.
|
|
*
|
|
* If the preparse() op is given, the free_preparse() op will be called to
|
|
* clear the contents.
|
|
*/
|
|
struct key_preparsed_payload {
|
|
char *description; /* Proposed key description (or NULL) */
|
|
void *type_data[2]; /* Private key-type data */
|
|
void *payload; /* Proposed payload */
|
|
const void *data; /* Raw data */
|
|
size_t datalen; /* Raw datalen */
|
|
size_t quotalen; /* Quota length for proposed payload */
|
|
};
|
|
|
|
typedef int (*request_key_actor_t)(struct key_construction *key,
|
|
const char *op, void *aux);
|
|
|
|
/*
|
|
* kernel managed key type definition
|
|
*/
|
|
struct key_type {
|
|
/* name of the type */
|
|
const char *name;
|
|
|
|
/* default payload length for quota precalculation (optional)
|
|
* - this can be used instead of calling key_payload_reserve(), that
|
|
* function only needs to be called if the real datalen is different
|
|
*/
|
|
size_t def_datalen;
|
|
|
|
/* vet a description */
|
|
int (*vet_description)(const char *description);
|
|
|
|
/* Preparse the data blob from userspace that is to be the payload,
|
|
* generating a proposed description and payload that will be handed to
|
|
* the instantiate() and update() ops.
|
|
*/
|
|
int (*preparse)(struct key_preparsed_payload *prep);
|
|
|
|
/* Free a preparse data structure.
|
|
*/
|
|
void (*free_preparse)(struct key_preparsed_payload *prep);
|
|
|
|
/* instantiate a key of this type
|
|
* - this method should call key_payload_reserve() to determine if the
|
|
* user's quota will hold the payload
|
|
*/
|
|
int (*instantiate)(struct key *key, struct key_preparsed_payload *prep);
|
|
|
|
/* update a key of this type (optional)
|
|
* - this method should call key_payload_reserve() to recalculate the
|
|
* quota consumption
|
|
* - the key must be locked against read when modifying
|
|
*/
|
|
int (*update)(struct key *key, struct key_preparsed_payload *prep);
|
|
|
|
/* match a key against a description */
|
|
int (*match)(const struct key *key, const void *desc);
|
|
|
|
/* clear some of the data from a key on revokation (optional)
|
|
* - the key's semaphore will be write-locked by the caller
|
|
*/
|
|
void (*revoke)(struct key *key);
|
|
|
|
/* clear the data from a key (optional) */
|
|
void (*destroy)(struct key *key);
|
|
|
|
/* describe a key */
|
|
void (*describe)(const struct key *key, struct seq_file *p);
|
|
|
|
/* read a key's data (optional)
|
|
* - permission checks will be done by the caller
|
|
* - the key's semaphore will be readlocked by the caller
|
|
* - should return the amount of data that could be read, no matter how
|
|
* much is copied into the buffer
|
|
* - shouldn't do the copy if the buffer is NULL
|
|
*/
|
|
long (*read)(const struct key *key, char __user *buffer, size_t buflen);
|
|
|
|
/* handle request_key() for this type instead of invoking
|
|
* /sbin/request-key (optional)
|
|
* - key is the key to instantiate
|
|
* - authkey is the authority to assume when instantiating this key
|
|
* - op is the operation to be done, usually "create"
|
|
* - the call must not return until the instantiation process has run
|
|
* its course
|
|
*/
|
|
request_key_actor_t request_key;
|
|
|
|
/* internal fields */
|
|
struct list_head link; /* link in types list */
|
|
struct lock_class_key lock_class; /* key->sem lock class */
|
|
};
|
|
|
|
extern struct key_type key_type_keyring;
|
|
|
|
extern int register_key_type(struct key_type *ktype);
|
|
extern void unregister_key_type(struct key_type *ktype);
|
|
|
|
extern int key_payload_reserve(struct key *key, size_t datalen);
|
|
extern int key_instantiate_and_link(struct key *key,
|
|
const void *data,
|
|
size_t datalen,
|
|
struct key *keyring,
|
|
struct key *instkey);
|
|
extern int key_reject_and_link(struct key *key,
|
|
unsigned timeout,
|
|
unsigned error,
|
|
struct key *keyring,
|
|
struct key *instkey);
|
|
extern void complete_request_key(struct key_construction *cons, int error);
|
|
|
|
static inline int key_negate_and_link(struct key *key,
|
|
unsigned timeout,
|
|
struct key *keyring,
|
|
struct key *instkey)
|
|
{
|
|
return key_reject_and_link(key, timeout, ENOKEY, keyring, instkey);
|
|
}
|
|
|
|
#endif /* CONFIG_KEYS */
|
|
#endif /* _LINUX_KEY_TYPE_H */
|