/* Keyring handling * * Copyright (C) 2004-2005, 2008, 2013 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 License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. */#include <linux/module.h>#include <linux/init.h>#include <linux/sched.h>#include <linux/slab.h>#include <linux/security.h>#include <linux/seq_file.h>#include <linux/err.h>#include <keys/keyring-type.h>#include <keys/user-type.h>#include <linux/assoc_array_priv.h>#include <linux/uaccess.h>#include"internal.h"/* * When plumbing the depths of the key tree, this sets a hard limit * set on how deep we're willing to go. */#define KEYRING_SEARCH_MAX_DEPTH 6/* * We keep all named keyrings in a hash to speed looking them up. */#define KEYRING_NAME_HASH_SIZE (1 << 5)/* * We mark pointers we pass to the associative array with bit 1 set if * they're keyrings and clear otherwise. */#define KEYRING_PTR_SUBTYPE 0x2ULstaticinlineboolkeyring_ptr_is_keyring(const struct assoc_array_ptr *x){return(unsigned long)x & KEYRING_PTR_SUBTYPE;}staticinlinestruct key *keyring_ptr_to_key(const struct assoc_array_ptr *x){void*object =assoc_array_ptr_to_leaf(x);return(struct key *)((unsigned long)object & ~KEYRING_PTR_SUBTYPE);}staticinlinevoid*keyring_key_to_ptr(struct key *key){if(key->type == &key_type_keyring)return(void*)((unsigned long)key | KEYRING_PTR_SUBTYPE);return key;}static struct list_head keyring_name_hash[KEYRING_NAME_HASH_SIZE];staticDEFINE_RWLOCK(keyring_name_lock);staticinlineunsignedkeyring_hash(const char*desc){unsigned bucket =0;for(; *desc; desc++)
bucket += (unsigned char)*desc;return bucket & (KEYRING_NAME_HASH_SIZE -1);}/* * The keyring key type definition. Keyrings are simply keys of this type and * can be treated as ordinary keys in addition to having their own special * operations. */static intkeyring_preparse(struct key_preparsed_payload *prep);static voidkeyring_free_preparse(struct key_preparsed_payload *prep);static intkeyring_instantiate(struct key *keyring,struct key_preparsed_payload *prep);static voidkeyring_revoke(struct key *keyring);static voidkeyring_destroy(