@@ -333,6 +333,9 @@ void tpm_buf_append_hmac_session(struct tpm_chip *chip, struct tpm_buf *buf,
333
333
}
334
334
335
335
#ifdef CONFIG_TCG_TPM2_HMAC
336
+ /* The first write to /dev/tpm{rm0} will flush the session. */
337
+ attributes |= TPM2_SA_CONTINUE_SESSION ;
338
+
336
339
/*
337
340
* The Architecture Guide requires us to strip trailing zeros
338
341
* before computing the HMAC
@@ -484,7 +487,8 @@ static void tpm2_KDFe(u8 z[EC_PT_SZ], const char *str, u8 *pt_u, u8 *pt_v,
484
487
sha256_final (& sctx , out );
485
488
}
486
489
487
- static void tpm_buf_append_salt (struct tpm_buf * buf , struct tpm_chip * chip )
490
+ static void tpm_buf_append_salt (struct tpm_buf * buf , struct tpm_chip * chip ,
491
+ struct tpm2_auth * auth )
488
492
{
489
493
struct crypto_kpp * kpp ;
490
494
struct kpp_request * req ;
@@ -543,7 +547,7 @@ static void tpm_buf_append_salt(struct tpm_buf *buf, struct tpm_chip *chip)
543
547
sg_set_buf (& s [0 ], chip -> null_ec_key_x , EC_PT_SZ );
544
548
sg_set_buf (& s [1 ], chip -> null_ec_key_y , EC_PT_SZ );
545
549
kpp_request_set_input (req , s , EC_PT_SZ * 2 );
546
- sg_init_one (d , chip -> auth -> salt , EC_PT_SZ );
550
+ sg_init_one (d , auth -> salt , EC_PT_SZ );
547
551
kpp_request_set_output (req , d , EC_PT_SZ );
548
552
crypto_kpp_compute_shared_secret (req );
549
553
kpp_request_free (req );
@@ -554,8 +558,7 @@ static void tpm_buf_append_salt(struct tpm_buf *buf, struct tpm_chip *chip)
554
558
* This works because KDFe fully consumes the secret before it
555
559
* writes the salt
556
560
*/
557
- tpm2_KDFe (chip -> auth -> salt , "SECRET" , x , chip -> null_ec_key_x ,
558
- chip -> auth -> salt );
561
+ tpm2_KDFe (auth -> salt , "SECRET" , x , chip -> null_ec_key_x , auth -> salt );
559
562
560
563
out :
561
564
crypto_free_kpp (kpp );
@@ -853,7 +856,9 @@ int tpm_buf_check_hmac_response(struct tpm_chip *chip, struct tpm_buf *buf,
853
856
if (rc )
854
857
/* manually close the session if it wasn't consumed */
855
858
tpm2_flush_context (chip , auth -> handle );
856
- memzero_explicit (auth , sizeof (* auth ));
859
+
860
+ kfree_sensitive (auth );
861
+ chip -> auth = NULL ;
857
862
} else {
858
863
/* reset for next use */
859
864
auth -> session = TPM_HEADER_SIZE ;
@@ -881,7 +886,8 @@ void tpm2_end_auth_session(struct tpm_chip *chip)
881
886
return ;
882
887
883
888
tpm2_flush_context (chip , auth -> handle );
884
- memzero_explicit (auth , sizeof (* auth ));
889
+ kfree_sensitive (auth );
890
+ chip -> auth = NULL ;
885
891
}
886
892
EXPORT_SYMBOL (tpm2_end_auth_session );
887
893
@@ -962,16 +968,20 @@ static int tpm2_load_null(struct tpm_chip *chip, u32 *null_key)
962
968
*/
963
969
int tpm2_start_auth_session (struct tpm_chip * chip )
964
970
{
971
+ struct tpm2_auth * auth ;
965
972
struct tpm_buf buf ;
966
- struct tpm2_auth * auth = chip -> auth ;
967
- int rc ;
968
973
u32 null_key ;
974
+ int rc ;
969
975
970
- if (! auth ) {
971
- dev_warn_once (& chip -> dev , "auth session is not active\n" );
976
+ if (chip -> auth ) {
977
+ dev_warn_once (& chip -> dev , "auth session is active\n" );
972
978
return 0 ;
973
979
}
974
980
981
+ auth = kzalloc (sizeof (* auth ), GFP_KERNEL );
982
+ if (!auth )
983
+ return - ENOMEM ;
984
+
975
985
rc = tpm2_load_null (chip , & null_key );
976
986
if (rc )
977
987
goto out ;
@@ -992,7 +1002,7 @@ int tpm2_start_auth_session(struct tpm_chip *chip)
992
1002
tpm_buf_append (& buf , auth -> our_nonce , sizeof (auth -> our_nonce ));
993
1003
994
1004
/* append encrypted salt and squirrel away unencrypted in auth */
995
- tpm_buf_append_salt (& buf , chip );
1005
+ tpm_buf_append_salt (& buf , chip , auth );
996
1006
/* session type (HMAC, audit or policy) */
997
1007
tpm_buf_append_u8 (& buf , TPM2_SE_HMAC );
998
1008
@@ -1014,10 +1024,13 @@ int tpm2_start_auth_session(struct tpm_chip *chip)
1014
1024
1015
1025
tpm_buf_destroy (& buf );
1016
1026
1017
- if (rc )
1018
- goto out ;
1027
+ if (rc == TPM2_RC_SUCCESS ) {
1028
+ chip -> auth = auth ;
1029
+ return 0 ;
1030
+ }
1019
1031
1020
- out :
1032
+ out :
1033
+ kfree_sensitive (auth );
1021
1034
return rc ;
1022
1035
}
1023
1036
EXPORT_SYMBOL (tpm2_start_auth_session );
@@ -1367,10 +1380,6 @@ int tpm2_sessions_init(struct tpm_chip *chip)
1367
1380
return rc ;
1368
1381
}
1369
1382
1370
- chip -> auth = kmalloc (sizeof (* chip -> auth ), GFP_KERNEL );
1371
- if (!chip -> auth )
1372
- return - ENOMEM ;
1373
-
1374
1383
return rc ;
1375
1384
}
1376
1385
EXPORT_SYMBOL (tpm2_sessions_init );
0 commit comments