linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] xirc2ps_cs: Fix use after free bug in xirc2ps_detach
@ 2023-03-11 17:08 Zheng Wang
  2023-03-14  0:15 ` Jakub Kicinski
  0 siblings, 1 reply; 3+ messages in thread
From: Zheng Wang @ 2023-03-11 17:08 UTC (permalink / raw)
  To: davem
  Cc: simon.horman, edumazet, kuba, pabeni, petrm, thomas.lendacky,
	wsa+renesas, leon, shayagr, netdev, linux-kernel, hackerzheng666,
	1395428693sheep, alex000young, Zheng Wang

In xirc2ps_probe, the local->tx_timeout_task was bounded
with xirc2ps_tx_timeout_task. When timeout occurs,
it will call xirc_tx_timeout->schedule_work to start the
work.

When we call xirc2ps_detach to remove the driver, there
may be a sequence as follows:

Stop responding to timeout tasks and complete scheduled
tasks before cleanup in xirc2ps_detach, which will fix
the problem.

CPU0                  CPU1

                    |xirc2ps_tx_timeout_task
xirc2ps_detach      |
  free_netdev       |
    kfree(dev);     |
                    |
                    | do_reset
                    |   //use dev

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Zheng Wang <zyytlz.wz@163.com>
---
v2:
- fix indentation error suggested by Simon Horman,
and stop the timeout tasks  suggested by Yunsheng Lin
---
 drivers/net/ethernet/xircom/xirc2ps_cs.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/net/ethernet/xircom/xirc2ps_cs.c b/drivers/net/ethernet/xircom/xirc2ps_cs.c
index 894e92ef415b..c77ca11d9497 100644
--- a/drivers/net/ethernet/xircom/xirc2ps_cs.c
+++ b/drivers/net/ethernet/xircom/xirc2ps_cs.c
@@ -503,6 +503,11 @@ static void
 xirc2ps_detach(struct pcmcia_device *link)
 {
     struct net_device *dev = link->priv;
+		struct local_info *local = netdev_priv(dev);
+
+		netif_carrier_off(dev);
+		netif_tx_disable(dev);
+		cancel_work_sync(&local->tx_timeout_task);
 
     dev_dbg(&link->dev, "detach\n");
 
-- 
2.25.1


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

* Re: [PATCH v2] xirc2ps_cs: Fix use after free bug in xirc2ps_detach
  2023-03-11 17:08 [PATCH v2] xirc2ps_cs: Fix use after free bug in xirc2ps_detach Zheng Wang
@ 2023-03-14  0:15 ` Jakub Kicinski
  2023-03-14  2:12   ` Zheng Hacker
  0 siblings, 1 reply; 3+ messages in thread
From: Jakub Kicinski @ 2023-03-14  0:15 UTC (permalink / raw)
  To: Zheng Wang
  Cc: davem, simon.horman, edumazet, pabeni, petrm, thomas.lendacky,
	wsa+renesas, leon, shayagr, netdev, linux-kernel, hackerzheng666,
	1395428693sheep, alex000young

On Sun, 12 Mar 2023 01:08:36 +0800 Zheng Wang wrote:
> In xirc2ps_probe, the local->tx_timeout_task was bounded
> with xirc2ps_tx_timeout_task. When timeout occurs,
> it will call xirc_tx_timeout->schedule_work to start the
> work.
> 
> When we call xirc2ps_detach to remove the driver, there
> may be a sequence as follows:
> 
> Stop responding to timeout tasks and complete scheduled
> tasks before cleanup in xirc2ps_detach, which will fix
> the problem.
> 
> CPU0                  CPU1
> 
>                     |xirc2ps_tx_timeout_task
> xirc2ps_detach      |
>   free_netdev       |
>     kfree(dev);     |
>                     |
>                     | do_reset
>                     |   //use dev
> 
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Signed-off-by: Zheng Wang <zyytlz.wz@163.com>
> ---
> v2:
> - fix indentation error suggested by Simon Horman,
> and stop the timeout tasks  suggested by Yunsheng Lin
> ---
>  drivers/net/ethernet/xircom/xirc2ps_cs.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/net/ethernet/xircom/xirc2ps_cs.c b/drivers/net/ethernet/xircom/xirc2ps_cs.c
> index 894e92ef415b..c77ca11d9497 100644
> --- a/drivers/net/ethernet/xircom/xirc2ps_cs.c
> +++ b/drivers/net/ethernet/xircom/xirc2ps_cs.c
> @@ -503,6 +503,11 @@ static void
>  xirc2ps_detach(struct pcmcia_device *link)
>  {
>      struct net_device *dev = link->priv;
> +		struct local_info *local = netdev_priv(dev);
> +
> +		netif_carrier_off(dev);
> +		netif_tx_disable(dev);
> +		cancel_work_sync(&local->tx_timeout_task);
>  
>      dev_dbg(&link->dev, "detach\n");
>  

Please fix the formatting and make sure you CC the maintainers when you
post v3.

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

* Re: [PATCH v2] xirc2ps_cs: Fix use after free bug in xirc2ps_detach
  2023-03-14  0:15 ` Jakub Kicinski
@ 2023-03-14  2:12   ` Zheng Hacker
  0 siblings, 0 replies; 3+ messages in thread
From: Zheng Hacker @ 2023-03-14  2:12 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: Zheng Wang, davem, simon.horman, edumazet, pabeni, petrm,
	thomas.lendacky, wsa+renesas, leon, shayagr, netdev,
	linux-kernel, 1395428693sheep, alex000young

Jakub Kicinski <kuba@kernel.org> 于2023年3月14日周二 08:15写道:
>
> On Sun, 12 Mar 2023 01:08:36 +0800 Zheng Wang wrote:
> > In xirc2ps_probe, the local->tx_timeout_task was bounded
> > with xirc2ps_tx_timeout_task. When timeout occurs,
> > it will call xirc_tx_timeout->schedule_work to start the
> > work.
> >
> > When we call xirc2ps_detach to remove the driver, there
> > may be a sequence as follows:
> >
> > Stop responding to timeout tasks and complete scheduled
> > tasks before cleanup in xirc2ps_detach, which will fix
> > the problem.
> >
> > CPU0                  CPU1
> >
> >                     |xirc2ps_tx_timeout_task
> > xirc2ps_detach      |
> >   free_netdev       |
> >     kfree(dev);     |
> >                     |
> >                     | do_reset
> >                     |   //use dev
> >
> > Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> > Signed-off-by: Zheng Wang <zyytlz.wz@163.com>
> > ---
> > v2:
> > - fix indentation error suggested by Simon Horman,
> > and stop the timeout tasks  suggested by Yunsheng Lin
> > ---
> >  drivers/net/ethernet/xircom/xirc2ps_cs.c | 5 +++++
> >  1 file changed, 5 insertions(+)
> >
> > diff --git a/drivers/net/ethernet/xircom/xirc2ps_cs.c b/drivers/net/ethernet/xircom/xirc2ps_cs.c
> > index 894e92ef415b..c77ca11d9497 100644
> > --- a/drivers/net/ethernet/xircom/xirc2ps_cs.c
> > +++ b/drivers/net/ethernet/xircom/xirc2ps_cs.c
> > @@ -503,6 +503,11 @@ static void
> >  xirc2ps_detach(struct pcmcia_device *link)
> >  {
> >      struct net_device *dev = link->priv;
> > +             struct local_info *local = netdev_priv(dev);
> > +
> > +             netif_carrier_off(dev);
> > +             netif_tx_disable(dev);
> > +             cancel_work_sync(&local->tx_timeout_task);
> >
> >      dev_dbg(&link->dev, "detach\n");
> >
>
> Please fix the formatting and make sure you CC the maintainers when you
> post v3.

Hi Jakub,

Get it!

Best regards,
Zheng

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

end of thread, other threads:[~2023-03-14  2:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-11 17:08 [PATCH v2] xirc2ps_cs: Fix use after free bug in xirc2ps_detach Zheng Wang
2023-03-14  0:15 ` Jakub Kicinski
2023-03-14  2:12   ` Zheng Hacker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).