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-next>] [day] [month] [year] [list]
Date:   Mon, 23 Jan 2023 22:21:23 +0800
From:   Duoming Zhou <duoming@....edu.cn>
To:     linux-media@...r.kernel.org, sean@...s.org
Cc:     maximlevitsky@...il.com, mchehab@...nel.org,
        linux-kernel@...r.kernel.org, Duoming Zhou <duoming@....edu.cn>
Subject: [PATCH v2] media: rc: Fix use-after-free bugs caused by ene_tx_irqsim()

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@....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);
 }
 
-- 
2.17.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ