From patchwork Wed Mar 12 20:07:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 14013820 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9EE6D1ADC6C; Wed, 12 Mar 2025 20:07:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741810026; cv=none; b=bxSGOvDizI+MWX30Zc8dKco5Oh3KFADCqnpo75WNe4gF3OGcIo4fdwz7qdsBNZsEJOV2BQnoxl1Vsd6du62kCJgR2nuQurq28Q1X5fR/+9soGWh5EiLNodAsl2wQ25u9HZmMwJ5kbTfcUwZwOMoswdo2zY5ghgXHHGas+dF5jjE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741810026; c=relaxed/simple; bh=GBnlE5zE4WucF8iLnWQgHp7rfMGPZL48Cv0Cjo6JR0c=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=DgJWcaJaVa2UwmMprOT70/X9BrLWofXhnreH5lh6jQ707y4PiZVS5Uh7PUYJvMvkB51PVqILImD0AfOJ5u0DijYWhfFtA8vgv79yO9c3YvXNGeHQfcf4boi7FWyQpdaj0a8Ph7R3j/+oKVDI7QjO6WOddELjI12pLMQlGSQF/n8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EJrj1rk8; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="EJrj1rk8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 16638C4CEDD; Wed, 12 Mar 2025 20:07:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741810026; bh=GBnlE5zE4WucF8iLnWQgHp7rfMGPZL48Cv0Cjo6JR0c=; h=From:To:Cc:Subject:Date:From; b=EJrj1rk8SH10JTGrI1rXTuUL0AZet2AcGmgdfUz4zYxcQRrigpGaXMG3dPzqHvSdj +iVJV4TOpRjd8EuF8SBHrg0fF98C81nGZnAwtqfMAYo6XzDHrduRxFPfktT93WXluI c83shzuCKLhvIyyD9gXKjWbPyUkCq0gmIwXrc0pWF+/VhCTJ/Mcc/4N9DkWALb1Ul5 Er3Rp3p7ipMBTPkyl6VGIQBNHi0YD3TxrwSfIuEb87i9C6cQ6G8qKSmOUIA6fVbtTc FIsCFx5trgPB0IRjbtsjJl+/SqrILQo27p0WJKbl3wJt9eZMc+ubx2RiXsx8vY/0kS gYNFl66xRo1Jw== From: Kees Cook To: Nicolas Ferre Cc: Kees Cook , Claudiu Beznea , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH v3] net: macb: Add __nonstring annotations for unterminated strings Date: Wed, 12 Mar 2025 13:07:01 -0700 Message-Id: <20250312200700.make.521-kees@kernel.org> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3457; i=kees@kernel.org; h=from:subject:message-id; bh=GBnlE5zE4WucF8iLnWQgHp7rfMGPZL48Cv0Cjo6JR0c=; b=owGbwMvMwCVmps19z/KJym7G02pJDOkXX6ZsaBFbd7L4Qff7ee+fLpwzK3JG8+8XETckeOTe/ +SrmreQqaOUhUGMi0FWTJElyM49zsXjbXu4+1xFmDmsTCBDGLg4BWAib2oZ/hkVybR8NbAv685Z Z/EsfZbQu0ccAXM+rnJ9W/z97MzvlxQZGRoVjGVtvJw2zIs261gxr/3OTnUPqwVu8xrNTn5+8FR 9GisA X-Developer-Key: i=kees@kernel.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 When a character array without a terminating NUL character has a static initializer, GCC 15's -Wunterminated-string-initialization will only warn if the array lacks the "nonstring" attribute[1]. Mark the arrays with __nonstring to correctly identify the char array as "not a C string" and thereby eliminate the warning: In file included from ../drivers/net/ethernet/cadence/macb_main.c:42: ../drivers/net/ethernet/cadence/macb.h:1070:35: warning: initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute (33 chars into 32 available) [-Wunterminated-string-initialization] 1070 | GEM_STAT_TITLE(TX1519CNT, "tx_greater_than_1518_byte_frames"), | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../drivers/net/ethernet/cadence/macb.h:1050:24: note: in definition of macro 'GEM_STAT_TITLE_BITS' 1050 | .stat_string = title, \ | ^~~~~ ../drivers/net/ethernet/cadence/macb.h:1070:9: note: in expansion of macro 'GEM_STAT_TITLE' 1070 | GEM_STAT_TITLE(TX1519CNT, "tx_greater_than_1518_byte_frames"), | ^~~~~~~~~~~~~~ ../drivers/net/ethernet/cadence/macb.h:1097:35: warning: initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute (33 chars into 32 available) [-Wunterminated-string-initialization] 1097 | GEM_STAT_TITLE(RX1519CNT, "rx_greater_than_1518_byte_frames"), | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../drivers/net/ethernet/cadence/macb.h:1050:24: note: in definition of macro 'GEM_STAT_TITLE_BITS' 1050 | .stat_string = title, \ | ^~~~~ ../drivers/net/ethernet/cadence/macb.h:1097:9: note: in expansion of macro 'GEM_STAT_TITLE' 1097 | GEM_STAT_TITLE(RX1519CNT, "rx_greater_than_1518_byte_frames"), | ^~~~~~~~~~~~~~ Since these strings are copied with memcpy() they do not need to be NUL terminated, and can use __nonstring: memcpy(p, gem_statistics[i].stat_string, ETH_GSTRING_LEN); Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178 [1] Signed-off-by: Kees Cook Reviewed-by: Jacob Keller --- v3: improve commit message (Bill), drop whitespace change (Bill) v2: https://lore.kernel.org/lkml/20250311224412.it.153-kees@kernel.org/ v1: https://lore.kernel.org/lkml/20250310222415.work.815-kees@kernel.org/ Cc: Nicolas Ferre Cc: Claudiu Beznea Cc: Andrew Lunn Cc: "David S. Miller" Cc: Eric Dumazet Cc: Jakub Kicinski Cc: Paolo Abeni Cc: netdev@vger.kernel.org --- drivers/net/ethernet/cadence/macb.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/cadence/macb.h b/drivers/net/ethernet/cadence/macb.h index 2847278d9cd4..d2a4c180d6a6 100644 --- a/drivers/net/ethernet/cadence/macb.h +++ b/drivers/net/ethernet/cadence/macb.h @@ -1027,7 +1027,7 @@ struct gem_stats { * this register should contribute to. */ struct gem_statistic { - char stat_string[ETH_GSTRING_LEN]; + char stat_string[ETH_GSTRING_LEN] __nonstring; int offset; u32 stat_bits; };