Skip to content

Commit 4f6282b

Browse files
committed
Validate GetProductInfo payload length
Reject undersized SWTPM responses before copying product info to avoid signed underflow and out-of-bounds access.
1 parent ae73063 commit 4f6282b

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/tpm2.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5483,9 +5483,16 @@ TPM_RC TPM2_GetProductInfo(uint8_t* info, uint16_t size)
54835483
*/
54845484

54855485
/* start of product info starts at byte 26 */
5486-
if (size > packet.size - 26)
5487-
size = packet.size - 26;
5488-
XMEMCPY(info, &packet.buf[25], size);
5486+
if (packet.size <= 26) {
5487+
rc = TPM_RC_SIZE;
5488+
}
5489+
else if (size > 0) {
5490+
size_t payloadSz = (size_t)(packet.size - 26);
5491+
if (payloadSz > (size_t)size) {
5492+
payloadSz = (size_t)size;
5493+
}
5494+
XMEMCPY(info, &packet.buf[25], payloadSz);
5495+
}
54895496
}
54905497
TPM2_ReleaseLock(ctx);
54915498
}

0 commit comments

Comments
 (0)