netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Duoming Zhou <duoming@zju.edu.cn>
Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
	isdn@linux-pingi.de, kuba@kernel.org, andrii@kernel.org,
	davem@davemloft.net, axboe@kernel.dk
Subject: Re: [PATCH] mISDN: hfcpci: Fix use-after-free bug in hfcpci_Timer
Date: Thu, 13 Oct 2022 15:20:05 +0200	[thread overview]
Message-ID: <Y0gQhe6EL6nDstlL@kroah.com> (raw)
In-Reply-To: <20221013125729.105652-1-duoming@zju.edu.cn>

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

  reply	other threads:[~2022-10-13 13:19 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2022-10-14  6:07   ` Leon Romanovsky
2022-10-14  6:58     ` duoming

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=Y0gQhe6EL6nDstlL@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 \
    /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;
as well as URLs for NNTP newsgroup(s).