Netdev List
 help / color / mirror / Atom feed
* [PATCH net v1] mac802154: drain mac_wq before unregistering interfaces
@ 2026-08-28 10:19 Xuanqiang Luo
  2026-08-31  8:10 ` Miquel Raynal
  0 siblings, 1 reply; 3+ messages in thread
From: Xuanqiang Luo @ 2026-08-28 10:19 UTC (permalink / raw)
  To: linux-wpan
  Cc: netdev, linux-kernel, alex.aring, stefan, miquel.raynal, davem,
	edumazet, kuba, pabeni, horms, Xuanqiang Luo

From: Xuanqiang Luo <luoxuanqiang@kylinos.cn>

ieee802154_unregister_hw() unregisters the wpan netdevs before
destroying mac_wq. The RX path stores the receiving sub-interface
(sdata) in the queued MAC command descriptor without taking a
reference to the netdev.

If mac802154_rx_mac_cmd_worker() runs after the netdev has been freed,
it dereferences the stale pointer and triggers a KASAN
slab-use-after-free:

  BUG: KASAN: slab-use-after-free in mac802154_rx_mac_cmd_worker+0xc0/0x498 [mac802154]
  Read of size 8 at addr ffff0000c6db0ba8 by task kworker/u16:3/61
  ...
  Call trace:
   show_stack+0x20/0x38 (C)
   dump_stack_lvl+0x78/0x90
   print_address_description.constprop.0+0x88/0x398
   print_report+0xa8/0x278
   kasan_report+0xa8/0xf8
   __asan_load8+0x9c/0xc0
   mac802154_rx_mac_cmd_worker+0xc0/0x498 [mac802154]
   process_one_work+0x334/0x8b8
  ...
  Allocated by task 630:
   kasan_save_stack+0x2c/0x58
   kasan_save_track+0x20/0x40
   kasan_save_alloc_info+0x40/0x58
   __kasan_kmalloc+0xa0/0xb8
   __kvmalloc_node_noprof+0x1e8/0x588
   alloc_netdev_mqs+0x74/0x7f0
   ieee802154_if_add+0xac/0x630 [mac802154]
   ieee802154_register_hw+0x31c/0x3d0 [mac802154]
   fakelb_add_one+0x250/0x318 [fakelb]
  ...
  Freed by task 652:
   kasan_save_stack+0x2c/0x58
   kasan_save_track+0x20/0x40
   kasan_save_free_info+0x4c/0x78
   __kasan_slab_free+0x60/0x90
   kfree+0x194/0x478
   kvfree+0x44/0x60
   netdev_release+0x4c/0x68
   device_release+0xac/0x130
   kobject_cleanup+0x84/0x248
   kobject_put+0x98/0xf8
   netdev_run_todo+0x3a0/0x5e0
   rtnl_unlock+0x18/0x30
   ieee802154_unregister_hw+0x48/0x90 [mac802154]
   fakelb_remove+0xe8/0x148 [fakelb]

After killing local->tasklet, drain mac_wq before calling
ieee802154_remove_interfaces() so pending work completes before the
interfaces are unregistered. Do this without holding rtnl because scan
and beacon workers acquire it themselves.

Fixes: d021d218f6d9 ("mac802154: Handle received BEACON_REQ")
Signed-off-by: Xuanqiang Luo <luoxuanqiang@kylinos.cn>
---
 net/mac802154/main.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/net/mac802154/main.c b/net/mac802154/main.c
index ea1efef3572ae..dc80184d7d091 100644
--- a/net/mac802154/main.c
+++ b/net/mac802154/main.c
@@ -276,6 +276,11 @@ void ieee802154_unregister_hw(struct ieee802154_hw *hw)
 
 	tasklet_kill(&local->tasklet);
 	flush_workqueue(local->workqueue);
+	/*
+	 * Drain mac_wq before unregistering interfaces; some workers access
+	 * sub-interface data and acquire rtnl themselves.
+	 */
+	drain_workqueue(local->mac_wq);
 
 	rtnl_lock();
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net v1] mac802154: drain mac_wq before unregistering interfaces
  2026-08-28 10:19 [PATCH net v1] mac802154: drain mac_wq before unregistering interfaces Xuanqiang Luo
@ 2026-08-31  8:10 ` Miquel Raynal
  2026-09-01  1:24   ` Xuanqiang Luo
  0 siblings, 1 reply; 3+ messages in thread
From: Miquel Raynal @ 2026-08-31  8:10 UTC (permalink / raw)
  To: Xuanqiang Luo
  Cc: linux-wpan, netdev, linux-kernel, alex.aring, stefan, davem,
	edumazet, kuba, pabeni, horms, Xuanqiang Luo

On 28/08/2026 at 18:19:05 +08, Xuanqiang Luo <xuanqiang.luo@linux.dev> wrote:

> From: Xuanqiang Luo <luoxuanqiang@kylinos.cn>
>
> ieee802154_unregister_hw() unregisters the wpan netdevs before
> destroying mac_wq. The RX path stores the receiving sub-interface
> (sdata) in the queued MAC command descriptor without taking a
> reference to the netdev.
>
> If mac802154_rx_mac_cmd_worker() runs after the netdev has been freed,
> it dereferences the stale pointer and triggers a KASAN
> slab-use-after-free:
>
>   BUG: KASAN: slab-use-after-free in mac802154_rx_mac_cmd_worker+0xc0/0x498 [mac802154]
>   Read of size 8 at addr ffff0000c6db0ba8 by task kworker/u16:3/61
>   ...
>   Call trace:
>    show_stack+0x20/0x38 (C)
>    dump_stack_lvl+0x78/0x90
>    print_address_description.constprop.0+0x88/0x398
>    print_report+0xa8/0x278
>    kasan_report+0xa8/0xf8
>    __asan_load8+0x9c/0xc0
>    mac802154_rx_mac_cmd_worker+0xc0/0x498 [mac802154]
>    process_one_work+0x334/0x8b8
>   ...
>   Allocated by task 630:
>    kasan_save_stack+0x2c/0x58
>    kasan_save_track+0x20/0x40
>    kasan_save_alloc_info+0x40/0x58
>    __kasan_kmalloc+0xa0/0xb8
>    __kvmalloc_node_noprof+0x1e8/0x588
>    alloc_netdev_mqs+0x74/0x7f0
>    ieee802154_if_add+0xac/0x630 [mac802154]
>    ieee802154_register_hw+0x31c/0x3d0 [mac802154]
>    fakelb_add_one+0x250/0x318 [fakelb]
>   ...
>   Freed by task 652:
>    kasan_save_stack+0x2c/0x58
>    kasan_save_track+0x20/0x40
>    kasan_save_free_info+0x4c/0x78
>    __kasan_slab_free+0x60/0x90
>    kfree+0x194/0x478
>    kvfree+0x44/0x60
>    netdev_release+0x4c/0x68
>    device_release+0xac/0x130
>    kobject_cleanup+0x84/0x248
>    kobject_put+0x98/0xf8
>    netdev_run_todo+0x3a0/0x5e0
>    rtnl_unlock+0x18/0x30
>    ieee802154_unregister_hw+0x48/0x90 [mac802154]
>    fakelb_remove+0xe8/0x148 [fakelb]
>
> After killing local->tasklet, drain mac_wq before calling
> ieee802154_remove_interfaces() so pending work completes before the
> interfaces are unregistered. Do this without holding rtnl because scan
> and beacon workers acquire it themselves.
>
> Fixes: d021d218f6d9 ("mac802154: Handle received BEACON_REQ")
> Signed-off-by: Xuanqiang Luo <luoxuanqiang@kylinos.cn>

Missing Cc: stable.

Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>

Thanks,
Miquèl

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net v1] mac802154: drain mac_wq before unregistering interfaces
  2026-08-31  8:10 ` Miquel Raynal
@ 2026-09-01  1:24   ` Xuanqiang Luo
  0 siblings, 0 replies; 3+ messages in thread
From: Xuanqiang Luo @ 2026-09-01  1:24 UTC (permalink / raw)
  To: Miquel Raynal
  Cc: linux-wpan, netdev, linux-kernel, alex.aring, stefan, davem,
	edumazet, kuba, pabeni, horms, Xuanqiang Luo


在 2026/8/31 16:10, Miquel Raynal 写道:
> On 28/08/2026 at 18:19:05 +08, Xuanqiang Luo <xuanqiang.luo@linux.dev> wrote:
>
>> From: Xuanqiang Luo <luoxuanqiang@kylinos.cn>
>>
>> ieee802154_unregister_hw() unregisters the wpan netdevs before
>> destroying mac_wq. The RX path stores the receiving sub-interface
>> (sdata) in the queued MAC command descriptor without taking a
>> reference to the netdev.
>>
>> If mac802154_rx_mac_cmd_worker() runs after the netdev has been freed,
>> it dereferences the stale pointer and triggers a KASAN
>> slab-use-after-free:
>>
>>    BUG: KASAN: slab-use-after-free in mac802154_rx_mac_cmd_worker+0xc0/0x498 [mac802154]
>>    Read of size 8 at addr ffff0000c6db0ba8 by task kworker/u16:3/61
>>    ...
>>    Call trace:
>>     show_stack+0x20/0x38 (C)
>>     dump_stack_lvl+0x78/0x90
>>     print_address_description.constprop.0+0x88/0x398
>>     print_report+0xa8/0x278
>>     kasan_report+0xa8/0xf8
>>     __asan_load8+0x9c/0xc0
>>     mac802154_rx_mac_cmd_worker+0xc0/0x498 [mac802154]
>>     process_one_work+0x334/0x8b8
>>    ...
>>    Allocated by task 630:
>>     kasan_save_stack+0x2c/0x58
>>     kasan_save_track+0x20/0x40
>>     kasan_save_alloc_info+0x40/0x58
>>     __kasan_kmalloc+0xa0/0xb8
>>     __kvmalloc_node_noprof+0x1e8/0x588
>>     alloc_netdev_mqs+0x74/0x7f0
>>     ieee802154_if_add+0xac/0x630 [mac802154]
>>     ieee802154_register_hw+0x31c/0x3d0 [mac802154]
>>     fakelb_add_one+0x250/0x318 [fakelb]
>>    ...
>>    Freed by task 652:
>>     kasan_save_stack+0x2c/0x58
>>     kasan_save_track+0x20/0x40
>>     kasan_save_free_info+0x4c/0x78
>>     __kasan_slab_free+0x60/0x90
>>     kfree+0x194/0x478
>>     kvfree+0x44/0x60
>>     netdev_release+0x4c/0x68
>>     device_release+0xac/0x130
>>     kobject_cleanup+0x84/0x248
>>     kobject_put+0x98/0xf8
>>     netdev_run_todo+0x3a0/0x5e0
>>     rtnl_unlock+0x18/0x30
>>     ieee802154_unregister_hw+0x48/0x90 [mac802154]
>>     fakelb_remove+0xe8/0x148 [fakelb]
>>
>> After killing local->tasklet, drain mac_wq before calling
>> ieee802154_remove_interfaces() so pending work completes before the
>> interfaces are unregistered. Do this without holding rtnl because scan
>> and beacon workers acquire it themselves.
>>
>> Fixes: d021d218f6d9 ("mac802154: Handle received BEACON_REQ")
>> Signed-off-by: Xuanqiang Luo <luoxuanqiang@kylinos.cn>
> Missing Cc: stable.
>
> Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
>
> Thanks,
> Miquèl

Thanks.

I see Sashiko has also found a few new issues, which look valid.
I'll address them as well in the next revision.

pw-bot: cr


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-09-01  1:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-28 10:19 [PATCH net v1] mac802154: drain mac_wq before unregistering interfaces Xuanqiang Luo
2026-08-31  8:10 ` Miquel Raynal
2026-09-01  1:24   ` Xuanqiang Luo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox