kcf.c revision ef56a3c55098f8a52f056c7aa6ab084bfebef4e7
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Core KCF (Kernel Cryptographic Framework). This file implements
* the loadable module entry points and module verification routines.
*/
#ifdef DEBUG
int kcf_frmwrk_debug = 0;
#else /* DEBUG */
#define KCF_FRMWRK_DEBUG(l, x)
#endif /* DEBUG */
/*
* Door to make upcalls to kcfd. kcfd will send us this
* handle when it is coming up.
*/
&mod_miscops, "Kernel Crypto Framework"
};
static struct modlinkage modlinkage = {
};
static int rngtimer_started;
int
_init()
{
/* initialize the mechanisms tables supported out-of-the-box */
/* initialize the providers tables */
/* initialize the policy table */
/* initialize soft_config_list */
/*
* Initialize scheduling structures. Note that this does NOT
* start any threads since it might not be safe to do so.
*/
/* initialize the RNG support structures */
rngtimer_started = 0;
kcf_rnd_init();
return (mod_install(&modlinkage));
}
int
{
}
/*
* We do not allow kcf to unload.
*/
int
_fini(void)
{
return (EBUSY);
}
/*
* Return a pointer to the modctl structure of the
* provider's module.
*/
struct modctl *
{
/* Get the modctl struct for this module */
else {
char *drvmod;
if ((major =
} else
return (NULL);
}
return (mctlp);
}
/*
* Check if signature verification is needed for a provider.
*
* Returns 0, if no verification is needed. Returns 1, if
* verification is needed. Returns -1, if there is an
* error.
*/
int
{
return (0);
return (-1);
/*
* Check if this provider needs to be verified. We always verify
* the module if it carries a signature. Any operation set which has
* a encryption/decryption component is a candidate for verification.
*/
return (0);
}
/*
* See if this module has a proper signature section.
*/
return (-1);
}
return (1);
}
/*
* Do the signature verification on the given module. This function can
* be called from user context or kernel context.
*
* We call kcfd with the full pathname of the module to be
* verified. kcfd will return success/restricted/fail, signature length
* and the actual signature in the ELF section of the module. If kcfd
* returns success or restricted, we compare the signature and the length
* with the values that krtld stored in the module structure. We log an
* error message in case of a failure.
*
* The provider state is changed to KCF_PROV_READY on success.
*/
void
kcf_verify_signature(void *arg)
{
int rv;
char *filename;
for (;;) {
/* No need to do verification */
goto out;
}
goto out;
}
/*
* This check is needed since a software provider can call
* us directly from the _init->crypto_register_provider path.
*/
break;
}
/*
* We could be in a race with the register thread or
* the unregister thread. So, retry if register or
* unregister is in progress. Note that we can't do
* mod_hold_by_modctl without this check since that
* could result in a deadlock with the other threads.
*/
/* delay for 10ms and try again */
continue;
}
(void) mod_hold_by_modctl(mctlp,
break;
}
/*
* Check if the door is set up yet. This will be set when kcfd
* comes up. If not, we return and leave the provider state unchanged
* at KCF_PROV_UNVERIFIED. This will trigger the verification of
* the module later when kcfd is up. This is safe as we NEVER use
* a provider that has not been verified yet.
*/
goto out;
}
/*
* Make door upcall. door_ki_upcall() checks for validity of the handle.
*/
if (rv == 0) {
/* Check kcfd result and compare against module struct fields */
filename);
} else {
error = 0;
}
}
} else {
}
/* change state only if the original state is unchanged */
if (error == 0) {
} else {
}
}
if (do_notify) {
/* Dispatch events for this new provider */
}
out:
if (modhold_done)
}
/* called from the CRYPTO_LOAD_DOOR ioctl */
int
{
/* Start the timeout handler to get random numbers */
if (rngtimer_started == 0) {
rngtimer_started = 1;
}
return (0);
}