In the Linux kernel, the following vulnerability has been resolved: drm/xe/i2c: cancel the client work on remove xe_i2c_notifier() stores the DesignWare adapter in i2c->adapter and schedules i2c->work when the adapter is registered under the xe I2C platform device, and xe_i2c_client_work() then instantiates the AMC client device on that adapter. xe_i2c_remove() tears down the AMC, unregisters the client devices, the bus notifier and the adapter platform device, but it never drains i2c->work. Рабочий элемент, который все еще стоит в очереди или работает, когда адаптер незарегистрирован, удаляет ссылки i2c->adapter в i2c_new_client_device() после того, как platform_device_unregister() выпустил адаптер. Рабочий элемент также встроен в выделенную devm структуру xe_i2c, поэтому рабочий элемент все еще стоит в очереди после того, как devm devm devm освобождает, что выделение выполняет свой обратный вызов на освобожденной памяти.
Уведомитель шины - это единственное, что планирует эту работу, и она незарегистрирована после клиентских устройств. Экземпляр, который все еще стоит в очереди, когда разборка запускается, может, следовательно, записать i2c->client[XE_I2C_CLIENT_AMC], в то время как цикл разрегистрируется и очищает тот же массив, а клиент AMC, который он инстансифицирует поздно, очищается только собственным дочерним сканированием адаптера в i2c_del_adapter(). Переместите bus_unregister_notifier() перед циклом разбора клиента и отмените работу сразу после него, поэтому новый экземпляр не может быть запланирован, и экземпляр в очереди будет удален до того, как клиентский массив будет затронут.
Запускаемый экземпляр по-прежнему находит живой адаптер, так как адаптер позже незарегистрирован. (Вишня выбрана из commit a23f27d5ec11c3f418c5e5531eea34ccda2b5b20)
Показать оригинальное описание (EN)
In the Linux kernel, the following vulnerability has been resolved: drm/xe/i2c: cancel the client work on remove xe_i2c_notifier() stores the DesignWare adapter in i2c->adapter and schedules i2c->work when the adapter is registered under the xe I2C platform device, and xe_i2c_client_work() then instantiates the AMC client device on that adapter. xe_i2c_remove() tears down the AMC, unregisters the client devices, the bus notifier and the adapter platform device, but it never drains i2c->work. A work item that is still queued or running when the adapter is unregistered dereferences i2c->adapter in i2c_new_client_device() after platform_device_unregister() has released the adapter. The work item is also embedded in the devm-allocated struct xe_i2c, so a work item still queued after the drm device devm unwind frees that allocation runs its callback on freed memory. The bus notifier is the only thing that schedules this work, and it is unregistered after the client devices. An instance that is still queued when the teardown runs can therefore write i2c->client[XE_I2C_CLIENT_AMC] while the loop is unregistering and clearing the same array, and an AMC client it instantiates late is only cleaned up by the adapter's own child sweep in i2c_del_adapter(). Move bus_unregister_notifier() in front of the client teardown loop and cancel the work right after it, so no new instance can be scheduled and a queued instance is drained before the client array is touched. A running instance still finds a live adapter, since the adapter is unregistered later. (cherry picked from commit a23f27d5ec11c3f418c5e5531eea34ccda2b5b20)