@@ -464,7 +464,7 @@ int tpm2_seal_trusted(struct tpm_chip *chip,
{
unsigned int blob_len;
struct tpm_buf buf;
- u32 hash;
+ u32 hash, rlength;
int i;
int rc;
@@ -533,11 +533,21 @@ int tpm2_seal_trusted(struct tpm_chip *chip,
if (rc)
goto out;
+ rlength = be32_to_cpu(((struct tpm2_cmd*)&buf)->header.out.length);
+ if (rlength < TPM_HEADER_SIZE + 4) {
+ rc = -EFAULT;
+ goto out;
+ }
+
blob_len = be32_to_cpup((__be32 *) &buf.data[TPM_HEADER_SIZE]);
if (blob_len > MAX_BLOB_SIZE) {
rc = -E2BIG;
goto out;
}
+ if (rlength < TPM_HEADER_SIZE + 4 + blob_len) {
+ rc = -EFAULT;
+ goto out;
+ }
memcpy(payload->blob, &buf.data[TPM_HEADER_SIZE + 4], blob_len);
payload->blob_len = blob_len;
Check the size of the response before accessing data in the response packet. This is to avoid accessing data beyond the end of the response. Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com> --- drivers/char/tpm/tpm2-cmd.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)