CVE-2023-52478

Severity CVSS v4.0:
Pending analysis
Type:
Unavailable / Other
Publication date:
29/02/2024
Last modified:
10/01/2025

Description

In the Linux kernel, the following vulnerability has been resolved:<br /> <br /> HID: logitech-hidpp: Fix kernel crash on receiver USB disconnect<br /> <br /> hidpp_connect_event() has *four* time-of-check vs time-of-use (TOCTOU)<br /> races when it races with itself.<br /> <br /> hidpp_connect_event() primarily runs from a workqueue but it also runs<br /> on probe() and if a "device-connected" packet is received by the hw<br /> when the thread running hidpp_connect_event() from probe() is waiting on<br /> the hw, then a second thread running hidpp_connect_event() will be<br /> started from the workqueue.<br /> <br /> This opens the following races (note the below code is simplified):<br /> <br /> 1. Retrieving + printing the protocol (harmless race):<br /> <br /> if (!hidpp-&gt;protocol_major) {<br /> hidpp_root_get_protocol_version()<br /> hidpp-&gt;protocol_major = response.rap.params[0];<br /> }<br /> <br /> We can actually see this race hit in the dmesg in the abrt output<br /> attached to rhbz#2227968:<br /> <br /> [ 3064.624215] logitech-hidpp-device 0003:046D:4071.0049: HID++ 4.5 device connected.<br /> [ 3064.658184] logitech-hidpp-device 0003:046D:4071.0049: HID++ 4.5 device connected.<br /> <br /> Testing with extra logging added has shown that after this the 2 threads<br /> take turn grabbing the hw access mutex (send_mutex) so they ping-pong<br /> through all the other TOCTOU cases managing to hit all of them:<br /> <br /> 2. Updating the name to the HIDPP name (harmless race):<br /> <br /> if (hidpp-&gt;name == hdev-&gt;name) {<br /> ...<br /> hidpp-&gt;name = new_name;<br /> }<br /> <br /> 3. Initializing the power_supply class for the battery (problematic!):<br /> <br /> hidpp_initialize_battery()<br /> {<br /> if (hidpp-&gt;battery.ps)<br /> return 0;<br /> <br /> probe_battery(); /* Blocks, threads take turns executing this */<br /> <br /> hidpp-&gt;battery.desc.properties =<br /> devm_kmemdup(dev, hidpp_battery_props, cnt, GFP_KERNEL);<br /> <br /> hidpp-&gt;battery.ps =<br /> devm_power_supply_register(&amp;hidpp-&gt;hid_dev-&gt;dev,<br /> &amp;hidpp-&gt;battery.desc, cfg);<br /> }<br /> <br /> 4. Creating delayed input_device (potentially problematic):<br /> <br /> if (hidpp-&gt;delayed_input)<br /> return;<br /> <br /> hidpp-&gt;delayed_input = hidpp_allocate_input(hdev);<br /> <br /> The really big problem here is 3. Hitting the race leads to the following<br /> sequence:<br /> <br /> hidpp-&gt;battery.desc.properties =<br /> devm_kmemdup(dev, hidpp_battery_props, cnt, GFP_KERNEL);<br /> <br /> hidpp-&gt;battery.ps =<br /> devm_power_supply_register(&amp;hidpp-&gt;hid_dev-&gt;dev,<br /> &amp;hidpp-&gt;battery.desc, cfg);<br /> <br /> ...<br /> <br /> hidpp-&gt;battery.desc.properties =<br /> devm_kmemdup(dev, hidpp_battery_props, cnt, GFP_KERNEL);<br /> <br /> hidpp-&gt;battery.ps =<br /> devm_power_supply_register(&amp;hidpp-&gt;hid_dev-&gt;dev,<br /> &amp;hidpp-&gt;battery.desc, cfg);<br /> <br /> So now we have registered 2 power supplies for the same battery,<br /> which looks a bit weird from userspace&amp;#39;s pov but this is not even<br /> the really big problem.<br /> <br /> Notice how:<br /> <br /> 1. This is all devm-maganaged<br /> 2. The hidpp-&gt;battery.desc struct is shared between the 2 power supplies<br /> 3. hidpp-&gt;battery.desc.properties points to the result from the second<br /> devm_kmemdup()<br /> <br /> This causes a use after free scenario on USB disconnect of the receiver:<br /> 1. The last registered power supply class device gets unregistered<br /> 2. The memory from the last devm_kmemdup() call gets freed,<br /> hidpp-&gt;battery.desc.properties now points to freed memory<br /> 3. The first registered power supply class device gets unregistered,<br /> this involves sending a remove uevent to userspace which invokes<br /> power_supply_uevent() to fill the uevent data<br /> 4. power_supply_uevent() uses hidpp-&gt;battery.desc.properties which<br /> now points to freed memory leading to backtraces like this one:<br /> <br /> Sep 22 20:01:35 eric kernel: BUG: unable to handle page fault for address: ffffb2140e017f08<br /> ...<br /> Sep 22 20:01:35 eric kernel: Workqueue: usb_hub_wq hub_event<br /> Sep 22 20:01:35 eric kernel: RIP: 0010:power_supply_uevent+0xee/0x1d0<br /> ...<br /> Sep 22 20:01:35 eric kernel: ? asm_exc_page_fault+0x26/0x30<br /> Sep 22 20:01:35 eric kernel: ? power_supply_uevent+0xee/0x1d0<br /> Sep 22 20:01:35 eric kernel: ? power_supply_uevent+0x10d/0x1d0<br /> Sep 22 20:01:35 eric kernel: dev_uevent+0x10f/0x2d0<br /> Sep 22 20:01:35 eric kernel: kobject_uevent_env+0x291/0x680<br /> Sep 22 20:01:35 eric kernel: <br /> ---truncated---

Vulnerable products and versions

CPE From Up to
cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:* 4.14.328 (excluding)
cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:* 4.15 (including) 4.19.297 (excluding)
cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:* 4.20 (including) 5.4.259 (excluding)
cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:* 5.5 (including) 5.10.199 (excluding)
cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:* 5.11 (including) 5.15.136 (excluding)
cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:* 5.16 (including) 6.1.59 (excluding)
cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:* 6.2 (including) 6.5.8 (excluding)
cpe:2.3:o:linux:linux_kernel:6.6:rc1:*:*:*:*:*:*
cpe:2.3:o:linux:linux_kernel:6.6:rc2:*:*:*:*:*:*
cpe:2.3:o:linux:linux_kernel:6.6:rc3:*:*:*:*:*:*
cpe:2.3:o:linux:linux_kernel:6.6:rc4:*:*:*:*:*:*
cpe:2.3:o:linux:linux_kernel:6.6:rc5:*:*:*:*:*:*