From: Herbert Xu <herbert@gondor.apana.org.au>
To: Arnd Bergmann <arnd@arndb.de>,
Linus Torvalds <torvalds@linux-foundation.org>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>
Cc: Arnd Bergmann <arnd@kernel.org>,
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: Fri, 11 Aug 2023 18:48:53 +0800 [thread overview]
Message-ID: <ZNYSFWA3WNAdRqfg@gondor.apana.org.au> (raw)
In-Reply-To: <d9184ad7-7d34-45bf-81e3-db053bf7425c@app.fastmail.com>
On Mon, Aug 07, 2023 at 02:04:05PM +0200, Arnd Bergmann wrote:
>
> 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.
OK I can reproduce this now:
In file included from ../include/linux/string.h:254,
from ../arch/x86/include/asm/page_32.h:18,
from ../arch/x86/include/asm/page.h:14,
from ../arch/x86/include/asm/processor.h:20,
from ../arch/x86/include/asm/timex.h:5,
from ../include/linux/timex.h:67,
from ../include/linux/time32.h:13,
from ../include/linux/time.h:60,
from ../include/linux/stat.h:19,
from ../include/linux/module.h:13,
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 304 and 176 overlaps 1 or more bytes at offset 304 [-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);
| ^~~~~~
../include/linux/fortify-string.h:57:33: error: ‘__builtin_memcpy’ accessing 129 or more bytes at offsets 304 and 176 overlaps 1 or more bytes at offset 304 [-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);
| ^~~~~~
cc1: all warnings being treated as errors
But why are we turning these warnings on if they're giving completely
bogus false positives like this?
struct atmel_sha_hmac_ctx {
struct atmel_sha_ctx base;
struct atmel_sha_hmac_key hkey;
u32 ipad[SHA512_BLOCK_SIZE / sizeof(u32)];
u32 opad[SHA512_BLOCK_SIZE / sizeof(u32)];
atmel_sha_fn_t resume;
};
struct atmel_sha_hmac_ctx *hmac = crypto_ahash_ctx(tfm);
size_t bs = ctx->block_size;
memcpy(hmac->opad, hmac->ipad, bs);
The block_size is set by the algorithm, you can easily grep for
it in atmel-sha.c and the biggest one there is SHA512_BLOCK_SIZE,
which is how big hmac->ipad/hmac->opad are.
So logically this code is perfectly fine.
There is no way for the compiler to know how big ctx->block_size is.
So why do we expect it to make deductions on how big bs can be?
This warning looks broken to me.
It looks like there is already a solution to this though. Just use
unsafe_memcpy and be done with it.
Cheers,
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
next prev parent reply other threads:[~2023-08-11 10:52 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
2023-08-11 10:48 ` Herbert Xu [this message]
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=ZNYSFWA3WNAdRqfg@gondor.apana.org.au \
--to=herbert@gondor.apana.org.au \
--cc=Ryan.Wanner@microchip.com \
--cc=alexandre.belloni@bootlin.com \
--cc=arnd@arndb.de \
--cc=arnd@kernel.org \
--cc=ayush.sawal@chelsio.com \
--cc=claudiu.beznea@microchip.com \
--cc=cuigaosheng1@huawei.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=frank.li@vivo.com \
--cc=keescook@chromium.org \
--cc=kuba@kernel.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 \
--cc=torvalds@linux-foundation.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
all inboxes | Powered by JetHome®