Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp2917512rwb; Mon, 7 Aug 2023 05:43:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IENYNRfZVu68Zq4dt/31OJ+uKPlhU2fxRaCmXVfBYKd38m+8EkMSpJ9rK93sSaOaIYHiO1U X-Received: by 2002:a17:902:6947:b0:1bc:2c79:c6b5 with SMTP id k7-20020a170902694700b001bc2c79c6b5mr7457014plt.4.1691412235539; Mon, 07 Aug 2023 05:43:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691412235; cv=none; d=google.com; s=arc-20160816; b=VPtRUlozgVxasJp8ur4CZWeA22MFElx8Ai1x4h/WH3Xy/U/Yv49nwa4zgxXYuDeAU6 UvaaKJZ8k30ecVEnIlqLyyAR19Zn1k1jSj5OGJg45A/0gBss0NJgPZ6GrHzF8h0RuImV YT5EN/JnGgS7YPVXUkjxpiGSrf72sZtSFPwGKfAfRl4elArGrsu99pRHWGXWwASdrGnu 4kRusC93dOn8k96yC6iMLmUhz4lK4i5fKBSr222+TapGwTdXfQJnBgtDPxD71liQYIDC bzIPjkzsb3/Gc4uG6SParP6yw3KnnQl2vz9Onu8iR0WrsVkvpOUHW9bTCEsu0kQeVG3D TTfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:cc:to:from:date:references:in-reply-to :message-id:mime-version:user-agent:feedback-id:dkim-signature :dkim-signature; bh=4qR2S2MtVT1gufffbhUzZeedkipKDGuTgchxc/0LCac=; fh=PgljyQN59VUKJ5BHIm79P6eeznhoIjJZe4QWd28yAdg=; b=l8HwQ5xcUQ+xE2cRkS4apMqQvXxh8hGGb82KTJAoFrr0HJP43OwM2UEfWmNEUTquiO rhVVbFuNyxzmeAkCYeVEBHoqDBt1dhv4bQWGXzDWfSJNJgr6Zmx+rkABvoL/DPHgPCyc de/U16M3LQS4GVG16PgpG+ToJDpc8mK9T//h8nzt7o4S/h3MrSilkXM/C2ej61WK9y4p V7d0Ly3jwEHrLtFjoWccr9gkA9ZKryh5Ts48jAFM1yR4S0Plmie4jqm7gZEt3Cs0eYCy nlJqNjJYvGxLR9sEFEvFp5+uenOwvJEYLvyt6IhedS+nQoPy0ReCeSxrOjF6NlJZe5di Vvew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arndb.de header.s=fm3 header.b=Qlwvjflp; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=Qk4VLf08; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bi10-20020a170902bf0a00b001b20e2ba8e1si5537375plb.23.2023.08.07.05.43.36; Mon, 07 Aug 2023 05:43:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@arndb.de header.s=fm3 header.b=Qlwvjflp; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=Qk4VLf08; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231204AbjHGMFB (ORCPT + 99 others); Mon, 7 Aug 2023 08:05:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233206AbjHGME7 (ORCPT ); Mon, 7 Aug 2023 08:04:59 -0400 Received: from wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com [64.147.123.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0EFD1BF3; Mon, 7 Aug 2023 05:04:38 -0700 (PDT) Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id 01489320095B; Mon, 7 Aug 2023 08:04:27 -0400 (EDT) Received: from imap51 ([10.202.2.101]) by compute6.internal (MEProxy); Mon, 07 Aug 2023 08:04:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arndb.de; h=cc :cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm3; t=1691409867; x=1691496267; bh=4q R2S2MtVT1gufffbhUzZeedkipKDGuTgchxc/0LCac=; b=QlwvjflpzuAEvaxUPL +xZACfpn+GmIuZBxQGWdiykq/If49cEKM3odstW87to7HaMsjBdJj/n7VaWROGQ7 TUoPbXbrVHQjWQDlF0oMsDdBg0vGp69LpEU2E5b/PTBRSEA3UDM2BB9jvoQgkPUb aG1M234zfAj6O0RII4crLzOysHHC/q4JalH1LARDz5k4fhwPNI+pMSKLN8jQ3vp9 IimMQPpcCqQAJkjXQhoHBdTSrhSu+jC1372MDfz/Jo5c8BfdibO7jS5zSj4U9ay5 kli2ojMD7diVeG5rQKj6CVyedZePp32L+4H9dgUgkSM8QmCjqs1IBr4Jn1hButSA hSnw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; t=1691409867; x=1691496267; bh=4qR2S2MtVT1gu fffbhUzZeedkipKDGuTgchxc/0LCac=; b=Qk4VLf08hmFsYsFFSdEgCtC7I+HwG lshWiDjV7R/mJbnTfX0SQsva2CiqE+cEiFnmQA/KGAyT43veeaCLTxzSgvyA8NIF Mj+TnNTKt6YCVhIreek36gUKPWNVp3jb72fr589LKsc8XiAr220AoFaMroc6v3dh 138JWbOavi65y2guLY9jjx1OO0VRNQu/R+tim0kEHjwjvjLiEjSNJIlhYJ3GiBFe 4cbEwkSEPLUNMrm19SqARBI2+WyhNAT7mm4kz8+bE3TIcCukylVga4O8FGxn8VLV 2P1u0BO1PpD6XAdTQiDGrGyslDPhu5yxG4EIKWDAgvIXWgtKIFXeA7H6A== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrledtgdegiecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefofgggkfgjfhffhffvvefutgesthdtredtreertdenucfhrhhomhepfdetrhhn ugcuuegvrhhgmhgrnhhnfdcuoegrrhhnugesrghrnhgusgdruggvqeenucggtffrrghtth gvrhhnpefgtedtvedufefgffetgefgheefudehteeggffgheeukeevffdvfeeifeevjeef ieenucffohhmrghinhepphgrshhtvggsihhnrdgtohhmpdehqdhrtgdurdhinhenucevlh hushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrrhhnugesrghr nhgusgdruggv X-ME-Proxy: Feedback-ID: i56a14606:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 27325B60089; Mon, 7 Aug 2023 08:04:26 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.9.0-alpha0-624-g7714e4406d-fm-20230801.001-g7714e440 Mime-Version: 1.0 Message-Id: In-Reply-To: References: <20230724135327.1173309-1-arnd@kernel.org> Date: Mon, 07 Aug 2023 14:04:05 +0200 From: "Arnd Bergmann" To: "Herbert Xu" , "Arnd Bergmann" Cc: "Alexandre Belloni" , "Ryan Wanner" , "Yangtao Li" , linux-kernel@vger.kernel.org, "David S . Miller" , "Sergiu Moga" , "Ayush Sawal" , "Gaosheng Cui" , "Claudiu Beznea" , linux-arm-kernel@lists.infradead.org, linux-crypto@vger.kernel.org, "Kees Cook" Subject: Re: [PATCH 1/2] crypto: drivers - avoid memcpy size warning Content-Type: text/plain X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org 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 >> >> 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