syzbot


panic: rw_enter: dklk locking against myself

Status: fixed on 2021/10/10 16:58
Reported-by: syzbot+af49990b75015907fa0e@syzkaller.appspotmail.com
Fix commit: placing the same vnd underneath a vnd (with VNDIOCSET) is a lock violation, but other circumstances are also bad, so let's block all vnd on top of vnd. While here, fix some toctou multiple-copyin of the path, and restructure the ioctl defer all softc updates to the end. ok mpi
First crash: 450d, last: 422d

Sample crash report:
login: panic: rw_enter: dklk locking against myself
Stopped at      db_enter+0x18:  addq    $0x8,%rsp
    TID    PID    UID     PRFLAGS     PFLAGS  CPU  COMMAND
*407192  66264      0         0x2  0x4000000    0  syz-executor1941
db_enter() at db_enter+0x18 sys/arch/amd64/amd64/db_interface.c:440
panic(ffffffff8247f6c9) at panic+0x161 sys/kern/subr_prf.c:202
rw_enter(ffff8000006aa058,11) at rw_enter+0x36f sys/kern/kern_rwlock.c:174
vndopen(2902,3,2000,ffff8000ffff87e8) at vndopen+0x8d sys/dev/vnd.c:185
spec_open(ffff80002169a888) at spec_open+0x3c8 sys/kern/spec_vnops.c:157
VOP_OPEN(fffffd806e3ff848,3,fffffd807f7d8ba0,ffff8000ffff87e8) at VOP_OPEN+0x6c sys/kern/vfs_vops.c:138
vn_open(ffff80002169ab20,3,0) at vn_open+0x467 sys/kern/vfs_vnops.c:183
vndioctl(2902,c0384600,ffff80002169ae40,81,ffff8000ffff87e8) at vndioctl+0xa07 sys/dev/vnd.c:452
VOP_IOCTL(fffffd806e3ff848,c0384600,ffff80002169ae40,81,fffffd807f7d8ba0,ffff8000ffff87e8) at VOP_IOCTL+0x8d sys/kern/vfs_vops.c:264
vn_ioctl(fffffd807320eb48,c0384600,ffff80002169ae40,ffff8000ffff87e8) at vn_ioctl+0xb5 sys/kern/vfs_vnops.c:531
sys_ioctl(ffff8000ffff87e8,ffff80002169af58,ffff80002169afb0) at sys_ioctl+0x49e
syscall(ffff80002169b020) at syscall+0x571 sys/arch/amd64/amd64/trap.c:587
Xsyscall() at Xsyscall+0x128
end of kernel
end trace frame: 0xd579302b000, count: 2
https://www.openbsd.org/ddb.html describes the minimum info required in bug
reports.  Insufficient info makes it difficult to find and fix bugs.
ddb> 
ddb> set $lines = 0
ddb> set $maxwidth = 0
ddb> show panic
*cpu0: rw_enter: dklk locking against myself
ddb> trace
db_enter() at db_enter+0x18 sys/arch/amd64/amd64/db_interface.c:440
panic(ffffffff8247f6c9) at panic+0x161 sys/kern/subr_prf.c:202
rw_enter(ffff8000006aa058,11) at rw_enter+0x36f sys/kern/kern_rwlock.c:174
vndopen(2902,3,2000,ffff8000ffff87e8) at vndopen+0x8d sys/dev/vnd.c:185
spec_open(ffff80002169a888) at spec_open+0x3c8 sys/kern/spec_vnops.c:157
VOP_OPEN(fffffd806e3ff848,3,fffffd807f7d8ba0,ffff8000ffff87e8) at VOP_OPEN+0x6c sys/kern/vfs_vops.c:138
vn_open(ffff80002169ab20,3,0) at vn_open+0x467 sys/kern/vfs_vnops.c:183
vndioctl(2902,c0384600,ffff80002169ae40,81,ffff8000ffff87e8) at vndioctl+0xa07 sys/dev/vnd.c:452
VOP_IOCTL(fffffd806e3ff848,c0384600,ffff80002169ae40,81,fffffd807f7d8ba0,ffff8000ffff87e8) at VOP_IOCTL+0x8d sys/kern/vfs_vops.c:264
vn_ioctl(fffffd807320eb48,c0384600,ffff80002169ae40,ffff8000ffff87e8) at vn_ioctl+0xb5 sys/kern/vfs_vnops.c:531
sys_ioctl(ffff8000ffff87e8,ffff80002169af58,ffff80002169afb0) at sys_ioctl+0x49e
syscall(ffff80002169b020) at syscall+0x571 sys/arch/amd64/amd64/trap.c:587
Xsyscall() at Xsyscall+0x128
end of kernel
end trace frame: 0xd579302b000, count: -13
ddb> show registers
rdi                                0
rsi                              0x1
rbp               0xffff80002169a650
rbx                              0x4
rdx                             0x8b
rcx                              0x2
rax                             0x2d
r8                0xffffffff816b3695    kprintf+0x145
r9                               0x1
r10               0xfe16f6493c46bd6e
r11               0xc4be0aa87f9f6cd8
r12                                0
r13               0xffff8000ffff87ec
r14                                0
r15                              0x1
rip               0xffffffff81036b58    db_enter+0x18
cs                               0x8
rflags                         0x246
rsp               0xffff80002169a640
ss                              0x10
db_enter+0x18:  addq    $0x8,%rsp
ddb> show proc
PROC (syz-executor1941) pid=407192 stat=onproc
    flags process=2<EXEC> proc=4000000<THREAD>
    pri=32, usrpri=53, nice=20
    forw=0xffffffffffffffff, list=0xffff8000ffff8a88,0xffffffff829337f0
    process=0xffff8000ffff73c0 user=0xffff800021696000, vmspace=0xfffffd807f00b550
    estcpu=3, cpticks=0, pctcpu=0.0
    user=0, sys=0, intr=0
ddb> ps
   PID     TID   PPID    UID  S       FLAGS  WAIT          COMMAND
 66264  318256  33013      0  2         0x2                syz-executor1941
*66264  407192  33013      0  7   0x4000002                syz-executor1941
 33013  518112  67422      0  3    0x10008a  sigsusp       ksh
 67422  396821  27718      0  3        0x9a  select        sshd
 57434  439925      1      0  3    0x100083  ttyin         getty
 27718  100963      1      0  3        0x88  select        sshd
 15252  220668  96216     73  3    0x100090  kqread        syslogd
 96216   75708      1      0  3    0x100082  netio         syslogd
 93030   97484      1      0  3    0x100080  kqread        resolvd
 77844   23199  53652     77  3    0x100092  kqread        dhcpleased
 41901  367874  53652     77  3    0x100092  kqread        dhcpleased
 53652  368385      1      0  3        0x80  kqread        dhcpleased
 70662  351610      0      0  3     0x14200  bored         smr
 18873  340960      0      0  2     0x14200                zerothread
 57925  492904      0      0  3     0x14200  aiodoned      aiodoned
 93501  391128      0      0  3     0x14200  syncer        update
  7236  440225      0      0  3     0x14200  cleaner       cleaner
 37910   43541      0      0  3     0x14200  reaper        reaper
 86593  417391      0      0  3     0x14200  pgdaemon      pagedaemon
 43909  376950      0      0  3     0x14200  bored         crynlk
 34151  242648      0      0  3     0x14200  bored         crypto
 97091  478150      0      0  3     0x14200  bored         viomb
 93393  418114      0      0  3  0x40014200  acpi0         acpi0
 63556  495266      0      0  3     0x14200  bored         softnet
 23082   73247      0      0  3     0x14200  bored         systqmp
 30919  153874      0      0  3     0x14200  bored         systq
 20378  165207      0      0  3  0x40014200  bored         softclock
 22239  330260      0      0  3  0x40014200                idle0
     1  397759      0      0  3        0x82  wait          init
     0       0     -1      0  3     0x10200  scheduler     swapper
ddb> show all locks
No such command
ddb> show malloc
           Type InUse  MemUse  HighUse   Limit  Requests Type Lim
         devbuf 10093   6342K    6373K  78643K     11183        0
            pcb    13      8K       8K  78643K        13        0
         rtable    62      2K       2K  78643K       114        0
         ifaddr    24      7K       7K  78643K        24        0
       counters    19     16K      16K  78643K        19        0
       ioctlops     0      0K       2K  78643K        25        0
          mount     1      1K       1K  78643K         1        0
            log     0      0K       0K  78643K         4        0
         vnodes  1182     74K      74K  78643K      1187        0
      UFS quota     1     32K      32K  78643K         1        0
      UFS mount     5     36K      36K  78643K         5        0
            shm     2      1K       1K  78643K         2        0
         VM map     2      0K       0K  78643K         2        0
            sem     2      0K       0K  78643K         2        0
        dirhash    12      2K       2K  78643K        12        0
           ACPI  1697    195K     286K  78643K     12598        0
      file desc     1      0K       0K  78643K         1        0
           proc    55     54K      55K  78643K       222        0
    NFS srvsock     1      0K       0K  78643K         1        0
     NFS daemon     1     16K      16K  78643K         1        0
       in_multi    11      0K       0K  78643K        11        0
    ether_multi     1      0K       0K  78643K         1        0
    ISOFS mount     1     32K      32K  78643K         1        0
  MSDOSFS mount     1     16K      16K  78643K         1        0
           ttys    19     95K      95K  78643K        19        0
           exec     0      0K       2K  78643K       325        0
        pagedep     1      8K       8K  78643K         1        0
       inodedep     1     32K      32K  78643K         1        0
         newblk     1      0K       0K  78643K         1        0
        VM swap     7     26K      26K  78643K         7        0
       UVM amap    83      3K       5K  78643K      1519        0
       UVM aobj     3      2K       2K  78643K         3        0
        memdesc     1      4K       4K  78643K         1        0
    crypto data     1      1K       1K  78643K         1        0
            NDP     3      0K       0K  78643K         3        0
           temp    18   4189K    4253K  78643K      1787        0
         kqueue     9     12K      12K  78643K         9        0
      SYN cache     2     16K      16K  78643K         2        0
ddb> show all pools
Name      Size Requests Fail Releases Pgreq Pgrel Npage Hiwat Minpg Maxpg Idle
rtpcb      120       20    0       17     1     0     1     1     0     8    0
rtentry    112       23    0        1     1     0     1     1     0     8    0
unpcb      120       33    0       20     1     0     1     1     0     8    0
syncache   296        5    0        5     2     1     1     1     0     8    1
tcpcb      736        8    0        5     1     0     1     1     0     8    0
arp         88        2    0        0     1     0     1     1     0     8    0
inpcb      304       25    0       19     1     0     1     1     0     8    0
art_heap8  4096       1    0        0     1     0     1     1     0     8    0
art_heap4  256       96    0        0     6     0     6     6     0     8    0
art_table   32       97    0        0     1     0     1     1     0     8    0
art_node    16       22    0        2     1     0     1     1     0     8    0
dirhash    1024      17    0        0     3     0     3     3     0     8    0
dino2pl    256     1405    0       22    87     0    87    87     0     8    0
ffsino     240     1405    0       22    82     0    82    82     0     8    0
nchpl      144     1581    0       39    58     0    58    58     0     8    0
uvmvnodes   72     1414    0        0    26     0    26    26     0     8    0
vnodes     224     1414    0        0    84     0    84    84     0     8    0
namei      1024    3913    0     3913     2     1     1     1     0     8    1
scxspl     216     3715    0     3715    10     9     1     8     0     8    1
plimitpl   152       15    0        9     1     0     1     1     0     8    0
sigapl     424      235    0      207     4     0     4     4     0     8    0
futexpl     56        5    0        5     1     0     1     1     0     8    1
knotepl    112      121    0       98     1     0     1     1     0     8    0
kqueuepl   184        5    0        0     1     0     1     1     0     8    0
pipepl     304       65    0       62     2     1     1     1     0     8    0
fdescpl    432      220    0      207     2     0     2     2     0     8    0
filepl     120      969    0      913     2     0     2     2     0     8    0
lockfpl    104        6    0        4     1     0     1     1     0     8    0
lockfspl    48        4    0        2     1     0     1     1     0     8    0
sessionpl  144       17    0        9     1     0     1     1     0     8    0
pgrppl      48       17    0        9     1     0     1     1     0     8    0
ucredpl     96       64    0       54     1     0     1     1     0     8    0
zombiepl   144      207    0      207     2     1     1     1     0     8    1
processpl  1008     235    0      207     4     0     4     4     0     8    0
procpl     672      236    0      207     3     0     3     3     0     8    0
sockpl     448       78    0       56     3     0     3     3     0     8    0
mcl8k      8192       9    0        9     2     1     1     1     0     8    1
mcl4k      4096       5    0        5     2     1     1     1     0     8    1
mcl2k      2048    7966    0     7928     9     2     7     8     0     8    1
mtagpl      96        3    0        3     1     1     0     1     0     8    0
mbufpl     256    13399    0    13322     9     2     7     8     0     8    0
bufpl      280     2117    0       87   145     0   145   145     0     8    0
anonpl      24    32556    0    30241    18     3    15    15     0   188    1
amapchunkpl 152    2894    0     2743     6     0     6     6     0   158    0
amappl16   200       28    0       26     2     1     1     1     0     8    0
amappl15   192       61    0       58     1     0     1     1     0     8    0
amappl13   176       16    0       15     2     1     1     1     0     8    0
amappl12   168        4    0        4     2     1     1     1     0     8    1
amappl11   160       54    0       40     1     0     1     1     0     8    0
amappl9    144      298    0      296     1     0     1     1     0     8    0
amappl8    136      260    0      257     1     0     1     1     0     8    0
amappl7    128       29    0       28     1     0     1     1     0     8    0
amappl6    120       31    0       27     1     0     1     1     0     8    0
amappl5    112      246    0      232     1     0     1     1     0     8    0
amappl4    104      484    0      463     1     0     1     1     0     8    0
amappl3     96      151    0      137     1     0     1     1     0     8    0
amappl2     88      278    0      246     1     0     1     1     0     8    0
amappl1     80     7079    0     6721    12     3     9     9     0     8    1
amappl      88     1290    0     1223     2     0     2     2     0    92    0
dma4096    4096       1    0        1     1     1     0     1     0     8    0
dma1024    1024       1    0        0     1     0     1     1     0     8    0
dma256     256        6    0        6     1     1     0     1     0     8    0
dma128     128      253    0      253     1     1     0     1     0     8    0
dma64       64        6    0        6     1     1     0     1     0     8    0
dma32       32        7    0        7     1     1     0     1     0     8    0
dma16       16       18    0       17     1     0     1     1     0     8    0
aobjpl      64        2    0        0     1     0     1     1     0     8    0
uaddrrnd    24      220    0      207     1     0     1     1     0     8    0
uaddrbest   32        2    0        0     1     0     1     1     0     8    0
uaddr       24      220    0      207     1     0     1     1     0     8    0
vmmpekpl   168     5762    0     5750     1     0     1     1     0     8    0
vmmpepl    168    21461    0    20654    42     4    38    38     0   357    2
vmsppl     272      219    0      207     2     1     1     2     0     8    0
rwobjpl     24     6687    0     6163     5     1     4     4     0     8    0
pdppl      4096     446    0      414    52    20    32    38     0     8    0
pvpl        32   105456    0   101402    41     6    35    35     0   265    2
pmappl     192      219    0      207     1     0     1     1     0     8    0
extentpl    40       58    0       40     1     0     1     1     0     8    0
phpool     112      264    0       30     7     0     7     7     0     8    0
ddb> machine ddbcpu 0
No such command
ddb> trace
db_enter() at db_enter+0x18 sys/arch/amd64/amd64/db_interface.c:440
panic(ffffffff8247f6c9) at panic+0x161 sys/kern/subr_prf.c:202
rw_enter(ffff8000006aa058,11) at rw_enter+0x36f sys/kern/kern_rwlock.c:174
vndopen(2902,3,2000,ffff8000ffff87e8) at vndopen+0x8d sys/dev/vnd.c:185
spec_open(ffff80002169a888) at spec_open+0x3c8 sys/kern/spec_vnops.c:157
VOP_OPEN(fffffd806e3ff848,3,fffffd807f7d8ba0,ffff8000ffff87e8) at VOP_OPEN+0x6c sys/kern/vfs_vops.c:138
vn_open(ffff80002169ab20,3,0) at vn_open+0x467 sys/kern/vfs_vnops.c:183
vndioctl(2902,c0384600,ffff80002169ae40,81,ffff8000ffff87e8) at vndioctl+0xa07 sys/dev/vnd.c:452
VOP_IOCTL(fffffd806e3ff848,c0384600,ffff80002169ae40,81,fffffd807f7d8ba0,ffff8000ffff87e8) at VOP_IOCTL+0x8d sys/kern/vfs_vops.c:264
vn_ioctl(fffffd807320eb48,c0384600,ffff80002169ae40,ffff8000ffff87e8) at vn_ioctl+0xb5 sys/kern/vfs_vnops.c:531
sys_ioctl(ffff8000ffff87e8,ffff80002169af58,ffff80002169afb0) at sys_ioctl+0x49e
syscall(ffff80002169b020) at syscall+0x571 sys/arch/amd64/amd64/trap.c:587
Xsyscall() at Xsyscall+0x128
end of kernel
end trace frame: 0xd579302b000, count: -13
ddb> machine ddbcpu 1
No such command
ddb> trace
db_enter() at db_enter+0x18 sys/arch/amd64/amd64/db_interface.c:440
panic(ffffffff8247f6c9) at panic+0x161 sys/kern/subr_prf.c:202
rw_enter(ffff8000006aa058,11) at rw_enter+0x36f sys/kern/kern_rwlock.c:174
vndopen(2902,3,2000,ffff8000ffff87e8) at vndopen+0x8d sys/dev/vnd.c:185
spec_open(ffff80002169a888) at spec_open+0x3c8 sys/kern/spec_vnops.c:157
VOP_OPEN(fffffd806e3ff848,3,fffffd807f7d8ba0,ffff8000ffff87e8) at VOP_OPEN+0x6c sys/kern/vfs_vops.c:138
vn_open(ffff80002169ab20,3,0) at vn_open+0x467 sys/kern/vfs_vnops.c:183
vndioctl(2902,c0384600,ffff80002169ae40,81,ffff8000ffff87e8) at vndioctl+0xa07 sys/dev/vnd.c:452
VOP_IOCTL(fffffd806e3ff848,c0384600,ffff80002169ae40,81,fffffd807f7d8ba0,ffff8000ffff87e8) at VOP_IOCTL+0x8d sys/kern/vfs_vops.c:264
vn_ioctl(fffffd807320eb48,c0384600,ffff80002169ae40,ffff8000ffff87e8) at vn_ioctl+0xb5 sys/kern/vfs_vnops.c:531
sys_ioctl(ffff8000ffff87e8,ffff80002169af58,ffff80002169afb0) at sys_ioctl+0x49e
syscall(ffff80002169b020) at syscall+0x571 sys/arch/amd64/amd64/trap.c:587
Xsyscall() at Xsyscall+0x128
end of kernel
end trace frame: 0xd579302b000, count: -13
ddb> 

Crashes (6):
Manager Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Title
ci-openbsd-main 2021/10/06 18:06 openbsd 7699728a8abe 1d849ab4 .config log report syz C panic: rw_enter: dklk locking against myself
ci-openbsd-multicore 2021/10/01 15:43 openbsd 3c95f6f12797 1d849ab4 .config log report syz panic: rw_enter: dklk locking against myself
ci-openbsd-main 2021/09/08 16:06 openbsd 413a7a136984 e2776ee4 .config log report syz panic: rw_enter: dklk locking against myself
ci-openbsd-main 2021/10/06 17:48 openbsd 7699728a8abe 1d849ab4 .config log report panic: rw_enter: dklk locking against myself
ci-openbsd-multicore 2021/10/01 15:27 openbsd 3c95f6f12797 1d849ab4 .config log report panic: rw_enter: dklk locking against myself
ci-openbsd-main 2021/09/08 15:26 openbsd 413a7a136984 e2776ee4 .config log report panic: rw_enter: dklk locking against myself
* Struck through repros no longer work on HEAD.