tpm: fix response size validation in tpm_get_random()
authorJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Mon, 3 Sep 2018 01:01:26 +0000 (04:01 +0300)
committerJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Fri, 5 Oct 2018 10:47:33 +0000 (13:47 +0300)
When checking whether the response is large enough to be able to contain
the received random bytes in tpm_get_random() and tpm2_get_random(),
they fail to take account the header size, which should be added to the
minimum size. This commit fixes this issue.

Cc: stable@vger.kernel.org
Fixes: c659af78eb7b ("tpm: Check size of response before accessing data")
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
drivers/char/tpm/tpm-interface.c
drivers/char/tpm/tpm2-cmd.c

index 1a803b0cf980882f4eeb509c99379e5085c4ca6b..318a7078b2bafd6d0ff4911b765f071f2b0ef5c2 100644 (file)
@@ -1321,7 +1321,8 @@ int tpm_get_random(struct tpm_chip *chip, u8 *out, size_t max)
                }
 
                rlength = be32_to_cpu(tpm_cmd.header.out.length);
-               if (rlength < offsetof(struct tpm_getrandom_out, rng_data) +
+               if (rlength < TPM_HEADER_SIZE +
+                             offsetof(struct tpm_getrandom_out, rng_data) +
                              recd) {
                        total = -EFAULT;
                        break;
index c31b490bd41d97ebc94d3b27fc6080ee4acaf4b4..3acf4fd4e5a5397f4b6fa440ce46ee24bf7e6036 100644 (file)
@@ -329,7 +329,9 @@ int tpm2_get_random(struct tpm_chip *chip, u8 *dest, size_t max)
                        &buf.data[TPM_HEADER_SIZE];
                recd = min_t(u32, be16_to_cpu(out->size), num_bytes);
                if (tpm_buf_length(&buf) <
-                   offsetof(struct tpm2_get_random_out, buffer) + recd) {
+                   TPM_HEADER_SIZE +
+                   offsetof(struct tpm2_get_random_out, buffer) +
+                   recd) {
                        err = -EFAULT;
                        goto out;
                }