mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Carlos Bilbao <carlos.bilbao@amd.com>
To: Kuniyuki Iwashima <kuniyu@amazon.com>
Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
	linux-kernel@vger.kernel.org, mchan@broadcom.com,
	netdev@vger.kernel.org, pabeni@redhat.com, prashant@broadcom.com,
	siva.kallam@broadcom.com
Subject: Re: [PATCH] tg3: fix array subscript out of bounds compilation error
Date: Tue, 18 Jul 2023 10:52:39 -0500	[thread overview]
Message-ID: <c196f8f9-3d2c-27c6-6807-75a6e6e4d5a5@amd.com> (raw)
In-Reply-To: <20230717192403.96187-1-kuniyu@amazon.com>

On 7/17/23 14:24, Kuniyuki Iwashima wrote:
> From: Carlos Bilbao <carlos.bilbao@amd.com>
> Date: Mon, 17 Jul 2023 09:34:43 -0500
>> Fix encountered compilation error in tg3.c where an array subscript was
> 
> What is the error ?

drivers/net/ethernet/broadcom/tg3.c: In function ‘tg3_init_one’:
drivers/net/ethernet/broadcom/tg3.c:17795:51: error: array subscript 5 is 
above array bounds of ‘struct tg3_napi[5]’ [-Werror=array-bounds=]
17795 |                 struct tg3_napi *tnapi = &tp->napi[i];
       |                                           ~~~~~~~~^~~
In file included from drivers/net/ethernet/broadcom/tg3.c:72:
drivers/net/ethernet/broadcom/tg3.h:3203:41: note: while referencing ‘napi’
  3203 |         struct tg3_napi                 napi[TG3_IRQ_MAX_VECS];
       |                                         ^~~~
drivers/net/ethernet/broadcom/tg3.c:17795:51: error: array subscript 5 is 
above array bounds of ‘struct tg3_napi[5]’ [-Werror=array-bounds=]
17795 |                 struct tg3_napi *tnapi = &tp->napi[i];
       |                                           ~~~~~~~~^~~
drivers/net/ethernet/broadcom/tg3.h:3203:41: note: while referencing ‘napi’
  3203 |         struct tg3_napi                 napi[TG3_IRQ_MAX_VECS];

> 
> 
>> above the array bounds of 'struct tg3_napi[5]'. Add an additional check in
>> the for loop to ensure that it does not exceed the bounds of
>> 'struct tg3_napi' (defined by TG3_IRQ_MAX_VECS).
>>
>> Reviewed-By: Carlos Bilbao <carlos.bilbao@amd.com>
>> ---
>>   drivers/net/ethernet/broadcom/tg3.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/net/ethernet/broadcom/tg3.c b/drivers/net/ethernet/broadcom/tg3.c
>> index 4179a12fc881..33ad75b7ed91 100644
>> --- a/drivers/net/ethernet/broadcom/tg3.c
>> +++ b/drivers/net/ethernet/broadcom/tg3.c
>> @@ -17791,7 +17791,7 @@ static int tg3_init_one(struct pci_dev *pdev,
>>   	intmbx = MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW;
>>   	rcvmbx = MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW;
>>   	sndmbx = MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW;
>> -	for (i = 0; i < tp->irq_max; i++) {
>> +	for (i = 0; i < tp->irq_max && i < TG3_IRQ_MAX_VECS; i++) {
> 
> I'm not familiar with this driver, but it seem tg3_init_one() calls
> tg3_get_invariants() before the loop and initialises irq_max as 1
> or TG3_IRQ_MAX_VECS.

I'm also not familiar with this driver, but what you mention seems to be
the case, and also tp->irq_max is used for loop boundaries elsewhere just
fine. I don't know why was the compiler complaining, maybe a false positive.

> 
> Where does tp->irq_max go over TG3_IRQ_MAX_VECS ?
> 
> 
>>   		struct tg3_napi *tnapi = &tp->napi[i];
>>   
>>   		tnapi->tp = tp;
>> -- 
>> 2.41.0

Thanks,
Carlos

  reply	other threads:[~2023-07-18 15:53 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20230717143443.163732-1-carlos.bilbao@amd.com>
2023-07-17 19:24 ` Kuniyuki Iwashima
2023-07-18 15:52   ` Carlos Bilbao [this message]
2023-07-19  2:54     ` Jakub Kicinski
2023-07-19  4:30       ` Eric Dumazet
2023-07-21 22:29       ` Carlos Bilbao
2023-07-22  1:17         ` Michael Chan

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=c196f8f9-3d2c-27c6-6807-75a6e6e4d5a5@amd.com \
    --to=carlos.bilbao@amd.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=kuniyu@amazon.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mchan@broadcom.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=prashant@broadcom.com \
    --cc=siva.kallam@broadcom.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

all inboxes | Powered by JetHome®