Skip to content

Commit

Permalink
KEYS: trusted: Add generic trusted keys framework
Browse files Browse the repository at this point in the history
Current trusted keys framework is tightly coupled to use TPM device as
an underlying implementation which makes it difficult for implementations
like Trusted Execution Environment (TEE) etc. to provide trusted keys
support in case platform doesn't posses a TPM device.

Add a generic trusted keys framework where underlying implementations
can be easily plugged in. Create struct trusted_key_ops to achieve this,
which contains necessary functions of a backend.

Also, define a module parameter in order to select a particular trust
source in case a platform support multiple trust sources. In case its
not specified then implementation itetrates through trust sources list
starting with TPM and assign the first trust source as a backend which
has initiazed successfully during iteration.

Note that current implementation only supports a single trust source at
runtime which is either selectable at compile time or during boot via
aforementioned module parameter.

Suggested-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Signed-off-by: Sumit Garg <sumit.garg@linaro.org>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
  • Loading branch information
b49020 authored and jarkkojs committed Apr 14, 2021
1 parent e5fb5d2 commit 5d0682b
Show file tree
Hide file tree
Showing 6 changed files with 497 additions and 318 deletions.
12 changes: 12 additions & 0 deletions Documentation/admin-guide/kernel-parameters.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5462,6 +5462,18 @@
See Documentation/admin-guide/mm/transhuge.rst
for more details.

trusted.source= [KEYS]
Format: <string>
This parameter identifies the trust source as a backend
for trusted keys implementation. Supported trust
sources:
- "tpm"
- "tee"
If not specified then it defaults to iterating through
the trust source list starting with TPM and assigns the
first trust source as a backend which is initialized
successfully during iteration.

tsc= Disable clocksource stability checks for TSC.
Format: <string>
[x86] reliable: mark tsc clocksource as reliable, this
Expand Down
53 changes: 53 additions & 0 deletions include/keys/trusted-type.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
#include <linux/rcupdate.h>
#include <linux/tpm.h>

#ifdef pr_fmt
#undef pr_fmt
#endif

#define pr_fmt(fmt) "trusted_key: " fmt

#define MIN_KEY_SIZE 32
#define MAX_KEY_SIZE 128
#define MAX_BLOB_SIZE 512
Expand Down Expand Up @@ -42,6 +48,53 @@ struct trusted_key_options {
uint32_t policyhandle;
};

struct trusted_key_ops {
/*
* flag to indicate if trusted key implementation supports migration
* or not.
*/
unsigned char migratable;

/* Initialize key interface. */
int (*init)(void);

/* Seal a key. */
int (*seal)(struct trusted_key_payload *p, char *datablob);

/* Unseal a key. */
int (*unseal)(struct trusted_key_payload *p, char *datablob);

/* Get a randomized key. */
int (*get_random)(unsigned char *key, size_t key_len);

/* Exit key interface. */
void (*exit)(void);
};

struct trusted_key_source {
char *name;
struct trusted_key_ops *ops;
};

extern struct key_type key_type_trusted;

#define TRUSTED_DEBUG 0

#if TRUSTED_DEBUG
static inline void dump_payload(struct trusted_key_payload *p)
{
pr_info("key_len %d\n", p->key_len);
print_hex_dump(KERN_INFO, "key ", DUMP_PREFIX_NONE,
16, 1, p->key, p->key_len, 0);
pr_info("bloblen %d\n", p->blob_len);
print_hex_dump(KERN_INFO, "blob ", DUMP_PREFIX_NONE,
16, 1, p->blob, p->blob_len, 0);
pr_info("migratable %d\n", p->migratable);
}
#else
static inline void dump_payload(struct trusted_key_payload *p)
{
}
#endif

#endif /* _KEYS_TRUSTED_TYPE_H */
29 changes: 8 additions & 21 deletions include/keys/trusted_tpm.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#define LOAD32N(buffer, offset) (*(uint32_t *)&buffer[offset])
#define LOAD16(buffer, offset) (ntohs(*(uint16_t *)&buffer[offset]))

extern struct trusted_key_ops trusted_key_tpm_ops;

struct osapsess {
uint32_t handle;
unsigned char secret[SHA1_DIGEST_SIZE];
Expand Down Expand Up @@ -52,30 +54,19 @@ int tpm2_unseal_trusted(struct tpm_chip *chip,
#if TPM_DEBUG
static inline void dump_options(struct trusted_key_options *o)
{
pr_info("trusted_key: sealing key type %d\n", o->keytype);
pr_info("trusted_key: sealing key handle %0X\n", o->keyhandle);
pr_info("trusted_key: pcrlock %d\n", o->pcrlock);
pr_info("trusted_key: pcrinfo %d\n", o->pcrinfo_len);
pr_info("sealing key type %d\n", o->keytype);
pr_info("sealing key handle %0X\n", o->keyhandle);
pr_info("pcrlock %d\n", o->pcrlock);
pr_info("pcrinfo %d\n", o->pcrinfo_len);
print_hex_dump(KERN_INFO, "pcrinfo ", DUMP_PREFIX_NONE,
16, 1, o->pcrinfo, o->pcrinfo_len, 0);
}

static inline void dump_payload(struct trusted_key_payload *p)
{
pr_info("trusted_key: key_len %d\n", p->key_len);
print_hex_dump(KERN_INFO, "key ", DUMP_PREFIX_NONE,
16, 1, p->key, p->key_len, 0);
pr_info("trusted_key: bloblen %d\n", p->blob_len);
print_hex_dump(KERN_INFO, "blob ", DUMP_PREFIX_NONE,
16, 1, p->blob, p->blob_len, 0);
pr_info("trusted_key: migratable %d\n", p->migratable);
}

static inline void dump_sess(struct osapsess *s)
{
print_hex_dump(KERN_INFO, "trusted-key: handle ", DUMP_PREFIX_NONE,
16, 1, &s->handle, 4, 0);
pr_info("trusted-key: secret:\n");
pr_info("secret:\n");
print_hex_dump(KERN_INFO, "", DUMP_PREFIX_NONE,
16, 1, &s->secret, SHA1_DIGEST_SIZE, 0);
pr_info("trusted-key: enonce:\n");
Expand All @@ -87,7 +78,7 @@ static inline void dump_tpm_buf(unsigned char *buf)
{
int len;

pr_info("\ntrusted-key: tpm buffer\n");
pr_info("\ntpm buffer\n");
len = LOAD32(buf, TPM_SIZE_OFFSET);
print_hex_dump(KERN_INFO, "", DUMP_PREFIX_NONE, 16, 1, buf, len, 0);
}
Expand All @@ -96,10 +87,6 @@ static inline void dump_options(struct trusted_key_options *o)
{
}

static inline void dump_payload(struct trusted_key_payload *p)
{
}

static inline void dump_sess(struct osapsess *s)
{
}
Expand Down
1 change: 1 addition & 0 deletions security/keys/trusted-keys/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#

obj-$(CONFIG_TRUSTED_KEYS) += trusted.o
trusted-y += trusted_core.o
trusted-y += trusted_tpm1.o

$(obj)/trusted_tpm2.o: $(obj)/tpm2key.asn1.h
Expand Down
Loading

0 comments on commit 5d0682b

Please sign in to comment.