usb: typec: ucsi: Fixes for Huawei Matebook E Go UCSI driver
v2 cover usb: typec: ucsi: Fixes for Huawei Matebook E Go UCSI driver
This patch series addresses two critical issues in the Huawei Matebook E Go UCSI driver that were preventing proper functionality and causing potential use-after-free scenarios.
The first patch fixes a probe failure by adding the missing poll_cci to the UCSI operations structure, which is required by the UCSI core for proper initialization.
The second patch resolves use-after-free vulnerabilities where a delayed work item could access freed memory after device or module removal, by ensuring proper cancellation of the work item in gaokun_ucsi_remove().
Duoming Zhou (2):
usb: typec: ucsi: fix probe failure in gaokun_ucsi_probe()
usb: typec: ucsi: fix use-after-free caused by uec->work
drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c | 2 ++ 1 file changed, 2 insertions(+)
Signature · 1 line
2.34.1
PATCH v2 1/2 usb: typec: ucsi: fix probe failure in gaokun_ucsi_probe()
The gaokun_ucsi_probe() uses ucsi_create() to allocate a UCSI instance. The ucsi_create() validates whether ops->poll_cci is defined, and if not, it directly returns -EINVAL. However, the gaokun_ucsi_ops structure does not define the poll_cci, causing ucsi_create() always fail with -EINVAL. This issue can be observed in the kernel log with the following error:
ucsi_huawei_gaokun.ucsi huawei_gaokun_ec.ucsi.0: probe with driver ucsi_huawei_gaokun.ucsi failed with error -22
Fix the issue by adding the missing poll_cci callback to gaokun_ucsi_ops.
---
Changes in v2:
- Add cc: stable.
- Correct spelling mistake.
drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c | 1 + 1 file changed, 1 insertion(+)
drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c +1 -0
@@ -196,6 +196,7 @@ static void gaokun_ucsi_connector_status(struct ucsi_connector *con)const struct ucsi_operations gaokun_ucsi_ops = { .read_version = gaokun_ucsi_read_version, .read_cci = gaokun_ucsi_read_cci, + .poll_cci = gaokun_ucsi_read_cci, .read_message_in = gaokun_ucsi_read_message_in, .sync_control = ucsi_sync_control_common, .async_control = gaokun_ucsi_async_control,
Signature · 1 line
2.34.1
PATCH v2 2/2 usb: typec: ucsi: fix use-after-free caused by uec->work
In reply to Duoming ZhouThe delayed work uec->work is scheduled in gaokun_ucsi_probe() but never properly canceled in gaokun_ucsi_remove(). This creates use-after-free scenarios where the ucsi and gaokun_ucsi structure are freed after ucsi_destroy() completes execution, while the gaokun_ucsi_register_worker() might be either currently executing or still pending in the work queue. The already-freed gaokun_ucsi or ucsi structure may then be accessed.
Furthermore, the race window is 3 seconds, which is sufficiently long to make this bug easily reproducible. The following is the trace captured by KASAN:
==================================================================
BUG: KASAN: slab-use-after-free in __run_timers+0x5ec/0x630 Write of size 8 at addr ffff00000ec28cc8 by task swapper/0/0 ... Call trace: show_stack+0x18/0x24 (C) dump_stack_lvl+0x78/0x90 print_report+0x114/0x580 kasan_report+0xa4/0xf0 __asan_report_store8_noabort+0x20/0x2c __run_timers+0x5ec/0x630 run_timer_softirq+0xe8/0x1cc handle_softirqs+0x294/0x720 __do_softirq+0x14/0x20 ____do_softirq+0x10/0x1c call_on_irq_stack+0x30/0x48 do_softirq_own_stack+0x1c/0x28 __irq_exit_rcu+0x27c/0x364 irq_exit_rcu+0x10/0x1c el1_interrupt+0x40/0x60 el1h_64_irq_handler+0x18/0x24 el1h_64_irq+0x6c/0x70 arch_local_irq_enable+0x4/0x8 (P) do_idle+0x334/0x458 cpu_startup_entry+0x60/0x70 rest_init+0x158/0x174 start_kernel+0x2f8/0x394 __primary_switched+0x8c/0x94 Allocated by task 72 on cpu 0 at 27.510341s: kasan_save_stack+0x2c/0x54 kasan_save_track+0x24/0x5c kasan_save_alloc_info+0x40/0x54 __kasan_kmalloc+0xa0/0xb8 __kmalloc_node_track_caller_noprof+0x1c0/0x588 devm_kmalloc+0x7c/0x1c8 gaokun_ucsi_probe+0xa0/0x840 auxiliary_bus_probe+0x94/0xf8 really_probe+0x17c/0x5b8 __driver_probe_device+0x158/0x2c4 driver_probe_device+0x10c/0x264 __device_attach_driver+0x168/0x2d0 bus_for_each_drv+0x100/0x188 __device_attach+0x174/0x368 device_initial_probe+0x14/0x20 bus_probe_device+0x120/0x150 device_add+0xb3c/0x10fc __auxiliary_device_add+0x88/0x130
...
Freed by task 73 on cpu 1 at 28.910627s: kasan_save_stack+0x2c/0x54 kasan_save_track+0x24/0x5c __kasan_save_free_info+0x4c/0x74 __kasan_slab_free+0x60/0x8c kfree+0xd4/0x410 devres_release_all+0x140/0x1f0 device_unbind_cleanup+0x20/0x190 device_release_driver_internal+0x344/0x460 device_release_driver+0x18/0x24 bus_remove_device+0x198/0x274 device_del+0x310/0xa84
...
The buggy address belongs to the object at ffff00000ec28c00 which belongs to the cache kmalloc-512 of size 512 The buggy address is located 200 bytes inside of freed 512-byte region The buggy address belongs to the physical page: page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x4ec28 head: order:2 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0 flags: 0x3fffe0000000040(head|node=0|zone=0|lastcpupid=0x1ffff) page_type: f5(slab) raw: 03fffe0000000040 ffff000008801c80 dead000000000122 0000000000000000 raw: 0000000000000000 0000000080100010 00000000f5000000 0000000000000000
head: 03fffe0000000040 ffff000008801c80 dead000000000122 0000000000000000
head: 0000000000000000 0000000080100010 00000000f5000000 0000000000000000
head: 03fffe0000000002 fffffdffc03b0a01 00000000ffffffff 00000000ffffffff
head: ffffffffffffffff 0000000000000000 00000000ffffffff 0000000000000004
page dumped because: kasan: bad access detected
Memory state around the buggy address:
ffff00000ec28b80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
ffff00000ec28c00: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff00000ec28c80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff00000ec28d00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff00000ec28d80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================Add disable_delayed_work_sync() in gaokun_ucsi_remove() to ensure that uec->work is properly canceled and prevented from executing after the ucsi and gaokun_ucsi structure have been deallocated.
--- drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c | 1 + 1 file changed, 1 insertion(+)
drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c +1 -0
@@ -503,6 +503,7 @@ static void gaokun_ucsi_remove(struct auxiliary_device *adev) {struct gaokun_ucsi *uec =auxiliary_get_drvdata (adev); +disable_delayed_work_sync (&uec->work);gaokun_ec_unregister_notify (uec->ec, &uec->nb);ucsi_unregister (uec->ucsi);ucsi_destroy (uec->ucsi);
Signature · 1 line
2.34.1
Greg KH
maintainerRe: [PATCH v2 2/2] usb: typec: ucsi: fix use-after-free caused by uec->work
Quoted 128 lines · Duoming Zhou
The delayed work
uec->workis scheduled ingaokun_ucsi_probe()but never properly canceled ingaokun_ucsi_remove(). This creates use-after-free scenarios where the ucsi andgaokun_ucsistructure are freed afterucsi_destroy()completes execution, while thegaokun_ucsi_register_worker()might be either currently executing or still pending in the work queue. The already-freedgaokun_ucsior ucsi structure may then be accessed.Furthermore, the race window is 3 seconds, which is sufficiently long to make this bug easily reproducible. The following is the trace captured by KASAN:
==================================================================
BUG: KASAN: slab-use-after-free in __run_timers+0x5ec/0x630 Write of size 8 at addr ffff00000ec28cc8 by task swapper/0/0 ... Call trace: show_stack+0x18/0x24 (C) dump_stack_lvl+0x78/0x90 print_report+0x114/0x580 kasan_report+0xa4/0xf0 __asan_report_store8_noabort+0x20/0x2c __run_timers+0x5ec/0x630 run_timer_softirq+0xe8/0x1cc handle_softirqs+0x294/0x720 __do_softirq+0x14/0x20 ____do_softirq+0x10/0x1c call_on_irq_stack+0x30/0x48 do_softirq_own_stack+0x1c/0x28 __irq_exit_rcu+0x27c/0x364 irq_exit_rcu+0x10/0x1c el1_interrupt+0x40/0x60 el1h_64_irq_handler+0x18/0x24 el1h_64_irq+0x6c/0x70 arch_local_irq_enable+0x4/0x8 (P) do_idle+0x334/0x458 cpu_startup_entry+0x60/0x70 rest_init+0x158/0x174 start_kernel+0x2f8/0x394 __primary_switched+0x8c/0x94 Allocated by task 72 on cpu 0 at 27.510341s: kasan_save_stack+0x2c/0x54 kasan_save_track+0x24/0x5c kasan_save_alloc_info+0x40/0x54 __kasan_kmalloc+0xa0/0xb8 __kmalloc_node_track_caller_noprof+0x1c0/0x588 devm_kmalloc+0x7c/0x1c8 gaokun_ucsi_probe+0xa0/0x840 auxiliary_bus_probe+0x94/0xf8 really_probe+0x17c/0x5b8 __driver_probe_device+0x158/0x2c4 driver_probe_device+0x10c/0x264 __device_attach_driver+0x168/0x2d0 bus_for_each_drv+0x100/0x188 __device_attach+0x174/0x368 device_initial_probe+0x14/0x20 bus_probe_device+0x120/0x150 device_add+0xb3c/0x10fc __auxiliary_device_add+0x88/0x130...
Freed by task 73 on cpu 1 at 28.910627s: kasan_save_stack+0x2c/0x54 kasan_save_track+0x24/0x5c __kasan_save_free_info+0x4c/0x74 __kasan_slab_free+0x60/0x8c kfree+0xd4/0x410 devres_release_all+0x140/0x1f0 device_unbind_cleanup+0x20/0x190 device_release_driver_internal+0x344/0x460 device_release_driver+0x18/0x24 bus_remove_device+0x198/0x274 device_del+0x310/0xa84...
The buggy address belongs to the object at ffff00000ec28c00 which belongs to the cache kmalloc-512 of size 512 The buggy address is located 200 bytes inside of freed 512-byte region The buggy address belongs to the physical page: page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x4ec28 head: order:2 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0 flags: 0x3fffe0000000040(head|node=0|zone=0|lastcpupid=0x1ffff) page_type: f5(slab) raw: 03fffe0000000040 ffff000008801c80 dead000000000122 0000000000000000 raw: 0000000000000000 0000000080100010 00000000f5000000 0000000000000000head:
03fffe0000000040ffff000008801c80dead0000000001220000000000000000
head: 0000000000000000 000000008010001000000000f50000000000000000000000
head:03fffe0000000002fffffdffc03b0a0100000000ffffffff00000000ffffffff
head: ffffffffffffffff 000000000000000000000000ffffffff0000000000000004page dumped because: kasan: bad access detected Memory state around the buggy address: ffff00000ec28b80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc ffff00000ec28c00: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb >ffff00000ec28c80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ^ ffff00000ec28d00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ffff00000ec28d80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ==================================================================Add
disable_delayed_work_sync()ingaokun_ucsi_remove()to ensure thatuec->workis properly canceled and prevented from executing after the ucsi andgaokun_ucsistructure have been deallocated.Fixes 00327d7f2c8c ("usb: typec: ucsi: add Huawei Matebook E Go ucsi driver")Signed-off-by Duoming Zhou <[email protected]>--- drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c | 1 + 1 file changed, 1 insertion(+)drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c +1
-0@@ -503,6 +503,7 @@ static void gaokun_ucsi_remove(struct auxiliary_device *adev) {struct gaokun_ucsi *uec =auxiliary_get_drvdata (adev); +disable_delayed_work_sync (&uec->work);gaokun_ec_unregister_notify (uec->ec, &uec->nb);ucsi_unregister (uec->ucsi);ucsi_destroy (uec->ucsi);Signature · 1 line
2.34.1
What changed from v1?
Re: [PATCH v2 2/2] usb: typec: ucsi: fix use-after-free caused by uec->work
Quoted 120 lines · Greg KH
Quoted 120 lines
The delayed work
uec->workis scheduled ingaokun_ucsi_probe()but never properly canceled ingaokun_ucsi_remove(). This creates use-after-free scenarios where the ucsi andgaokun_ucsistructure are freed afterucsi_destroy()completes execution, while thegaokun_ucsi_register_worker()might be either currently executing or still pending in the work queue. The already-freedgaokun_ucsior ucsi structure may then be accessed.Furthermore, the race window is 3 seconds, which is sufficiently long to make this bug easily reproducible. The following is the trace captured by KASAN:
==================================================================
BUG: KASAN: slab-use-after-free in __run_timers+0x5ec/0x630 Write of size 8 at addr ffff00000ec28cc8 by task swapper/0/0 ... Call trace: show_stack+0x18/0x24 (C) dump_stack_lvl+0x78/0x90 print_report+0x114/0x580 kasan_report+0xa4/0xf0 __asan_report_store8_noabort+0x20/0x2c __run_timers+0x5ec/0x630 run_timer_softirq+0xe8/0x1cc handle_softirqs+0x294/0x720 __do_softirq+0x14/0x20 ____do_softirq+0x10/0x1c call_on_irq_stack+0x30/0x48 do_softirq_own_stack+0x1c/0x28 __irq_exit_rcu+0x27c/0x364 irq_exit_rcu+0x10/0x1c el1_interrupt+0x40/0x60 el1h_64_irq_handler+0x18/0x24 el1h_64_irq+0x6c/0x70 arch_local_irq_enable+0x4/0x8 (P) do_idle+0x334/0x458 cpu_startup_entry+0x60/0x70 rest_init+0x158/0x174 start_kernel+0x2f8/0x394 __primary_switched+0x8c/0x94 Allocated by task 72 on cpu 0 at 27.510341s: kasan_save_stack+0x2c/0x54 kasan_save_track+0x24/0x5c kasan_save_alloc_info+0x40/0x54 __kasan_kmalloc+0xa0/0xb8 __kmalloc_node_track_caller_noprof+0x1c0/0x588 devm_kmalloc+0x7c/0x1c8 gaokun_ucsi_probe+0xa0/0x840 auxiliary_bus_probe+0x94/0xf8 really_probe+0x17c/0x5b8 __driver_probe_device+0x158/0x2c4 driver_probe_device+0x10c/0x264 __device_attach_driver+0x168/0x2d0 bus_for_each_drv+0x100/0x188 __device_attach+0x174/0x368 device_initial_probe+0x14/0x20 bus_probe_device+0x120/0x150 device_add+0xb3c/0x10fc __auxiliary_device_add+0x88/0x130...
Freed by task 73 on cpu 1 at 28.910627s: kasan_save_stack+0x2c/0x54 kasan_save_track+0x24/0x5c __kasan_save_free_info+0x4c/0x74 __kasan_slab_free+0x60/0x8c kfree+0xd4/0x410 devres_release_all+0x140/0x1f0 device_unbind_cleanup+0x20/0x190 device_release_driver_internal+0x344/0x460 device_release_driver+0x18/0x24 bus_remove_device+0x198/0x274 device_del+0x310/0xa84...
The buggy address belongs to the object at ffff00000ec28c00 which belongs to the cache kmalloc-512 of size 512 The buggy address is located 200 bytes inside of freed 512-byte region The buggy address belongs to the physical page: page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x4ec28 head: order:2 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0 flags: 0x3fffe0000000040(head|node=0|zone=0|lastcpupid=0x1ffff) page_type: f5(slab) raw: 03fffe0000000040 ffff000008801c80 dead000000000122 0000000000000000 raw: 0000000000000000 0000000080100010 00000000f5000000 0000000000000000head:
03fffe0000000040ffff000008801c80dead0000000001220000000000000000
head: 0000000000000000 000000008010001000000000f50000000000000000000000
head:03fffe0000000002fffffdffc03b0a0100000000ffffffff00000000ffffffff
head: ffffffffffffffff 000000000000000000000000ffffffff0000000000000004page dumped because: kasan: bad access detected Memory state around the buggy address: ffff00000ec28b80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc ffff00000ec28c00: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb >ffff00000ec28c80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ^ ffff00000ec28d00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ffff00000ec28d80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ==================================================================Add
disable_delayed_work_sync()ingaokun_ucsi_remove()to ensure thatuec->workis properly canceled and prevented from executing after the ucsi andgaokun_ucsistructure have been deallocated.Fixes 00327d7f2c8c ("usb: typec: ucsi: add Huawei Matebook E Go ucsi driver")Signed-off-by Duoming Zhou <[email protected]>--- drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c | 1 + 1 file changed, 1 insertion(+)drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c +0
-0@@ -503,6 +503,7 @@ static void gaokun_ucsi_remove(struct auxiliary_device *adev) {struct gaokun_ucsi *uec =auxiliary_get_drvdata (adev);
Quoted 10 lines
Quoted 8 lines
drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c +1
-0+disable_delayed_work_sync (&uec->work);gaokun_ec_unregister_notify (uec->ec, &uec->nb);ucsi_unregister (uec->ucsi);ucsi_destroy (uec->ucsi);Signature · 1 line
2.34.1What changed from v1?
The original patch[1] only fixes the probe failure in gaokun_ucsi_probe(). This new version is a patch series that also addresses the use-after-free issue.
Greg KH
maintainerRe: [PATCH v2 2/2] usb: typec: ucsi: fix use-after-free caused by uec->work
Quoted 132 lines · On Tue, Nov 25, 2025 at 08:02:40PM +0800, [email protected] wrote:
Quoted 120 lines · Greg KH
Quoted 120 lines
The delayed work
uec->workis scheduled ingaokun_ucsi_probe()but never properly canceled ingaokun_ucsi_remove(). This creates use-after-free scenarios where the ucsi andgaokun_ucsistructure are freed afterucsi_destroy()completes execution, while thegaokun_ucsi_register_worker()might be either currently executing or still pending in the work queue. The already-freedgaokun_ucsior ucsi structure may then be accessed.Furthermore, the race window is 3 seconds, which is sufficiently long to make this bug easily reproducible. The following is the trace captured by KASAN:
==================================================================
BUG: KASAN: slab-use-after-free in __run_timers+0x5ec/0x630 Write of size 8 at addr ffff00000ec28cc8 by task swapper/0/0 ... Call trace: show_stack+0x18/0x24 (C) dump_stack_lvl+0x78/0x90 print_report+0x114/0x580 kasan_report+0xa4/0xf0 __asan_report_store8_noabort+0x20/0x2c __run_timers+0x5ec/0x630 run_timer_softirq+0xe8/0x1cc handle_softirqs+0x294/0x720 __do_softirq+0x14/0x20 ____do_softirq+0x10/0x1c call_on_irq_stack+0x30/0x48 do_softirq_own_stack+0x1c/0x28 __irq_exit_rcu+0x27c/0x364 irq_exit_rcu+0x10/0x1c el1_interrupt+0x40/0x60 el1h_64_irq_handler+0x18/0x24 el1h_64_irq+0x6c/0x70 arch_local_irq_enable+0x4/0x8 (P) do_idle+0x334/0x458 cpu_startup_entry+0x60/0x70 rest_init+0x158/0x174 start_kernel+0x2f8/0x394 __primary_switched+0x8c/0x94 Allocated by task 72 on cpu 0 at 27.510341s: kasan_save_stack+0x2c/0x54 kasan_save_track+0x24/0x5c kasan_save_alloc_info+0x40/0x54 __kasan_kmalloc+0xa0/0xb8 __kmalloc_node_track_caller_noprof+0x1c0/0x588 devm_kmalloc+0x7c/0x1c8 gaokun_ucsi_probe+0xa0/0x840 auxiliary_bus_probe+0x94/0xf8 really_probe+0x17c/0x5b8 __driver_probe_device+0x158/0x2c4 driver_probe_device+0x10c/0x264 __device_attach_driver+0x168/0x2d0 bus_for_each_drv+0x100/0x188 __device_attach+0x174/0x368 device_initial_probe+0x14/0x20 bus_probe_device+0x120/0x150 device_add+0xb3c/0x10fc __auxiliary_device_add+0x88/0x130...
Freed by task 73 on cpu 1 at 28.910627s: kasan_save_stack+0x2c/0x54 kasan_save_track+0x24/0x5c __kasan_save_free_info+0x4c/0x74 __kasan_slab_free+0x60/0x8c kfree+0xd4/0x410 devres_release_all+0x140/0x1f0 device_unbind_cleanup+0x20/0x190 device_release_driver_internal+0x344/0x460 device_release_driver+0x18/0x24 bus_remove_device+0x198/0x274 device_del+0x310/0xa84...
The buggy address belongs to the object at ffff00000ec28c00 which belongs to the cache kmalloc-512 of size 512 The buggy address is located 200 bytes inside of freed 512-byte region The buggy address belongs to the physical page: page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x4ec28 head: order:2 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0 flags: 0x3fffe0000000040(head|node=0|zone=0|lastcpupid=0x1ffff) page_type: f5(slab) raw: 03fffe0000000040 ffff000008801c80 dead000000000122 0000000000000000 raw: 0000000000000000 0000000080100010 00000000f5000000 0000000000000000head:
03fffe0000000040ffff000008801c80dead0000000001220000000000000000
head: 0000000000000000 000000008010001000000000f50000000000000000000000
head:03fffe0000000002fffffdffc03b0a0100000000ffffffff00000000ffffffff
head: ffffffffffffffff 000000000000000000000000ffffffff0000000000000004page dumped because: kasan: bad access detected Memory state around the buggy address: ffff00000ec28b80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc ffff00000ec28c00: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb >ffff00000ec28c80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ^ ffff00000ec28d00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ffff00000ec28d80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ==================================================================Add
disable_delayed_work_sync()ingaokun_ucsi_remove()to ensure thatuec->workis properly canceled and prevented from executing after the ucsi andgaokun_ucsistructure have been deallocated.Fixes 00327d7f2c8c ("usb: typec: ucsi: add Huawei Matebook E Go ucsi driver")Signed-off-by Duoming Zhou <[email protected]>--- drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c | 1 + 1 file changed, 1 insertion(+)drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c +0
-0@@ -503,6 +503,7 @@ static void gaokun_ucsi_remove(struct auxiliary_device *adev) {struct gaokun_ucsi *uec =auxiliary_get_drvdata (adev);Quoted 10 lines
Quoted 8 lines
drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c +1
-0+disable_delayed_work_sync (&uec->work);gaokun_ec_unregister_notify (uec->ec, &uec->nb);ucsi_unregister (uec->ucsi);ucsi_destroy (uec->ucsi);Signature · 1 line
2.34.1What changed from v1?
Quoted 5 lines
The original patch[1] only fixes the probe failure in
gaokun_ucsi_probe(). This new version is a patch series that also addresses the use-after-free issue.
Always document this in the future please.
Re: [PATCH v2 1/2] usb: typec: ucsi: fix probe failure in gaokun_ucsi_probe()
In reply to Duoming ZhouTue, Nov 25, 2025 at 06:36:26PM +0800, Duoming Zhou kirjoitti:
Quoted 6 lines
The
gaokun_ucsi_probe()usesucsi_create()to allocate a UCSI instance. Theucsi_create()validates whetherops->poll_cciis defined, and if not, it directly returns-EINVAL. However, thegaokun_ucsi_opsstructure does not define thepoll_cci, causingucsi_create()always fail with-EINVAL. This issue can be observed in the kernel log with the following error:
Quoted 8 lines
ucsi_huawei_gaokun.ucsi huawei_gaokun_ec.ucsi.0: probe with driver ucsi_huawei_gaokun.ucsi failed with error -22
Fix the issue by adding the missing
poll_ccicallback togaokun_ucsi_ops.Fixes 00327d7f2c8c ("usb: typec: ucsi: add Huawei Matebook E Go ucsi driver")Signed-off-by Duoming Zhou <[email protected]>
Quoted 22 lines
---
Changes in v2:
- Add cc: stable.
- Correct spelling mistake.drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c | 1 + 1 file changed, 1 insertion(+)drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c +1
-0@@ -196,6 +196,7 @@ static void gaokun_ucsi_connector_status(struct ucsi_connector *con)const struct ucsi_operations gaokun_ucsi_ops = { .read_version = gaokun_ucsi_read_version, .read_cci = gaokun_ucsi_read_cci, + .poll_cci = gaokun_ucsi_read_cci, .read_message_in = gaokun_ucsi_read_message_in, .sync_control = ucsi_sync_control_common, .async_control = gaokun_ucsi_async_control,Signature · 1 line
2.34.1
Signature · 1 line
heikki
Re: [PATCH v2 2/2] usb: typec: ucsi: fix use-after-free caused by uec->work
In reply to Duoming ZhouTue, Nov 25, 2025 at 06:36:27PM +0800, Duoming Zhou kirjoitti:
Quoted 101 lines
The delayed work
uec->workis scheduled ingaokun_ucsi_probe()but never properly canceled ingaokun_ucsi_remove(). This creates use-after-free scenarios where the ucsi andgaokun_ucsistructure are freed afterucsi_destroy()completes execution, while thegaokun_ucsi_register_worker()might be either currently executing or still pending in the work queue. The already-freedgaokun_ucsior ucsi structure may then be accessed.Furthermore, the race window is 3 seconds, which is sufficiently long to make this bug easily reproducible. The following is the trace captured by KASAN:
==================================================================
BUG: KASAN: slab-use-after-free in __run_timers+0x5ec/0x630 Write of size 8 at addr ffff00000ec28cc8 by task swapper/0/0 ... Call trace: show_stack+0x18/0x24 (C) dump_stack_lvl+0x78/0x90 print_report+0x114/0x580 kasan_report+0xa4/0xf0 __asan_report_store8_noabort+0x20/0x2c __run_timers+0x5ec/0x630 run_timer_softirq+0xe8/0x1cc handle_softirqs+0x294/0x720 __do_softirq+0x14/0x20 ____do_softirq+0x10/0x1c call_on_irq_stack+0x30/0x48 do_softirq_own_stack+0x1c/0x28 __irq_exit_rcu+0x27c/0x364 irq_exit_rcu+0x10/0x1c el1_interrupt+0x40/0x60 el1h_64_irq_handler+0x18/0x24 el1h_64_irq+0x6c/0x70 arch_local_irq_enable+0x4/0x8 (P) do_idle+0x334/0x458 cpu_startup_entry+0x60/0x70 rest_init+0x158/0x174 start_kernel+0x2f8/0x394 __primary_switched+0x8c/0x94 Allocated by task 72 on cpu 0 at 27.510341s: kasan_save_stack+0x2c/0x54 kasan_save_track+0x24/0x5c kasan_save_alloc_info+0x40/0x54 __kasan_kmalloc+0xa0/0xb8 __kmalloc_node_track_caller_noprof+0x1c0/0x588 devm_kmalloc+0x7c/0x1c8 gaokun_ucsi_probe+0xa0/0x840 auxiliary_bus_probe+0x94/0xf8 really_probe+0x17c/0x5b8 __driver_probe_device+0x158/0x2c4 driver_probe_device+0x10c/0x264 __device_attach_driver+0x168/0x2d0 bus_for_each_drv+0x100/0x188 __device_attach+0x174/0x368 device_initial_probe+0x14/0x20 bus_probe_device+0x120/0x150 device_add+0xb3c/0x10fc __auxiliary_device_add+0x88/0x130...
Freed by task 73 on cpu 1 at 28.910627s: kasan_save_stack+0x2c/0x54 kasan_save_track+0x24/0x5c __kasan_save_free_info+0x4c/0x74 __kasan_slab_free+0x60/0x8c kfree+0xd4/0x410 devres_release_all+0x140/0x1f0 device_unbind_cleanup+0x20/0x190 device_release_driver_internal+0x344/0x460 device_release_driver+0x18/0x24 bus_remove_device+0x198/0x274 device_del+0x310/0xa84...
The buggy address belongs to the object at ffff00000ec28c00 which belongs to the cache kmalloc-512 of size 512 The buggy address is located 200 bytes inside of freed 512-byte region The buggy address belongs to the physical page: page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x4ec28 head: order:2 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0 flags: 0x3fffe0000000040(head|node=0|zone=0|lastcpupid=0x1ffff) page_type: f5(slab) raw: 03fffe0000000040 ffff000008801c80 dead000000000122 0000000000000000 raw: 0000000000000000 0000000080100010 00000000f5000000 0000000000000000head:
03fffe0000000040ffff000008801c80dead0000000001220000000000000000
head: 0000000000000000 000000008010001000000000f50000000000000000000000
head:03fffe0000000002fffffdffc03b0a0100000000ffffffff00000000ffffffff
head: ffffffffffffffff 000000000000000000000000ffffffff0000000000000004page dumped because: kasan: bad access detected Memory state around the buggy address: ffff00000ec28b80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc ffff00000ec28c00: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb >ffff00000ec28c80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ^ ffff00000ec28d00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ffff00000ec28d80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ==================================================================
Quoted 7 lines
Add
disable_delayed_work_sync()ingaokun_ucsi_remove()to ensure thatuec->workis properly canceled and prevented from executing after the ucsi andgaokun_ucsistructure have been deallocated.Fixes 00327d7f2c8c ("usb: typec: ucsi: add Huawei Matebook E Go ucsi driver")Signed-off-by Duoming Zhou <[email protected]>
Quoted 18 lines
--- drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c | 1 + 1 file changed, 1 insertion(+)drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c +1
-0@@ -503,6 +503,7 @@ static void gaokun_ucsi_remove(struct auxiliary_device *adev) {struct gaokun_ucsi *uec =auxiliary_get_drvdata (adev); +disable_delayed_work_sync (&uec->work);gaokun_ec_unregister_notify (uec->ec, &uec->nb);ucsi_unregister (uec->ucsi);ucsi_destroy (uec->ucsi);Signature · 1 line
2.34.1
Signature · 1 line
heikki
Greg KH
maintainerRe: [PATCH v2 1/2] usb: typec: ucsi: fix probe failure in gaokun_ucsi_probe()
In reply to Duoming ZhouQuoted 37 lines · Duoming Zhou
The
gaokun_ucsi_probe()usesucsi_create()to allocate a UCSI instance. Theucsi_create()validates whetherops->poll_cciis defined, and if not, it directly returns-EINVAL. However, thegaokun_ucsi_opsstructure does not define thepoll_cci, causingucsi_create()always fail with-EINVAL. This issue can be observed in the kernel log with the following error:ucsi_huawei_gaokun.ucsi huawei_gaokun_ec.ucsi.0: probe with driver ucsi_huawei_gaokun.ucsi failed with error -22
Fix the issue by adding the missing
poll_ccicallback togaokun_ucsi_ops.Fixes 00327d7f2c8c ("usb: typec: ucsi: add Huawei Matebook E Go ucsi driver")Signed-off-by Duoming Zhou <[email protected]>---
Changes in v2:
- Add cc: stable.
- Correct spelling mistake.drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c | 1 + 1 file changed, 1 insertion(+)drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c +1
-0@@ -196,6 +196,7 @@ static void gaokun_ucsi_connector_status(struct ucsi_connector *con)const struct ucsi_operations gaokun_ucsi_ops = { .read_version = gaokun_ucsi_read_version, .read_cci = gaokun_ucsi_read_cci, + .poll_cci = gaokun_ucsi_read_cci, .read_message_in = gaokun_ucsi_read_message_in, .sync_control = ucsi_sync_control_common, .async_control = gaokun_ucsi_async_control,Signature · 1 line
2.34.1
What ever happened to this? if it is still needed, please rebase against 6.19-rc1 and resend.
thanks,
greg k-h