lkml.org 
[lkml]   [2022]   [Jan]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] tpm: vtpm_proxy: Avoid device-originated buffer overflow
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@linux.ibm.com>

Ah yes, thanks! I'll reword the commit log for v2. :)

--
Kees Cook

\
 
 \ /
  Last update: 2022-09-17 16:12    [W:0.124 / U:0.008 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site