Bug 2174400 (CVE-2023-1118) - CVE-2023-1118 kernel: use-after-free in drivers/media/rc/ene_ir.c due to race condition
Summary: CVE-2023-1118 kernel: use-after-free in drivers/media/rc/ene_ir.c due to race...
Keywords:
Status: NEW
Alias: CVE-2023-1118
Product: Security Response
Classification: Other
Component: vulnerability
Version: unspecified
Hardware: All
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Nobody
QA Contact:
URL:
Whiteboard:
Depends On: 2174401 2174409 2174410 2174411 2174412
Blocks: 2173942
TreeView+ depends on / blocked
 
Reported: 2023-03-01 13:46 UTC by Alex
Modified: 2024-04-05 04:19 UTC (History)
36 users (show)

Fixed In Version: Linux kernel 6.3-rc1
Doc Type: If docs needed, set a value
Doc Text:
A use-after-free flaw was found in the Linux kernel's integrated infrared receiver/transceiver driver. This issue occurs when a user detaches a rc device. This could allow a local user to crash the system or potentially escalate their privileges on the system.
Clone Of:
Environment:
Last Closed:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2023:7268 0 None None None 2023-11-15 18:25:18 UTC
Red Hat Product Errata RHBA-2023:7328 0 None None None 2023-11-16 11:38:50 UTC
Red Hat Product Errata RHBA-2023:7338 0 None None None 2023-11-16 18:04:10 UTC
Red Hat Product Errata RHBA-2023:7343 0 None None None 2023-11-20 01:58:37 UTC
Red Hat Product Errata RHBA-2023:7346 0 None None None 2023-11-20 09:25:39 UTC
Red Hat Product Errata RHSA-2023:6901 0 None None None 2023-11-14 15:15:01 UTC
Red Hat Product Errata RHSA-2023:7077 0 None None None 2023-11-14 15:20:37 UTC
Red Hat Product Errata RHSA-2024:1653 0 None None None 2024-04-03 00:31:00 UTC

Description Alex 2023-03-01 13:46:02 UTC
A flaw in the Linux Kernel found. There are use-after-free vulnerabilities in drivers/media/rc/ene_ir.c of linux that
allow attacker to crash linux kernel without any privilege by detaching rc device.

When the rc device is detaching, function ene_remove() will be called.
But the synchronizations in ene_remove() are bad. 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().

    (cleanup routine)      |        (open routine)
ene_remove()               | 
  ene_rx_disable(dev);     | ene_open()
                           |   ene_rx_enable(dev); //re-enable!

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.

    (free routine)                |        (use routine)
ene_remove()                      | ene_rx_enable()
  free_irq(dev->irq, ...); //FREE |   ene_rx_enable_hw()
                                  |     ene_write_reg(..., dev->irq << 1) //USE
                                  | 

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().

    (free routine)                        |        (use routine)
ene_remove()                              | ene_tx_sample()
  release_region(dev->hw_io, ...); //FREE |   ene_write_reg()
                                          |     outb(..., dev->hw_io + ENE_IO) //USE

Fourthly, 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.

    (free routine)             |        (use 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

------------------------------------------

Reference:
https://github.com/torvalds/linux/commit/29b0589a865b6f66d141d79b2dd1373e4e50fe17

Comment 1 Alex 2023-03-01 13:46:36 UTC
Created kernel tracking bugs for this issue:

Affects: fedora-all [bug 2174401]

Comment 3 Alex 2023-03-01 15:07:01 UTC
Expect that likely going to be fixed in Linux kernel 6.3-rc1 (check it later).

Comment 6 Justin M. Forbes 2023-03-21 13:14:14 UTC
This was fixed for Fedora in the 6.1.16 stable kernel updates.

Comment 9 errata-xmlrpc 2023-11-14 15:14:56 UTC
This issue has been addressed in the following products:

  Red Hat Enterprise Linux 8

Via RHSA-2023:6901 https://access.redhat.com/errata/RHSA-2023:6901

Comment 10 errata-xmlrpc 2023-11-14 15:20:33 UTC
This issue has been addressed in the following products:

  Red Hat Enterprise Linux 8

Via RHSA-2023:7077 https://access.redhat.com/errata/RHSA-2023:7077

Comment 13 errata-xmlrpc 2024-04-03 00:30:56 UTC
This issue has been addressed in the following products:

  Red Hat Enterprise Linux 8.6 Extended Update Support

Via RHSA-2024:1653 https://access.redhat.com/errata/RHSA-2024:1653


Note You need to log in before you can comment on or make changes to this bug.