public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Horatiu Vultur <horatiu.vultur@microchip.com>
To: Zheng Hacker <hackerzheng666@gmail.com>
Cc: Zheng Wang <zyytlz.wz@163.com>, <davem@davemloft.net>,
	<edumazet@google.com>, <kuba@kernel.org>, <pabeni@redhat.com>,
	<netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<1395428693sheep@gmail.com>, <alex000young@gmail.com>
Subject: Re: [PATCH net v2] net: ethernet: fix use after free bug in ns83820_remove_one due to race condition
Date: Fri, 14 Apr 2023 16:31:44 +0200	[thread overview]
Message-ID: <20230414143144.2e5hf6iokcbcrf5a@soft-dev3-1> (raw)
In-Reply-To: <CAJedcCyLXuqMEWt6f+_HFEzAdgEcq5oQc-hRtt0k=rd_vrz6ew@mail.gmail.com>

The 04/13/2023 18:49, Zheng Hacker wrote:

Hi Zheng,

> 
> Horatiu Vultur <horatiu.vultur@microchip.com> 于2023年4月13日周四 18:01写道:
> >
> > The 04/13/2023 15:14, Zheng Wang wrote:
> >
> > Hi Zheng,
> >
> > >
> > > In ns83820_init_one, dev->tq_refill was bound with queue_refill.
> > >
> > > If irq happens, it will call ns83820_irq->ns83820_do_isr.
> > > Then it invokes tasklet_schedule(&dev->rx_tasklet) to start
> > > rx_action function. And rx_action will call ns83820_rx_kick
> > > and finally start queue_refill function.
> > >
> > > If we remove the driver without finishing the work, there
> > > may be a race condition between ndev, which may cause UAF
> > > bug.
> > >
> > > CPU0                  CPU1
> > >
> > >                      |queue_refill
> > > ns83820_remove_one   |
> > > free_netdev                      |
> > > put_device                       |
> > > free ndev                        |
> > >                      |rx_refill
> > >                      |//use ndev
> >
> > Will you not have the same issue if you remove the driver after you
> > schedule rx_tasklet? Because rx_action will use also ndev.
> >
> 
> Hello Horatiu,
> 
> Thanks for your reply. In ns83820_remove_one, there is an invoking:
> 
> free_irq(dev->pci_dev->irq, ndev);
> 
> This will prevent the driver from handling more irq, But it couldn't prevent
> the rx_tasklet from being scheduled. So I think we should add the
> following code:
> 
> tasklet_kill(&dev->rx_tasklet);
> 
> after free_irq invoking. Is there anything wrong about my analysis?

I think you are right, I don't see a problem.

> 
> Thanks again for pointing the mistake out.
> 
> Best regards,
> Zheng
> 
> 
> > >
> > > Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> > > Signed-off-by: Zheng Wang <zyytlz.wz@163.com>
> > > ---
> > > v2:
> > > - cancel the work after unregister_netdev to make sure there
> > > is no more request suggested by Jakub Kicinski
> > > ---
> > >  drivers/net/ethernet/natsemi/ns83820.c | 5 +++++
> > >  1 file changed, 5 insertions(+)
> > >
> > > diff --git a/drivers/net/ethernet/natsemi/ns83820.c b/drivers/net/ethernet/natsemi/ns83820.c
> > > index 998586872599..2e84b9fcd8e9 100644
> > > --- a/drivers/net/ethernet/natsemi/ns83820.c
> > > +++ b/drivers/net/ethernet/natsemi/ns83820.c
> > > @@ -2208,8 +2208,13 @@ static void ns83820_remove_one(struct pci_dev *pci_dev)
> > >
> > >         ns83820_disable_interrupts(dev); /* paranoia */
> > >
> > > +       netif_carrier_off(ndev);
> > > +       netif_tx_disable(ndev);
> > > +
> > >         unregister_netdev(ndev);
> > >         free_irq(dev->pci_dev->irq, ndev);
> > > +       cancel_work_sync(&dev->tq_refill);
> > > +
> > >         iounmap(dev->base);
> > >         dma_free_coherent(&dev->pci_dev->dev, 4 * DESC_SIZE * NR_TX_DESC,
> > >                           dev->tx_descs, dev->tx_phy_descs);
> > > --
> > > 2.25.1
> > >
> >
> > --
> > /Horatiu

-- 
/Horatiu

      reply	other threads:[~2023-04-14 14:32 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-13  7:14 [PATCH net v2] net: ethernet: fix use after free bug in ns83820_remove_one due to race condition Zheng Wang
2023-04-13 10:01 ` Horatiu Vultur
2023-04-13 10:49   ` Zheng Hacker
2023-04-14 14:31     ` Horatiu Vultur [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=20230414143144.2e5hf6iokcbcrf5a@soft-dev3-1 \
    --to=horatiu.vultur@microchip.com \
    --cc=1395428693sheep@gmail.com \
    --cc=alex000young@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=hackerzheng666@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=zyytlz.wz@163.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