mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-23 01:10:04 +00:00
![Linus Torvalds](/assets/img/avatar_default.png)
-----BEGIN PGP SIGNATURE----- iQIVAwUAXRU89Pu3V2unywtrAQIdBBAAmMBsrfv+LUN4Vru/D6KdUO4zdYGcNK6m S56bcNfP6oIDEj6HrNNnzKkWIZpdZ61Odv1zle96+v4WZ/6rnLCTpcsdaFNTzaoO YT2jk7jplss0ImrMv1DSoykGqO3f0ThMIpGCxHKZADGSu0HMbjSEh+zLPV4BaMtT BVuF7P3eZtDRLdDtMtYcgvf5UlbdoBEY8w1FUjReQx8hKGxVopGmCo5vAeiY8W9S ybFSZhPS5ka33ynVrLJH2dqDo5A8pDhY8I4bdlcxmNtRhnPCYZnuvTqeAzyUKKdI YN9zJeDu1yHs9mi8dp45NPJiKy6xLzWmUwqH8AvR8MWEkrwzqbzNZCEHZ41j74hO YZWI0JXi72cboszFvOwqJERvITKxrQQyVQLPRQE2vVbG0bIZPl8i7oslFVhitsl+ evWqHb4lXY91rI9cC6JIXR1OiUjp68zXPv7DAnxv08O+PGcioU1IeOvPivx8QSx4 5aUeCkYIIAti/GISzv7xvcYh8mfO76kBjZSB35fX+R9DkeQpxsHmmpWe+UCykzWn EwhHQn86+VeBFP6RAXp8CgNCLbrwkEhjzXQl/70s1eYbwvK81VcpDAQ6+cjpf4Hb QUmrUJ9iE0wCNl7oqvJZoJvWVGlArvPmzpkTJk3N070X2R0T7x1WCsMlPDMJGhQ2 fVHvA3QdgWs= =Push -----END PGP SIGNATURE----- Merge tag 'keys-namespace-20190627' of git://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs Pull keyring namespacing from David Howells: "These patches help make keys and keyrings more namespace aware. Firstly some miscellaneous patches to make the process easier: - Simplify key index_key handling so that the word-sized chunks assoc_array requires don't have to be shifted about, making it easier to add more bits into the key. - Cache the hash value in the key so that we don't have to calculate on every key we examine during a search (it involves a bunch of multiplications). - Allow keying_search() to search non-recursively. Then the main patches: - Make it so that keyring names are per-user_namespace from the point of view of KEYCTL_JOIN_SESSION_KEYRING so that they're not accessible cross-user_namespace. keyctl_capabilities() shows KEYCTL_CAPS1_NS_KEYRING_NAME for this. - Move the user and user-session keyrings to the user_namespace rather than the user_struct. This prevents them propagating directly across user_namespaces boundaries (ie. the KEY_SPEC_* flags will only pick from the current user_namespace). - Make it possible to include the target namespace in which the key shall operate in the index_key. This will allow the possibility of multiple keys with the same description, but different target domains to be held in the same keyring. keyctl_capabilities() shows KEYCTL_CAPS1_NS_KEY_TAG for this. - Make it so that keys are implicitly invalidated by removal of a domain tag, causing them to be garbage collected. - Institute a network namespace domain tag that allows keys to be differentiated by the network namespace in which they operate. New keys that are of a type marked 'KEY_TYPE_NET_DOMAIN' are assigned the network domain in force when they are created. - Make it so that the desired network namespace can be handed down into the request_key() mechanism. This allows AFS, NFS, etc. to request keys specific to the network namespace of the superblock. This also means that the keys in the DNS record cache are thenceforth namespaced, provided network filesystems pass the appropriate network namespace down into dns_query(). For DNS, AFS and NFS are good, whilst CIFS and Ceph are not. Other cache keyrings, such as idmapper keyrings, also need to set the domain tag - for which they need access to the network namespace of the superblock" * tag 'keys-namespace-20190627' of git://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs: keys: Pass the network namespace into request_key mechanism keys: Network namespace domain tag keys: Garbage collect keys for which the domain has been removed keys: Include target namespace in match criteria keys: Move the user and user-session keyrings to the user_namespace keys: Namespace keyring names keys: Add a 'recurse' flag for keyring searches keys: Cache the hash value to avoid lots of recalculation keys: Simplify key description management
192 lines
6.5 KiB
C
192 lines
6.5 KiB
C
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
/* Definitions for key type implementations
|
|
*
|
|
* Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
|
|
* Written by David Howells (dhowells@redhat.com)
|
|
*/
|
|
|
|
#ifndef _LINUX_KEY_TYPE_H
|
|
#define _LINUX_KEY_TYPE_H
|
|
|
|
#include <linux/key.h>
|
|
#include <linux/errno.h>
|
|
|
|
#ifdef CONFIG_KEYS
|
|
|
|
struct kernel_pkey_query;
|
|
struct kernel_pkey_params;
|
|
|
|
/*
|
|
* 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) */
|
|
union key_payload payload; /* Proposed payload */
|
|
const void *data; /* Raw data */
|
|
size_t datalen; /* Raw datalen */
|
|
size_t quotalen; /* Quota length for proposed payload */
|
|
time64_t expiry; /* Expiry time of key */
|
|
} __randomize_layout;
|
|
|
|
typedef int (*request_key_actor_t)(struct key *auth_key, void *aux);
|
|
|
|
/*
|
|
* Preparsed matching criterion.
|
|
*/
|
|
struct key_match_data {
|
|
/* Comparison function, defaults to exact description match, but can be
|
|
* overridden by type->match_preparse(). Should return true if a match
|
|
* is found and false if not.
|
|
*/
|
|
bool (*cmp)(const struct key *key,
|
|
const struct key_match_data *match_data);
|
|
|
|
const void *raw_data; /* Raw match data */
|
|
void *preparsed; /* For ->match_preparse() to stash stuff */
|
|
unsigned lookup_type; /* Type of lookup for this search. */
|
|
#define KEYRING_SEARCH_LOOKUP_DIRECT 0x0000 /* Direct lookup by description. */
|
|
#define KEYRING_SEARCH_LOOKUP_ITERATE 0x0001 /* Iterative search. */
|
|
};
|
|
|
|
/*
|
|
* 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;
|
|
|
|
unsigned int flags;
|
|
#define KEY_TYPE_NET_DOMAIN 0x00000001 /* Keys of this type have a net namespace domain */
|
|
|
|
/* 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);
|
|
|
|
/* Preparse the data supplied to ->match() (optional). The
|
|
* data to be preparsed can be found in match_data->raw_data.
|
|
* The lookup type can also be set by this function.
|
|
*/
|
|
int (*match_preparse)(struct key_match_data *match_data);
|
|
|
|
/* Free preparsed match data (optional). This should be supplied it
|
|
* ->match_preparse() is supplied. */
|
|
void (*match_free)(struct key_match_data *match_data);
|
|
|
|
/* 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;
|
|
|
|
/* Look up a keyring access restriction (optional)
|
|
*
|
|
* - NULL is a valid return value (meaning the requested restriction
|
|
* is known but will never block addition of a key)
|
|
* - should return -EINVAL if the restriction is unknown
|
|
*/
|
|
struct key_restriction *(*lookup_restriction)(const char *params);
|
|
|
|
/* Asymmetric key accessor functions. */
|
|
int (*asym_query)(const struct kernel_pkey_params *params,
|
|
struct kernel_pkey_query *info);
|
|
int (*asym_eds_op)(struct kernel_pkey_params *params,
|
|
const void *in, void *out);
|
|
int (*asym_verify_signature)(struct kernel_pkey_params *params,
|
|
const void *in, const void *in2);
|
|
|
|
/* internal fields */
|
|
struct list_head link; /* link in types list */
|
|
struct lock_class_key lock_class; /* key->sem lock class */
|
|
} __randomize_layout;
|
|
|
|
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 *authkey);
|
|
extern int key_reject_and_link(struct key *key,
|
|
unsigned timeout,
|
|
unsigned error,
|
|
struct key *keyring,
|
|
struct key *authkey);
|
|
extern void complete_request_key(struct key *authkey, int error);
|
|
|
|
static inline int key_negate_and_link(struct key *key,
|
|
unsigned timeout,
|
|
struct key *keyring,
|
|
struct key *authkey)
|
|
{
|
|
return key_reject_and_link(key, timeout, ENOKEY, keyring, authkey);
|
|
}
|
|
|
|
extern int generic_key_instantiate(struct key *key, struct key_preparsed_payload *prep);
|
|
|
|
#endif /* CONFIG_KEYS */
|
|
#endif /* _LINUX_KEY_TYPE_H */
|