Dear developers and maintainers,
We encountered a kernel warning in function ax25_dev_device_down
during testing using our modified syzkaller. It is tested against the
latest upstream linux (6.9-rc3). C repro and kernel config are
attached to this email. Kernel log is listed below.
```
WARNING: CPU: 0 PID: 8121 at lib/ref_tracker.c:255
ref_tracker_free+0x610/0x830 lib/ref_tracker.c:255
Modules linked in:
CPU: 0 PID: 8121 Comm: syz-executor329 Not tainted 6.7.0-rc7 #2
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.15.0-1 04/01/2014
RIP: 0010:ref_tracker_free+0x610/0x830 lib/ref_tracker.c:255
Code: 00 00 44 8b 73 18 31 ff 44 89 f6 e8 7a 58 fe fc 45 85 f6 0f 85
a7 00 00 00 e8 4c 5c fe fc 4c 89 ee 48 89 ef e8 11 0a e5 05 90 <0f> 0b
90 41 bd ea ff ff ff e9 51 fd ff ff e8 2d 5c fe fc 4c 8d 75
RSP: 0018:ffffc900029bf8b8 EFLAGS: 00010286
RAX: 0000000080000000 RBX: ffff888106185480 RCX: 0000000000000000
RDX: 0000000000000001 RSI: 0000000000000001 RDI: 0000000000000001
RBP: ffff8881136c85b8 R08: 0000000000000001 R09: fffffbfff23e8bd1
R10: 0000000000000001 R11: 0000000000000001 R12: 1ffff92000537f19
R13: 0000000000000292 R14: 00000000067a01d1 R15: ffff888106185498
FS: 0000555556e663c0(0000) GS:ffff888063a00000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007fc148041ba8 CR3: 0000000016374000 CR4: 0000000000750ef0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
PKRU: 55555554
Call Trace:
<TASK>
netdev_tracker_free include/linux/netdevice.h:4127 [inline]
netdev_put include/linux/netdevice.h:4144 [inline]
netdev_put include/linux/netdevice.h:4140 [inline]
ax25_dev_device_down+0x2bc/0x420 net/ax25/ax25_dev.c:140
ax25_device_event+0x4bc/0x650 net/ax25/af_ax25.c:148
notifier_call_chain+0xb6/0x3d0 kernel/notifier.c:93
call_netdevice_notifiers_info+0xbe/0x140 net/core/dev.c:1967
call_netdevice_notifiers_extack net/core/dev.c:2005 [inline]
call_netdevice_notifiers net/core/dev.c:2019 [inline]
__dev_notify_flags+0x1f5/0x2e0 net/core/dev.c:8649
dev_change_flags+0x11b/0x170 net/core/dev.c:8685
change_flags net/core/net-sysfs.c:371 [inline]
netdev_store net/core/net-sysfs.c:100 [inline]
flags_store+0x1ba/0x240 net/core/net-sysfs.c:377
dev_attr_store+0x54/0x80 drivers/base/core.c:2366
sysfs_kf_write+0x114/0x170 fs/sysfs/file.c:136
kernfs_fop_write_iter+0x337/0x500 fs/kernfs/file.c:334
call_write_iter include/linux/fs.h:2020 [inline]
new_sync_write fs/read_write.c:491 [inline]
vfs_write+0x96a/0xd80 fs/read_write.c:584
ksys_write+0x122/0x250 fs/read_write.c:637
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0x40/0x110 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x63/0x6b
RIP: 0033:0x7f80fd95f697
Code: ff ff f7 d8 64 89 02 48 c7 c0 ff ff ff ff eb b7 0f 1f 00 f3 0f
1e fa 64 8b 04 25 18 00 00 00 85 c0 75 10 b8 01 00 00 00 0f 05 <48> 3d
00 f0 ff ff 77 51 c3 48 83 ec 28 48 89 54 24 18 48 89 74 24
RSP: 002b:00007ffed044c0b8 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
RAX: ffffffffffffffda RBX: 0000000000000006 RCX: 00007f80fd95f697
RDX: 0000000000000004 RSI: 00007ffed044c8d0 RDI: 0000000000000007
RBP: 0000000000000007 R08: 000000000000000f R09: 0074656e2d74736f
R10: 0000000000000000 R11: 0000000000000246 R12: 00007ffed044c8d0
R13: 00007ffed044c4d0 R14: 00007f80fd9dd4f0 R15: 0000000000000001
</TASK>
```
If you have any questions, please contact us.
Reported by: Yue Sun <[email protected]>
Reported by: xingwei lee <[email protected]>
Best Regards,
Yue
On Tue, Apr 09, 2024 at 10:02:49PM +0800, Sam Sun wrote:
> Dear developers and maintainers,
>
> We encountered a kernel warning in function ax25_dev_device_down
> during testing using our modified syzkaller. It is tested against the
> latest upstream linux (6.9-rc3). C repro and kernel config are
> attached to this email. Kernel log is listed below.
> ```
> WARNING: CPU: 0 PID: 8121 at lib/ref_tracker.c:255
> ref_tracker_free+0x610/0x830 lib/ref_tracker.c:255
> Modules linked in:
> CPU: 0 PID: 8121 Comm: syz-executor329 Not tainted 6.7.0-rc7 #2
> Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.15.0-1 04/01/2014
> RIP: 0010:ref_tracker_free+0x610/0x830 lib/ref_tracker.c:255
> Code: 00 00 44 8b 73 18 31 ff 44 89 f6 e8 7a 58 fe fc 45 85 f6 0f 85
> a7 00 00 00 e8 4c 5c fe fc 4c 89 ee 48 89 ef e8 11 0a e5 05 90 <0f> 0b
> 90 41 bd ea ff ff ff e9 51 fd ff ff e8 2d 5c fe fc 4c 8d 75
> RSP: 0018:ffffc900029bf8b8 EFLAGS: 00010286
> RAX: 0000000080000000 RBX: ffff888106185480 RCX: 0000000000000000
> RDX: 0000000000000001 RSI: 0000000000000001 RDI: 0000000000000001
> RBP: ffff8881136c85b8 R08: 0000000000000001 R09: fffffbfff23e8bd1
> R10: 0000000000000001 R11: 0000000000000001 R12: 1ffff92000537f19
> R13: 0000000000000292 R14: 00000000067a01d1 R15: ffff888106185498
> FS: 0000555556e663c0(0000) GS:ffff888063a00000(0000) knlGS:0000000000000000
> CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
> CR2: 00007fc148041ba8 CR3: 0000000016374000 CR4: 0000000000750ef0
> DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
> DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
> PKRU: 55555554
> Call Trace:
> <TASK>
> netdev_tracker_free include/linux/netdevice.h:4127 [inline]
> netdev_put include/linux/netdevice.h:4144 [inline]
> netdev_put include/linux/netdevice.h:4140 [inline]
> ax25_dev_device_down+0x2bc/0x420 net/ax25/ax25_dev.c:140
^^^^
The locking in ax25_dev_device_down() seems pretty suspect.
It takes:
ax25_dev = ax25_dev_ax25dev()
then it takes the &ax25_dev_lock, then it drops the lock, then on line
140 mentioned in this stack trace it calls:
netdev_put(dev, &ax25_dev->dev_tracker);
That can race with ax25_dev_free() which has proper locking. The
temptation is to do something like this, but I don't know this code well
and can't test it.
regards,
dan carpenter
diff --git a/net/ax25/ax25_dev.c b/net/ax25/ax25_dev.c
index 282ec581c072..68c2945d6051 100644
--- a/net/ax25/ax25_dev.c
+++ b/net/ax25/ax25_dev.c
@@ -97,13 +97,15 @@ void ax25_dev_device_down(struct net_device *dev)
{
ax25_dev *s, *ax25_dev;
- if ((ax25_dev = ax25_dev_ax25dev(dev)) == NULL)
+ spin_lock_bh(&ax25_dev_lock);
+
+ if ((ax25_dev = ax25_dev_ax25dev(dev)) == NULL) {
+ spin_unlock_bh(&ax25_dev_lock);
return;
+ }
ax25_unregister_dev_sysctl(ax25_dev);
- spin_lock_bh(&ax25_dev_lock);
-
#ifdef CONFIG_AX25_DAMA_SLAVE
timer_shutdown_sync(&ax25_dev->dama.slave_timer);
#endif
@@ -128,17 +130,17 @@ void ax25_dev_device_down(struct net_device *dev)
s = s->next;
}
- spin_unlock_bh(&ax25_dev_lock);
dev->ax25_ptr = NULL;
ax25_dev_put(ax25_dev);
+ spin_unlock_bh(&ax25_dev_lock);
return;
unlock_put:
- spin_unlock_bh(&ax25_dev_lock);
ax25_dev_put(ax25_dev);
dev->ax25_ptr = NULL;
netdev_put(dev, &ax25_dev->dev_tracker);
ax25_dev_put(ax25_dev);
+ spin_unlock_bh(&ax25_dev_lock);
}
int ax25_fwd_ioctl(unsigned int cmd, struct ax25_fwd_struct *fwd)