CVE-2022-49385: driver: base: fix UAF when driver_attach failed
Description
===========
In the Linux kernel, the following vulnerability has been resolved:
driver: base: fix UAF when driver_attach failed
When driver_attach(drv); failed, the driver_private will be freed. But it has been added to the bus, which caused a UAF.
To fix it, we need to delete it from the bus when failed.
The Linux kernel CVE team has assigned CVE-2022-49385 to this issue.
Affected and fixed versions
===========================
Issue introduced in 3.9 with commit 190888ac01d059e38ffe77a2291d44cafa9016fb and fixed in 5.4.198 with commit 5d709f58c743166fe1c6914b9de0ae8868600d9b Issue introduced in 3.9 with commit 190888ac01d059e38ffe77a2291d44cafa9016fb and fixed in 5.10.122 with commit 823f24f2e329babd0330200d0b74882516fe57f4 Issue introduced in 3.9 with commit 190888ac01d059e38ffe77a2291d44cafa9016fb and fixed in 5.15.47 with commit cdf1a683a01583bca4b618dd16223cbd6e462e21 Issue introduced in 3.9 with commit 190888ac01d059e38ffe77a2291d44cafa9016fb and fixed in 5.17.15 with commit 5389101257828d1913d713d9a40acbe14f5961df Issue introduced in 3.9 with commit 190888ac01d059e38ffe77a2291d44cafa9016fb and fixed in 5.18.4 with commit c059665c84feab46b7173d3a1bf36c2fb7f9df86 Issue introduced in 3.9 with commit 190888ac01d059e38ffe77a2291d44cafa9016fb and fixed in 5.19 with commit 310862e574001a97ad02272bac0fd13f75f42a27
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-49385
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/base/bus.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/5d709f58c743166fe1c6914b9de0ae8868600d9b https://git.kernel.org/stable/c/823f24f2e329babd0330200d0b74882516fe57f4 https://git.kernel.org/stable/c/cdf1a683a01583bca4b618dd16223cbd6e462e21 https://git.kernel.org/stable/c/5389101257828d1913d713d9a40acbe14f5961df https://git.kernel.org/stable/c/c059665c84feab46b7173d3a1bf36c2fb7f9df86 https://git.kernel.org/stable/c/310862e574001a97ad02272bac0fd13f75f42a27