From: Leon Romanovsky <leon@kernel.org>
To: Peter Kosyh <pkosyh@yandex.ru>
Cc: Tariq Toukan <tariqt@nvidia.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
netdev@vger.kernel.org, linux-rdma@vger.kernel.org,
linux-kernel@vger.kernel.org, lvc-project@linuxtesting.org
Subject: Re: [PATCH] mlx4: use snprintf() instead of sprintf() for safety
Date: Tue, 22 Nov 2022 16:48:15 +0200 [thread overview]
Message-ID: <Y3zhL0/OItHF1R03@unreal> (raw)
In-Reply-To: <20221122130453.730657-1-pkosyh@yandex.ru>
On Tue, Nov 22, 2022 at 04:04:53PM +0300, Peter Kosyh wrote:
> Use snprintf() to avoid the potential buffer overflow. Although in the
> current code this is hardly possible, the safety is unclean.
Let's fix the tools instead. The kernel code is correct.
Thanks
>
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>
> Signed-off-by: Peter Kosyh <pkosyh@yandex.ru>
> ---
> drivers/net/ethernet/mellanox/mlx4/main.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
> index d3fc86cd3c1d..0616d352451b 100644
> --- a/drivers/net/ethernet/mellanox/mlx4/main.c
> +++ b/drivers/net/ethernet/mellanox/mlx4/main.c
> @@ -3057,7 +3057,8 @@ static int mlx4_init_port_info(struct mlx4_dev *dev, int port)
> info->base_qpn = mlx4_get_base_qpn(dev, port);
> }
>
> - sprintf(info->dev_name, "mlx4_port%d", port);
> + snprintf(info->dev_name, sizeof(info->dev_name),
> + "mlx4_port%d", port);
> info->port_attr.attr.name = info->dev_name;
> if (mlx4_is_mfunc(dev)) {
> info->port_attr.attr.mode = 0444;
> @@ -3077,7 +3078,8 @@ static int mlx4_init_port_info(struct mlx4_dev *dev, int port)
> return err;
> }
>
> - sprintf(info->dev_mtu_name, "mlx4_port%d_mtu", port);
> + snprintf(info->dev_mtu_name, sizeof(info->dev_mtu_name),
> + "mlx4_port%d_mtu", port);
> info->port_mtu_attr.attr.name = info->dev_mtu_name;
> if (mlx4_is_mfunc(dev)) {
> info->port_mtu_attr.attr.mode = 0444;
> --
> 2.38.1
>
next prev parent reply other threads:[~2022-11-22 14:48 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-22 13:04 [PATCH] mlx4: use snprintf() instead of sprintf() for safety Peter Kosyh
2022-11-22 14:48 ` Leon Romanovsky [this message]
2022-11-22 20:12 ` Jakub Kicinski
2022-11-23 4:43 ` Saeed Mahameed
2022-11-23 6:40 ` Leon Romanovsky
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=Y3zhL0/OItHF1R03@unreal \
--to=leon@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=lvc-project@linuxtesting.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=pkosyh@yandex.ru \
--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).