[PATCH] crypto: caam - Prevent fortify error

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <u.kleine-koenig@xxxxxxxxxxxxxx>
---
 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




[Index of Archives]     [Kernel]     [Gnu Classpath]     [Gnu Crypto]     [DM Crypt]     [Netfilter]     [Bugtraq]
  Powered by Linux