keys: trusted: tpm1: add bounds check in tpm_seal() before memcpy
Subsystems (3)
PATCH 1/2 keys: trusted: tpm1: add bounds check in tpm_seal() before memcpy
tpm_seal() computes storedsize from TPM response fields and passes it directly to memcpy() into a MAX_BLOB_SIZE buffer without bounds validation. A forged TPM response can set storedsize to 4086, overflowing the 512-byte blob by 3574 bytes into adjacent slab objects.
Add a check that storedsize does not exceed MAX_BLOB_SIZE before the memcpy, returning -EINVAL on oversized responses.
--- security/keys/trusted-keys/trusted_tpm1.c | 4 ++++ 1 file changed, 4 insertions(+)
security/keys/trusted-keys/trusted_tpm1.c +4 -0
@@ -531,6 +531,10 @@ static int tpm_seal(struct tpm_buf *tb, uint16_t keytype,/* copy the returned blob to caller */ if (!ret) { +if (storedsize >MAX_BLOB_SIZE ) { + ret = -EINVAL ; + goto out; + }memcpy (blob, tb->data +TPM_DATA_OFFSET , storedsize); *bloblen = storedsize; }
Signature · 1 line
2.53.0
PATCH 2/2 keys: trusted: tpm1: reject unauthenticated response tag in TSS_checkhmac1/2
TSS_checkhmac1() and TSS_checkhmac2() silently return success when the response tag is TPM_TAG_RSP_COMMAND (0x00c4), bypassing HMAC verification entirely. A forged TPM response with this unauthenticated tag allows an attacker to skip integrity checks on TPM responses.
Reject TPM_TAG_RSP_COMMAND with -EINVAL in both functions, requiring all responses to carry a proper authenticated tag.
--- security/keys/trusted-keys/trusted_tpm1.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
security/keys/trusted-keys/trusted_tpm1.c +2 -2
@@ -202,7 +202,7 @@ static int TSS_checkhmac1(unsigned char *buffer, ordinal = command; result =LOAD32N (buffer,TPM_RETURN_OFFSET );if (tag ==TPM_TAG_RSP_COMMAND ) -return 0 ; +return -EINVAL ;if (tag !=TPM_TAG_RSP_AUTH1_COMMAND )return -EINVAL ; authdata = buffer + bufsize -SHA1_DIGEST_SIZE ;
@@ -270,7 +270,7 @@ static int TSS_checkhmac2(unsigned char *buffer, result =LOAD32N (buffer,TPM_RETURN_OFFSET );if (tag ==TPM_TAG_RSP_COMMAND ) -return 0 ; +return -EINVAL ;if (tag !=TPM_TAG_RSP_AUTH2_COMMAND )return -EINVAL ; authdata1 = buffer + bufsize - (SHA1_DIGEST_SIZE + 1
Signature · 1 line
2.53.0
Jarkko Sakkinen
maintainerRe: [PATCH 2/2] keys: trusted: tpm1: reject unauthenticated response tag in TSS_checkhmac1/2
Quoted 9 lines · On Tue, Aug 25, 2026 at 06:29:19PM +0000, sn0x-sharma wrote:
TSS_checkhmac1()andTSS_checkhmac2()silently return success when the response tag isTPM_TAG_RSP_COMMAND(0x00c4), bypassing HMAC verification entirely. A forged TPM response with this unauthenticated tag allows an attacker to skip integrity checks on TPM responses.Reject
TPM_TAG_RSP_COMMANDwith-EINVALin both functions, requiring all responses to carry a proper authenticated tag.Reported-by sn0x-sharma <[email protected]>
SOB is enough.
Quoted 2 lines
Signed-off-by sn0x-sharma <[email protected]>
If by any means possible, use your real name here.
Quoted 29 lines
--- security/keys/trusted-keys/trusted_tpm1.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)security/keys/trusted-keys/trusted_tpm1.c +2
-2@@ -202,7 +202,7 @@ static int TSS_checkhmac1(unsigned char *buffer, ordinal = command; result =LOAD32N (buffer,TPM_RETURN_OFFSET );if (tag ==TPM_TAG_RSP_COMMAND ) -return 0 ; +return -EINVAL ;if (tag !=TPM_TAG_RSP_AUTH1_COMMAND )return -EINVAL ; authdata = buffer + bufsize -SHA1_DIGEST_SIZE ;@@ -270,7 +270,7 @@ static int TSS_checkhmac2(unsigned char *buffer, result =LOAD32N (buffer,TPM_RETURN_OFFSET );if (tag ==TPM_TAG_RSP_COMMAND ) -return 0 ; +return -EINVAL ;if (tag !=TPM_TAG_RSP_AUTH2_COMMAND )return -EINVAL ; authdata1 = buffer + bufsize - (SHA1_DIGEST_SIZE + 1Signature · 1 line
2.53.0
otherwise looks ok
BR, Jarkko
Quoted 11 lines · On Tue, Aug 25, 2026 at 06:29:18PM +0000, sn0x-sharma wrote:
tpm_seal()computes storedsize from TPM response fields and passes it directly tomemcpy()into aMAX_BLOB_SIZEbuffer without bounds validation. A forged TPM response can set storedsize to 4086, overflowing the 512-byte blob by 3574 bytes into adjacent slab objects.Add a check that storedsize does not exceed
MAX_BLOB_SIZEbefore the memcpy, returning-EINVALon oversized responses.
That's not a valid link :(
Quoted 1 line
Signed-off-by sn0x-sharma <[email protected]>
No need for a reported-by: if you author and sign off on the patch.
And we need a real name please, not an alias.
thanks,
greg k-h
Jarkko Sakkinen
maintainerQuoted 7 lines · Greg KH
Quoted 6 lines · On Tue, Aug 25, 2026 at 06:29:18PM +0000, sn0x-sharma wrote:
tpm_seal()computes storedsize from TPM response fields and passes it directly tomemcpy()into aMAX_BLOB_SIZEbuffer without bounds validation. A forged TPM response can set storedsize to 4086, overflowing the 512-byte blob by 3574 bytes into adjacent slab objects.
Quoted 7 lines
Quoted 5 lines
Add a check that storedsize does not exceed
MAX_BLOB_SIZEbefore the memcpy, returning-EINVALon oversized responses.That's not a valid link :(
Oops, missed this one ;-)
Should be just deleted, b4 shazam will set the link tag.
Quoted 10 lines
Quoted 2 lines
Signed-off-by sn0x-sharma <[email protected]>No need for a reported-by: if you author and sign off on the patch.
And we need a real name please, not an alias.
thanks,
greg k-h
BR, Jarkko
A message that is not in the archive (sent off-list or not yet received): CAEb43b2C_eyR8ncUbJ+3MsT3ap-tB3_O0Mbaqgy1ncXwZAd_Yw@mail.gmail.com
Quoted 8 lines · sanket sharma
Hi Team,
Thank you both for the review feedback all points have been addressed in the latest versions.
One quick question: once the patches are merged, will a CVE be assigned automatically by the kernel CVE team, or do I need to separately request one via [email protected]?
<formletter>
Please see:
https://www.kernel.org/doc/html/latest/process/cve.html
for how kernel CVEs are assigned.
</formletter>
A message that is not in the archive (sent off-list or not yet received): CAEb43b0bc7rNvrpLmjF-9HPEfUcOdTKsUC68vzh+JfDf7E+OcA@mail.gmail.com
Jarkko Sakkinen
maintainerQuoted 7 lines · sanket sharma
Hi Jarkko,
Just checking in both patches (v3) have been sent as per the previous
discussion: Message-ID: [email protected]Please let me know if anything else is needed from my side.
Quoted 8 lines
Also, regarding CVE assignment Greg pointed me to the kernel CVE doc, which mentions CVEs are assigned for security fixes. Given that these patches address an HMAC bypass and an unchecked memcpy, would these qualify for CVE assignment once merged, or is that at the discretion of the CVE team?
Thanks,
Sanket Sharma
[email protected]
1. Please use plain text and avoid top-posting:
https://docs.kernel.org/process/email-clients.html
2. I asked to not document assumed attack scenarios to the commit message. It is not useful information to log.
Quoted 13 lines · Greg KH
On Fri, Aug 28, 2026 at 01:00:11PM +0530, sanket sharma wrote:
> Hi Team,
>
> Thank you both for the review feedback all points have been addressed in > the latest versions.
>
> One quick question: once the patches are merged, will a CVE be assigned > automatically by the kernel CVE team, or do I need to separately request > one via [email protected]?
Quoted 8 lines
<formletter>
Please see:
https://www.kernel.org/doc/html/latest/process/cve.html
for how kernel CVEs are assigned.</formletter>
BR, Jarkko
PATCH v2 1/2 keys: trusted: tpm1: add bounds check in tpm_seal() before memcpy
In reply to sn0x-sharmatpm_seal() computes storedsize from TPM response fields and passes it directly to memcpy() into a MAX_BLOB_SIZE buffer without bounds validation. A forged TPM response can set storedsize to 4086, overflowing the 512-byte blob by 3574 bytes into adjacent slab objects.
Add a check that storedsize does not exceed MAX_BLOB_SIZE before the memcpy, returning -EINVAL on oversized responses.
--- security/keys/trusted-keys/trusted_tpm1.c | 4 ++++ 1 file changed, 4 insertions(+)
security/keys/trusted-keys/trusted_tpm1.c +4 -0
@@ -531,6 +531,10 @@ static int tpm_seal(struct tpm_buf *tb, uint16_t keytype,/* copy the returned blob to caller */ if (!ret) { +if (storedsize >MAX_BLOB_SIZE ) { + ret = -EINVAL ; + goto out; + }memcpy (blob, tb->data +TPM_DATA_OFFSET , storedsize); *bloblen = storedsize; }
Signature · 1 line
2.53.0
PATCH v2 2/2 keys: trusted: tpm1: reject unauthenticated response tag in TSS_checkhmac1/2
TSS_checkhmac1() and TSS_checkhmac2() silently return success when the response tag is TPM_TAG_RSP_COMMAND (0x00c4), bypassing HMAC verification entirely. A forged TPM response with this unauthenticated tag allows an attacker to skip integrity checks on TPM responses.
Reject TPM_TAG_RSP_COMMAND with -EINVAL in both functions, requiring all responses to carry a proper authenticated tag.
--- security/keys/trusted-keys/trusted_tpm1.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
security/keys/trusted-keys/trusted_tpm1.c +2 -2
@@ -202,7 +202,7 @@ static int TSS_checkhmac1(unsigned char *buffer, ordinal = command; result =LOAD32N (buffer,TPM_RETURN_OFFSET );if (tag ==TPM_TAG_RSP_COMMAND ) -return 0 ; +return -EINVAL ;if (tag !=TPM_TAG_RSP_AUTH1_COMMAND )return -EINVAL ; authdata = buffer + bufsize -SHA1_DIGEST_SIZE ;
@@ -270,7 +270,7 @@ static int TSS_checkhmac2(unsigned char *buffer, result =LOAD32N (buffer,TPM_RETURN_OFFSET );if (tag ==TPM_TAG_RSP_COMMAND ) -return 0 ; +return -EINVAL ;if (tag !=TPM_TAG_RSP_AUTH2_COMMAND )return -EINVAL ; authdata1 = buffer + bufsize - (SHA1_DIGEST_SIZE + 1
Signature · 1 line
2.53.0
Re: [PATCH v2 2/2] keys: trusted: tpm1: reject unauthenticated response tag in TSS_checkhmac1/2
Quoted 22 lines · Sanket Sharma
TSS_checkhmac1()andTSS_checkhmac2()silently return success when the response tag isTPM_TAG_RSP_COMMAND(0x00c4), bypassing HMAC verification entirely. A forged TPM response with this unauthenticated tag allows an attacker to skip integrity checks on TPM responses.Reject
TPM_TAG_RSP_COMMANDwith-EINVALin both functions, requiring all responses to carry a proper authenticated tag.Signed-off-by Sanket Sharma <[email protected]>---
security/keys/trusted-keys/trusted_tpm1.c| 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)security/keys/trusted-keys/trusted_tpm1.c +0
-0
security/keys/trusted-keys/trusted_tpm1.c static int TSS_checkhmac1(unsigned char *buffer, · line 205
Quoted 5 lines
security/keys/trusted-keys/trusted_tpm1.c +1
-1@@ -202,7 +202,7 @@ static int TSS_checkhmac1(unsigned char *buffer, ordinal = command; result =LOAD32N (buffer,TPM_RETURN_OFFSET );if (tag ==TPM_TAG_RSP_COMMAND ) -return 0 ; +return -EINVAL ;
Hi Sanket Sharma,
Instead of changing the return value to -EINVAL inside the TPM_TAG_RSP_COMMAND check, we can simplify the control flow by removing that block entirely.Since TPM_TAG_RSP_COMMAND is inherently not equal to TPM_TAG_RSP_AUTH1_COMMAND, the subsequent mismatch check will naturally catch it and return -EINVAL.
Thanks,
Sudhakar
Quoted 16 lines
security/keys/trusted-keys/trusted_tpm1.c +1
-1if (tag !=TPM_TAG_RSP_AUTH1_COMMAND )return -EINVAL ; authdata = buffer + bufsize -SHA1_DIGEST_SIZE ;@@ -270,7 +270,7 @@ static int TSS_checkhmac2(unsigned char *buffer, result =LOAD32N (buffer,TPM_RETURN_OFFSET );if (tag ==TPM_TAG_RSP_COMMAND ) -return 0 ; +return -EINVAL ;if (tag !=TPM_TAG_RSP_AUTH2_COMMAND )return -EINVAL ;authdata1 = buffer + bufsize - (
SHA1_DIGEST_SIZE+ 1Signature · 1 line
2.53.0
Quoted 10 lines · Sanket Sharma
tpm_seal()computes storedsize from TPM response fields and passes it directly tomemcpy()into aMAX_BLOB_SIZEbuffer without bounds validation. A forged TPM response can set storedsize to 4086, overflowing the 512-byte blob by 3574 bytes into adjacent slab objects.
Quoted 4 lines
Add a check that storedsize does not exceed
MAX_BLOB_SIZEbefore the memcpy, returning-EINVALon oversized responses.Signed-off-by Sanket Sharma <[email protected]>
Thanks,
Sudhakar
Quoted 23 lines
---
security/keys/trusted-keys/trusted_tpm1.c| 4 ++++1 file changed, 4 insertions(+)security/keys/trusted-keys/trusted_tpm1.c +4
-0@@ -531,6 +531,10 @@ static int tpm_seal(struct tpm_buf *tb, uint16_t keytype,/* copy the returned blob to caller */ if (!ret) { +if (storedsize >MAX_BLOB_SIZE ) { + ret = -EINVAL ; + goto out; + }memcpy (blob, tb->data +TPM_DATA_OFFSET , storedsize); *bloblen = storedsize; }Signature · 1 line
2.53.0
PATCH v3 1/2 keys: trusted: tpm1: add bounds check in tpm_seal() before memcpy
In reply to Sanket Sharmatpm_seal() computes storedsize from TPM response fields and passes it directly to memcpy() into a MAX_BLOB_SIZE buffer without bounds validation. A forged TPM response can set storedsize to 4086, overflowing the 512-byte blob by 3574 bytes into adjacent slab objects.
Add a check that storedsize does not exceed MAX_BLOB_SIZE before the memcpy, returning -EINVAL on oversized responses.
--- security/keys/trusted-keys/trusted_tpm1.c | 4 ++++ 1 file changed, 4 insertions(+)
security/keys/trusted-keys/trusted_tpm1.c +4 -0
@@ -531,6 +531,10 @@ static int tpm_seal(struct tpm_buf *tb, uint16_t keytype,/* copy the returned blob to caller */ if (!ret) { +if (storedsize >MAX_BLOB_SIZE ) { + ret = -EINVAL ; + goto out; + }memcpy (blob, tb->data +TPM_DATA_OFFSET , storedsize); *bloblen = storedsize; }
Signature · 1 line
2.53.0
PATCH v3 2/2 keys: trusted: tpm1: reject unauthenticated response tag in TSS_checkhmac1/2
TSS_checkhmac1() and TSS_checkhmac2() silently return success when the response tag is TPM_TAG_RSP_COMMAND (0x00c4), bypassing HMAC verification entirely. A forged TPM response with this unauthenticated tag allows an attacker to skip integrity checks on TPM responses.
Reject TPM_TAG_RSP_COMMAND with -EINVAL in both functions, requiring all responses to carry a proper authenticated tag.
--- security/keys/trusted-keys/trusted_tpm1.c | 4 ---- 1 file changed, 4 deletions(-)
security/keys/trusted-keys/trusted_tpm1.c +0 -4
@@ -201,8 +201,6 @@ static int TSS_checkhmac1(unsigned char *buffer, tag =LOAD16 (buffer,0 ); ordinal = command; result =LOAD32N (buffer,TPM_RETURN_OFFSET ); -if (tag ==TPM_TAG_RSP_COMMAND ) -return 0 ;if (tag !=TPM_TAG_RSP_AUTH1_COMMAND )return -EINVAL ; authdata = buffer + bufsize -SHA1_DIGEST_SIZE ;
@@ -269,8 +267,6 @@ static int TSS_checkhmac2(unsigned char *buffer, ordinal = command; result =LOAD32N (buffer,TPM_RETURN_OFFSET ); -if (tag ==TPM_TAG_RSP_COMMAND ) -return 0 ;if (tag !=TPM_TAG_RSP_AUTH2_COMMAND )return -EINVAL ; authdata1 = buffer + bufsize - (SHA1_DIGEST_SIZE + 1
Signature · 1 line
2.53.0
Jarkko Sakkinen
maintainerRe: [PATCH v3 2/2] keys: trusted: tpm1: reject unauthenticated response tag in TSS_checkhmac1/2
Quoted 4 lines · Sanket Sharma
TSS_checkhmac1()andTSS_checkhmac2()silently return success when the response tag isTPM_TAG_RSP_COMMAND(0x00c4), bypassing HMAC verification entirely. A forged TPM response with this unauthenticated tag allows an attacker to skip integrity checks on TPM responses.
I don't think we need threat scenario role play here.
Quoted 34 lines
Reject
TPM_TAG_RSP_COMMANDwith-EINVALin both functions, requiring all responses to carry a proper authenticated tag.Signed-off-by Sanket Sharma <[email protected]>--- security/keys/trusted-keys/trusted_tpm1.c | 4 ---- 1 file changed, 4 deletions(-)security/keys/trusted-keys/trusted_tpm1.c +0
-4@@ -201,8 +201,6 @@ static int TSS_checkhmac1(unsigned char *buffer, tag =LOAD16 (buffer,0 ); ordinal = command; result =LOAD32N (buffer,TPM_RETURN_OFFSET ); -if (tag ==TPM_TAG_RSP_COMMAND ) -return 0 ;if (tag !=TPM_TAG_RSP_AUTH1_COMMAND )return -EINVAL ; authdata = buffer + bufsize -SHA1_DIGEST_SIZE ;@@ -269,8 +267,6 @@ static int TSS_checkhmac2(unsigned char *buffer, ordinal = command; result =LOAD32N (buffer,TPM_RETURN_OFFSET ); -if (tag ==TPM_TAG_RSP_COMMAND ) -return 0 ;if (tag !=TPM_TAG_RSP_AUTH2_COMMAND )return -EINVAL ; authdata1 = buffer + bufsize - (SHA1_DIGEST_SIZE + 1Signature · 1 line
2.53.0
BR, Jarkko