34
34
35
35
static const char hmac_alg [] = "hmac(sha1)" ;
36
36
static const char hash_alg [] = "sha1" ;
37
+ static struct tpm_chip * chip ;
37
38
38
39
struct sdesc {
39
40
struct shash_desc shash ;
@@ -362,7 +363,7 @@ int trusted_tpm_send(unsigned char *cmd, size_t buflen)
362
363
int rc ;
363
364
364
365
dump_tpm_buf (cmd );
365
- rc = tpm_send (NULL , cmd , buflen );
366
+ rc = tpm_send (chip , cmd , buflen );
366
367
dump_tpm_buf (cmd );
367
368
if (rc > 0 )
368
369
/* Can't return positive return codes values to keyctl */
@@ -384,10 +385,10 @@ static int pcrlock(const int pcrnum)
384
385
385
386
if (!capable (CAP_SYS_ADMIN ))
386
387
return - EPERM ;
387
- ret = tpm_get_random (NULL , hash , SHA1_DIGEST_SIZE );
388
+ ret = tpm_get_random (chip , hash , SHA1_DIGEST_SIZE );
388
389
if (ret != SHA1_DIGEST_SIZE )
389
390
return ret ;
390
- return tpm_pcr_extend (NULL , pcrnum , hash ) ? - EINVAL : 0 ;
391
+ return tpm_pcr_extend (chip , pcrnum , hash ) ? - EINVAL : 0 ;
391
392
}
392
393
393
394
/*
@@ -400,7 +401,7 @@ static int osap(struct tpm_buf *tb, struct osapsess *s,
400
401
unsigned char ononce [TPM_NONCE_SIZE ];
401
402
int ret ;
402
403
403
- ret = tpm_get_random (NULL , ononce , TPM_NONCE_SIZE );
404
+ ret = tpm_get_random (chip , ononce , TPM_NONCE_SIZE );
404
405
if (ret != TPM_NONCE_SIZE )
405
406
return ret ;
406
407
@@ -496,7 +497,7 @@ static int tpm_seal(struct tpm_buf *tb, uint16_t keytype,
496
497
if (ret < 0 )
497
498
goto out ;
498
499
499
- ret = tpm_get_random (NULL , td -> nonceodd , TPM_NONCE_SIZE );
500
+ ret = tpm_get_random (chip , td -> nonceodd , TPM_NONCE_SIZE );
500
501
if (ret != TPM_NONCE_SIZE )
501
502
goto out ;
502
503
ordinal = htonl (TPM_ORD_SEAL );
@@ -606,7 +607,7 @@ static int tpm_unseal(struct tpm_buf *tb,
606
607
607
608
ordinal = htonl (TPM_ORD_UNSEAL );
608
609
keyhndl = htonl (SRKHANDLE );
609
- ret = tpm_get_random (NULL , nonceodd , TPM_NONCE_SIZE );
610
+ ret = tpm_get_random (chip , nonceodd , TPM_NONCE_SIZE );
610
611
if (ret != TPM_NONCE_SIZE ) {
611
612
pr_info ("trusted_key: tpm_get_random failed (%d)\n" , ret );
612
613
return ret ;
@@ -751,7 +752,7 @@ static int getoptions(char *c, struct trusted_key_payload *pay,
751
752
int i ;
752
753
int tpm2 ;
753
754
754
- tpm2 = tpm_is_tpm2 (NULL );
755
+ tpm2 = tpm_is_tpm2 (chip );
755
756
if (tpm2 < 0 )
756
757
return tpm2 ;
757
758
@@ -920,7 +921,7 @@ static struct trusted_key_options *trusted_options_alloc(void)
920
921
struct trusted_key_options * options ;
921
922
int tpm2 ;
922
923
923
- tpm2 = tpm_is_tpm2 (NULL );
924
+ tpm2 = tpm_is_tpm2 (chip );
924
925
if (tpm2 < 0 )
925
926
return NULL ;
926
927
@@ -970,7 +971,7 @@ static int trusted_instantiate(struct key *key,
970
971
size_t key_len ;
971
972
int tpm2 ;
972
973
973
- tpm2 = tpm_is_tpm2 (NULL );
974
+ tpm2 = tpm_is_tpm2 (chip );
974
975
if (tpm2 < 0 )
975
976
return tpm2 ;
976
977
@@ -1011,7 +1012,7 @@ static int trusted_instantiate(struct key *key,
1011
1012
switch (key_cmd ) {
1012
1013
case Opt_load :
1013
1014
if (tpm2 )
1014
- ret = tpm_unseal_trusted (NULL , payload , options );
1015
+ ret = tpm_unseal_trusted (chip , payload , options );
1015
1016
else
1016
1017
ret = key_unseal (payload , options );
1017
1018
dump_payload (payload );
@@ -1021,13 +1022,13 @@ static int trusted_instantiate(struct key *key,
1021
1022
break ;
1022
1023
case Opt_new :
1023
1024
key_len = payload -> key_len ;
1024
- ret = tpm_get_random (NULL , payload -> key , key_len );
1025
+ ret = tpm_get_random (chip , payload -> key , key_len );
1025
1026
if (ret != key_len ) {
1026
1027
pr_info ("trusted_key: key_create failed (%d)\n" , ret );
1027
1028
goto out ;
1028
1029
}
1029
1030
if (tpm2 )
1030
- ret = tpm_seal_trusted (NULL , payload , options );
1031
+ ret = tpm_seal_trusted (chip , payload , options );
1031
1032
else
1032
1033
ret = key_seal (payload , options );
1033
1034
if (ret < 0 )
@@ -1225,17 +1226,26 @@ static int __init init_trusted(void)
1225
1226
{
1226
1227
int ret ;
1227
1228
1229
+ chip = tpm_default_chip ();
1230
+ if (!chip )
1231
+ return - ENOENT ;
1228
1232
ret = trusted_shash_alloc ();
1229
1233
if (ret < 0 )
1230
- return ret ;
1234
+ goto err_put ;
1231
1235
ret = register_key_type (& key_type_trusted );
1232
1236
if (ret < 0 )
1233
- trusted_shash_release ();
1237
+ goto err_release ;
1238
+ return 0 ;
1239
+ err_release :
1240
+ trusted_shash_release ();
1241
+ err_put :
1242
+ put_device (& chip -> dev );
1234
1243
return ret ;
1235
1244
}
1236
1245
1237
1246
static void __exit cleanup_trusted (void )
1238
1247
{
1248
+ put_device (& chip -> dev );
1239
1249
trusted_shash_release ();
1240
1250
unregister_key_type (& key_type_trusted );
1241
1251
}
0 commit comments