The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: "Arnd Bergmann" <arnd@arndb.de>
To: "Kees Cook" <keescook@chromium.org>, "Andy Shevchenko" <andy@kernel.org>
Cc: linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] string: Adjust strtomem_pad() logic to allow for smaller sources
Date: Wed, 18 Oct 2023 21:16:15 +0200	[thread overview]
Message-ID: <136b4130-8ba4-43f1-8ef7-2bf2a8fcb71b@app.fastmail.com> (raw)
In-Reply-To: <20231018180709.work.293-kees@kernel.org>

On Wed, Oct 18, 2023, at 20:07, Kees Cook wrote:
> Arnd noticed we have a case where a shorter source string is being copied
> into a destination byte array, but this results in a strnlen() call that
> exceeds the size of the source. This is seen with -Wstringop-overread:
>
> In file included from ../include/linux/uuid.h:11,
>                  from ../include/linux/mod_devicetable.h:14,
>                  from ../include/linux/cpufeature.h:12,
>                  from ../arch/x86/coco/tdx/tdx.c:7:
> ../arch/x86/coco/tdx/tdx.c: In function 'tdx_panic.constprop':
> ../include/linux/string.h:284:9: error: 'strnlen' specified bound 64 
> exceeds source size 60 [-Werror=stringop-overread]
>   284 |         memcpy_and_pad(dest, _dest_len, src, strnlen(src, 
> _dest_len), pad); \
>       |         
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ../arch/x86/coco/tdx/tdx.c:124:9: note: in expansion of macro 
> 'strtomem_pad'
>   124 |         strtomem_pad(message.str, msg, '\0');
>       |         ^~~~~~~~~~~~
>
> Use the smaller of the two buffer sizes when calling strnlen(). When
> src length is unknown (SIZE_MAX), it will use dest length, which is what
> the original code did.
>
> Reported-by: Arnd Bergmann <arnd@arndb.de>
> Fixes: dfbafa70bde2 ("string: Introduce strtomem() and strtomem_pad()")
> Cc: Andy Shevchenko <andy@kernel.org>
> Cc: linux-hardening@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>

Thanks for addressing this, looks good

Tested-by: Arnd Bergmann <arnd@arndb.de>

      reply	other threads:[~2023-10-18 19:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-18 18:07 [PATCH] string: Adjust strtomem_pad() logic to allow for smaller sources Kees Cook
2023-10-18 19:16 ` Arnd Bergmann [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=136b4130-8ba4-43f1-8ef7-2bf2a8fcb71b@app.fastmail.com \
    --to=arnd@arndb.de \
    --cc=andy@kernel.org \
    --cc=keescook@chromium.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@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