Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp349644rwj; Thu, 22 Dec 2022 08:29:01 -0800 (PST) X-Google-Smtp-Source: AMrXdXsaHbKvouUjmmQpOV5+0HQguAc9mmOuAzc+r0pEuvrxO4dY74pEUQEFWyrT/m77DKIZVMuf X-Received: by 2002:a05:6402:2296:b0:479:400a:d940 with SMTP id cw22-20020a056402229600b00479400ad940mr5056051edb.17.1671726541386; Thu, 22 Dec 2022 08:29:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671726541; cv=none; d=google.com; s=arc-20160816; b=eMp/KP29yzM0KbAK96YLyjCClUrsZgBhcUpXtR/QEFFZQU51oQUA4i/CCZtSU7ILyh ZKm0gzAYznO5+v+u2O4zcJr11dcdyO4BvZrwbTGxjItfIqQCW3RdVj1tfNYQJw4Iunmp BoIXaPbl7fx2gqxuOkrOVHFmgs+jGXQ8WUXb0Js0TeGET3rC1Eb5ZXOnyeT5+0R2KSr0 yOYkdTViBH/inccpNFV89txJUqfydMKkxkjfLW3LjPv27AHWyEsjPzjDY/7Sa8xlIXze oYbzW1iejAeBS8zMU5h/+peXbhEqcqOvJqZIuGzEKHd/dafv0MRszlYWedyOimRVWb5q /M3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=rFqsu64RnibNq7bCOIYFw1Pnjark2Q82EVYXjJlDsiw=; b=hpMokb5At1cRSonnQlbkT/iZhALPqq8omJZOTgiZUcsj7AYK1sg1QHm+qyYDV1n5mY COc/NfTMbDAQxO3eF9WxAalh7nxPUgn5+jbFfdbYVNDyeHXNiYyT1CLza2L0tVnwVwnI 6NNxMLcZl7HkSJaQUaeP4KRKxrY+ouDTzdiV/z4XouzY89cHCyTEsghEkPU1M9+lDrqJ aEj6ftWgE3GYYWczcKH5Nb0MYTbhAFqubwX5YlXvMPJWoDvKM7yWy+5l6kgApHNwJb5x XazcIQpnQ0osAeXWaK/CRnzGs5nu/z8m/z8OUXJqwpHwRbUQ7GIrU9DUg7DVmVgVi/dj FPlw== ARC-Authentication-Results: i=1; mx.google.com; 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 fd16-20020a056402389000b0046ba3001425si898861edb.60.2022.12.22.08.28.32; Thu, 22 Dec 2022 08:29:01 -0800 (PST) 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; 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 S229545AbiLVQZb (ORCPT + 99 others); Thu, 22 Dec 2022 11:25:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229526AbiLVQZ3 (ORCPT ); Thu, 22 Dec 2022 11:25:29 -0500 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 25253248E9 for ; Thu, 22 Dec 2022 08:25:28 -0800 (PST) Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p8ONm-00068N-SX; Thu, 22 Dec 2022 17:25:22 +0100 Received: from [2a0a:edc0:0:1101:1d::ac] (helo=dude04.red.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.94.2) (envelope-from ) id 1p8ONj-0012y7-UN; Thu, 22 Dec 2022 17:25:19 +0100 Received: from ukl by dude04.red.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1p8ONj-00GsId-4k; Thu, 22 Dec 2022 17:25:19 +0100 From: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= To: =?UTF-8?q?Horia=20Geant=C4=83?= , Pankaj Gupta , Gaurav Jain Cc: Herbert Xu , "David S. Miller" , linux-crypto@vger.kernel.org, kernel@pengutronix.de Subject: [PATCH] crypto: caam - Prevent fortify error Date: Thu, 22 Dec 2022 17:25:13 +0100 Message-Id: <20221222162513.4021928-1-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-crypto@vger.kernel.org X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,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 When compiling arm64 allmodconfig with gcc 10.2.1 I get drivers/crypto/caam/desc_constr.h: In function ‘append_data.constprop’: include/linux/fortify-string.h:57:29: error: argument 2 null where non-null expected [-Werror=nonnull] Fix this by skipping the memcpy if data is NULL and add a BUG_ON instead that triggers on a problematic call that is now prevented to trigger. After data == NULL && len != 0 is known to be false, logically if (len) memcpy(...) could be enough to know that memcpy is not called with dest=NULL, but gcc doesn't seem smart enough for that conclusion. gcc 12 doesn't have a problem with the original code. Signed-off-by: Uwe Kleine-König --- drivers/crypto/caam/desc_constr.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/crypto/caam/desc_constr.h b/drivers/crypto/caam/desc_constr.h index 62ce6421bb3f..163e0e740b11 100644 --- a/drivers/crypto/caam/desc_constr.h +++ b/drivers/crypto/caam/desc_constr.h @@ -163,7 +163,13 @@ static inline void append_data(u32 * const desc, const void *data, int len) { u32 *offset = desc_end(desc); - if (len) /* avoid sparse warning: memcpy with byte count of 0 */ + /* + * avoid sparse warning: "memcpy with byte count of 0" and + * and "error: argument 2 null where non-null expected + * [-Werror=nonnull]" with fortify enabled. + */ + BUG_ON(data == NULL && len != 0); + if (len && data) memcpy(offset, data, len); (*desc) = cpu_to_caam32(caam32_to_cpu(*desc) + base-commit: 9d2f6060fe4c3b49d0cdc1dce1c99296f33379c8 -- 2.30.2