Netdev List
 help / color / mirror / Atom feed
From: Baran TUna <barant@fastmail.com>
To: Breno Leitao <leitao@debian.org>
Cc: Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	"open list:QLOGIC QL4xxx ETHERNET DRIVER"
	<netdev@vger.kernel.org>,
	open list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] qede: Prevent possible snprintf() truncation by bounding %s string format
Date: Wed, 1 Jul 2026 19:23:27 +0300	[thread overview]
Message-ID: <fe22e7b2-4cf9-4816-a513-5dfa9d3bf84f@fastmail.com> (raw)
In-Reply-To: <akUw_GsNELK4NKTN@gmail.com>

The current solution is pretty arbitrary.

Numbers are coming from a simple calculation, to make sure output always 
fits.


I will take a further look and send a patch if there is a more 
generalized solution.

On 7/1/26 6:27 PM, Breno Leitao wrote:
> On Wed, Jul 01, 2026 at 05:47:11PM +0300, Baran Tuna wrote:
>> GCC warning shows that formatted strings may
>> exceed the fixed-size destination buffers.
>>
>> Bounding the %s string format
>> so the maximum formatted output always fits.
>>
>> This eliminates the -Wformat-truncation warning.
>>
>> Signed-off-by: Baran Tuna <barant@fastmail.com>
>> ---
>>   drivers/net/ethernet/qlogic/qede/qede_ethtool.c | 8 ++++----
>>   1 file changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/net/ethernet/qlogic/qede/qede_ethtool.c b/drivers/net/ethernet/qlogic/qede/qede_ethtool.c
>> index 647f30a16a94..5428f53150a0 100644
>> --- a/drivers/net/ethernet/qlogic/qede/qede_ethtool.c
>> +++ b/drivers/net/ethernet/qlogic/qede/qede_ethtool.c
>> @@ -618,10 +618,10 @@ static void qede_get_drvinfo(struct net_device *ndev,
>>   	if ((strlen(storm) + strlen("[storm]")) <
>>   	    sizeof(info->version))
>>   		snprintf(info->version, sizeof(info->version),
>> -			 "[storm %s]", storm);
>> +			 "[storm %.16s]", storm);
> Where is this 16 coming from?
>
> Also, isn't the if above checking for no overflow? I.e,
> we got here only if strlen(storm) + strlen("[storm]") < sizeof(info->version))
>
> For whoever else is reviwewing this, this the buffers:
>
> 	#define ETHTOOL_FWVERS_LEN      32
>          char    version[32];
> 	char storm[ETHTOOL_FWVERS_LEN];
>

  reply	other threads:[~2026-07-01 16:23 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-01 14:47 [PATCH] qede: Prevent possible snprintf() truncation by bounding %s string format Baran Tuna
2026-07-01 15:27 ` Breno Leitao
2026-07-01 16:23   ` Baran TUna [this message]
2026-07-01 19:33 ` David Laight

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=fe22e7b2-4cf9-4816-a513-5dfa9d3bf84f@fastmail.com \
    --to=barant@fastmail.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=leitao@debian.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.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