lkml.org 
[lkml]   [2018]   [Nov]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH 4.19 268/361] tpm: fix response size validation in tpm_get_random()
    Date
    4.19-stable review patch.  If anyone has any objections, please let me know.

    ------------------

    From: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>

    commit 84b59f6487d82d3ab4247a099aba66d4d17e8b08 upstream.

    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>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

    ---
    drivers/char/tpm/tpm-interface.c | 3 ++-
    drivers/char/tpm/tpm2-cmd.c | 4 +++-
    2 files changed, 5 insertions(+), 2 deletions(-)

    --- a/drivers/char/tpm/tpm-interface.c
    +++ b/drivers/char/tpm/tpm-interface.c
    @@ -1322,7 +1322,8 @@ int tpm_get_random(struct tpm_chip *chip
    }

    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;
    --- a/drivers/char/tpm/tpm2-cmd.c
    +++ b/drivers/char/tpm/tpm2-cmd.c
    @@ -329,7 +329,9 @@ int tpm2_get_random(struct tpm_chip *chi
    &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;
    }

    \
     
     \ /
      Last update: 2018-11-12 00:55    [W:4.137 / U:0.036 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site