Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mISDN: annotate data-race around dev->work

dev->work can re read locklessly in mISDN_read()
and mISDN_poll(). Add READ_ONCE()/WRITE_ONCE() annotations.

BUG: KCSAN: data-race in mISDN_ioctl / mISDN_read

write to 0xffff88812d848280 of 4 bytes by task 10864 on cpu 1:
misdn_add_timer drivers/isdn/mISDN/timerdev.c:175 [inline]
mISDN_ioctl+0x2fb/0x550 drivers/isdn/mISDN/timerdev.c:233
vfs_ioctl fs/ioctl.c:51 [inline]
__do_sys_ioctl fs/ioctl.c:597 [inline]
__se_sys_ioctl+0xce/0x140 fs/ioctl.c:583
__x64_sys_ioctl+0x43/0x50 fs/ioctl.c:583
x64_sys_call+0x14b0/0x3000 arch/x86/include/generated/asm/syscalls_64.h:17
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xd8/0x2c0 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f

read to 0xffff88812d848280 of 4 bytes by task 10857 on cpu 0:
mISDN_read+0x1f2/0x470 drivers/isdn/mISDN/timerdev.c:112
do_loop_readv_writev fs/read_write.c:847 [inline]
vfs_readv+0x3fb/0x690 fs/read_write.c:1020
do_readv+0xe7/0x210 fs/read_write.c:1080
__do_sys_readv fs/read_write.c:1165 [inline]
__se_sys_readv fs/read_write.c:1162 [inline]
__x64_sys_readv+0x45/0x50 fs/read_write.c:1162
x64_sys_call+0x2831/0x3000 arch/x86/include/generated/asm/syscalls_64.h:20
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xd8/0x2c0 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f

value changed: 0x00000000 -> 0x00000001

Fixes: 1b2b03f8e514 ("Add mISDN core files")
Reported-by: syzbot <syzkaller@googlegroups.com>
Signed-off-by: Eric Dumazet <edumazet@google.com>
Link: https://patch.msgid.link/20260118132528.2349573-1-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Eric Dumazet and committed by
Jakub Kicinski
8175dbf1 3d778e65

+8 -5
+8 -5
drivers/isdn/mISDN/timerdev.c
··· 109 109 spin_unlock_irq(&dev->lock); 110 110 if (filep->f_flags & O_NONBLOCK) 111 111 return -EAGAIN; 112 - wait_event_interruptible(dev->wait, (dev->work || 112 + wait_event_interruptible(dev->wait, (READ_ONCE(dev->work) || 113 113 !list_empty(list))); 114 114 if (signal_pending(current)) 115 115 return -ERESTARTSYS; 116 116 spin_lock_irq(&dev->lock); 117 117 } 118 118 if (dev->work) 119 - dev->work = 0; 119 + WRITE_ONCE(dev->work, 0); 120 120 if (!list_empty(list)) { 121 121 timer = list_first_entry(list, struct mISDNtimer, list); 122 122 list_del(&timer->list); ··· 141 141 if (*debug & DEBUG_TIMER) 142 142 printk(KERN_DEBUG "%s(%p, %p)\n", __func__, filep, wait); 143 143 if (dev) { 144 + u32 work; 145 + 144 146 poll_wait(filep, &dev->wait, wait); 145 147 mask = 0; 146 - if (dev->work || !list_empty(&dev->expired)) 148 + work = READ_ONCE(dev->work); 149 + if (work || !list_empty(&dev->expired)) 147 150 mask |= (EPOLLIN | EPOLLRDNORM); 148 151 if (*debug & DEBUG_TIMER) 149 152 printk(KERN_DEBUG "%s work(%d) empty(%d)\n", __func__, 150 - dev->work, list_empty(&dev->expired)); 153 + work, list_empty(&dev->expired)); 151 154 } 152 155 return mask; 153 156 } ··· 175 172 struct mISDNtimer *timer; 176 173 177 174 if (!timeout) { 178 - dev->work = 1; 175 + WRITE_ONCE(dev->work, 1); 179 176 wake_up_interruptible(&dev->wait); 180 177 id = 0; 181 178 } else {