From: "Arnd Bergmann" <arnd@arndb.de>
To: "Herbert Xu" <herbert@gondor.apana.org.au>,
"Arnd Bergmann" <arnd@kernel.org>
Cc: "Alexandre Belloni" <alexandre.belloni@bootlin.com>,
"Ryan Wanner" <Ryan.Wanner@microchip.com>,
"Yangtao Li" <frank.li@vivo.com>,
linux-kernel@vger.kernel.org,
"David S . Miller" <davem@davemloft.net>,
"Sergiu Moga" <sergiu.moga@microchip.com>,
"Ayush Sawal" <ayush.sawal@chelsio.com>,
"Gaosheng Cui" <cuigaosheng1@huawei.com>,
"Claudiu Beznea" <claudiu.beznea@microchip.com>,
linux-arm-kernel@lists.infradead.org,
linux-crypto@vger.kernel.org, "Kees Cook" <keescook@chromium.org>
Subject: Re: [PATCH 1/2] crypto: drivers - avoid memcpy size warning
Date: Mon, 07 Aug 2023 14:04:05 +0200 [thread overview]
Message-ID: <d9184ad7-7d34-45bf-81e3-db053bf7425c@app.fastmail.com> (raw)
In-Reply-To: <ZMyz27awrVJ8QHzA@gondor.apana.org.au>
On Fri, Aug 4, 2023, at 10:16, Herbert Xu wrote:
> On Mon, Jul 24, 2023 at 03:53:01PM +0200, Arnd Bergmann wrote:
>> From: Arnd Bergmann <arnd@arndb.de>
>>
>> Some configurations with gcc-12 or gcc-13 produce a warning for the source
>> and destination of a memcpy() in atmel_sha_hmac_compute_ipad_hash() potentially
>> overlapping:
>>
>> In file included from include/linux/string.h:254,
>> from drivers/crypto/atmel-sha.c:15:
>> drivers/crypto/atmel-sha.c: In function 'atmel_sha_hmac_compute_ipad_hash':
>> include/linux/fortify-string.h:57:33: error: '__builtin_memcpy' accessing 129 or more bytes at offsets 408 and 280 overlaps 1 or more bytes at offset 408 [-Werror=restrict]
>> 57 | #define __underlying_memcpy __builtin_memcpy
>> | ^
>> include/linux/fortify-string.h:648:9: note: in expansion of macro '__underlying_memcpy'
>> 648 | __underlying_##op(p, q, __fortify_size); \
>> | ^~~~~~~~~~~~~
>> include/linux/fortify-string.h:693:26: note: in expansion of macro '__fortify_memcpy_chk'
>> 693 | #define memcpy(p, q, s) __fortify_memcpy_chk(p, q, s, \
>> | ^~~~~~~~~~~~~~~~~~~~
>> drivers/crypto/atmel-sha.c:1773:9: note: in expansion of macro 'memcpy'
>> 1773 | memcpy(hmac->opad, hmac->ipad, bs);
>> | ^~~~~~
>>
>> The same thing happens in two more drivers that have the same logic:
>
> Please send me the configurations which triggers these warnings.
> As these are false positives, I'd like to enable them only on the
> configurations where they actually cause a problem.
See https://pastebin.com/raw/ip3tfpJF for a config that triggers this
on x86 with the chelsio and atmel drivers. The bcm driver is only
available on arm64, so you won't hit that one here. I also
see this with allmodconfig, as well as defconfig after enabling
CONFIG_FORTIFY_SOURCE and the three crypto drivers.
I see that commit df8fc4e934c12 ("kbuild: Enable -fstrict-flex-arrays=3")
turned on the strict flex-array behavior that triggers the
warning, so this did not show up until linux-6.5-rc1.
In linux-next, I see no other code hit this warning after all
my other patches for it got merged, regardless strict flex
arrays.
At the moment, -Wrestrict is completely disabled in all builds,
so you have to add a patch to enable it in the build system,
this is what I use locally to enable it at the W=1 level,
though you can probably just replace the cc-disable-warning
line with a -Wrestrict line.
Arnd
--- a/scripts/Makefile.extrawarn
+++ b/scripts/Makefile.extrawarn
@@ -49,9 +49,6 @@ KBUILD_CFLAGS += -Wno-pointer-sign
# globally built with -Wcast-function-type.
KBUILD_CFLAGS += $(call cc-option, -Wcast-function-type)
-# Another good warning that we'll want to enable eventually
-KBUILD_CFLAGS += $(call cc-disable-warning, restrict)
-
# The allocators already balk at large sizes, so silence the compiler
# warnings for bounds checks involving those possible values. While
# -Wno-alloc-size-larger-than would normally be used here, earlier versions
@@ -93,6 +90,7 @@ export KBUILD_EXTRA_WARN
ifneq ($(findstring 1, $(KBUILD_EXTRA_WARN)),)
KBUILD_CFLAGS += -Wextra -Wunused -Wno-unused-parameter
+KBUILD_CFLAGS += $(call cc-option, -Wrestrict)
KBUILD_CFLAGS += -Wmissing-format-attribute
KBUILD_CFLAGS += -Wold-style-definition
KBUILD_CFLAGS += -Wmissing-include-dirs
@@ -105,6 +103,7 @@ else
# Some diagnostics enabled by default are noisy.
# Suppress them by using -Wno... except for W=1.
+KBUILD_CFLAGS += $(call cc-disable-warning, restrict)
KBUILD_CFLAGS += $(call cc-disable-warning, packed-not-aligned)
ifdef CONFIG_CC_IS_CLANG
next prev parent reply other threads:[~2023-08-07 12:05 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-24 13:53 Arnd Bergmann
2023-07-24 13:53 ` [PATCH 2/2] [v2] kallsyms: rework symbol lookup return codes Arnd Bergmann
2023-07-24 19:28 ` Luis Chamberlain
2023-07-26 8:02 ` Jiri Olsa
2023-07-26 13:54 ` Arnd Bergmann
2023-07-27 5:46 ` [PATCH 1/2] crypto: drivers - avoid memcpy size warning claudiu beznea
2023-08-04 8:16 ` Herbert Xu
2023-08-07 12:04 ` Arnd Bergmann [this message]
2023-08-11 10:48 ` Herbert Xu
2023-08-11 13:38 ` Arnd Bergmann
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=d9184ad7-7d34-45bf-81e3-db053bf7425c@app.fastmail.com \
--to=arnd@arndb.de \
--cc=Ryan.Wanner@microchip.com \
--cc=alexandre.belloni@bootlin.com \
--cc=arnd@kernel.org \
--cc=ayush.sawal@chelsio.com \
--cc=claudiu.beznea@microchip.com \
--cc=cuigaosheng1@huawei.com \
--cc=davem@davemloft.net \
--cc=frank.li@vivo.com \
--cc=herbert@gondor.apana.org.au \
--cc=keescook@chromium.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sergiu.moga@microchip.com \
/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
all inboxes | Powered by JetHome®