From: stefanb@linux.vnet.ibm.com (Stefan Berger)
To: linux-security-module@vger.kernel.org
Subject: [PATCH] tpm: fix response size validation in tpm_get_random()
Date: Wed, 5 Sep 2018 09:16:01 -0400 [thread overview]
Message-ID: <b3fdb8d4-0e50-389b-86e1-d74761ca325e@linux.vnet.ibm.com> (raw)
In-Reply-To: <20180903011004.12161-1-jarkko.sakkinen@linux.intel.com>
On 09/02/2018 09:10 PM, Jarkko Sakkinen wrote:
> 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 at 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 | 3 ++-
> drivers/char/tpm/tpm2-cmd.c | 4 +++-
> 2 files changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
> index 1a803b0cf980..318a7078b2ba 100644
> --- a/drivers/char/tpm/tpm-interface.c
> +++ b/drivers/char/tpm/tpm-interface.c
> @@ -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;
> diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
> index c31b490bd41d..3acf4fd4e5a5 100644
> --- 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 *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;
> }
Reviewed-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
prev parent reply other threads:[~2018-09-05 13:16 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-03 1:10 [PATCH] tpm: fix response size validation in tpm_get_random() Jarkko Sakkinen
2018-09-05 11:12 ` Jarkko Sakkinen
2018-09-05 13:16 ` Stefan Berger [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b3fdb8d4-0e50-389b-86e1-d74761ca325e@linux.vnet.ibm.com \
--to=stefanb@linux.vnet.ibm.com \
--cc=linux-security-module@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).