Received: by 2002:a05:7412:bc1a:b0:d7:7d3a:4fe2 with SMTP id ki26csp372172rdb; Sat, 19 Aug 2023 05:22:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE809QpFb6SILGlmcM/8heQcvXUDUe3FDK+RfUA1eZbSF+d7vHt2OypRMuMd2hXl/D1SZSA X-Received: by 2002:a17:902:e802:b0:1b8:85c4:48f5 with SMTP id u2-20020a170902e80200b001b885c448f5mr2271559plg.2.1692447726870; Sat, 19 Aug 2023 05:22:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692447726; cv=none; d=google.com; s=arc-20160816; b=IBV9N2bHuAVCKT2MadI7A8wi1PEhX/6SIdVgxraBI2V6jAkLXC/pLfJn5MavwI3w1M 4M4XtXiRsHNdTC3RqrNBis7wvlIRQBWAO5UylyUroC0F6+qtQ94chyqrDwtC8KS7wRgc qdpvxZycbXsUT8pD6b4RWBj5AsrjfN6DVBZVJfYIkEG5CXZ2tD8JR4dUsmUFdseKlZfZ SKboMv6YtS1nhs4mHRG7u4jRQX7tbTLItKOW9+QApXUvQuiF8yCrvLIX9lmn3+6RBV04 JDUaCIBMHB/e/lHSbTrxW4Ws9+l2pspi3SuWZEXULueO3hIKuW0CxwAspUG4LO+PYSi8 c5Lg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=rhnSGfcrilFtOe1pITSRJNIcZJXxa71+4mNdy4r5WS0=; fh=RSEKkhgGg/BrwxIbvSOrb2ThIoJQaUWOF0+CV5oyrZY=; b=01iFeENPjoRRZohDQc01OTsW24MKHkswH4vH4X1MRYF0KtyUQXpB9123vjKtSF/UjB V8W5VRQaxntrR++LTBfi8KP0APIzNxDpVIyaFLs7I7x/b/gsfDBAMD+5HKhX5fnw4bvo rismnJUSeGHgEhXYEdEj2QdyCrAxRv6qHZVcOmhQWjdd9uGbPyD/Fxrw/whcjIwFuvsi OwE95HQsuv7soXBQ8SBWpFeTlO/8nfF3+JacGt/cXJjYeWx69dqhddtvU/T4IG1gafN5 aL3dCVhTG2hd2qImsLwGAfLA0PCV5ZJGd7gaZ2+HAHRHVDQDoeVsYSRogq8oS9sRlchD 3jUw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id q9-20020a17090311c900b001ae40e07fb0si3536056plh.216.2023.08.19.05.22.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Aug 2023 05:22:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D3E9A80F8A; Sat, 19 Aug 2023 01:37:04 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358846AbjHRK1S (ORCPT + 99 others); Fri, 18 Aug 2023 06:27:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1359419AbjHRK0t (ORCPT ); Fri, 18 Aug 2023 06:26:49 -0400 Received: from 167-179-156-38.a7b39c.syd.nbn.aussiebb.net (167-179-156-38.a7b39c.syd.nbn.aussiebb.net [167.179.156.38]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2E3935B6; Fri, 18 Aug 2023 03:26:31 -0700 (PDT) Received: from loth.rohan.me.apana.org.au ([192.168.167.2]) by formenos.hmeau.com with smtp (Exim 4.94.2 #2 (Debian)) id 1qWwfv-005Gi5-3n; Fri, 18 Aug 2023 18:25:52 +0800 Received: by loth.rohan.me.apana.org.au (sSMTP sendmail emulation); Fri, 18 Aug 2023 18:25:51 +0800 Date: Fri, 18 Aug 2023 18:25:51 +0800 From: Herbert Xu To: Arnd Bergmann Cc: Arnd Bergmann , "David S. Miller" , Nicolas Ferre , Alexandre Belloni , Claudiu Beznea , Ayush Sawal , Ryan Wanner , Yangtao Li , Wang Ming , Sergiu Moga , Gaosheng Cui , linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] [v2] crypto: drivers - avoid memcpy size warning Message-ID: References: <20230811134704.3252535-1-arnd@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230811134704.3252535-1-arnd@kernel.org> X-Spam-Status: No, score=2.7 required=5.0 tests=BAYES_00,HELO_DYNAMIC_IPADDR2, PDS_RDNS_DYNAMIC_FP,RCVD_IN_DNSWL_BLOCKED,RDNS_DYNAMIC,SPF_HELO_NONE, SPF_PASS,TVD_RCVD_IP,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: ** X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Aug 11, 2023 at 03:46:33PM +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: > > drivers/crypto/chelsio/chcr_algo.c: In function 'chcr_ahash_setkey': > include/linux/fortify-string.h:57:33: error: '__builtin_memcpy' accessing 129 or more bytes at offsets 260 and 132 overlaps 1 or more bytes at offset 260 [-Werror=restrict] > drivers/crypto/bcm/cipher.c: In function 'ahash_hmac_setkey': > include/linux/fortify-string.h:57:33: error: '__builtin_memcpy' accessing between 129 and 4294967295 bytes at offsets 840 and 712 overlaps between 1 and 4294967167 bytes at offset 840 [-Werror=restrict] > > I don't think it can actually happen because the size is strictly bounded > to the available block sizes, at most 128 bytes, though inlining decisions > could lead gcc to not see that. > > Use the unsafe_memcpy() helper instead of memcpy(), with the only difference > being that this skips the hardening checks that produce the warning. > > Suggested-by: Herbert Xu > Signed-off-by: Arnd Bergmann > --- > drivers/crypto/atmel-sha.c | 3 ++- > drivers/crypto/bcm/cipher.c | 3 ++- > drivers/crypto/chelsio/chcr_algo.c | 3 ++- > 3 files changed, 6 insertions(+), 3 deletions(-) Patch applied. Thanks. -- Email: Herbert Xu Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt