From: Jarkko Sakkinen <jarkko@kernel.org>
To: Dan Carpenter <dan.carpenter@oracle.com>,
Peter Huewe <peterhuewe@gmx.de>
Cc: Jason Gunthorpe <jgg@ziepe.ca>,
James Bottomley <James.Bottomley@HansenPartnership.com>,
linux-integrity@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] tpm: Check for integer overflow in tpm2_map_response_body()
Date: Thu, 09 Sep 2021 17:04:24 +0300 [thread overview]
Message-ID: <f92e564c91755b0df70ae9b2237a034fe98f00c5.camel@kernel.org> (raw)
In-Reply-To: <20210908053356.GB28725@kili>
On Wed, 2021-09-08 at 08:33 +0300, Dan Carpenter wrote:
> The "4 * be32_to_cpu(data->count)" multiplication can potentially
> overflow which would lead to memory corruption. Add a check for that.
>
> Fixes: 745b361e989a ("tpm: infrastructure for TPM spaces")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> drivers/char/tpm/tpm2-space.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/char/tpm/tpm2-space.c b/drivers/char/tpm/tpm2-space.c
> index 784b8b3cb903..97e916856cf3 100644
> --- a/drivers/char/tpm/tpm2-space.c
> +++ b/drivers/char/tpm/tpm2-space.c
> @@ -455,6 +455,9 @@ static int tpm2_map_response_body(struct tpm_chip *chip, u32 cc, u8 *rsp,
> if (be32_to_cpu(data->capability) != TPM2_CAP_HANDLES)
> return 0;
>
> + if (be32_to_cpu(data->count) > (UINT_MAX - TPM_HEADER_SIZE - 9) / 4)
> + return -EFAULT;
> +
> if (len != TPM_HEADER_SIZE + 9 + 4 * be32_to_cpu(data->count))
> return -EFAULT;
>
Thanks!
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
/Jarkko
prev parent reply other threads:[~2021-09-09 14:05 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-08 5:33 [PATCH] tpm: Check for integer overflow in tpm2_map_response_body() Dan Carpenter
2021-09-09 14:04 ` Jarkko Sakkinen [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=f92e564c91755b0df70ae9b2237a034fe98f00c5.camel@kernel.org \
--to=jarkko@kernel.org \
--cc=James.Bottomley@HansenPartnership.com \
--cc=dan.carpenter@oracle.com \
--cc=jgg@ziepe.ca \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-integrity@vger.kernel.org \
--cc=peterhuewe@gmx.de \
/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