i2c: core: fix debugfs UAF on adapter removal
Subsystems (2)
PATCH v2 1/1 i2c: core: fix debugfs UAF on adapter removal
i2c_del_adapter() frees the adapter's debugfs directory before it unregisters the adapter device, but the new_device sysfs attribute stays writable until device_del(). A write racing with removal still reaches i2c_device_probe(), which passes the freed adap->debugfs to debugfs_create_dir() as the new client's parent:
BUG: KASAN: slab-use-after-free in lookup_noperm_common+0x407/0x430 Read of size 4 at addr ffff88803ef87810 by task syz.0.61/6090 lookup_noperm_common+0x407/0x430 simple_start_creating+0x9c/0x110 debugfs_start_creating+0xdb/0x1a0 debugfs_create_dir+0x24/0x350 i2c_device_probe+0x814/0xbf0
Its technically possible to create a client after i2c_deregister_clients has run. That client will never be unregistered and making wait_for_completion hang.
Close the window by removing the new_device attribute at the start of i2c_del_adapter(). device_remove_file() will drain any clients left.
--- drivers/i2c/i2c-core-base.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/i2c/i2c-core-base.c +6 -0
@@ -1815,6 +1815,12 @@ void i2c_del_adapter(struct i2c_adapter *adap)return ; } +/* +* This drains any in-flight writers, so all +* clients will be caught by i2c_deregister_clients(). +*/ +device_remove_file (&adap->dev, &dev_attr_new_device); +i2c_acpi_remove_space_handler (adap);i2c_deregister_clients (adap);
---
base-commit: 8ba098e6b6ff0db8edf28528d1552be261af30d4
change-id: 20260801-i2c-fb34477c0106
Best regards,
Signature · 1 line
Vasileios Almpanis <[email protected]>
Andi Shyti
maintainerHi Vasileios,
Quoted 18 lines · Vasileios Almpanis
i2c_del_adapter()frees the adapter's debugfs directory before it unregisters the adapter device, but thenew_devicesysfs attribute stays writable untildevice_del(). A write racing with removal still reachesi2c_device_probe(), which passes the freedadap->debugfstodebugfs_create_dir()as the new client's parent:BUG: KASAN: slab-use-after-free in lookup_noperm_common+0x407/0x430 Read of size 4 at addr ffff88803ef87810 by task syz.0.61/6090 lookup_noperm_common+0x407/0x430 simple_start_creating+0x9c/0x110 debugfs_start_creating+0xdb/0x1a0 debugfs_create_dir+0x24/0x350 i2c_device_probe+0x814/0xbf0Its technically possible to create a client after
i2c_deregister_clientshas run. That client will never be unregistered and makingwait_for_completionhang.
Quoted 8 lines
Close the window by removing the
new_deviceattribute at the start ofi2c_del_adapter().device_remove_file()will drain any clients left.Fixes 73febd775bdb ("i2c: create debugfs entry per adapter")Reported-by [email protected]Tested-by [email protected]Signed-off-by Vasileios Almpanis <[email protected]>
with a few fixes in the commit messages, I pushed your patch to i2c/i2c-fixes.
Thanks,
Andi