Skip to content

Commit c787192

Browse files
Jarkko SakkinenJames Morris
Jarkko Sakkinen
authored and
James Morris
committed
KEYS: trusted: allow trusted.ko to initialize w/o a TPM
Allow trusted.ko to initialize w/o a TPM. This commit also adds checks to the exported functions to fail when a TPM is not available. Fixes: 2407304 ("KEYS: trusted: explicitly use tpm_chip structure...") Cc: James Morris <[email protected]> Reported-by: Dan Williams <[email protected]> Tested-by: Dan Williams <[email protected]> Signed-off-by: Jarkko Sakkinen <[email protected]> Signed-off-by: James Morris <[email protected]>
1 parent 7110629 commit c787192

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

security/keys/trusted.c

+23-5
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ int TSS_authhmac(unsigned char *digest, const unsigned char *key,
135135
int ret;
136136
va_list argp;
137137

138+
if (!chip)
139+
return -ENODEV;
140+
138141
sdesc = init_sdesc(hashalg);
139142
if (IS_ERR(sdesc)) {
140143
pr_info("trusted_key: can't alloc %s\n", hash_alg);
@@ -196,6 +199,9 @@ int TSS_checkhmac1(unsigned char *buffer,
196199
va_list argp;
197200
int ret;
198201

202+
if (!chip)
203+
return -ENODEV;
204+
199205
bufsize = LOAD32(buffer, TPM_SIZE_OFFSET);
200206
tag = LOAD16(buffer, 0);
201207
ordinal = command;
@@ -363,6 +369,9 @@ int trusted_tpm_send(unsigned char *cmd, size_t buflen)
363369
{
364370
int rc;
365371

372+
if (!chip)
373+
return -ENODEV;
374+
366375
dump_tpm_buf(cmd);
367376
rc = tpm_send(chip, cmd, buflen);
368377
dump_tpm_buf(cmd);
@@ -429,6 +438,9 @@ int oiap(struct tpm_buf *tb, uint32_t *handle, unsigned char *nonce)
429438
{
430439
int ret;
431440

441+
if (!chip)
442+
return -ENODEV;
443+
432444
INIT_BUF(tb);
433445
store16(tb, TPM_TAG_RQU_COMMAND);
434446
store32(tb, TPM_OIAP_SIZE);
@@ -1245,9 +1257,13 @@ static int __init init_trusted(void)
12451257
{
12461258
int ret;
12471259

1260+
/* encrypted_keys.ko depends on successful load of this module even if
1261+
* TPM is not used.
1262+
*/
12481263
chip = tpm_default_chip();
12491264
if (!chip)
1250-
return -ENOENT;
1265+
return 0;
1266+
12511267
ret = init_digests();
12521268
if (ret < 0)
12531269
goto err_put;
@@ -1269,10 +1285,12 @@ static int __init init_trusted(void)
12691285

12701286
static void __exit cleanup_trusted(void)
12711287
{
1272-
put_device(&chip->dev);
1273-
kfree(digests);
1274-
trusted_shash_release();
1275-
unregister_key_type(&key_type_trusted);
1288+
if (chip) {
1289+
put_device(&chip->dev);
1290+
kfree(digests);
1291+
trusted_shash_release();
1292+
unregister_key_type(&key_type_trusted);
1293+
}
12761294
}
12771295

12781296
late_initcall(init_trusted);

0 commit comments

Comments
 (0)