tpm: Check return value of crypto_kpp_set_secret()
Subsystems (4)
PATCH 1/1 tpm: Check return value of crypto_kpp_set_secret()
crypto_kpp_set_secret() can fail, for example if the kernel is booted with fips=1 and the broken-by-design FIPS RNG used for ECC private key generation doesn't feel like generating random bytes at the moment. Check for error, cancelling the TPM session creation rather than proceeding with a zero or uninitialized private key.
--- drivers/char/tpm/tpm2-sessions.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/char/tpm/tpm2-sessions.c +3 -1
@@ -527,7 +527,9 @@ static int tpm_buf_append_salt(struct tpm_buf *buf, struct tpm_chip *chip, }crypto_ecdh_encode_key (encoded_key, buf_len, &p);/* this generates a random private key */ -crypto_kpp_set_secret (kpp, encoded_key, buf_len); + rc =crypto_kpp_set_secret (kpp, encoded_key, buf_len); +if (rc) + goto err_free_kpp;/* salt is now the public point of this private key */ req =kpp_request_alloc (kpp,GFP_KERNEL );
base-commit: 21a7f44fd0765fcc5194130b28767786eba1d1e7
Signature · 1 line
2.56.0
Jarkko Sakkinen
maintainerQuoted 18 lines · Eric Biggers
crypto_kpp_set_secret()can fail, for example if the kernel is booted with fips=1 and the broken-by-design FIPS RNG used for ECC private key generation doesn't feel like generating random bytes at the moment. Check for error, cancelling the TPM session creation rather than proceeding with a zero or uninitialized private key.Fixes 699e3efd6c64 ("tpm: Add HMAC session start and end functions")Signed-off-by Eric Biggers <[email protected]>--- drivers/char/tpm/tpm2-sessions.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/char/tpm/tpm2-sessions.c +0
-0
drivers/char/tpm/tpm2-sessions.c static int tpm_buf_append_salt(struct tpm_buf *buf, struct tpm_chip *chip, · line 529
Quoted 3 lines
drivers/char/tpm/tpm2-sessions.c +0
-0@@ -527,7 +527,9 @@ static int tpm_buf_append_salt(struct tpm_buf *buf, struct tpm_chip *chip, }crypto_ecdh_encode_key (encoded_key, buf_len, &p);/* this generates a random private key */
Could you delete this comment while at it? It's not helping with anything.
Quoted 8 lines
drivers/char/tpm/tpm2-sessions.c +3
-1-crypto_kpp_set_secret (kpp, encoded_key, buf_len); + rc =crypto_kpp_set_secret (kpp, encoded_key, buf_len); +if (rc) + goto err_free_kpp;/* salt is now the public point of this private key */ req =kpp_request_alloc (kpp,GFP_KERNEL );
Quoted 4 lines
base-commit:
21a7f44fd0765fcc5194130b28767786eba1d1e7Signature · 1 line
2.56.0
[1] https://lore.kernel.org/linux-integrity/[email protected]/
Br, Jarkko
Quoted 26 lines · Jarkko Sakkinen
Quoted 18 lines · Eric Biggers
crypto_kpp_set_secret()can fail, for example if the kernel is booted with fips=1 and the broken-by-design FIPS RNG used for ECC private key generation doesn't feel like generating random bytes at the moment. Check for error, cancelling the TPM session creation rather than proceeding with a zero or uninitialized private key.Fixes 699e3efd6c64 ("tpm: Add HMAC session start and end functions")Signed-off-by Eric Biggers <[email protected]>--- drivers/char/tpm/tpm2-sessions.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/char/tpm/tpm2-sessions.c +0
-0drivers/char/tpm/tpm2-sessions.c static int tpm_buf_append_salt(struct tpm_buf *buf, struct tpm_chip *chip, · line 529
Quoted 3 lines
drivers/char/tpm/tpm2-sessions.c +0
-0@@ -527,7 +527,9 @@ static int tpm_buf_append_salt(struct tpm_buf *buf, struct tpm_chip *chip, }crypto_ecdh_encode_key (encoded_key, buf_len, &p);/* this generates a random private key */ Could you delete this comment while at it? It's not helping with anything.
Quoted 8 lines
drivers/char/tpm/tpm2-sessions.c static int tpm_buf_append_salt(struct tpm_buf *buf, struct tpm_chip *chip, · line 535
Quoted 8 lines
drivers/char/tpm/tpm2-sessions.c +3
-1-crypto_kpp_set_secret (kpp, encoded_key, buf_len); + rc =crypto_kpp_set_secret (kpp, encoded_key, buf_len); +if (rc) + goto err_free_kpp;/* salt is now the public point of this private key */ req =kpp_request_alloc (kpp,GFP_KERNEL );
I actually think the comment is helpful, because of how unreadable the crypto_kpp API is. It's generating a private key, but to request that, crypto_kpp apparently requires that an empty key be encoded into a byte string. Then that key is "set", which actually generates a new key.
In comparison, the Curve25519 equivalent is curve25519_generate_secret(), which is clearly named and also always succeeds. At some point we need to fix the ECDH API...
- Eric
Quoted 41 lines · Eric Biggers
Quoted 26 lines · Jarkko Sakkinen
Quoted 18 lines · Eric Biggers
crypto_kpp_set_secret()can fail, for example if the kernel is booted with fips=1 and the broken-by-design FIPS RNG used for ECC private key generation doesn't feel like generating random bytes at the moment. Check for error, cancelling the TPM session creation rather than proceeding with a zero or uninitialized private key.Fixes 699e3efd6c64 ("tpm: Add HMAC session start and end functions")Signed-off-by Eric Biggers <[email protected]>--- drivers/char/tpm/tpm2-sessions.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/char/tpm/tpm2-sessions.c +0
-0drivers/char/tpm/tpm2-sessions.c static int tpm_buf_append_salt(struct tpm_buf *buf, struct tpm_chip *chip, · line 529
Quoted 3 lines
drivers/char/tpm/tpm2-sessions.c +0
-0@@ -527,7 +527,9 @@ static int tpm_buf_append_salt(struct tpm_buf *buf, struct tpm_chip *chip, }crypto_ecdh_encode_key (encoded_key, buf_len, &p);/* this generates a random private key */ Could you delete this comment while at it? It's not helping with anything.
Quoted 8 lines
drivers/char/tpm/tpm2-sessions.c static int tpm_buf_append_salt(struct tpm_buf *buf, struct tpm_chip *chip, · line 535
Quoted 8 lines
drivers/char/tpm/tpm2-sessions.c +3
-1-crypto_kpp_set_secret (kpp, encoded_key, buf_len); + rc =crypto_kpp_set_secret (kpp, encoded_key, buf_len); +if (rc) + goto err_free_kpp;/* salt is now the public point of this private key */ req =kpp_request_alloc (kpp,GFP_KERNEL );I actually think the comment is helpful, because of how unreadable the
crypto_kppAPI is. It's generating a private key, but to request that,crypto_kppapparently requires that an empty key be encoded into a byte string. Then that key is "set", which actually generates a new key.
Quoted 3 lines
In comparison, the Curve25519 equivalent is
curve25519_generate_secret(), which is clearly named and also always succeeds. At some point we need to fix the ECDH API...
Ah, right it gets zero filled echd. I've not consciously thought this detail before, thanks :-)
Quoted 2 lines
- Eric
tpm2-sessions overall would need some refurbishing work now that also Matthew's hibernate patches depend on it. I have to take a serious look at it some point.
Br, Jarkko
Jarkko Sakkinen
maintainerQuoted 49 lines · Jarkko Sakkinen
Quoted 41 lines · Eric Biggers
Quoted 26 lines · Jarkko Sakkinen
Quoted 18 lines · Eric Biggers
crypto_kpp_set_secret()can fail, for example if the kernel is booted with fips=1 and the broken-by-design FIPS RNG used for ECC private key generation doesn't feel like generating random bytes at the moment. Check for error, cancelling the TPM session creation rather than proceeding with a zero or uninitialized private key.Fixes 699e3efd6c64 ("tpm: Add HMAC session start and end functions")Signed-off-by Eric Biggers <[email protected]>--- drivers/char/tpm/tpm2-sessions.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/char/tpm/tpm2-sessions.c +0
-0drivers/char/tpm/tpm2-sessions.c static int tpm_buf_append_salt(struct tpm_buf *buf, struct tpm_chip *chip, · line 529
Quoted 3 lines
drivers/char/tpm/tpm2-sessions.c +0
-0@@ -527,7 +527,9 @@ static int tpm_buf_append_salt(struct tpm_buf *buf, struct tpm_chip *chip, }crypto_ecdh_encode_key (encoded_key, buf_len, &p);/* this generates a random private key */ Could you delete this comment while at it? It's not helping with anything.
Quoted 8 lines
drivers/char/tpm/tpm2-sessions.c static int tpm_buf_append_salt(struct tpm_buf *buf, struct tpm_chip *chip, · line 535
Quoted 8 lines
drivers/char/tpm/tpm2-sessions.c +3
-1-crypto_kpp_set_secret (kpp, encoded_key, buf_len); + rc =crypto_kpp_set_secret (kpp, encoded_key, buf_len); +if (rc) + goto err_free_kpp;/* salt is now the public point of this private key */ req =kpp_request_alloc (kpp,GFP_KERNEL );I actually think the comment is helpful, because of how unreadable the
crypto_kppAPI is. It's generating a private key, but to request that,crypto_kppapparently requires that an empty key be encoded into a byte string. Then that key is "set", which actually generates a new key.Quoted 3 lines
In comparison, the Curve25519 equivalent is
curve25519_generate_secret(), which is clearly named and also always succeeds. At some point we need to fix the ECDH API...Ah, right it gets zero filled echd. I've not consciously thought this detail before, thanks :-)
Quoted 7 lines
Reviewed-by Jarkko Sakkinen <[email protected]>Quoted 2 lines
- Eric
tpm2-sessions overall would need some refurbishing work now that also Matthew's hibernate patches depend on it. I have to take a serious look at it some point.
I'll apply this after Linus has accepted/rejected my TPM pull request.
I'm not sure if it already is but if it isn't, probably also at linux-integrity turning on Sashiko would make sense.
Br, Jarkko
Quoted 2 lines · Jarkko Sakkinen
I'm not sure if it already is but if it isn't, probably also at linux-integrity turning on Sashiko would make sense.
Sashiko currently has monitoring enabled for linux-integrity, but not email replies
(https://github.com/sashiko-dev/sashiko/blob/main/projects/linux/mailing_lists.toml#L45).
(Note: this particular patch was Cc'ed to linux-crypto, which does have Sashiko email replies enabled. So Sashiko would have replied if it had found an issue anyway.)
I definitely would support enabling email replies on linux-integrity (for issues found only), like a lot of other lists already do:
["[email protected]"]
reply_to = ["author", "list", "recipients"]
If the maintainers of security/integrity/ would ack that, I can open a pull request to the Sashiko GitHub repo that changes it. Or someone else can go ahead and do it if they want.
- Eric
Jarkko Sakkinen
maintainerAdding Mimi and Roberto.
Quoted 15 lines · Eric Biggers
Quoted 2 lines · Jarkko Sakkinen
I'm not sure if it already is but if it isn't, probably also at linux-integrity turning on Sashiko would make sense.
Sashiko currently has monitoring enabled for linux-integrity, but not email replies
(https://github.com/sashiko-dev/sashiko/blob/main/projects/linux/mailing_lists.toml#L45).(Note: this particular patch was Cc'ed to linux-crypto, which does have Sashiko email replies enabled. So Sashiko would have replied if it had found an issue anyway.)
I definitely would support enabling email replies on linux-integrity (for issues found only), like a lot of other lists already do:
Quoted 8 lines
["[email protected]"] reply_to = ["author", "list", "recipients"]If the maintainers of
security/integrity/would ack that, I can open a pull request to the Sashiko GitHub repo that changes it. Or someone else can go ahead and do it if they want.- Eric
Br, Jarkko
Quoted 25 lines · Jarkko Sakkinen
Adding Mimi and Roberto.
Quoted 22 lines · Eric Biggers
Quoted 2 lines · Jarkko Sakkinen
I'm not sure if it already is but if it isn't, probably also at linux-integrity turning on Sashiko would make sense.
Sashiko currently has monitoring enabled for linux-integrity, but not email replies
(https://github.com/sashiko-dev/sashiko/blob/main/projects/linux/mailing_lists.toml#L45).(Note: this particular patch was Cc'ed to linux-crypto, which does have Sashiko email replies enabled. So Sashiko would have replied if it had found an issue anyway.)
I definitely would support enabling email replies on linux-integrity (for issues found only), like a lot of other lists already do:
["[email protected]"] reply_to = ["author", "list", "recipients"]If the maintainers of
security/integrity/would ack that, I can open a pull request to the Sashiko GitHub repo that changes it. Or someone else can go ahead and do it if they want.
Mimi and Roberto, any thoughts on whether you want Sashiko replies enabled on linux-integrity?
- Eric