net/mac80211/debugfs_sta.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
#syz test git://git.kernel.org/pub/scm/linux/kernel/git/wireless/wireless-next.git main
A NULL pointer dereference may occur in ieee80211_sta_debugfs_remove()
when debugfs_remove_recursive() is called on a dentry whose inode has
already been freed. This can happen due to a race between STA teardown
and debugfs cleanup.
Fix this by checking that both sta->debugfs_dir and its d_inode are
valid before invoking debugfs_remove_recursive().
This avoids the crash reported in syzbot bug:
wlan1: send auth to aa:09:b7:99:c0:d7 (try 2/3)
wlan1: send auth to aa:09:b7:99:c0:d7 (try 3/3)
wlan1: authentication with aa:09:b7:99:c0:d7 timed out
Oops: general protection fault, probably for non-canonical address 0xdffffc0000000029: 0000 [#1] SMP KASAN NOPTI
KASAN: null-ptr-deref in range [0x0000000000000148-0x000000000000014f]
CPU: 0 UID: 0 PID: 171 Comm: kworker/u4:4 Not tainted 6.16.0-rc7-syzkaller #0 PREEMPT(full)
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2~bpo12+1 04/01/2014
Workqueue: events_unbound cfg80211_wiphy_work
RIP: 0010:kasan_byte_accessible+0x12/0x30 mm/kasan/generic.c:199
Code: 0f 1f 84 00 00 00 00 00 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 66 0f 1f 00 48 c1 ef 03 48 b8 00 00 00 00 00 fc ff df <0f> b6 04 07 3c 08 0f 92 c0 c3 cc cc cc cc cc 66 66 66 66 66 66 2e
RSP: 0018:ffffc90001977400 EFLAGS: 00010202
RAX: dffffc0000000000 RBX: ffffffff8b713286 RCX: ca5c1933e35f3700
RDX: 0000000000000000 RSI: ffffffff8b713286 RDI: 0000000000000029
RBP: ffffffff824067f0 R08: 0000000000000001 R09: 0000000000000000
R10: dffffc0000000000 R11: ffffed10085cf24c R12: 0000000000000000
R13: 0000000000000148 R14: 0000000000000148 R15: 0000000000000001
FS: 0000000000000000(0000) GS:ffff88808d218000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000001b2f55ffff CR3: 000000005030a000 CR4: 0000000000352ef0
Call Trace:
<TASK>
__kasan_check_byte+0x12/0x40 mm/kasan/common.c:556
kasan_check_byte include/linux/kasan.h:399 [inline]
lock_acquire+0x8d/0x360 kernel/locking/lockdep.c:5845
down_write+0x96/0x1f0 kernel/locking/rwsem.c:1577
inode_lock include/linux/fs.h:869 [inline]
simple_recursive_removal+0x90/0x690 fs/libfs.c:616
debugfs_remove+0x5b/0x70 fs/debugfs/inode.c:805
ieee80211_sta_debugfs_remove+0x40/0x70 net/mac80211/debugfs_sta.c:1279
__sta_info_destroy_part2+0x352/0x450 net/mac80211/sta_info.c:1501
__sta_info_destroy net/mac80211/sta_info.c:1517 [inline]
sta_info_destroy_addr+0xf5/0x140 net/mac80211/sta_info.c:1529
ieee80211_destroy_auth_data+0x12d/0x260 net/mac80211/mlme.c:4597
ieee80211_sta_work+0x11cf/0x3600 net/mac80211/mlme.c:8310
cfg80211_wiphy_work+0x2df/0x460 net/wireless/core.c:435
process_one_work kernel/workqueue.c:3238 [inline]
process_scheduled_works+0xae1/0x17b0 kernel/workqueue.c:3321
worker_thread+0x8a0/0xda0 kernel/workqueue.c:3402
kthread+0x70e/0x8a0 kernel/kthread.c:464
ret_from_fork+0x3fc/0x770 arch/x86/kernel/process.c:148
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245
</TASK>
---
net/mac80211/debugfs_sta.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/net/mac80211/debugfs_sta.c b/net/mac80211/debugfs_sta.c
index 49061bd4151b..912b69abab52 100644
--- a/net/mac80211/debugfs_sta.c
+++ b/net/mac80211/debugfs_sta.c
@@ -1276,7 +1276,8 @@ void ieee80211_sta_debugfs_add(struct sta_info *sta)
void ieee80211_sta_debugfs_remove(struct sta_info *sta)
{
- debugfs_remove_recursive(sta->debugfs_dir);
+ if (sta->debugfs_dir && sta->debugfs_dir->d_inode)
+ debugfs_remove_recursive(sta->debugfs_dir);
sta->debugfs_dir = NULL;
}
--
2.43.0
On Wed, Jul 23, 2025 at 11:40:52PM -0700, Moon Hee Lee wrote: > #syz test git://git.kernel.org/pub/scm/linux/kernel/git/wireless/wireless-next.git main > > A NULL pointer dereference may occur in ieee80211_sta_debugfs_remove() > when debugfs_remove_recursive() is called on a dentry whose inode has > already been freed. This can happen due to a race between STA teardown > and debugfs cleanup. > > Fix this by checking that both sta->debugfs_dir and its d_inode are > valid before invoking debugfs_remove_recursive(). > void ieee80211_sta_debugfs_remove(struct sta_info *sta) > { > - debugfs_remove_recursive(sta->debugfs_dir); > + if (sta->debugfs_dir && sta->debugfs_dir->d_inode) > + debugfs_remove_recursive(sta->debugfs_dir); > sta->debugfs_dir = NULL; > } It might paper over the specific reproducer, but that's not a fix... I'm not familiar with that code; will check the details, but in this form it is obviously still racy. NAK.
On Thu, Jul 24, 2025 at 8:58 AM Al Viro <viro@zeniv.linux.org.uk> wrote: > It might paper over the specific reproducer, but that's not a fix... > I'm not familiar with that code; will check the details, but in > this form it is obviously still racy. Thanks for the feedback, Al. Agreed, this only papers over the issue. I'm tracing the sta_info_destroy() path to confirm the race and will follow up with a proper fix if confirmed. -- moon
On Thu, Jul 24, 2025 at 10:29:47AM -0700, Moon Hee Lee wrote: > On Thu, Jul 24, 2025 at 8:58 AM Al Viro <viro@zeniv.linux.org.uk> wrote: > > It might paper over the specific reproducer, but that's not a fix... > > I'm not familiar with that code; will check the details, but in > > this form it is obviously still racy. > > Thanks for the feedback, Al. > > Agreed, this only papers over the issue. I'm tracing the > sta_info_destroy() path to confirm the race and will follow up with a > proper fix if confirmed. Note that if you have nested subtrees, you have to be very careful about removals - after all, removal of the bigger one drops the references we are holding to the roots of the smaller ones.
On Thu, 24 Jul 2025 10:29:47 -0700 Moon Hee Lee wrote: > On Thu, Jul 24, 2025 at 8:58 AM Al Viro <viro@zeniv.linux.org.uk> wrote: > > It might paper over the specific reproducer, but that's not a fix... > > I'm not familiar with that code; will check the details, but in > > this form it is obviously still racy. > > Thanks for the feedback, Al. > > Agreed, this only papers over the issue. I'm tracing the > sta_info_destroy() path to confirm the race and will follow up with a > proper fix if confirmed. > A look at net/mac80211/debugfs_netdev.c:1021 [1] helps to prepare a proper fix. [1] https://lore.kernel.org/lkml/6881aed3.a00a0220.2f88df.000b.GAE@google.com/
Hello, syzbot has tested the proposed patch and the reproducer did not trigger any issue: Reported-by: syzbot+d6ccd49ae046542a0641@syzkaller.appspotmail.com Tested-by: syzbot+d6ccd49ae046542a0641@syzkaller.appspotmail.com Tested on: commit: 3630f043 Merge tag 'iwlwifi-next-2025-07-23' of https:.. git tree: git://git.kernel.org/pub/scm/linux/kernel/git/wireless/wireless-next.git main console output: https://syzkaller.appspot.com/x/log.txt?x=16a740a2580000 kernel config: https://syzkaller.appspot.com/x/.config?x=51ebcb9cd994f900 dashboard link: https://syzkaller.appspot.com/bug?extid=d6ccd49ae046542a0641 compiler: Debian clang version 20.1.7 (++20250616065708+6146a88f6049-1~exp1~20250616065826.132), Debian LLD 20.1.7 patch: https://syzkaller.appspot.com/x/patch.diff?x=1449d0a2580000 Note: testing is done by a robot and is best-effort only.
© 2016 - 2025 Red Hat, Inc.