lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <12da9ba8.218f7.185dec51aa9.Coremail.duoming@zju.edu.cn>
Date:   Mon, 23 Jan 2023 21:15:37 +0800 (GMT+08:00)
From:   duoming@....edu.cn
To:     "Sean Young" <sean@...s.org>
Cc:     linux-media@...r.kernel.org, linux-kernel@...r.kernel.org,
        maximlevitsky@...il.com, mchehab@...nel.org
Subject: Re: [PATCH] media: rc: Fix use-after-free bugs caused by
 ene_tx_irqsim()

Hello,

On Mon, 23 Jan 2023 09:10:01, Sean Young wrote:

> On Mon, Jan 23, 2023 at 09:12:23AM +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.
> > 
> > This problem is found by static analysis.
> > 
> > Fixes: 9ea53b74df9c ("V4L/DVB: STAGING: remove lirc_ene0100 driver")
> > Signed-off-by: Duoming Zhou <duoming@....edu.cn>
> > ---
> >  drivers/media/rc/ene_ir.c | 1 +
> >  1 file changed, 1 insertion(+)
> > 
> > diff --git a/drivers/media/rc/ene_ir.c b/drivers/media/rc/ene_ir.c
> > index e09270916fb..716b72a048f 100644
> > --- a/drivers/media/rc/ene_ir.c
> > +++ b/drivers/media/rc/ene_ir.c
> > @@ -1114,6 +1114,7 @@ static void ene_remove(struct pnp_dev *pnp_dev)
> >  	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);
> 
> Great catch!
> 
> The timer can call ene_tx_sample() which can write to the io ports, so the
> ordering still is not quite right. I think the rc_unregister_device() and
> del_timer_sync() should be call first in ene_remove().

Thank you for your time and suggestions! I will put rc_unregister_device() and
del_timer_sync() before release_region() in order that the tx_sim_timer could
finish before io ports are released.

Best regards,
Duoming Zhou

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ