mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sean Young <sean@mess.org>
To: Duoming Zhou <duoming@zju.edu.cn>
Cc: linux-media@vger.kernel.org, maximlevitsky@gmail.com,
	mchehab@kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] media: rc: Fix use-after-free bugs caused by ene_tx_irqsim()
Date: Mon, 23 Jan 2023 15:13:40 +0000	[thread overview]
Message-ID: <Y86kJKofh+tLYl6A@gofer.mess.org> (raw)
In-Reply-To: <20230123142123.58870-1-duoming@zju.edu.cn>

On Mon, Jan 23, 2023 at 10:21:23PM +0800, Duoming Zhou wrote:
> When the ene device is detaching, function ene_remove() will
> be called. But there is no function to cancel tx_sim_timer
> in ene_remove(), the timer handler ene_tx_irqsim() could race
> with ene_remove(). As a result, the UAF bugs could happen,
> the process is shown below.
> 
>     (cleanup routine)          |        (timer routine)
>                                | mod_timer(&dev->tx_sim_timer, ..)
> ene_remove()                   | (wait a time)
>   kfree(dev) //FREE            |
>                                | ene_tx_irqsim()
>                                |   dev->hw_lock //USE
>                                |   ene_tx_sample(dev) //USE
> 
> Fix by adding del_timer_sync(&dev->tx_sim_timer) in ene_remove(),
> The tx_sim_timer could stop before ene device is deallocated.
> 
> What's more, the timer can call ene_tx_sample() which can write
> to the io ports. So we should put rc_unregister_device() and
> del_timer_sync(&dev->tx_sim_timer) before release_region() in
> ene_remove().
> 
> Fixes: 9ea53b74df9c ("V4L/DVB: STAGING: remove lirc_ene0100 driver")
> Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
> ---
> Changes in v2:
>   - Move rc_unregister_device() and del_timer_sync() before release_region().
> 
>  drivers/media/rc/ene_ir.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/media/rc/ene_ir.c b/drivers/media/rc/ene_ir.c
> index e09270916fb..2864360af9e 100644
> --- a/drivers/media/rc/ene_ir.c
> +++ b/drivers/media/rc/ene_ir.c
> @@ -1112,8 +1112,9 @@ static void ene_remove(struct pnp_dev *pnp_dev)
>  	spin_unlock_irqrestore(&dev->hw_lock, flags);
>  
>  	free_irq(dev->irq, dev);
> -	release_region(dev->hw_io, ENE_IO_SIZE);
>  	rc_unregister_device(dev->rdev);
> +	del_timer_sync(&dev->tx_sim_timer);
> +	release_region(dev->hw_io, ENE_IO_SIZE);
>  	kfree(dev);
>  }

I'm sorry, I think there might be a problem there: the irq is freed before
the rc device is unregistered.

The rx receiver is disabled with ene_rx_disable() before rc_unregister_device()
is called, which means it can be enabled again if a process opens /dev/lirc0
between ene_rx_disable() and rc_unregister_device().

ene_remove() should call rc_unregister_device() and del_timer_sync() before
anything else.


Sean

  reply	other threads:[~2023-01-23 15:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-23 14:21 Duoming Zhou
2023-01-23 15:13 ` Sean Young [this message]
2023-01-24  6:57   ` 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=Y86kJKofh+tLYl6A@gofer.mess.org \
    --to=sean@mess.org \
    --cc=duoming@zju.edu.cn \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=maximlevitsky@gmail.com \
    --cc=mchehab@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

all inboxes | Powered by JetHome®