netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Saeed Mahameed <saeed@kernel.org>
To: "David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Eric Dumazet <edumazet@google.com>
Cc: Saeed Mahameed <saeedm@nvidia.com>,
	netdev@vger.kernel.org, Tariq Toukan <tariqt@nvidia.com>,
	Rahul Rameshbabu <rrameshbabu@nvidia.com>,
	David Laight <David.Laight@ACULAB.COM>,
	Simon Horman <horms@kernel.org>
Subject: [net V3 14/15] net/mlx5e: Correct snprintf truncation handling for fw_version buffer
Date: Tue,  5 Dec 2023 13:45:33 -0800	[thread overview]
Message-ID: <20231205214534.77771-15-saeed@kernel.org> (raw)
In-Reply-To: <20231205214534.77771-1-saeed@kernel.org>

From: Rahul Rameshbabu <rrameshbabu@nvidia.com>

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>
Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: Saeed Mahameed <saeedm@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.43.0


  parent reply	other threads:[~2023-12-05 21:45 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-05 21:45 [pull request][net V3 00/15] mlx5 fixes 2023-12-05 Saeed Mahameed
2023-12-05 21:45 ` [net V3 01/15] net/mlx5e: Honor user choice of IPsec replay window size Saeed Mahameed
2023-12-08 10:40   ` patchwork-bot+netdevbpf
2023-12-05 21:45 ` [net V3 02/15] net/mlx5e: Ensure that IPsec sequence packet number starts from 1 Saeed Mahameed
2023-12-05 21:45 ` [net V3 03/15] net/mlx5e: Unify esw and normal IPsec status table creation/destruction Saeed Mahameed
2023-12-05 21:45 ` [net V3 04/15] net/mlx5e: Remove exposure of IPsec RX flow steering struct Saeed Mahameed
2023-12-05 21:45 ` [net V3 05/15] net/mlx5e: Add IPsec and ASO syndromes check in HW Saeed Mahameed
2023-12-05 21:45 ` [net V3 06/15] net/mlx5e: Tidy up IPsec NAT-T SA discovery Saeed Mahameed
2023-12-05 21:45 ` [net V3 07/15] net/mlx5e: Reduce eswitch mode_lock protection context Saeed Mahameed
2023-12-05 21:45 ` [net V3 08/15] net/mlx5e: Disable IPsec offload support if not FW steering Saeed Mahameed
2023-12-05 21:45 ` [net V3 09/15] net/mlx5e: Fix possible deadlock on mlx5e_tx_timeout_work Saeed Mahameed
2023-12-05 21:45 ` [net V3 10/15] net/mlx5e: TC, Don't offload post action rule if not supported Saeed Mahameed
2023-12-05 21:45 ` [net V3 11/15] net/mlx5: Nack sync reset request when HotPlug is enabled Saeed Mahameed
2023-12-05 21:45 ` [net V3 12/15] net/mlx5e: Check netdev pointer before checking its net ns Saeed Mahameed
2023-12-05 21:45 ` [net V3 13/15] net/mlx5: Fix a NULL vs IS_ERR() check Saeed Mahameed
2023-12-05 21:45 ` Saeed Mahameed [this message]
2023-12-05 21:45 ` [net V3 15/15] net/mlx5e: Correct snprintf truncation handling for fw_version buffer used by representors Saeed Mahameed
2023-12-05 22:48 ` [pull request][net V3 00/15] mlx5 fixes 2023-12-05 Jakub Kicinski
2023-12-06 20:58   ` Saeed Mahameed
2023-12-07  2:41     ` Jakub Kicinski
2023-12-07 19:03       ` Saeed Mahameed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231205214534.77771-15-saeed@kernel.org \
    --to=saeed@kernel.org \
    --cc=David.Laight@ACULAB.COM \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=rrameshbabu@nvidia.com \
    --cc=saeedm@nvidia.com \
    --cc=tariqt@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).