Message ID | d17868ea-cef9-4f8c-a318-9f98b8341f5b@moroto.mountain (mailing list archive) |
---|---|
State | Awaiting Upstream |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | [net] net/mlx5e: Fix snprintf return check | expand |
On Mon, 27 Nov, 2023 16:00:53 +0300 Dan Carpenter <dan.carpenter@linaro.org> wrote: > This code prints a string and then if there wasn't enough space for the > whole string, then it prints a slightly shorter string. However, the > test for overflow should have been >= instead of == because snprintf() > returns the number of bytes which *would* have been printed if there > were enough space. > > Fixes: 41e63c2baa11 ("net/mlx5e: Check return value of snprintf writing to fw_version buffer") > Fixes: 1b2bd0c0264f ("net/mlx5e: Check return value of snprintf writing to fw_version buffer for representors") > Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org> > --- I have already sent out patches targeting net for this on the mailing list. That said, thanks for the follow-up. * https://lore.kernel.org/netdev/20231121230022.89102-1-rrameshbabu@nvidia.com/ * https://lore.kernel.org/netdev/20231121230022.89102-2-rrameshbabu@nvidia.com/ These have been reviewed by Simon Horman. -- Thanks, Rahul Rameshbabu
On Mon, Nov 27, 2023 at 10:46:17AM -0800, Rahul Rameshbabu wrote: > On Mon, 27 Nov, 2023 16:00:53 +0300 Dan Carpenter <dan.carpenter@linaro.org> wrote: > > This code prints a string and then if there wasn't enough space for the > > whole string, then it prints a slightly shorter string. However, the > > test for overflow should have been >= instead of == because snprintf() > > returns the number of bytes which *would* have been printed if there > > were enough space. > > > > Fixes: 41e63c2baa11 ("net/mlx5e: Check return value of snprintf writing to fw_version buffer") > > Fixes: 1b2bd0c0264f ("net/mlx5e: Check return value of snprintf writing to fw_version buffer for representors") > > Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org> > > --- > > I have already sent out patches targeting net for this on the mailing > list. That said, thanks for the follow-up. Ah. Good. I hadn't seen the earlier discussion about this. When you said "follow-up" I worried that I had reported this earlier and forgotten about it. regards, dan carpenter
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)); diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c index fe0726c7b847..a7c77a63cc29 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c @@ -78,7 +78,7 @@ static void mlx5e_rep_get_drvinfo(struct net_device *dev, 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));
This code prints a string and then if there wasn't enough space for the whole string, then it prints a slightly shorter string. However, the test for overflow should have been >= instead of == because snprintf() returns the number of bytes which *would* have been printed if there were enough space. Fixes: 41e63c2baa11 ("net/mlx5e: Check return value of snprintf writing to fw_version buffer") Fixes: 1b2bd0c0264f ("net/mlx5e: Check return value of snprintf writing to fw_version buffer for representors") Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org> --- drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c | 2 +- drivers/net/ethernet/mellanox/mlx5/core/en_rep.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)