Skip to content

Commit 9208830

Browse files
committed
media: rc: Fix use-after-free bugs caused by ene_tx_irqsim()
jira VULN-3963 cve CVE-2023-1118 commit-author Duoming Zhou <duoming@zju.edu.cn> commit 29b0589 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) | 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 rc_unregister_device() and del_timer_sync() should be called first in ene_remove() and the deallocated functions such as free_irq(), release_region() and so on should be called behind them. Because the rc_unregister_device() is well synchronized. Otherwise, race conditions may happen. The situations that may lead to race conditions are shown below. Firstly, the rx receiver is disabled with ene_rx_disable() before rc_unregister_device() in ene_remove(), which means it can be enabled again if a process opens /dev/lirc0 between ene_rx_disable() and rc_unregister_device(). Secondly, the irqaction descriptor is freed by free_irq() before the rc device is unregistered, which means irqaction descriptor may be accessed again after it is deallocated. Thirdly, the timer can call ene_tx_sample() that can write to the io ports, which means the io ports could be accessed again after they are deallocated by release_region(). Therefore, the rc_unregister_device() and del_timer_sync() should be called first in ene_remove(). Suggested by: Sean Young <sean@mess.org> Fixes: 9ea53b7 ("V4L/DVB: STAGING: remove lirc_ene0100 driver") Signed-off-by: Duoming Zhou <duoming@zju.edu.cn> Signed-off-by: Sean Young <sean@mess.org> Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org> (cherry picked from commit 29b0589) Signed-off-by: Marcin Wcisło <marcin.wcislo@conclusive.pl>
1 parent b033dc8 commit 9208830

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

drivers/media/rc/ene_ir.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1116,14 +1116,15 @@ static void ene_remove(struct pnp_dev *pnp_dev)
11161116
struct ene_device *dev = pnp_get_drvdata(pnp_dev);
11171117
unsigned long flags;
11181118

1119+
rc_unregister_device(dev->rdev);
1120+
del_timer_sync(&dev->tx_sim_timer);
11191121
spin_lock_irqsave(&dev->hw_lock, flags);
11201122
ene_rx_disable(dev);
11211123
ene_rx_restore_hw_buffer(dev);
11221124
spin_unlock_irqrestore(&dev->hw_lock, flags);
11231125

11241126
free_irq(dev->irq, dev);
11251127
release_region(dev->hw_io, ENE_IO_SIZE);
1126-
rc_unregister_device(dev->rdev);
11271128
kfree(dev);
11281129
}
11291130

0 commit comments

Comments
 (0)