CVE-2022-49980: USB: gadget: Fix use-after-free Read in usb_udc_uevent()
From: Greg Kroah-Hartman <[email protected]>
Description
===========
In the Linux kernel, the following vulnerability has been resolved:
USB: gadget: Fix use-after-free Read in usb_udc_uevent()
The syzbot fuzzer found a race between uevent callbacks and gadget driver unregistration that can cause a use-after-free bug:
---------------------------------------------------------------
BUG: KASAN: use-after-free in usb_udc_uevent+0x11f/0x130 drivers/usb/gadget/udc/core.c:1732 Read of size 8 at addr ffff888078ce2050 by task udevd/2968 CPU: 1 PID: 2968 Comm: udevd Not tainted 5.19.0-rc4-next-20220628-syzkaller #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 06/29/2022 Call Trace: <TASK> __dump_stack lib/dump_stack.c:88 [inline] dump_stack_lvl+0xcd/0x134 lib/dump_stack.c:106 print_address_description mm/kasan/report.c:317 [inline] print_report.cold+0x2ba/0x719 mm/kasan/report.c:433 kasan_report+0xbe/0x1f0 mm/kasan/report.c:495 usb_udc_uevent+0x11f/0x130 drivers/usb/gadget/udc/core.c:1732 dev_uevent+0x290/0x770 drivers/base/core.c:2424 ---------------------------------------------------------------
The bug occurs because usb_udc_uevent() dereferences udc->driver but does so without acquiring the udc_lock mutex, which protects this field. If the gadget driver is unbound from the udc concurrently with uevent processing, the driver structure may be accessed after it has been deallocated.
To prevent the race, we make sure that the routine holds the mutex around the racing accesses.
The Linux kernel CVE team has assigned CVE-2022-49980 to this issue.
Affected and fixed versions
===========================
Fixed in 5.19.7 with commit f44b0b95d50fffeca036e1ba36770390e0b519dd Fixed in 6.0 with commit 2191c00855b03aa59c20e698be713d952d51fc18
Please see https://www.kernel.org for a full list of currently supported kernel versions by the kernel community.
Unaffected versions might change over time as fixes are backported to older supported kernel versions. The official CVE entry at
https://cve.org/CVERecord/?id=CVE-2022-49980
will be updated if fixes are backported, please check that for the most up to date information about this issue.
Affected files
==============
The file(s) affected by this issue are:
drivers/usb/gadget/udc/core.c
Mitigation
==========
The Linux kernel CVE team recommends that you update to the latest stable kernel version for this, and many other bugfixes. Individual changes are never tested alone, but rather are part of a larger kernel release. Cherry-picking individual commits is not recommended or supported by the Linux kernel community at all. If however, updating to the latest release is impossible, the individual changes to resolve this issue can be found at these commits:
https://git.kernel.org/stable/c/f44b0b95d50fffeca036e1ba36770390e0b519dd https://git.kernel.org/stable/c/2191c00855b03aa59c20e698be713d952d51fc18
[Question] fix CVE-2022-49980 introduces deadlock in linux-5.10.y
Hello,
I noticed that the community has assigned CVE-2022-49980. I found that the issue described by this CVE also exists in the linux-5.10.y. Therefore, I attempted to backport the fix patch to the linux-5.10.y, but encountered a potential deadlock after applying the patch.
The specific call path is as follows:
usb_add_gadget [(1) mutex_lock(&udc_lock]
-> device_add
-> kobject_uevent
-> uevent_ops->uevent
-> dev->class->dev_uevent
-> usb_udc_uevent [(2) mutex_lock(&udc_lock)]This results in repeated acquisition of udc_lock, causing a deadlock.
Does the community have any suggestions on how to resolve this new deadlock issue introduced by the CVE fix?
Best regards,
--
Cheng Yu
Re: [Question] fix CVE-2022-49980 introduces deadlock in linux-5.10.y
Quoted 13 lines · Cheng Yu
Hello,
I noticed that the community has assigned CVE-2022-49980. I found that the issue described by this CVE also exists in the linux-5.10.y. Therefore, I attempted to backport the fix patch to the linux-5.10.y, but encountered a potential deadlock after applying the patch.
The specific call path is as follows:usb_add_gadget [(1) mutex_lock(&udc_lock] -> device_add -> kobject_uevent -> uevent_ops->uevent -> dev->class->dev_uevent -> usb_udc_uevent [(2) mutex_lock(&udc_lock)]
Quoted 4 lines
This results in repeated acquisition of
udc_lock, causing a deadlock.
Does the community have any suggestions on how to resolve this new deadlock issue introduced by the CVE fix?
As you are making a business decision to stay on a very old kernel version, I think that business decision includes doing the development of fixes for it on your own :)
Seriously, the community doesn't do much, if any, work on older kernels like this, especially ones as old as 5.10.y, as we do not even have systems that run that kernel anymore.
Why not just move to a newer kernel version instead? What's preventing that from happening today? You are going to have to do it soon anyway, why not use this as a prompt to do so?
thanks,
greg k-h