netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net v1 1/2] net/mlx5e: Correct snprintf truncation handling for fw_version buffer
@ 2023-11-21 23:00 Rahul Rameshbabu
  2023-11-21 23:00 ` [PATCH net v1 2/2] net/mlx5e: Correct snprintf truncation handling for fw_version buffer used by representors Rahul Rameshbabu
  2023-11-24 11:39 ` [PATCH net v1 1/2] net/mlx5e: Correct snprintf truncation handling for fw_version buffer Simon Horman
  0 siblings, 2 replies; 4+ messages in thread
From: Rahul Rameshbabu @ 2023-11-21 23:00 UTC (permalink / raw)
  To: netdev
  Cc: Jakub Kicinski, Paolo Abeni, Eric Dumazet, David S. Miller,
	Saeed Mahameed, Gal Pressman, Dragos Tatulea, David Laight,
	Rahul Rameshbabu

snprintf returns the length of the formatted string, excluding the trailing
null, without accounting for truncation. This means that is the return
value is greater than or equal to the size parameter, the fw_version string
was truncated.

Reported-by: David Laight <David.Laight@ACULAB.COM>
Closes: https://lore.kernel.org/netdev/81cae734ee1b4cde9b380a9a31006c1a@AcuMS.aculab.com/
Link: https://docs.kernel.org/core-api/kernel-api.html#c.snprintf
Fixes: 41e63c2baa11 ("net/mlx5e: Check return value of snprintf writing to fw_version buffer")
Signed-off-by: Rahul Rameshbabu <rrameshbabu@nvidia.com>
---
 drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c b/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c
index 792a0ea544cd..c7c1b667b105 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c
@@ -49,7 +49,7 @@ void mlx5e_ethtool_get_drvinfo(struct mlx5e_priv *priv,
 	count = snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
 			 "%d.%d.%04d (%.16s)", fw_rev_maj(mdev),
 			 fw_rev_min(mdev), fw_rev_sub(mdev), mdev->board_id);
-	if (count == sizeof(drvinfo->fw_version))
+	if (count >= sizeof(drvinfo->fw_version))
 		snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
 			 "%d.%d.%04d", fw_rev_maj(mdev),
 			 fw_rev_min(mdev), fw_rev_sub(mdev));
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-11-24 11:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-21 23:00 [PATCH net v1 1/2] net/mlx5e: Correct snprintf truncation handling for fw_version buffer Rahul Rameshbabu
2023-11-21 23:00 ` [PATCH net v1 2/2] net/mlx5e: Correct snprintf truncation handling for fw_version buffer used by representors Rahul Rameshbabu
2023-11-24 11:40   ` Simon Horman
2023-11-24 11:39 ` [PATCH net v1 1/2] net/mlx5e: Correct snprintf truncation handling for fw_version buffer Simon Horman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).