All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net]  net: ethernet: fix use after free bug in ns83820_remove_one due to race condition
@ 2023-03-09  9:42 Zheng Wang
  2023-03-13 23:26 ` Jakub Kicinski
  0 siblings, 1 reply; 5+ messages in thread
From: Zheng Wang @ 2023-03-09  9:42 UTC (permalink / raw)
  To: davem
  Cc: edumazet, kuba, pabeni, netdev, linux-kernel, hackerzheng666,
	1395428693sheep, alex000young, Zheng Wang

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.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Zheng Wang <zyytlz.wz@163.com>
---
 drivers/net/ethernet/natsemi/ns83820.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/ethernet/natsemi/ns83820.c b/drivers/net/ethernet/natsemi/ns83820.c
index 998586872599..285fe0fa33eb 100644
--- a/drivers/net/ethernet/natsemi/ns83820.c
+++ b/drivers/net/ethernet/natsemi/ns83820.c
@@ -2206,6 +2206,7 @@ static void ns83820_remove_one(struct pci_dev *pci_dev)
 	if (!ndev)			/* paranoia */
 		return;
 
+	cancel_work_sync(&dev->tq_refill);
 	ns83820_disable_interrupts(dev); /* paranoia */
 
 	unregister_netdev(ndev);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH net]  net: ethernet: fix use after free bug in ns83820_remove_one due to race condition
  2023-03-09  9:42 [PATCH net] net: ethernet: fix use after free bug in ns83820_remove_one due to race condition Zheng Wang
@ 2023-03-13 23:26 ` Jakub Kicinski
  2023-03-14  1:59   ` Zheng Hacker
  0 siblings, 1 reply; 5+ messages in thread
From: Jakub Kicinski @ 2023-03-13 23:26 UTC (permalink / raw)
  To: Zheng Wang
  Cc: davem, edumazet, pabeni, netdev, linux-kernel, hackerzheng666,
	1395428693sheep, alex000young

On Thu,  9 Mar 2023 17:42:31 +0800 Zheng Wang wrote:
> +	cancel_work_sync(&dev->tq_refill);
>  	ns83820_disable_interrupts(dev); /* paranoia */
>  
>  	unregister_netdev(ndev);

Canceling the work before unregister can't work.
Please take a closer look, the work to refill a ring should be
canceled when the ring itself is dismantled. 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net] net: ethernet: fix use after free bug in ns83820_remove_one due to race condition
  2023-03-13 23:26 ` Jakub Kicinski
@ 2023-03-14  1:59   ` Zheng Hacker
  2023-03-15  4:10     ` Jakub Kicinski
  0 siblings, 1 reply; 5+ messages in thread
From: Zheng Hacker @ 2023-03-14  1:59 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: Zheng Wang, davem, edumazet, pabeni, netdev, linux-kernel,
	1395428693sheep, alex000young

Jakub Kicinski <kuba@kernel.org> 于2023年3月14日周二 07:26写道:
>
> On Thu,  9 Mar 2023 17:42:31 +0800 Zheng Wang wrote:
> > +     cancel_work_sync(&dev->tq_refill);
> >       ns83820_disable_interrupts(dev); /* paranoia */
> >
> >       unregister_netdev(ndev);
>
> Canceling the work before unregister can't work.
> Please take a closer look, the work to refill a ring should be
> canceled when the ring itself is dismantled.

Hi Jakub,

Thanks for your review! After seeing code again, I found when handling
IRQ request, it will finally call ns83820_irq->ns83820_do_isr->
ns83820_rx_kick->schedule_work to start work. So I think we should
move the code after free_irq. What do you think?

Best regards,
Zheng

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net] net: ethernet: fix use after free bug in ns83820_remove_one due to race condition
  2023-03-14  1:59   ` Zheng Hacker
@ 2023-03-15  4:10     ` Jakub Kicinski
  2023-03-15  8:58       ` Zheng Hacker
  0 siblings, 1 reply; 5+ messages in thread
From: Jakub Kicinski @ 2023-03-15  4:10 UTC (permalink / raw)
  To: Zheng Hacker
  Cc: Zheng Wang, davem, edumazet, pabeni, netdev, linux-kernel,
	1395428693sheep, alex000young

On Tue, 14 Mar 2023 09:59:09 +0800 Zheng Hacker wrote:
> Jakub Kicinski <kuba@kernel.org> 于2023年3月14日周二 07:26写道:
> > On Thu,  9 Mar 2023 17:42:31 +0800 Zheng Wang wrote:  
> > > +     cancel_work_sync(&dev->tq_refill);
> > >       ns83820_disable_interrupts(dev); /* paranoia */
> > >
> > >       unregister_netdev(ndev);  
> >
> > Canceling the work before unregister can't work.
> > Please take a closer look, the work to refill a ring should be
> > canceled when the ring itself is dismantled.  
> 
> Hi Jakub,
> 
> Thanks for your review! After seeing code again, I found when handling
> IRQ request, it will finally call ns83820_irq->ns83820_do_isr->
> ns83820_rx_kick->schedule_work to start work. So I think we should
> move the code after free_irq. What do you think?

Sorry, we have over 300 patches which need reviews. I don't have 
the time to help you. Perhaps someone else will.

Please make sure you work on a single networking fix at a time.
All the patches you posted had the same issues.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net] net: ethernet: fix use after free bug in ns83820_remove_one due to race condition
  2023-03-15  4:10     ` Jakub Kicinski
@ 2023-03-15  8:58       ` Zheng Hacker
  0 siblings, 0 replies; 5+ messages in thread
From: Zheng Hacker @ 2023-03-15  8:58 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: Zheng Wang, davem, edumazet, pabeni, netdev, linux-kernel,
	1395428693sheep, alex000young

Jakub Kicinski <kuba@kernel.org> 于2023年3月15日周三 12:10写道:
>
> On Tue, 14 Mar 2023 09:59:09 +0800 Zheng Hacker wrote:
> > Jakub Kicinski <kuba@kernel.org> 于2023年3月14日周二 07:26写道:
> > > On Thu,  9 Mar 2023 17:42:31 +0800 Zheng Wang wrote:
> > > > +     cancel_work_sync(&dev->tq_refill);
> > > >       ns83820_disable_interrupts(dev); /* paranoia */
> > > >
> > > >       unregister_netdev(ndev);
> > >
> > > Canceling the work before unregister can't work.
> > > Please take a closer look, the work to refill a ring should be
> > > canceled when the ring itself is dismantled.
> >
> > Hi Jakub,
> >
> > Thanks for your review! After seeing code again, I found when handling
> > IRQ request, it will finally call ns83820_irq->ns83820_do_isr->
> > ns83820_rx_kick->schedule_work to start work. So I think we should
> > move the code after free_irq. What do you think?
>
> Sorry, we have over 300 patches which need reviews. I don't have
> the time to help you. Perhaps someone else will.
>

Hi Jakub,

Thanks for your precious and kind reminder. I'll think about it again
and write the next version of patch.

> Please make sure you work on a single networking fix at a time.
> All the patches you posted had the same issues.

Yes, I'll keep that in mind.

Best regards,
Zheng

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-03-15  8:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-09  9:42 [PATCH net] net: ethernet: fix use after free bug in ns83820_remove_one due to race condition Zheng Wang
2023-03-13 23:26 ` Jakub Kicinski
2023-03-14  1:59   ` Zheng Hacker
2023-03-15  4:10     ` Jakub Kicinski
2023-03-15  8:58       ` Zheng Hacker

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.