i2c: prevent new device registration during adapter removal
Subsystems (2)
PATCH 1/1 i2c: prevent new device registration during adapter removal
Remove new_device and delete_device sysfs attributes early in i2c_del_adapter() to prevent concurrent client registrations during adapter teardown. Without this, a racing new_device_store() can register a client that will never be cleaned up, causing wait_for_completion() to block indefinitely.
--- drivers/i2c/i2c-core-base.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/i2c/i2c-core-base.c +8 -0
@@ -1817,6 +1817,14 @@ void i2c_del_adapter(struct i2c_adapter *adap)i2c_acpi_remove_space_handler (adap); +/* +* Remove new_device/delete_device sysfs attrs early to prevent +* new client registrations via userspace while we're tearing down. +* kernfs will wait for any in-flight writes to complete. +*/ +device_remove_file (&adap->dev, &dev_attr_new_device); +device_remove_file (&adap->dev, &dev_attr_delete_device); +i2c_deregister_clients (adap);/* device name is gone after device_unregister */
Signature · 1 line
2.43.0
Andi Shyti
maintainerHi Yun,
uuhh... woow, check this patch here[*]. Your AI agents look to be in sync.
I read Vasileios patch first and then yours.
Quoted 5 lines · Yun Zhou
Remove
new_deviceanddelete_devicesysfs attributes early ini2c_del_adapter()to prevent concurrent client registrations during adapter teardown. Without this, a racingnew_device_store()can register a client that will never be cleaned up, causingwait_for_completion()to block indefinitely.
You can also mention the UAF that Vasileios AI found.
Quoted 12 lines
Fixes 99cd8e25875a ("i2c: Add a sysfs interface to instantiate devices")Signed-off-by Yun Zhou <[email protected]>--- drivers/i2c/i2c-core-base.c | 8 ++++++++ 1 file changed, 8 insertions(+)drivers/i2c/i2c-core-base.c +0
-0
drivers/i2c/i2c-core-base.c void i2c_del_adapter(struct i2c_adapter *adap) · line 1826
Quoted 10 lines
drivers/i2c/i2c-core-base.c +7
-0@@ -1817,6 +1817,14 @@ void i2c_del_adapter(struct i2c_adapter *adap)i2c_acpi_remove_space_handler (adap); +/* +* Remove new_device/delete_device sysfs attrs early to prevent +* new client registrations via userspace while we're tearing down. +* kernfs will wait for any in-flight writes to complete. +*/ +device_remove_file (&adap->dev, &dev_attr_new_device); +device_remove_file (&adap->dev, &dev_attr_delete_device);
I prefer this fix, though, but I don't think we need to manually remove delete_device.
Andi
[*] https://patchwork.ozlabs.org/project/linux-i2c/patch/[email protected]/
Quoted 7 lines
drivers/i2c/i2c-core-base.c +1
-0+i2c_deregister_clients (adap);/* device name is gone after device_unregister */ Signature · 1 line
2.43.0