KEYS: trusted_tpm2: Only check options->keyhandle for ASN.1
Subsystems (4)
Jarkko Sakkinen
maintainerPATCH 1/1 KEYS: trusted_tpm2: Only check options->keyhandle for ASN.1
tpm2_load_cmd incorrectly checks options->keyhandle also for the legacy format, as also implied by the inline comment. Check options->keyhandle when ASN.1 is loaded.
--- security/keys/trusted-keys/trusted_tpm2.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
security/keys/trusted-keys/trusted_tpm2.c +3 -4
@@ -400,12 +400,11 @@ static int tpm2_load_cmd(struct tpm_chip *chip,/* old form */ blob = payload->blob; payload->old_format =1 ; + }else { +if (!options->keyhandle) +return -EINVAL ; } -/* new format carries keyhandle but old format doesn't */ -if (!options->keyhandle) -return -EINVAL ; -/* must be big enough for at least the two be16 size counts */ if (payload->blob_len <4 )return -EINVAL ;
Signature · 1 line
2.45.1
James Bottomley
maintainerQuoted 3 lines · Jarkko Sakkinen
tpm2_load_cmdincorrectly checksoptions->keyhandlealso for the legacy format, as also implied by the inline comment. Checkoptions->keyhandlewhen ASN.1 is loaded.
No that's not right. keyhandle must be specified for the old format, because it's just the two private/public blobs and doesn't know it's parent. Since tpm2_key_decode() always places the ASN.1 parent into options->keyhandle, the proposed new code is fully redundant (options-
Quoted 1 line
keyhandle must be non zero if the ASN.1 parsed correctly) but it loses
the check that the loader must specify it for the old format.
What the comment above the code you removed means is that the keyhandle must be non zero here, either extracted from the ASN.1 for the new format or specified on the command line for the old.
James
Jarkko Sakkinen
maintainerQuoted 9 lines · James Bottomley
Quoted 3 lines · Jarkko Sakkinen
tpm2_load_cmdincorrectly checksoptions->keyhandlealso for the legacy format, as also implied by the inline comment. Checkoptions->keyhandlewhen ASN.1 is loaded.No that's not right. keyhandle must be specified for the old format, because it's just the two private/public blobs and doesn't know it's parent. Since
tpm2_key_decode()always places the ASN.1 parent intooptions->keyhandle, the proposed new code is fully redundant (options-
Quoted 6 lines
Quoted 1 line
keyhandle must be non zero if the ASN.1 parsed correctly) but it loses
the check that the loader must specify it for the old format.
What the comment above the code you removed means is that the keyhandle must be non zero here, either extracted from the ASN.1 for the new format or specified on the command line for the old.
My code change was plain direct to the word interpreation of the comment.
So I just take the last paragraph of yours and instead fix the misleading comment:
/*
* Keyhandle must be non zero here, either extracted from the ASN.1 for
* the new format or specified on the command line for the old. */
BR, Jarkko