]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
tpm_crb: check for bad response size
authorJerry Snitselaar <jsnitsel@redhat.com>
Sat, 11 Mar 2017 00:46:04 +0000 (17:46 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 25 May 2017 13:46:10 +0000 (15:46 +0200)
commit 8569defde8057258835c51ce01a33de82e14b148 upstream.

Make sure size of response buffer is at least 6 bytes, or
we will underflow and pass large size_t to memcpy_fromio().
This was encountered while testing earlier version of
locality patchset.

Fixes: 30fc8d138e912 ("tpm: TPM 2.0 CRB Interface")
Signed-off-by: Jerry Snitselaar <jsnitsel@redhat.com>
Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/char/tpm/tpm_crb.c

index 86f355b6df1d345ff9cf0874c40a29f5f986b0f2..dc760117f5adef461183f8f4164da411704200ab 100644 (file)
@@ -176,8 +176,7 @@ static int crb_recv(struct tpm_chip *chip, u8 *buf, size_t count)
 
        memcpy_fromio(buf, priv->rsp, 6);
        expected = be32_to_cpup((__be32 *) &buf[2]);
-
-       if (expected > count)
+       if (expected > count || expected < 6)
                return -EIO;
 
        memcpy_fromio(&buf[6], &priv->rsp[6], expected - 6);