Skip to content

Commit a8504cf

Browse files
b49020jforissier
authored andcommitted
KEYS: trusted: Add generic trusted keys framework
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 <[email protected]> Signed-off-by: Sumit Garg <[email protected]> Reviewed-by: Jarkko Sakkinen <[email protected]> Signed-off-by: Jarkko Sakkinen <[email protected]> [jf cherry-pick 5d0682b upstream] Signed-off-by: Jerome Forissier <[email protected]>
1 parent 4993c0d commit a8504cf

File tree

6 files changed

+497
-318
lines changed

6 files changed

+497
-318
lines changed

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5462,6 +5462,18 @@
54625462
See Documentation/admin-guide/mm/transhuge.rst
54635463
for more details.
54645464

5465+
trusted.source= [KEYS]
5466+
Format: <string>
5467+
This parameter identifies the trust source as a backend
5468+
for trusted keys implementation. Supported trust
5469+
sources:
5470+
- "tpm"
5471+
- "tee"
5472+
If not specified then it defaults to iterating through
5473+
the trust source list starting with TPM and assigns the
5474+
first trust source as a backend which is initialized
5475+
successfully during iteration.
5476+
54655477
tsc= Disable clocksource stability checks for TSC.
54665478
Format: <string>
54675479
[x86] reliable: mark tsc clocksource as reliable, this

include/keys/trusted-type.h

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
#include <linux/rcupdate.h>
1212
#include <linux/tpm.h>
1313

14+
#ifdef pr_fmt
15+
#undef pr_fmt
16+
#endif
17+
18+
#define pr_fmt(fmt) "trusted_key: " fmt
19+
1420
#define MIN_KEY_SIZE 32
1521
#define MAX_KEY_SIZE 128
1622
#define MAX_BLOB_SIZE 512
@@ -40,6 +46,53 @@ struct trusted_key_options {
4046
uint32_t policyhandle;
4147
};
4248

49+
struct trusted_key_ops {
50+
/*
51+
* flag to indicate if trusted key implementation supports migration
52+
* or not.
53+
*/
54+
unsigned char migratable;
55+
56+
/* Initialize key interface. */
57+
int (*init)(void);
58+
59+
/* Seal a key. */
60+
int (*seal)(struct trusted_key_payload *p, char *datablob);
61+
62+
/* Unseal a key. */
63+
int (*unseal)(struct trusted_key_payload *p, char *datablob);
64+
65+
/* Get a randomized key. */
66+
int (*get_random)(unsigned char *key, size_t key_len);
67+
68+
/* Exit key interface. */
69+
void (*exit)(void);
70+
};
71+
72+
struct trusted_key_source {
73+
char *name;
74+
struct trusted_key_ops *ops;
75+
};
76+
4377
extern struct key_type key_type_trusted;
4478

79+
#define TRUSTED_DEBUG 0
80+
81+
#if TRUSTED_DEBUG
82+
static inline void dump_payload(struct trusted_key_payload *p)
83+
{
84+
pr_info("key_len %d\n", p->key_len);
85+
print_hex_dump(KERN_INFO, "key ", DUMP_PREFIX_NONE,
86+
16, 1, p->key, p->key_len, 0);
87+
pr_info("bloblen %d\n", p->blob_len);
88+
print_hex_dump(KERN_INFO, "blob ", DUMP_PREFIX_NONE,
89+
16, 1, p->blob, p->blob_len, 0);
90+
pr_info("migratable %d\n", p->migratable);
91+
}
92+
#else
93+
static inline void dump_payload(struct trusted_key_payload *p)
94+
{
95+
}
96+
#endif
97+
4598
#endif /* _KEYS_TRUSTED_TYPE_H */

include/keys/trusted_tpm.h

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#define LOAD32N(buffer, offset) (*(uint32_t *)&buffer[offset])
1717
#define LOAD16(buffer, offset) (ntohs(*(uint16_t *)&buffer[offset]))
1818

19+
extern struct trusted_key_ops trusted_key_tpm_ops;
20+
1921
struct osapsess {
2022
uint32_t handle;
2123
unsigned char secret[SHA1_DIGEST_SIZE];
@@ -52,30 +54,19 @@ int tpm2_unseal_trusted(struct tpm_chip *chip,
5254
#if TPM_DEBUG
5355
static inline void dump_options(struct trusted_key_options *o)
5456
{
55-
pr_info("trusted_key: sealing key type %d\n", o->keytype);
56-
pr_info("trusted_key: sealing key handle %0X\n", o->keyhandle);
57-
pr_info("trusted_key: pcrlock %d\n", o->pcrlock);
58-
pr_info("trusted_key: pcrinfo %d\n", o->pcrinfo_len);
57+
pr_info("sealing key type %d\n", o->keytype);
58+
pr_info("sealing key handle %0X\n", o->keyhandle);
59+
pr_info("pcrlock %d\n", o->pcrlock);
60+
pr_info("pcrinfo %d\n", o->pcrinfo_len);
5961
print_hex_dump(KERN_INFO, "pcrinfo ", DUMP_PREFIX_NONE,
6062
16, 1, o->pcrinfo, o->pcrinfo_len, 0);
6163
}
6264

63-
static inline void dump_payload(struct trusted_key_payload *p)
64-
{
65-
pr_info("trusted_key: key_len %d\n", p->key_len);
66-
print_hex_dump(KERN_INFO, "key ", DUMP_PREFIX_NONE,
67-
16, 1, p->key, p->key_len, 0);
68-
pr_info("trusted_key: bloblen %d\n", p->blob_len);
69-
print_hex_dump(KERN_INFO, "blob ", DUMP_PREFIX_NONE,
70-
16, 1, p->blob, p->blob_len, 0);
71-
pr_info("trusted_key: migratable %d\n", p->migratable);
72-
}
73-
7465
static inline void dump_sess(struct osapsess *s)
7566
{
7667
print_hex_dump(KERN_INFO, "trusted-key: handle ", DUMP_PREFIX_NONE,
7768
16, 1, &s->handle, 4, 0);
78-
pr_info("trusted-key: secret:\n");
69+
pr_info("secret:\n");
7970
print_hex_dump(KERN_INFO, "", DUMP_PREFIX_NONE,
8071
16, 1, &s->secret, SHA1_DIGEST_SIZE, 0);
8172
pr_info("trusted-key: enonce:\n");
@@ -87,7 +78,7 @@ static inline void dump_tpm_buf(unsigned char *buf)
8778
{
8879
int len;
8980

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

99-
static inline void dump_payload(struct trusted_key_payload *p)
100-
{
101-
}
102-
10390
static inline void dump_sess(struct osapsess *s)
10491
{
10592
}

security/keys/trusted-keys/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
#
55

66
obj-$(CONFIG_TRUSTED_KEYS) += trusted.o
7+
trusted-y += trusted_core.o
78
trusted-y += trusted_tpm1.o
89
trusted-y += trusted_tpm2.o

0 commit comments

Comments
 (0)