public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Duoming Zhou <duoming@zju.edu.cn>
Cc: linux-kernel@vger.kernel.org, isdn@linux-pingi.de,
	kuba@kernel.org, andrii@kernel.org, axboe@kernel.dk,
	davem@davemloft.net, netdev@vger.kernel.org, zou_wei@huawei.com
Subject: Re: [PATCH] mISDN: hfcpci: Fix use-after-free bug in hfcpci_softirq
Date: Thu, 10 Nov 2022 18:48:43 +0100	[thread overview]
Message-ID: <Y205e/GpYNUVm9Bv@kroah.com> (raw)
In-Reply-To: <20221009063731.22733-1-duoming@zju.edu.cn>

On Sun, Oct 09, 2022 at 02:37:31PM +0800, Duoming Zhou wrote:
> The function hfcpci_softirq() is a timer handler. If it
> is running, the timer_pending() will return 0 and the
> del_timer_sync() in HFC_cleanup() will not be executed.
> As a result, the use-after-free bug will happen. The
> process is shown below:
> 
>     (cleanup routine)          |        (timer handler)
> HFC_cleanup()                  | hfcpci_softirq()
>  if (timer_pending(&hfc_tl))   |
>    del_timer_sync()            |
>  ...                           | ...
>  pci_unregister_driver(hc)     |
>   driver_unregister            |  driver_for_each_device
>    bus_remove_driver           |   _hfcpci_softirq
>     driver_detach              |   ...
>      put_device(dev) //[1]FREE |
>                                |    dev_get_drvdata(dev) //[2]USE
> 
> The device is deallocated is position [1] and used in
> position [2].
> 
> Fix by removing the "timer_pending" check in HFC_cleanup(),
> which makes sure that the hfcpci_softirq() have finished
> before the resource is deallocated.
> 
> Fixes: 009fc857c5f6 ("mISDN: fix possible use-after-free in HFC_cleanup()")
> Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
> ---
>  drivers/isdn/hardware/mISDN/hfcpci.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/isdn/hardware/mISDN/hfcpci.c b/drivers/isdn/hardware/mISDN/hfcpci.c
> index af17459c1a5..e964a8dd851 100644
> --- a/drivers/isdn/hardware/mISDN/hfcpci.c
> +++ b/drivers/isdn/hardware/mISDN/hfcpci.c
> @@ -2345,8 +2345,7 @@ HFC_init(void)
>  static void __exit
>  HFC_cleanup(void)
>  {
> -	if (timer_pending(&hfc_tl))
> -		del_timer_sync(&hfc_tl);
> +	del_timer_sync(&hfc_tl);

How was this tested?  Do you have this hardware?

thanks,

greg k-h

      parent reply	other threads:[~2022-11-10 17:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-09  6:37 [PATCH] mISDN: hfcpci: Fix use-after-free bug in hfcpci_softirq Duoming Zhou
2022-10-09 19:00 ` patchwork-bot+netdevbpf
2022-11-10 17:48 ` Greg KH [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=Y205e/GpYNUVm9Bv@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=andrii@kernel.org \
    --cc=axboe@kernel.dk \
    --cc=davem@davemloft.net \
    --cc=duoming@zju.edu.cn \
    --cc=isdn@linux-pingi.de \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=zou_wei@huawei.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