* [PATCH net] xirc2ps_cs: Fix use after free bug in xirc2ps_detach
@ 2023-03-09 16:57 Zheng Wang
2023-03-10 13:58 ` Simon Horman
0 siblings, 1 reply; 3+ messages in thread
From: Zheng Wang @ 2023-03-09 16:57 UTC (permalink / raw)
To: davem
Cc: 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:
Fix it by finishing the work before cleanup in xirc2ps_detach
CPU0 CPU1
|xirc2ps_tx_timeout_task
xirc2ps_detach |
free_netdev |
kfree(dev); |
|
| do_reset
| //use
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Zheng Wang <zyytlz.wz@163.com>
---
drivers/net/ethernet/xircom/xirc2ps_cs.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/xircom/xirc2ps_cs.c b/drivers/net/ethernet/xircom/xirc2ps_cs.c
index 894e92ef415b..ea7b06f75691 100644
--- a/drivers/net/ethernet/xircom/xirc2ps_cs.c
+++ b/drivers/net/ethernet/xircom/xirc2ps_cs.c
@@ -503,7 +503,10 @@ static void
xirc2ps_detach(struct pcmcia_device *link)
{
struct net_device *dev = link->priv;
-
+ struct local_info *local;
+
+ local = netdev_priv(dev);
+ cancel_work_sync(&local->tx_timeout_task)
dev_dbg(&link->dev, "detach\n");
unregister_netdev(dev);
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net] xirc2ps_cs: Fix use after free bug in xirc2ps_detach
2023-03-09 16:57 [PATCH net] xirc2ps_cs: Fix use after free bug in xirc2ps_detach Zheng Wang
@ 2023-03-10 13:58 ` Simon Horman
2023-03-10 16:51 ` Zheng Hacker
0 siblings, 1 reply; 3+ messages in thread
From: Simon Horman @ 2023-03-10 13:58 UTC (permalink / raw)
To: Zheng Wang
Cc: davem, edumazet, kuba, pabeni, petrm, thomas.lendacky,
wsa+renesas, leon, shayagr, netdev, linux-kernel, hackerzheng666,
1395428693sheep, alex000young
On Fri, Mar 10, 2023 at 12:57:29AM +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:
>
> Fix it by finishing the work before cleanup in xirc2ps_detach
>
> CPU0 CPU1
>
> |xirc2ps_tx_timeout_task
> xirc2ps_detach |
> free_netdev |
> kfree(dev); |
> |
> | do_reset
> | //use
>
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Signed-off-by: Zheng Wang <zyytlz.wz@163.com>
> ---
> drivers/net/ethernet/xircom/xirc2ps_cs.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/xircom/xirc2ps_cs.c b/drivers/net/ethernet/xircom/xirc2ps_cs.c
> index 894e92ef415b..ea7b06f75691 100644
> --- a/drivers/net/ethernet/xircom/xirc2ps_cs.c
> +++ b/drivers/net/ethernet/xircom/xirc2ps_cs.c
> @@ -503,7 +503,10 @@ static void
> xirc2ps_detach(struct pcmcia_device *link)
> {
> struct net_device *dev = link->priv;
> -
> + struct local_info *local;
> +
> + local = netdev_priv(dev);
> + cancel_work_sync(&local->tx_timeout_task)
> dev_dbg(&link->dev, "detach\n");
>
> unregister_netdev(dev);
This doesn't compile.
Also, the indentation is incorrect.
I think what should have been posted is:
diff --git a/drivers/net/ethernet/xircom/xirc2ps_cs.c b/drivers/net/ethernet/xircom/xirc2ps_cs.c
index 894e92ef415b..b607fea486ab 100644
--- a/drivers/net/ethernet/xircom/xirc2ps_cs.c
+++ b/drivers/net/ethernet/xircom/xirc2ps_cs.c
@@ -503,7 +503,10 @@ static void
xirc2ps_detach(struct pcmcia_device *link)
{
struct net_device *dev = link->priv;
+ struct local_info *local;
+ local = netdev_priv(dev);
+ cancel_work_sync(&local->tx_timeout_task);
dev_dbg(&link->dev, "detach\n");
unregister_netdev(dev);
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net] xirc2ps_cs: Fix use after free bug in xirc2ps_detach
2023-03-10 13:58 ` Simon Horman
@ 2023-03-10 16:51 ` Zheng Hacker
0 siblings, 0 replies; 3+ messages in thread
From: Zheng Hacker @ 2023-03-10 16:51 UTC (permalink / raw)
To: Simon Horman
Cc: Zheng Wang, davem, edumazet, kuba, pabeni, petrm,
thomas.lendacky, wsa+renesas, leon, shayagr, netdev,
linux-kernel, 1395428693sheep, alex000young
Simon Horman <simon.horman@corigine.com> 于2023年3月10日周五 21:59写道:
>
> On Fri, Mar 10, 2023 at 12:57:29AM +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:
> >
> > Fix it by finishing the work before cleanup in xirc2ps_detach
> >
> > CPU0 CPU1
> >
> > |xirc2ps_tx_timeout_task
> > xirc2ps_detach |
> > free_netdev |
> > kfree(dev); |
> > |
> > | do_reset
> > | //use
> >
> > Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> > Signed-off-by: Zheng Wang <zyytlz.wz@163.com>
> > ---
> > drivers/net/ethernet/xircom/xirc2ps_cs.c | 5 ++++-
> > 1 file changed, 4 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/net/ethernet/xircom/xirc2ps_cs.c b/drivers/net/ethernet/xircom/xirc2ps_cs.c
> > index 894e92ef415b..ea7b06f75691 100644
> > --- a/drivers/net/ethernet/xircom/xirc2ps_cs.c
> > +++ b/drivers/net/ethernet/xircom/xirc2ps_cs.c
> > @@ -503,7 +503,10 @@ static void
> > xirc2ps_detach(struct pcmcia_device *link)
> > {
> > struct net_device *dev = link->priv;
> > -
> > + struct local_info *local;
> > +
> > + local = netdev_priv(dev);
> > + cancel_work_sync(&local->tx_timeout_task)
> > dev_dbg(&link->dev, "detach\n");
> >
> > unregister_netdev(dev);
>
> This doesn't compile.
> Also, the indentation is incorrect.
Sorry for my mistake. I was hurried to report the issue and ignored
the compile test.
>
> I think what should have been posted is:
Yes, will correct it in the next version of patch.
Best regards,
Zheng
>
> diff --git a/drivers/net/ethernet/xircom/xirc2ps_cs.c b/drivers/net/ethernet/xircom/xirc2ps_cs.c
> index 894e92ef415b..b607fea486ab 100644
> --- a/drivers/net/ethernet/xircom/xirc2ps_cs.c
> +++ b/drivers/net/ethernet/xircom/xirc2ps_cs.c
> @@ -503,7 +503,10 @@ static void
> xirc2ps_detach(struct pcmcia_device *link)
> {
> struct net_device *dev = link->priv;
> + struct local_info *local;
>
> + local = netdev_priv(dev);
> + cancel_work_sync(&local->tx_timeout_task);
> dev_dbg(&link->dev, "detach\n");
>
> unregister_netdev(dev);
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-03-10 16:55 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-09 16:57 [PATCH net] xirc2ps_cs: Fix use after free bug in xirc2ps_detach Zheng Wang
2023-03-10 13:58 ` Simon Horman
2023-03-10 16:51 ` 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).