Patch "net/mlx5e: Check return value of snprintf writing to fw_version buffer for representors" has been added to the 6.5-stable tree

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

 



This is a note to let you know that I've just added the patch titled

    net/mlx5e: Check return value of snprintf writing to fw_version buffer for representors

to the 6.5-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     net-mlx5e-check-return-value-of-snprintf-writing-to-.patch
and it can be found in the queue-6.5 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 3964d49c0548dba295ce26da2db6dbd2be810a64
Author: Rahul Rameshbabu <rrameshbabu@xxxxxxxxxx>
Date:   Tue Nov 14 13:58:46 2023 -0800

    net/mlx5e: Check return value of snprintf writing to fw_version buffer for representors
    
    [ Upstream commit 1b2bd0c0264febcd8d47209079a6671c38e6558b ]
    
    Treat the operation as an error case when the return value is equivalent to
    the size of the name buffer. Failed to write null terminator to the name
    buffer, making the string malformed and should not be used. Provide a
    string with only the firmware version when forming the string with the
    board id fails. This logic for representors is identical to normal flow
    with ethtool.
    
    Without check, will trigger -Wformat-truncation with W=1.
    
        drivers/net/ethernet/mellanox/mlx5/core/en_rep.c: In function 'mlx5e_rep_get_drvinfo':
        drivers/net/ethernet/mellanox/mlx5/core/en_rep.c:78:31: warning: '%.16s' directive output may be truncated writing up to 16 bytes into a region of size between 13 and 22 [-Wformat-truncation=]
          78 |                  "%d.%d.%04d (%.16s)",
             |                               ^~~~~
        drivers/net/ethernet/mellanox/mlx5/core/en_rep.c:77:9: note: 'snprintf' output between 12 and 37 bytes into a destination of size 32
          77 |         snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
             |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          78 |                  "%d.%d.%04d (%.16s)",
             |                  ~~~~~~~~~~~~~~~~~~~~~
          79 |                  fw_rev_maj(mdev), fw_rev_min(mdev),
             |                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          80 |                  fw_rev_sub(mdev), mdev->board_id);
             |                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    Fixes: cf83c8fdcd47 ("net/mlx5e: Add missing ethtool driver info for representors")
    Link: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=6d4ab2e97dcfbcd748ae71761a9d8e5e41cc732c
    Signed-off-by: Rahul Rameshbabu <rrameshbabu@xxxxxxxxxx>
    Reviewed-by: Dragos Tatulea <dtatulea@xxxxxxxxxx>
    Signed-off-by: Saeed Mahameed <saeedm@xxxxxxxxxx>
    Link: https://lore.kernel.org/r/20231114215846.5902-16-saeed@xxxxxxxxxx
    Signed-off-by: Jakub Kicinski <kuba@xxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
index 0cd44ef190058..87fda65852fb7 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
@@ -71,13 +71,17 @@ static void mlx5e_rep_get_drvinfo(struct net_device *dev,
 {
 	struct mlx5e_priv *priv = netdev_priv(dev);
 	struct mlx5_core_dev *mdev = priv->mdev;
+	int count;
 
 	strscpy(drvinfo->driver, mlx5e_rep_driver_name,
 		sizeof(drvinfo->driver));
-	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);
+	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))
+		snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
+			 "%d.%d.%04d", fw_rev_maj(mdev),
+			 fw_rev_min(mdev), fw_rev_sub(mdev));
 }
 
 static const struct counter_desc sw_rep_stats_desc[] = {



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux