Re: [PATCH v2] crypto: AF_ALG - add support for keys/asymmetric-type

From: David Woodhouse
Date: Wed Jan 13 2016 - 07:27:57 EST


On Sat, 2015-12-26 at 07:50 -0800, Tadeusz Struk wrote:
> +static int alg_setkey_id(void *private, const u8 *key, unsigned int keylen,
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ int (*setkey)(void *private, const u8 *key,
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ unsigned int keylen))
> +{
> +ÂÂÂÂÂÂÂstruct key *keyring;
> +ÂÂÂÂÂÂÂstruct public_key *pkey;
> +ÂÂÂÂÂÂÂchar key_name[12];
> +ÂÂÂÂÂÂÂu32 keyid = *((u32 *)key);
> +ÂÂÂÂÂÂÂint err;
> +
> +ÂÂÂÂÂÂÂsprintf(key_name, "id:%08x", keyid);
> +ÂÂÂÂÂÂÂkeyring = request_key(&key_type_asymmetric, key_name, NULL);
> +
> +ÂÂÂÂÂÂÂerr = -ENOKEY;
> +ÂÂÂÂÂÂÂif (IS_ERR(keyring))
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂgoto out;
> +
> +ÂÂÂÂÂÂÂpkey = keyring->payload.data[asym_crypto];
> +ÂÂÂÂÂÂÂif (!pkey) {
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂkey_put(keyring);
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂgoto out;
> +ÂÂÂÂÂÂÂ}
> +
> +ÂÂÂÂÂÂÂerr = setkey(private, pkey->key, pkey->keylen);
> +ÂÂÂÂÂÂÂkey_put(keyring);
> +
> +out:
> +ÂÂÂÂÂÂÂreturn err;
> +}

This seems entirely wrong to me. You cannot just assume that the
private key data are available in software form to the kernel and can
be extracted.

Please ensure you test this with a key in a TPM, or in a SGX software
enclave or something like that.

David, is there a way to do that test purely in software without
needing hardware support? We know that the data might not actually be
present in all cases... is there an easy test for that case?

--
David Woodhouse Open Source Technology Centre
David.Woodhouse@xxxxxxxxx Intel Corporation

Attachment: smime.p7s
Description: S/MIME cryptographic signature