Re: [PATCH] tpm: vtpm_proxy: Avoid device-originated buffer overflow
From: Kees Cook
Date: Tue Jan 18 2022 - 13:35:37 EST
On Thu, Jan 13, 2022 at 04:19:32PM -0500, Stefan Berger wrote:
> I just want to clarify this. In vtpm_proxy_tpm_op_send() we have the only
> place that sets req_len to a value larger than 0:
>
> static int vtpm_proxy_tpm_op_send(struct tpm_chip *chip, u8 *buf, size_t
> count)
> {
> struct proxy_dev *proxy_dev = dev_get_drvdata(&chip->dev);
>
> if (count > sizeof(proxy_dev->buffer)) {
> dev_err(&chip->dev,
> "Invalid size in send: count=%zd, buffer size=%zd\n",
> count, sizeof(proxy_dev->buffer));
> return -EIO;
> }
>
> [...]
>
> proxy_dev->req_len = count;
> memcpy(proxy_dev->buffer, buf, count);
>
> [...]
>
> }
>
>
> The above makes sure that we cannot copy more bytes into the
> proxy_dev->buffer than the what the buffer has bytes for.
>
> It then sets req_len to a valid value that is less or equal to the buffer
> size.
>
> Considering this your check above seems to only be there to make the
> compiler happy but otherwise I don't see that this is a real problem with a
> buffer overflow?!
>
> Nevertheless, let all those compilers be happy:
>
> Reviewed-by: Stefan Berger <stefanb@xxxxxxxxxxxxx>
Ah yes, thanks! I'll reword the commit log for v2. :)
--
Kees Cook