Hello,
syzbot has tested the proposed patch but the reproducer still triggered
crash:
witness: userret: returning with the following locks held:
login: witness: userret: returning with the following locks held:
exclusive rrwlock inode r = 0 (0xfffffd806944f708)
#0 witness_lock+0x52e sys/kern/subr_witness.c:1163
#1 rw_enter+0x46d sys/kern/kern_rwlock.c:306
#2 rrw_enter+0x4f sys/kern/kern_rwlock.c:435
#3 VOP_LOCK+0x4b sys/kern/vfs_vops.c:602
#4 vn_write+0x179 vn_lock sys/kern/vfs_vnops.c:561 [inline]
#4 vn_write+0x179 sys/kern/vfs_vnops.c:401
#5 dofilewritev+0x1ac sys/kern/sys_generic.c:364
#6 sys_write+0x83 sys/kern/sys_generic.c:284
#7 syscall+0x552 mi_syscall sys/sys/syscall_mi.h:92 [inline]
#7 syscall+0x552 sys/arch/amd64/amd64/trap.c:555
#8 Xsyscall+0x128
panic: witness_warn
Stopped at db_enter+0x18: addq $0x8,%rsp
TID PID UID PRFLAGS PFLAGS CPU COMMAND
* 80115 18947 0 0 0x4000000 1 syz-executor0
299896 62775 73 0x100010 0 0K syslogd
db_enter() at db_enter+0x18 sys/arch/amd64/amd64/db_interface.c:398
panic() at panic+0x15c sys/kern/subr_prf.c:207
witness_warn(2,0,ffffffff82208600) at witness_warn+0x69e witness_debugger
sys/kern/subr_witness.c:2509 [inline]
witness_warn(2,0,ffffffff82208600) at witness_warn+0x69e
sys/kern/subr_witness.c:1454
userret(ffff800020ab0c78) at userret+0x36a sys/kern/kern_sig.c:1916
syscall(ffff800020b9dab0) at syscall+0x44a mi_syscall_return
sys/sys/syscall_mi.h:115 [inline]
syscall(ffff800020b9dab0) at syscall+0x44a sys/arch/amd64/amd64/trap.c:577
Xsyscall(6,5,c,0,3,7bcb641f0d8) at Xsyscall+0x128
end of kernel
end trace frame: 0x7bf83ff0720, count: 9
ddb{1}>
ddb{1}> set $lines = 0
ddb{1}> set $maxwidth = 0
ddb{1}> show panic
witness_warn
ddb{1}> trace
db_enter() at db_enter+0x18 sys/arch/amd64/amd64/db_interface.c:398
panic() at panic+0x15c sys/kern/subr_prf.c:207
witness_warn(2,0,ffffffff82208600) at witness_warn+0x69e witness_debugger
sys/kern/subr_witness.c:2509 [inline]
witness_warn(2,0,ffffffff82208600) at witness_warn+0x69e
sys/kern/subr_witness.c:1454
userret(ffff800020ab0c78) at userret+0x36a sys/kern/kern_sig.c:1916
syscall(ffff800020b9dab0) at syscall+0x44a mi_syscall_return
sys/sys/syscall_mi.h:115 [inline]
syscall(ffff800020b9dab0) at syscall+0x44a sys/arch/amd64/amd64/trap.c:577
Xsyscall(6,5,c,0,3,7bcb641f0d8) at Xsyscall+0x128
end of kernel
end trace frame: 0x7bf83ff0720, count: -6
ddb{1}> show registers
rdi 0
rsi 0x1
rbp 0xffff800020b9d7f0
rbx 0xffff800020b9d8a0
rdx 0xffff800020ab0c78
rcx 0
rax 0
r8 0xffffffff81419ea3 kprintf+0x173
r9 0x1
r10 0x25
r11 0xde79626c8c0721ef
r12 0x3000000008
r13 0xffff800020b9d800
r14 0x100
r15 0x1
rip 0xffffffff8131c258 db_enter+0x18
cs 0x8
rflags 0x246
rsp 0xffff800020b9d7e0
ss 0x10
db_enter+0x18: addq $0x8,%rsp
ddb{1}> show proc
PROC (syz-executor0) pid=80115 stat=onproc
flags process=0 proc=4000000<THREAD>
pri=32, usrpri=86, nice=20
forw=0xffffffffffffffff, list=0xffff800020ab1658,0xffff800020ab13f0
process=0xffff800020add500 user=0xffff800020b98000,
vmspace=0xfffffd806e792008
estcpu=36, cpticks=4, pctcpu=0.0
user=0, sys=4, intr=0
ddb{1}> ps
PID TID PPID UID S FLAGS WAIT COMMAND
2013 379530 60502 0 2 0 syz-executor1
2013 428993 60502 0 3 0x4000000 inode syz-executor1
2013 491568 60502 0 3 0x4000000 fdlock syz-executor1
18947 285148 63561 0 2 0 syz-executor0
18947 167120 63561 0 3 0x4000080 fsleep syz-executor0
*18947 80115 63561 0 7 0x4000000 syz-executor0
18947 22450 63561 0 2 0x4000000 syz-executor0
60502 276705 30528 0 2 0x482 syz-executor1
63561 214348 30528 0 2 0x482 syz-executor0
30528 207844 10752 0 3 0x82 thrsleep syz-execprog
30528 522672 10752 0 3 0x4000082 thrsleep syz-execprog
30528 44794 10752 0 3 0x4000082 thrsleep syz-execprog
30528 75166 10752 0 3 0x4000082 thrsleep syz-execprog
30528 212739 10752 0 3 0x4000082 thrsleep syz-execprog
30528 519189 10752 0 3 0x4000082 thrsleep syz-execprog
30528 330248 10752 0 3 0x4000082 thrsleep syz-execprog
30528 125884 10752 0 3 0x4000082 thrsleep syz-execprog
30528 101037 10752 0 3 0x4000082 kqread syz-execprog
30528 42905 10752 0 3 0x4000082 thrsleep syz-execprog
10752 82775 3903 0 3 0x10008a pause ksh
3903 34556 86945 0 3 0x92 select sshd
61788 199541 1 0 3 0x100083 ttyin getty
86945 195944 1 0 3 0x80 select sshd
43925 522324 49301 74 3 0x100092 bpf pflogd
49301 141094 1 0 3 0x80 netio pflogd
62775 299896 71049 73 7 0x100010 syslogd
71049 161457 1 0 3 0x100082 netio syslogd
60772 244397 1 77 3 0x100090 poll dhclient
75688 75097 1 0 3 0x80 poll dhclient
45998 76790 0 0 3 0x14200 pgzero zerothread
67986 339506 0 0 3 0x14200 aiodoned aiodoned
87731 468024 0 0 3 0x14200 syncer update
22190 7179 0 0 3 0x14200 cleaner cleaner
56326 485463 0 0 3 0x14200 reaper reaper
37333 92293 0 0 3 0x14200 pgdaemon pagedaemon
43142 159405 0 0 3 0x14200 bored crynlk
5671 370911 0 0 3 0x14200 bored crypto
26260 119428 0 0 3 0x40014200 acpi0 acpi0
94438 239520 0 0 3 0x40014200 idle1
68651 26846 0 0 3 0x14200 bored softnet
73455 294796 0 0 3 0x14200 bored systqmp
95702 363389 0 0 3 0x14200 bored systq
75275 99696 0 0 3 0x40014200 bored softclock
95968 112087 0 0 3 0x40014200 idle0
46729 72175 0 0 3 0x14200 bored smr
1 150433 0 0 3 0x82 wait init
0 0 -1 0 3 0x10200 scheduler swapper
ddb{1}> show all locks
Process 2013 (syz-executor1) thread 0xffff800020ab1658 (428993)
exclusive rrwlock inode r = 0 (0xfffffd807ec56d58)
#0 witness_lock+0x52e sys/kern/subr_witness.c:1163
#1 rw_enter+0x46d sys/kern/kern_rwlock.c:306
#2 rrw_enter+0x4f sys/kern/kern_rwlock.c:435
#3 VOP_LOCK+0x4b sys/kern/vfs_vops.c:602
#4 vn_lock+0x6c sys/kern/vfs_vnops.c:561
#5 vget+0x1c3 sys/kern/vfs_subr.c:672
#6 cache_lookup+0x2cf sys/kern/vfs_cache.c:224
#7 ufs_lookup+0x1ad sys/ufs/ufs/ufs_lookup.c:162
#8 VOP_LOOKUP+0x5b sys/kern/vfs_vops.c:90
#9 vfs_lookup+0x7a5 sys/kern/vfs_lookup.c:567
#10 namei+0x61c sys/kern/vfs_lookup.c:248
#11 ptmioctl+0x3af sys/kern/tty_pty.c:1121
#12 VOP_IOCTL+0x88 sys/kern/vfs_vops.c:290
#13 vn_ioctl+0xb7 sys/kern/vfs_vnops.c:524
#14 sys_ioctl+0x5b8
#15 syscall+0x552 mi_syscall sys/sys/syscall_mi.h:92 [inline]
#15 syscall+0x552 sys/arch/amd64/amd64/trap.c:555
#16 Xsyscall+0x128
exclusive rwlock fdlock r = 0 (0xfffffd807df6c068)
#0 witness_lock+0x52e sys/kern/subr_witness.c:1163
#1 ptmioctl+0xe7 sys/kern/tty_pty.c:1071
#2 VOP_IOCTL+0x88 sys/kern/vfs_vops.c:290
#3 vn_ioctl+0xb7 sys/kern/vfs_vnops.c:524
#4 sys_ioctl+0x5b8
#5 syscall+0x552 mi_syscall sys/sys/syscall_mi.h:92 [inline]
#5 syscall+0x552 sys/arch/amd64/amd64/trap.c:555
#6 Xsyscall+0x128
Process 18947 (syz-executor0) thread 0xffff800020ab0c78 (80115)
exclusive rrwlock inode r = 0 (0xfffffd806944f708)
#0 witness_lock+0x52e sys/kern/subr_witness.c:1163
#1 rw_enter+0x46d sys/kern/kern_rwlock.c:306
#2 rrw_enter+0x4f sys/kern/kern_rwlock.c:435
#3 VOP_LOCK+0x4b sys/kern/vfs_vops.c:602
#4 vn_write+0x179 vn_lock sys/kern/vfs_vnops.c:561 [inline]
#4 vn_write+0x179 sys/kern/vfs_vnops.c:401
#5 dofilewritev+0x1ac sys/kern/sys_generic.c:364
#6 sys_write+0x83 sys/kern/sys_generic.c:284
#7 syscall+0x552 mi_syscall sys/sys/syscall_mi.h:92 [inline]
#7 syscall+0x552 sys/arch/amd64/amd64/trap.c:555
#8 Xsyscall+0x128
Process 62775 (syslogd) thread 0xffff800020ac1158 (299896)
exclusive rrwlock inode r = 0 (0xfffffd807e2dac48)
#0 witness_lock+0x52e sys/kern/subr_witness.c:1163
#1 rw_enter+0x46d sys/kern/kern_rwlock.c:306
#2 rrw_enter+0x4f sys/kern/kern_rwlock.c:435
#3 VOP_LOCK+0x4b sys/kern/vfs_vops.c:602
#4 vn_lock+0x6c sys/kern/vfs_vnops.c:561
#5 sys_fsync+0x114 sys/kern/vfs_syscalls.c:2806
#6 syscall+0x552 mi_syscall sys/sys/syscall_mi.h:92 [inline]
#6 syscall+0x552 sys/arch/amd64/amd64/trap.c:555
#7 Xsyscall+0x128
exclusive kernel_lock &kernel_lock r = 0 (0xffffffff82618c78)
#0 witness_lock+0x52e sys/kern/subr_witness.c:1163
#1 syscall+0x412 mi_syscall sys/sys/syscall_mi.h:83 [inline]
#1 syscall+0x412 sys/arch/amd64/amd64/trap.c:555
#2 Xsyscall+0x128
ddb{1}> show malloc
Type InUse MemUse HighUse Limit Requests Type Lim Kern Lim
devbuf 9469 6388K 6388K 78643K 10556 0 0
pcb 13 8K 8K 78643K 13 0 0
rtable 97 3K 3K 78643K 177 0 0
ifaddr 38 10K 10K 78643K 39 0 0
counters 39 33K 33K 78643K 39 0 0
ioctlops 0 0K 4K 78643K 1469 0 0
mount 1 1K 1K 78643K 1 0 0
vnodes 1198 75K 75K 78643K 39808 0 0
UFS quota 1 32K 32K 78643K 1 0 0
UFS mount 5 36K 36K 78643K 5 0 0
shm 2 1K 1K 78643K 2 0 0
VM map 2 1K 1K 78643K 2 0 0
sem 2 0K 0K 78643K 2 0 0
dirhash 12 2K 2K 78643K 12 0 0
ACPI 1808 196K 290K 78643K 12765 0 0
file desc 5 16K 20K 78643K 17603 0 0
proc 52 50K 71K 78643K 374 0 0
subproc 0 0K 1K 78643K 17 0 0
NFS srvsock 1 0K 0K 78643K 1 0 0
NFS daemon 1 16K 16K 78643K 1 0 0
in_multi 33 2K 2K 78643K 33 0 0
ether_multi 1 0K 0K 78643K 1 0 0
ISOFS mount 1 32K 32K 78643K 1 0 0
MSDOSFS mount 1 16K 16K 78643K 1 0 0
ttys 60 265K 265K 78643K 60 0 0
exec 0 0K 1K 78643K 212 0 0
pagedep 1 8K 8K 78643K 1 0 0
inodedep 1 32K 32K 78643K 1 0 0
newblk 1 0K 0K 78643K 1 0 0
VM swap 7 26K 26K 78643K 7 0 0
UVM amap 87 20K 20K 78643K 53771 0 0
UVM aobj 2 2K 2K 78643K 2 0 0
memdesc 1 4K 4K 78643K 1 0 0
crypto data 1 1K 1K 78643K 1 0 0
NDP 6 0K 0K 78643K 10 0 0
temp 55 3526K 3590K 78643K 38485 0 0
SYN cache 2 16K 16K 78643K 2 0 0
ddb{1}> show all pools
Name Size Requests Fail Releases Pgreq Pgrel Npage Hiwat Minpg Maxpg
Idle
arp 64 4 0 0 1 0 1 1 0
8 0
plcache 128 20 0 0 1 0 1 1 0
8 0
rtpcb 80 15 0 13 1 0 1 1 0
8 0
rtentry 112 41 0 1 2 0 2 2 0
8 0
unpcb 120 41 0 31 1 0 1 1 0
8 0
syncache 264 8 0 8 1 1 0 1 0
8 0
dino1pl 128 57643 0 56214 47 0 47 47 0
8 0
ffsino 272 57643 0 56214 96 0 96 96 0
8 0
nchpl 144 75487 0 73848 61 0 61 61 0
8 0
uvmvnodes 72 5926 0 0 108 0 108 108 0
8 0
vnodes 200 5926 0 0 312 0 312 312 0
8 0
namei 1024 446686 0 446685 1 0 1 1 0
8 0
percpumem 16 30 0 0 1 0 1 1 0
8 0
scxspl 192 144620 0 144619 8 7 1 7 0
8 0
plimitpl 152 20 0 12 1 0 1 1 0
8 0
sigapl 432 17823 0 17807 2 0 2 2 0
8 0
futexpl 56 156212 0 156211 2 1 1 1 0
8 0
knotepl 112 95 0 78 1 0 1 1 0
8 0
kqueuepl 104 3 0 1 1 0 1 1 0
8 0
pipepl 112 218 0 199 1 0 1 1 0
8 0
fdescpl 488 17824 0 17807 3 0 3 3 0
8 0
filepl 152 298445 0 298363 5 1 4 4 0
8 0
lockfpl 104 6 0 6 1 1 0 1 0
8 0
lockfspl 48 3 0 3 1 1 0 1 0
8 0
sessionpl 112 27 0 16 1 0 1 1 0
8 0
pgrppl 48 27 0 16 1 0 1 1 0
8 0
ucredpl 96 274976 0 274967 1 0 1 1 0
8 0
zombiepl 144 17807 0 17807 1 0 1 1 0
8 1
processpl 896 17839 0 17807 4 0 4 4 0
8 0
procpl 632 52968 0 52922 5 1 4 4 0
8 0
sockpl 384 95 0 77 3 1 2 3 0
8 0
mcl4k 4096 3 0 0 1 0 1 1 0
8 0
mcl2k 2048 89 0 0 11 0 11 11 0
8 0
mtagpl 80 1 0 0 1 0 1 1 0
8 0
mbufpl 256 113 0 0 7 0 7 7 0
8 0
bufpl 256 23594 0 16574 439 0 439 439 0
8 0
anonpl 16 973703 0 970998 17 6 11 13 0
124 0
amapchunkpl 152 88654 0 88556 7 3 4 5 0
158 0
amappl16 192 73778 0 73676 7 1 6 6 0
8 0
amappl15 184 2 0 1 2 1 1 1 0
8 0
amappl14 176 8827 0 8816 1 0 1 1 0
8 0
amappl13 168 12 0 12 2 2 0 1 0
8 0
amappl12 160 10 0 9 2 1 1 1 0
8 0
amappl11 152 59 0 44 1 0 1 1 0
8 0
amappl10 144 93 0 91 1 0 1 1 0
8 0
amappl9 136 9633 0 9628 1 0 1 1 0
8 0
amappl8 128 8993 0 8979 1 0 1 1 0
8 0
amappl7 120 41 0 38 1 0 1 1 0
8 0
amappl6 112 82 0 75 1 0 1 1 0
8 0
amappl5 104 180 0 166 1 0 1 1 0
8 0
amappl4 96 18180 0 18151 3 2 1 2 0
8 0
amappl3 88 233 0 222 1 0 1 1 0
8 0
amappl2 80 141759 0 141680 4 2 2 3 0
8 0
amappl1 72 416823 0 416351 30 20 10 20 0
8 0
amappl 80 53194 0 53155 1 0 1 1 0
84 0
dma4096 4096 1 0 1 1 1 0 1 0
8 0
dma256 256 6 0 6 1 1 0 1 0
8 0
dma64 64 259 0 259 1 1 0 1 0
8 0
dma32 32 7 0 7 1 1 0 1 0
8 0
dma16 16 17 0 17 1 1 0 1 0
8 0
aobjpl 64 1 0 0 1 0 1 1 0
8 0
uaddrrnd 24 17824 0 17807 1 0 1 1 0
8 0
uaddrbest 32 2 0 0 1 0 1 1 0
8 0
uaddr 24 17824 0 17807 1 0 1 1 0
8 0
vmmpekpl 168 130135 0 130110 2 0 2 2 0
8 0
vmmpepl 168 1499646 0 1498450 98 46 52 78 0
357 0
vmsppl 368 17823 0 17807 2 0 2 2 0
8 0
pdppl 4096 35655 0 35614 7 1 6 6 0
8 0
pvpl 32 2705102 0 2699710 110 66 44 107 0
265 0
pmappl 232 17823 0 17807 2 1 1 2 0
8 0
extentpl 40 41 0 26 1 0 1 1 0
8 0
phpool 112 585 0 4 17 0 17 17 0
8 0
Tested on:
commit: 92c86d03 enable witness lock trace
console output:
https://syzkaller.appspot.com/x/log.txt?x=16dd1f72600000