usb: typec: ucsi_acpi: fix NULL pointer dereference in ucsi_acpi_probe()
Subsystems (2)
PATCH 1/1 usb: typec: ucsi_acpi: fix NULL pointer dereference in ucsi_acpi_probe()
ucsi_acpi_probe() dereferences the ACPI companion device pointer returned by ACPI_COMPANION() without checking it for NULL. While this driver is normally probed through ACPI device enumeration where a companion is always present, a platform_device can also be manually bound to any platform driver via the sysfs 'bind' file (bind_store() -> bus_find_device() -> driver_attach_device()), which matches purely on device name and bypasses ACPI matching.
If ucsi_acpi is bound this way to a platform device with no ACPI companion, ACPI_COMPANION() returns NULL and the subsequent adev->dep_unmet access dereferences a NULL pointer, resulting in a
general protection fault.
Add a NULL check for adev immediately after it is obtained and before any resource allocation, returning -ENODEV to decline binding cleanly.
--- drivers/usb/typec/ucsi/ucsi_acpi.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/usb/typec/ucsi/ucsi_acpi.c +3 -0
@@ -196,6 +196,9 @@ static int ucsi_acpi_probe(struct platform_device *pdev)acpi_status status;int ret; +if (!adev) +return -ENODEV ; +if (adev->dep_unmet)return -EPROBE_DEFER ;
Signature · 1 line
2.43.0
Greg KH
maintainerQuoted 7 lines · Deepanshu Kartikey
ucsi_acpi_probe()dereferences the ACPI companion device pointer returned byACPI_COMPANION()without checking it for NULL. While this driver is normally probed through ACPI device enumeration where a companion is always present, aplatform_devicecan also be manually bound to any platform driver via the sysfs 'bind' file (bind_store()->bus_find_device()->driver_attach_device()), which matches purely on device name and bypasses ACPI matching.
Again, if someone does a manual bind, they get to keep the pieces that break if something goes wrong.
I should just add a taint-flag to the kernel for this. Well, maybe just for unbind. But really, don't do this on random drivers, bad things, like this, can happen, and are in fact, guaranteed :)
thanks,
greg k-h