mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Ziyang Xuan (William)" <william.xuanziyang@huawei.com>
To: Paolo Abeni <pabeni@redhat.com>, <sgoutham@marvell.com>,
	<gakula@marvell.com>, <sbhatta@marvell.com>, <hkelam@marvell.com>,
	<davem@davemloft.net>, <edumazet@google.com>, <kuba@kernel.org>,
	<netdev@vger.kernel.org>
Cc: <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH net 2/2] octeontx2-pf: Fix a potential double free in otx2_sq_free_sqbs()
Date: Fri, 2 Dec 2022 09:39:45 +0800	[thread overview]
Message-ID: <1a39ec51-0879-a17f-7f4c-4ca0edbeb2a7@huawei.com> (raw)
In-Reply-To: <a3c723c5a27a75924f9d2f4ecabe26c04add08f3.camel@redhat.com>

> Hello,
> 
> On Fri, 2022-11-25 at 15:45 +0800, Ziyang Xuan wrote:
>> otx2_sq_free_sqbs() will be called twice when goto "err_free_nix_queues"
>> label in otx2_init_hw_resources(). The first calling is within
>> otx2_free_sq_res() at "err_free_nix_queues" label, and the second calling
>> is at later "err_free_sq_ptrs" label.
>>
>> In otx2_sq_free_sqbs(), If sq->sqb_ptrs[i] is not 0, the memory page it
>> points to will be freed, and sq->sqb_ptrs[i] do not be assigned 0 after
>> memory page be freed. If otx2_sq_free_sqbs() is called twice, the memory
>> page pointed by sq->sqb_ptrs[i] will be freeed twice. To fix the bug,
>> assign 0 to sq->sqb_ptrs[i] after memory page be freed.
>>
>> Fixes: caa2da34fd25 ("octeontx2-pf: Initialize and config queues")
>> Signed-off-by: Ziyang Xuan <william.xuanziyang@huawei.com>
>> ---
>>  drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c | 1 +
>>  1 file changed, 1 insertion(+)
>>
>> diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c
>> index 9e10e7471b88..5a25fe51d102 100644
>> --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c
>> +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c
>> @@ -1146,6 +1146,7 @@ void otx2_sq_free_sqbs(struct otx2_nic *pfvf)
>>  					     DMA_FROM_DEVICE,
>>  					     DMA_ATTR_SKIP_CPU_SYNC);
>>  			put_page(virt_to_page(phys_to_virt(pa)));
>> +			sq->sqb_ptrs[sqb] = 0;
> 
> The above looks not needed...
>>  		}
>>  		sq->sqb_count = 0;
> 
> ... as this will prevent the next invocation of otx2_sq_free_sqbs()
> from traversing and freeing any sq->sqb_ptrs[] element.

Yes, you are right. I did pay much attention to sq->sqb_ptrs[],
and omitted the for loop condition.

Thank you!

> 
> Cheers,
> 
> Paolo
>>  	}
> 
> 
> .
> 

      reply	other threads:[~2022-12-02  1:40 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-25  7:45 [PATCH net 0/2] octeontx2-pf: Fix several bugs in exception paths Ziyang Xuan
2022-11-25  7:45 ` [PATCH net 1/2] octeontx2-pf: Fix potential memory leak in otx2_init_tc() Ziyang Xuan
2022-11-25  7:45 ` [PATCH net 2/2] octeontx2-pf: Fix a potential double free in otx2_sq_free_sqbs() Ziyang Xuan
2022-11-29 12:03   ` Paolo Abeni
2022-12-02  1:39     ` Ziyang Xuan (William) [this message]

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=1a39ec51-0879-a17f-7f4c-4ca0edbeb2a7@huawei.com \
    --to=william.xuanziyang@huawei.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=gakula@marvell.com \
    --cc=hkelam@marvell.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sbhatta@marvell.com \
    --cc=sgoutham@marvell.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®