All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mISDN: hfcpci: Fix use-after-free bug in hfcpci_Timer
@ 2022-10-13 12:57 Duoming Zhou
  2022-10-13 13:20 ` Greg KH
  0 siblings, 1 reply; 4+ messages in thread
From: Duoming Zhou @ 2022-10-13 12:57 UTC (permalink / raw)
  To: linux-kernel
  Cc: netdev, isdn, kuba, gregkh, andrii, davem, axboe, Duoming Zhou

If the timer handler hfcpci_Timer() is running, the
del_timer(&hc->hw.timer) in release_io_hfcpci() could
not stop it. As a result, the use-after-free bug will
happen. The process is shown below:

    (cleanup routine)          |        (timer handler)
release_card()                 | hfcpci_Timer()
  release_io_hfcpci            |
    del_timer(&hc->hw.timer)   |
  ...                          |  ...
  kfree(hc) //[1]FREE          |
                               |   hc->hw.timer.expires //[2]USE

The hfc_pci is deallocated in position [1] and used in
position [2].

Fix by changing del_timer() in release_io_hfcpci() to
del_timer_sync(), which makes sure the hfcpci_Timer()
have finished before the hfc_pci is deallocated.

Fixes: 1700fe1a10dc ("Add mISDN HFC PCI driver")
Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
---
 drivers/isdn/hardware/mISDN/hfcpci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/isdn/hardware/mISDN/hfcpci.c b/drivers/isdn/hardware/mISDN/hfcpci.c
index af17459c1a5..5cf37fe7de2 100644
--- a/drivers/isdn/hardware/mISDN/hfcpci.c
+++ b/drivers/isdn/hardware/mISDN/hfcpci.c
@@ -157,7 +157,7 @@ release_io_hfcpci(struct hfc_pci *hc)
 {
 	/* disable memory mapped ports + busmaster */
 	pci_write_config_word(hc->pdev, PCI_COMMAND, 0);
-	del_timer(&hc->hw.timer);
+	del_timer_sync(&hc->hw.timer);
 	dma_free_coherent(&hc->pdev->dev, 0x8000, hc->hw.fifos,
 			  hc->hw.dmahandle);
 	iounmap(hc->hw.pci_io);
-- 
2.17.1


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

* Re: [PATCH] mISDN: hfcpci: Fix use-after-free bug in hfcpci_Timer
  2022-10-13 12:57 [PATCH] mISDN: hfcpci: Fix use-after-free bug in hfcpci_Timer Duoming Zhou
@ 2022-10-13 13:20 ` Greg KH
  2022-10-14  6:07   ` Leon Romanovsky
  0 siblings, 1 reply; 4+ messages in thread
From: Greg KH @ 2022-10-13 13:20 UTC (permalink / raw)
  To: Duoming Zhou; +Cc: linux-kernel, netdev, isdn, kuba, andrii, davem, axboe

On Thu, Oct 13, 2022 at 08:57:29PM +0800, Duoming Zhou wrote:
> If the timer handler hfcpci_Timer() is running, the
> del_timer(&hc->hw.timer) in release_io_hfcpci() could
> not stop it. As a result, the use-after-free bug will
> happen. The process is shown below:
> 
>     (cleanup routine)          |        (timer handler)
> release_card()                 | hfcpci_Timer()
>   release_io_hfcpci            |
>     del_timer(&hc->hw.timer)   |
>   ...                          |  ...
>   kfree(hc) //[1]FREE          |
>                                |   hc->hw.timer.expires //[2]USE
> 
> The hfc_pci is deallocated in position [1] and used in
> position [2].
> 
> Fix by changing del_timer() in release_io_hfcpci() to
> del_timer_sync(), which makes sure the hfcpci_Timer()
> have finished before the hfc_pci is deallocated.
> 
> Fixes: 1700fe1a10dc ("Add mISDN HFC PCI driver")
> Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
> ---
>  drivers/isdn/hardware/mISDN/hfcpci.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/isdn/hardware/mISDN/hfcpci.c b/drivers/isdn/hardware/mISDN/hfcpci.c
> index af17459c1a5..5cf37fe7de2 100644
> --- a/drivers/isdn/hardware/mISDN/hfcpci.c
> +++ b/drivers/isdn/hardware/mISDN/hfcpci.c
> @@ -157,7 +157,7 @@ release_io_hfcpci(struct hfc_pci *hc)
>  {
>  	/* disable memory mapped ports + busmaster */
>  	pci_write_config_word(hc->pdev, PCI_COMMAND, 0);
> -	del_timer(&hc->hw.timer);
> +	del_timer_sync(&hc->hw.timer);

Nice, how did you test that this will work properly?  Do you have this
hardware for testing?  How was this issue found and verified that this
is the correct resolution?

thanks,

greg k-h

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

* Re: [PATCH] mISDN: hfcpci: Fix use-after-free bug in hfcpci_Timer
  2022-10-13 13:20 ` Greg KH
@ 2022-10-14  6:07   ` Leon Romanovsky
  2022-10-14  6:58     ` duoming
  0 siblings, 1 reply; 4+ messages in thread
From: Leon Romanovsky @ 2022-10-14  6:07 UTC (permalink / raw)
  To: Greg KH
  Cc: Duoming Zhou, linux-kernel, netdev, isdn, kuba, andrii, davem, axboe

On Thu, Oct 13, 2022 at 03:20:05PM +0200, Greg KH wrote:
> On Thu, Oct 13, 2022 at 08:57:29PM +0800, Duoming Zhou wrote:
> > If the timer handler hfcpci_Timer() is running, the
> > del_timer(&hc->hw.timer) in release_io_hfcpci() could
> > not stop it. As a result, the use-after-free bug will
> > happen. The process is shown below:
> > 
> >     (cleanup routine)          |        (timer handler)
> > release_card()                 | hfcpci_Timer()
> >   release_io_hfcpci            |
> >     del_timer(&hc->hw.timer)   |
> >   ...                          |  ...
> >   kfree(hc) //[1]FREE          |
> >                                |   hc->hw.timer.expires //[2]USE
> > 
> > The hfc_pci is deallocated in position [1] and used in
> > position [2].
> > 
> > Fix by changing del_timer() in release_io_hfcpci() to
> > del_timer_sync(), which makes sure the hfcpci_Timer()
> > have finished before the hfc_pci is deallocated.
> > 
> > Fixes: 1700fe1a10dc ("Add mISDN HFC PCI driver")
> > Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
> > ---
> >  drivers/isdn/hardware/mISDN/hfcpci.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/isdn/hardware/mISDN/hfcpci.c b/drivers/isdn/hardware/mISDN/hfcpci.c
> > index af17459c1a5..5cf37fe7de2 100644
> > --- a/drivers/isdn/hardware/mISDN/hfcpci.c
> > +++ b/drivers/isdn/hardware/mISDN/hfcpci.c
> > @@ -157,7 +157,7 @@ release_io_hfcpci(struct hfc_pci *hc)
> >  {
> >  	/* disable memory mapped ports + busmaster */
> >  	pci_write_config_word(hc->pdev, PCI_COMMAND, 0);
> > -	del_timer(&hc->hw.timer);
> > +	del_timer_sync(&hc->hw.timer);
> 
> Nice, how did you test that this will work properly?  Do you have this
> hardware for testing?  How was this issue found and verified that this
> is the correct resolution?

According to his previous response [1], the answer will be no. I'm not
super-excited that this unmaintained and old driver chosen as playground
for new tool.

[1] https://lore.kernel.org/all/17ad6913.ff8e0.1838933840d.Coremail.duoming@zju.edu.cn/#t

> 
> thanks,
> 
> greg k-h

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

* Re: [PATCH] mISDN: hfcpci: Fix use-after-free bug in hfcpci_Timer
  2022-10-14  6:07   ` Leon Romanovsky
@ 2022-10-14  6:58     ` duoming
  0 siblings, 0 replies; 4+ messages in thread
From: duoming @ 2022-10-14  6:58 UTC (permalink / raw)
  To: Leon Romanovsky
  Cc: Greg KH, linux-kernel, netdev, isdn, kuba, andrii, davem, axboe

Hello,

On Fri, 14 Oct 2022 09:07:07 +0300 Leon Romanovsky wrote:

> On Thu, Oct 13, 2022 at 03:20:05PM +0200, Greg KH wrote:
> > On Thu, Oct 13, 2022 at 08:57:29PM +0800, Duoming Zhou wrote:
> > > If the timer handler hfcpci_Timer() is running, the
> > > del_timer(&hc->hw.timer) in release_io_hfcpci() could
> > > not stop it. As a result, the use-after-free bug will
> > > happen. The process is shown below:
> > > 
> > >     (cleanup routine)          |        (timer handler)
> > > release_card()                 | hfcpci_Timer()
> > >   release_io_hfcpci            |
> > >     del_timer(&hc->hw.timer)   |
> > >   ...                          |  ...
> > >   kfree(hc) //[1]FREE          |
> > >                                |   hc->hw.timer.expires //[2]USE
> > > 
> > > The hfc_pci is deallocated in position [1] and used in
> > > position [2].
> > > 
> > > Fix by changing del_timer() in release_io_hfcpci() to
> > > del_timer_sync(), which makes sure the hfcpci_Timer()
> > > have finished before the hfc_pci is deallocated.
> > > 
> > > Fixes: 1700fe1a10dc ("Add mISDN HFC PCI driver")
> > > Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
> > > ---
> > >  drivers/isdn/hardware/mISDN/hfcpci.c | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > 
> > > diff --git a/drivers/isdn/hardware/mISDN/hfcpci.c b/drivers/isdn/hardware/mISDN/hfcpci.c
> > > index af17459c1a5..5cf37fe7de2 100644
> > > --- a/drivers/isdn/hardware/mISDN/hfcpci.c
> > > +++ b/drivers/isdn/hardware/mISDN/hfcpci.c
> > > @@ -157,7 +157,7 @@ release_io_hfcpci(struct hfc_pci *hc)
> > >  {
> > >  	/* disable memory mapped ports + busmaster */
> > >  	pci_write_config_word(hc->pdev, PCI_COMMAND, 0);
> > > -	del_timer(&hc->hw.timer);
> > > +	del_timer_sync(&hc->hw.timer);
> > 
> > Nice, how did you test that this will work properly?  Do you have this
> > hardware for testing?  How was this issue found and verified that this
> > is the correct resolution?

I am trying to simulate the hardware to verified that this is the correct
resolution. I will give feedback in a few weeks later.

> According to his previous response [1], the answer will be no. I'm not
> super-excited that this unmaintained and old driver chosen as playground
> for new tool.
> 
> [1] https://lore.kernel.org/all/17ad6913.ff8e0.1838933840d.Coremail.duoming@zju.edu.cn/#t

Best regards,
Duoming Zhou

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

end of thread, other threads:[~2022-10-14  6:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-13 12:57 [PATCH] mISDN: hfcpci: Fix use-after-free bug in hfcpci_Timer Duoming Zhou
2022-10-13 13:20 ` Greg KH
2022-10-14  6:07   ` Leon Romanovsky
2022-10-14  6:58     ` duoming

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.