KASAN: invalid memory access in mtx_leave

Status: fixed on 2026/09/04 02:14
Reported-by: syzbot+bf11bb99176436b58ec5@syzkaller.appspotmail.com
Fix commit: 53d74301dd9a Close mtx_wantipl race in mtx_leave
First crash: 21d, last: 21d

Sample crash report:
panic: Caught invalid memory access at ffff800034aebaf8 size 4 op 0
Stopped at      db_enter+0x17:  popq    %rbp
    TID    PID    UID     PRFLAGS     PFLAGS  CPU  COMMAND
*390033  76491      0     0x14000      0x200    0  reaper
db_enter() at db_enter+0x17 sys/arch/amd64/amd64/db_interface.c:457
panic(ffffffff8463b860) at panic+0x270 sys/kern/subr_prf.c:198
__asan_load4_noabort(ffff800034aebaf8) at __asan_load4_noabort+0xa3
mtx_leave(ffff800034aebaf0) at mtx_leave+0x295 sys/kern/kern_lock.c:532
reaper(ffff8000298954c8) at reaper+0x4e5 sys/kern/kern_exit.c:527
end trace frame: 0x0, count: 10
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{0}> 
ddb{0}> set $lines = 0
ddb{0}> set $maxwidth = 0
ddb{0}> show panic
*cpu0: Caught invalid memory access at ffff800034aebaf8 size 4 op 0
ddb{0}> show kasan
KASAN: invalid read of 4 bytes at 0xffff800034aebaf8 from pc 0xffffffff82d15ec5
KASAN: first bad byte at 0xffff800034aebaf8 (+0); shadow 0x08: valid
KASAN: 0xffff800034aebaf8 is 272 bytes inside the 1232-byte item [0xffff800034aeb9e8..0xffff800034aebeb8) in pool 'processpl'
KASAN: allocated at:
#0  pool_get+0x770 sys/kern/subr_pool.c:834
#1  process_new+0x47 sys/kern/kern_fork.c:221
#2  fork1+0x533 sys/kern/kern_fork.c:408
#3  syscall+0x1089 mi_syscall sys/sys/syscall_mi.h:176 [inline]
#3  syscall+0x1089 sys/arch/amd64/amd64/trap.c:791
#4  Xsyscall+0x128
KASAN: freed at:
#0  pool_put+0x79 sys/kern/subr_pool.c:1019
#1  process_zap+0x46c sys/kern/kern_exit.c:912
#2  dowait6+0x10dd sys/kern/kern_exit.c:589
#3  sys_wait4+0x244 sys/kern/kern_exit.c:730
#4  syscall+0x1089 mi_syscall sys/sys/syscall_mi.h:176 [inline]
#4  syscall+0x1089 sys/arch/amd64/amd64/trap.c:791
#5  Xsyscall+0x128
KASAN: pc: mtx_leave+0x295
KASAN: call trace:
#0  __asan_load4_noabort+0x82 kasan_shadow_check sys/kern/subr_kasan.c:1014 [inline]
#0  __asan_load4_noabort+0x82 sys/kern/subr_kasan.c:1098
#1  mtx_leave+0x295 sys/kern/kern_lock.c:532
#2  reaper+0x4e5 sys/kern/kern_exit.c:527
#3  proc_trampoline+0x10
KASAN: shadow of 0xffff800034aeb980..0xffff800034aebc00 (1 cell = 8 bytes):
 0xffff800034aeb980: 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08
 0xffff800034aeba00: 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08
>0xffff800034aeba80: 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08[08]
 0xffff800034aebb00: 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08
 0xffff800034aebb80: 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08
KASAN: legend: 00 valid; 01..07 partial; fb malloc redzone; fc malloc freed; fd pool freed; fe kmem; fa global; f1..f4/f8 stack/scope
ddb{0}> trace
db_enter() at db_enter+0x17 sys/arch/amd64/amd64/db_interface.c:457
panic(ffffffff8463b860) at panic+0x270 sys/kern/subr_prf.c:198
__asan_load4_noabort(ffff800034aebaf8) at __asan_load4_noabort+0xa3
mtx_leave(ffff800034aebaf0) at mtx_leave+0x295 sys/kern/kern_lock.c:532
reaper(ffff8000298954c8) at reaper+0x4e5 sys/kern/kern_exit.c:527
end trace frame: 0x0, count: -5
ddb{0}> show registers
rdi                                0
rsi                              0x1
rbp               0xffff800029893610
rbx               0xffff800029893680
rdx                                0
rcx               0xffffffff85355ff0    cpu_info_full_primary+0x1ff0
rax                                0
r8                 0x101010101010101
r9                0x8080808080808080
r10                             0x21
r11               0xffffffff816a3620    x86_bus_space_io_read_1
r12               0xffffffff8463b860    .str.7+0x9be80
r13               0xffffffff85356c08    cpu_info_full_primary+0x2c08
r14               0xffffffff85356e07    cpu_info_full_primary+0x2e07
r15                              0x1
rip               0xffffffff84365cd7    db_enter+0x17
cs                               0x8
rflags                         0x246
rsp               0xffff800029893610
ss                                 0
db_enter+0x17:  popq    %rbp
ddb{0}> show proc
PROC (reaper) tid=390033 pid=76491 tcnt=1 stat=onproc
    flags process=14000<NOZOMBIE,SYSTEM> proc=200<SYSTEM>
    runpri=4, usrpri=51, slppri=4, nice=20
    wchan=0x0, wmesg=, ps_single=0x0 scnt=0 ecnt=0
    forw=0xffffffffffffffff, list=0xffff800045fffc88,0xffff800029895240
    process=0xffff800029803020 user=0xffff800029888000, vmspace=0xffffffff854cdfa0
    estcpu=1, cpticks=39, pctcpu=0.1, user=0, sys=0, intr=0
ddb{0}> ps
   PID     TID   PPID   UID  S      PRLAGS     PFLAGS WAIT      COMMAND
  1165  245887  76695     0  3    0x100002       0x88 sigsusp   sh
 82170  117316  95107     0  2    0x100000          0           sh
 95107  503730  43701     0  3    0x100002       0x88 sigsusp   sh
 18527  517636  57847     0  3    0x100002       0x88 sigsusp   sh
 37428  331779  94715     0  2         0x2          0           sh
 94715   38521  52944     0  3         0x2       0x80 wait      syz-executor
 76695   31244  52944     0  3         0x2       0x80 wait      syz-executor
 43701  399497  52944     0  3         0x2       0x80 wait      syz-executor
 57847  287908  52944     0  3         0x2       0x80 wait      syz-executor
 12777  232158  52944     0  3         0x2       0x80 nanoslp   syz-executor
 70670  321203      0     0  3     0x14000      0x280 nfsidl    nfsio
 36126  145599      0     0  3     0x14000      0x280 nfsidl    nfsio
 86813  111293      0     0  3     0x14000      0x280 nfsidl    nfsio
  7853  150846      0     0  3     0x14000      0x280 nfsidl    nfsio
 60573  340709      0     0  3     0x14000      0x280 nfsidl    nfsio
 35356   94246      0     0  3     0x14000      0x280 nfsidl    nfsio
 53260   67823      0     0  3     0x14000      0x280 nfsidl    nfsio
 15089   85308      0     0  3     0x14000      0x280 nfsidl    nfsio
 55806  208870      0     0  3     0x14000      0x280 nfsidl    nfsio
 90284   25711      0     0  3     0x14000      0x280 nfsidl    nfsio
 15661  395172      0     0  3     0x14000      0x280 nfsidl    nfsio
 67767  146152      0     0  3     0x14000      0x280 nfsidl    nfsio
 17812  310743      0     0  3     0x14000      0x280 nfsidl    nfsio
 79406  307100      0     0  3     0x14000      0x280 nfsidl    nfsio
  9301   67573      0     0  3     0x14000      0x280 nfsidl    nfsio
 21057  191600      0     0  3     0x14000      0x280 nfsidl    nfsio
 12371  350578      0     0  3     0x14000      0x280 nfsidl    nfsio
 10924   31195      0     0  3     0x14000      0x280 nfsidl    nfsio
  8859  421627      0     0  3     0x14000      0x280 nfsidl    nfsio
 37463    3310      0     0  3     0x14000      0x280 nfsidl    nfsio
 55424  231081      0     0  3     0x14000      0x200 acct      acct
 52944  476727  60142     0  3         0x2       0x80 nanoslp   syz-executor
 60142  303997  92083     0  3    0x100002       0x88 sigsusp   ksh
 92083  201705   8222     0  3        0x10       0x88 kqread    sshd-session
  8222  380274   9641     0  3        0x12       0x80 kqread    sshd-session
 60235  169880      1     0  3    0x100003       0x80 ttyin     getty
  9641  150191      1     0  3           0       0x88 kqread    sshd
  6156  364270  17533    74  3   0x1100012       0x80 bpf       pflogd
 17533  237866      1     0  3           0       0x80 sbwait    pflogd
 80447  245545  84576    73  3   0x1100010       0x80 kqread    syslogd
 84576   34629      1     0  3    0x100002       0x80 sbwait    syslogd
  7848  349868      1     0  3    0x100000       0x80 kqread    resolvd
 69856  222927  98031    77  3    0x100012       0x80 kqread    dhcpleased
 53254   85916  98031    77  3    0x100012       0x80 kqread    dhcpleased
 98031   83269      1     0  3           0       0x80 kqread    dhcpleased
 30255  486058      0     0  3     0x14000      0x200 bored     smr
 90006  432903      0     0  2     0x14000      0x200           zerothread
 41284  521242      0     0  3     0x14000      0x200 aiodoned  aiodoned
 45348  476601      0     0  3     0x14000      0x200 syncer    update
 63579  297732      0     0  3     0x14000      0x200 cleaner   cleaner
*76491  390033      0     0  7     0x14000      0x200           reaper
 83705  367431      0     0  3     0x14000      0x200 pgdaemon  pagedaemon
 77694  442513      0     0  3     0x14000      0x200 bored     viomb
 18449  221346      0     0  3     0x14000 0x40000200 acpi0     acpi0
 96174  461254      0     0  7     0x14000 0x40000200           idle1
 34021   93904      0     0  3     0x14000      0x200 bored     softnet1
  9286  252378      0     0  3     0x14000      0x200 bored     softnet0
 86844  489623      0     0  3     0x14000      0x200 smrbar    systqmp
 44159  121766      0     0  3     0x14000      0x200 bored     systq
 82617  485255      0     0  3     0x14000      0x200 tmoslp    softclockmp
 65903  225780      0     0  3     0x14000 0x40000200 tmoslp    softclock
  2076  264413      0     0  3     0x14000 0x40000200           idle0
     1  442434      0     0  3         0x2       0x80 wait      init
     0       0     -1     0  3     0x10000      0x200 scheduler swapper
ddb{0}> show all locks
CPU 0:
exclusive mutex /syzkaller/managers/kasan/kernel/sys/kern/kern_event.c:210 r = 0 (0xffffffff851fa250)
#0  witness_lock+0x632 stacktrace_save sys/sys/stacktrace.h:37 [inline]
#0  witness_lock+0x632 sys/kern/subr_witness.c:1160
#1  mtx_enter+0x683 sys/kern/kern_lock.c:487
#2  reaper+0x32d sys/kern/kern_exit.c:511
#3  proc_trampoline+0x10
Process 86844 (systqmp) thread 0xffff800045ffe000 (489623)
shared rwlock systqmp r = 0 (0xffffffff85063f78)
#0  witness_lock+0x632 stacktrace_save sys/sys/stacktrace.h:37 [inline]
#0  witness_lock+0x632 sys/kern/subr_witness.c:1160
#1  taskq_thread+0x1ba sys/kern/kern_task.c:442
#2  proc_trampoline+0x10
ddb{0}> show malloc
           Type InUse  MemUse  HighUse   Limit  Requests Type Lim
         devbuf 11046  12237K   12533K 166960K     12624        0
            pcb    17     28K      30K 166960K        58        0
         rtable   139      7K      13K 166960K      2703        0
             pf    28     20K      23K 166960K       224        0
         ifaddr    27      8K      13K 166960K       372        0
        ifgroup    43      2K       2K 166960K       397        0
         sysctl     1      1K      13K 166960K         7        0
       counters    64     41K      43K 166960K       240        0
       ioctlops     0      0K       4K 166960K      1600        0
            iov     0      0K       4K 166960K         7        0
          mount     1      1K       1K 166960K         1        0
            log     0      0K       0K 166960K         4        0
         vnodes  1352     87K      87K 166960K      2512        0
      UFS quota     1     36K      36K 166960K         1        0
      UFS mount     5     44K      44K 166960K         5        0
            shm     2      2K       6K 166960K         6        0
         VM map     2      1K       1K 166960K         2        0
            sem     7      0K       0K 166960K         8        0
        dirhash    15      2K       2K 166960K        15        0
           ACPI  1734    201K     292K 166960K     11964        0
      file desc    13     45K      93K 166960K      1547        0
          sigio     0      0K       0K 166960K         1        0
           proc    71    128K     210K 166960K      2791        0
        subproc    45      5K       9K 166960K       792        0
    NFS srvsock     1      0K       0K 166960K         1        0
     NFS daemon     1     20K      20K 166960K         1        0
    ip_moptions     0      0K       0K 166960K         6        0
       in_multi    46      3K       7K 166960K       959        0
    ether_multi     1      0K       0K 166960K         1        0
            mrt     0      0K       0K 166960K        21        0
    ISOFS mount     1     36K      36K 166960K         1        0
  MSDOSFS mount     1     20K      20K 166960K         1        0
           ttys    55    384K     384K 166960K        55        0
           exec     0      0K       2K 166960K      1416        0
   fusefs mount     1     36K      36K 166960K         1        0
            tdb     3      1K       1K 166960K         3        0
        VM swap    14    124K     124K 166960K        15        0
       UVM amap   173    223K     279K 166960K     11432        0
       UVM aobj    15     12K      12K 166960K        18        0
     pinsyscall  1062   1747K    1818K 166960K      4759        0
        memdesc     1      4K       4K 166960K         1        0
    crypto data     1      1K       1K 166960K         1        0
    ip6_options     0      0K       0K 166960K         1        0
            NDP    13      0K       2K 166960K       269        0
           temp    22   9165K    9186K 166960K     14579        0
         kqueue    13     40K      68K 166960K        64        0
      SYN cache     2     16K      16K 166960K         2        0
ddb{0}> show all pools
Name      Size Requests Fail Releases Pgreq Pgrel Npage Hiwat Minpg Maxpg Idle
plcache    128       28    0        0     1     0     1     1     0     8    0
rtpcb      120      194    0      191     1     0     1     1     0     8    0
rtentry    176      975    0      914     7     2     5     6     0     8    2
unpcb      144      777    0      760     4     0     4     4     0     8    3
syncache   336        4    0        4     1     1     0     1     0     8    0
sackhl      24        1    0        1     1     1     0     1     0     8    0
tcpcb      736      169    0      165     7     6     1     7     0     8    0
arp        136      177    0      166     1     0     1     1     0     8    0
inpcb      328     1247    0     1240     7     0     7     7     0     8    6
nd6        152      257    0      249     1     0     1     1     0     8    0
kcovpl      48       88    0       83     1     0     1     1     0     8    0
ppxss      1192       1    0        1     1     1     0     1     0     8    0
pffrag     232        3    0        0     1     0     1     1     0   482    0
pffrnode    88        3    0        0     1     0     1     1     0     8    0
pffrent     40        3    0        0     1     0     1     1     0     8    0
pfosfp      40     1428    0     1005     5     0     5     5     0     8    0
pfosfpen   112     1428    0      714    21     0    21    21     0     8    0
pfstitem    24       35    0        8     1     0     1     1     0     8    0
pfstkey    128       35    0        8     1     0     1     1     0     8    0
pfstate    448       35    0        8     4     0     4     4     0     8    0
pfrule     1360      21    0       16     2     1     1     2     0     8    0
art_heap8  4096       1    0        0     1     0     1     1     0     8    0
art_heap4  256     3934    0     3645    40    14    26    29     0     8    7
art_table   40     3935    0     3645     6     1     5     5     0     8    1
art_node    32      975    0      917     1     0     1     1     0     8    0
semapl      72        6    0        1     1     0     1     1     0     8    0
shmpl      112       15    0        3     1     0     1     1     0     8    0
dirhash    1024      19    0        0     3     0     3     3     0     8    0
dino2pl    256     2001    0      369   102     0   102   102     0     8    0
ffsino     296     2001    0      369   126     0   126   126     0     8    0
nchpl      144     2536    0      515    75     0    75    75     0     8    0
vnodes     216     3174    0        0   177     0   177   177     0     8    0
namei      1024   16136    0    16136     2     1     1     2     0     8    1
percpumem   16      136    0       88     1     0     1     1     0     8    0
kstatmem   264      197    0      176     2     0     2     2     0     8    0
scxspl     216     8981    0     8981     5     4     1     3     1     8    1
plimitpl   152      222    0      206     1     0     1     1     0     8    0
sigapl     424     1725    0     1657     9     0     9     9     0     8    1
knotepl    120       94    0        0     3     0     3     3     0     8    0
kqueuepl   224      226    0      217     5     4     1     5     0     8    0
pipepl     344      393    0      366     4     1     3     4     0     8    0
fdescpl    528     1688    0     1661     3     0     3     3     0     8    0
filepl     160     7090    0     6919    18     3    15    16     0     8    6
lockfpl    104       59    0       57     1     0     1     1     0     8    0
lockfspl    48       30    0       28     1     0     1     1     0     8    0
sessionpl  144      197    0      188     1     0     1     1     0     8    0
pgrppl      48      286    0      270     1     0     1     1     0     8    0
ucredpl    104      428    0      415     1     0     1     1     0     8    0
zombiepl   144     1662    0     1657     1     0     1     1     0     8    0
processpl  1232    1725    0     1657     6     0     6     6     0     8    0
procpl     664     2243    0     2175     8     1     7     8     0     8    0
sockpl     752     2223    0     2196    51    40    11    17     0     8    8
mcl64k     65536      1    0        0     1     0     1     1     0     8    0
mcl8k      8192       3    0        0     1     0     1     1     0     8    0
mcl4k      4096     124    0        0    16     0    16    16     0     8    0
mcl2k      2048      22    0        0     3     0     3     3     0     8    0
mextrefs    64       21    0        0     1     0     1     1     0     8    0
mtagpl      96        3    0        0     1     0     1     1     0     8    0
mbufpl     256      155    0        0    10     0    10    10     0     8    0
bufpl      272     2740    0      106   176     0   176   176     0     8    0
anonpl      32     3841    0        0    31     0    31    31     0   222    0
amapchunkpl 152   30074    0    29777    23     6    17    22     0   158    2
amappl16   200     2195    0     2187     5     4     1     5     0     8    0
amappl15   192        6    0        6     1     1     0     1     0     8    0
amappl14   184     1383    0     1378     1     0     1     1     0     8    0
amappl13   176      281    0      268     1     0     1     1     0     8    0
amappl12   168     2252    0     2226     2     0     2     2     0     8    0
amappl11   160        3    0        3     1     1     0     1     0     8    0
amappl10   152       69    0       53     1     0     1     1     0     8    0
amappl9    144      270    0      269     1     0     1     1     0     8    0
amappl8    136      414    0      412     1     0     1     1     0     8    0
amappl7    128      305    0      292     1     0     1     1     0     8    0
amappl6    120      950    0      943     1     0     1     1     0     8    0
amappl5    112      100    0       90     1     0     1     1     0     8    0
amappl4    104      540    0      520     1     0     1     1     0     8    0
amappl3     96     5843    0     5777     3     0     3     3     0     8    0
amappl2     88     1494    0     1424     2     0     2     2     0     8    0
amappl1     80    21430    0    20852    16     2    14    15     0     8    1
amappl      88     9352    0     9250     5     0     5     5     0    92    0
uvmvnodes   80      106    0        0     3     0     3     3     0     8    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      72       17    0        3     1     0     1     1     0     8    0
uaddrrnd    24     1688    0     1661     1     0     1     1     0     8    0
uaddrbest   32        2    0        0     1     0     1     1     0     8    0
uaddr       24     1688    0     1661     1     0     1     1     0     8    0
vmmpekpl   168    15013    0    14965     3     0     3     3     0     8    0
vmmpepl    168   115583    0   114020    87     7    80    87     0   357    3
vmsppl     488     1687    0     1659     5     0     5     5     0     8    1
rwobjpl     80    34296    0    33335    26     3    23    25     0     8    0
pdppl      4096    3384    0     3318   188   120    68    86     0     8    2
pvpl        32    10404    0        0    85     1    84    84     0   265    0
pmappl     256     1687    0     1659     3     0     3     3     0     8    0
extentpl    40       47    0       29     1     0     1     1     0     8    0
phpool     120      563    0      145    13     0    13    13     0     8    0
ddb{0}> machine ddbcpu 0
Invalid cpu 0
ddb{0}> trace
db_enter() at db_enter+0x17 sys/arch/amd64/amd64/db_interface.c:457
panic(ffffffff8463b860) at panic+0x270 sys/kern/subr_prf.c:198
__asan_load4_noabort(ffff800034aebaf8) at __asan_load4_noabort+0xa3
mtx_leave(ffff800034aebaf0) at mtx_leave+0x295 sys/kern/kern_lock.c:532
reaper(ffff8000298954c8) at reaper+0x4e5 sys/kern/kern_exit.c:527
end trace frame: 0x0, count: -5
ddb{0}> machine ddbcpu 1
Stopped at      x86_ipi_db+0x19:        leave
x86_ipi_db(ffff800028fe3ff0) at x86_ipi_db+0x19 sys/arch/amd64/amd64/db_interface.c:412
x86_ipi_handler() at x86_ipi_handler+0x112 sys/arch/amd64/amd64/ipi.c:106
Xresume_lapic_ipi() at Xresume_lapic_ipi+0x27
acpicpu_idle() at acpicpu_idle+0x63c sys/dev/acpi/acpicpu_x86.c:-1
sched_idle(ffff800028fe3ff0) at sched_idle+0x566 sys/kern/kern_sched.c:204
end trace frame: 0x0, count: 10
ddb{1}> trace
x86_ipi_db(ffff800028fe3ff0) at x86_ipi_db+0x19 sys/arch/amd64/amd64/db_interface.c:412
x86_ipi_handler() at x86_ipi_handler+0x112 sys/arch/amd64/amd64/ipi.c:106
Xresume_lapic_ipi() at Xresume_lapic_ipi+0x27
acpicpu_idle() at acpicpu_idle+0x63c sys/dev/acpi/acpicpu_x86.c:-1
sched_idle(ffff800028fe3ff0) at sched_idle+0x566 sys/kern/kern_sched.c:204
end trace frame: 0x0, count: -5

Crashes (1):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2026/08/30 11:23 https://github.com/blackgnezdo/openbsd-src.git syzbot-kasan eb6d9273e3e5 2f52988a .config console log report [disk image] [bsd.gdb] [kernel image] ci-openbsd-kasan KASAN: invalid memory access in mtx_leave
* Struck through repros no longer work on HEAD.