untrusted comment: verify with openbsd-80-base.pub RWSMSt0erHTctTZSwG0LTP5tRCzpAp8UCN+llxghP7ZBFgV7HUNwFK3ChhV3Vw0ytLinR8YKrvkpHk/OGLhU7WeDKhG4KJx5Hw4= OpenBSD 8.0 errata 023, November 26, 2026: Advisory locks on a device could use freed memory when revoke(2) ran concurrently. Apply by doing: signify -Vep /etc/signify/openbsd-80-base.pub -x 023_vnode.patch.sig \ -m - | (cd /usr/src && patch -p0) And then rebuild and install a new kernel: KK=`sysctl -n kern.osversion | cut -d# -f1` cd /usr/src/sys/arch/`machine`/compile/$KK make obj make config make make install Index: sys/kern/spec_vnops.c =================================================================== RCS file: /cvs/src/sys/kern/spec_vnops.c,v diff -u -p -r1.114 spec_vnops.c --- sys/kern/spec_vnops.c 27 Mar 2025 23:30:54 -0000 1.114 +++ sys/kern/spec_vnops.c 13 Nov 2026 20:18:40 -0000 @@ -53,6 +53,7 @@ #define v_lastr v_specinfo->si_lastr int spec_open_clone(struct vop_open_args *); +int lf_specadvlock(struct specinfo **, caddr_t, int, struct flock *, int); struct vnodechain speclisth[SPECHSZ]; @@ -662,8 +663,8 @@ spec_advlock(void *v) struct vop_advlock_args *ap = v; struct vnode *vp = ap->a_vp; - return (lf_advlock(&vp->v_speclockf, (off_t)0, ap->a_id, - ap->a_op, ap->a_fl, ap->a_flags)); + return (lf_specadvlock(&vp->v_specinfo, ap->a_id, ap->a_op, + ap->a_fl, ap->a_flags)); } /* Index: sys/kern/vfs_lockf.c =================================================================== RCS file: /cvs/src/sys/kern/vfs_lockf.c,v diff -u -p -r1.50 vfs_lockf.c --- sys/kern/vfs_lockf.c 14 Aug 2022 01:58:28 -0000 1.50 +++ sys/kern/vfs_lockf.c 13 Nov 2026 20:18:40 -0000 @@ -43,6 +43,7 @@ #include #include #include +#include /* * The lockf structure is a kernel structure which contains the information @@ -102,6 +103,8 @@ void lf_printlist(const char *, struct l #define LFPRINT(args, level) #endif +static int lf_doadvlock(struct lockf_state **, off_t, caddr_t, int, + struct flock *, int); struct lockf *lf_alloc(uid_t, int); void lf_free(struct lockf *); int lf_clearlock(struct lockf *); @@ -114,6 +117,8 @@ void lf_wakelock(struct lockf *, int); int lf_deadlock(struct lockf *); void ls_ref(struct lockf_state *); void ls_rele(struct lockf_state *); +int lf_specadvlock(struct specinfo **, caddr_t, int, struct flock *, int); +struct specinfo *lf_purgespec(struct specinfo **); /* * Serializes access to each instance of struct lockf and struct lockf_state @@ -215,6 +220,36 @@ int lf_advlock(struct lockf_state **state, off_t size, caddr_t id, int op, struct flock *fl, int flags) { + int error; + + rw_enter_write(&lockf_lock); + error = lf_doadvlock(state, size, id, op, fl, flags); + rw_exit_write(&lockf_lock); + return (error); +} + +/* + * Resolve the lock-state slot while the device is still attached. + */ +int +lf_specadvlock(struct specinfo **sip, caddr_t id, int op, struct flock *fl, + int flags) +{ + int error; + + rw_enter_write(&lockf_lock); + if (*sip == NULL) + error = EBADF; + else + error = lf_doadvlock(&(*sip)->si_lockf, 0, id, op, fl, flags); + rw_exit_write(&lockf_lock); + return (error); +} + +static int +lf_doadvlock(struct lockf_state **state, off_t size, caddr_t id, int op, + struct flock *fl, int flags) +{ struct proc *p = curproc; struct lockf_state *ls; struct lockf *lock; @@ -257,7 +292,7 @@ lf_advlock(struct lockf_state **state, o end = -1; } - rw_enter_write(&lockf_lock); + rw_assert_wrlock(&lockf_lock); ls = *state; /* @@ -312,7 +347,6 @@ lf_advlock(struct lockf_state **state, o } out: - rw_exit_write(&lockf_lock); return (error); } @@ -718,25 +752,32 @@ lf_findoverlap(struct lockf *lf, struct } /* - * Purge all locks associated with the given lock state. + * Detach the device before sleeping, so no new request can join the drain. + * Return its storage only after the last lock-state reference is gone. */ -void -lf_purgelocks(struct lockf_state **state) +struct specinfo * +lf_purgespec(struct specinfo **sip) { + struct specinfo *si; struct lockf_state *ls; struct lockf *lock; rw_enter_write(&lockf_lock); - ls = *state; + si = *sip; + *sip = NULL; + ls = si->si_lockf; if (ls == NULL) goto out; ls_ref(ls); + /* Include waiters already woken by a concurrent unlock. */ + TAILQ_FOREACH(lock, &ls->ls_pending, lf_entry) + lock->lf_flags |= F_INTR; /* Interrupt blocked locks and wait for all of them to finish. */ TAILQ_FOREACH(lock, &ls->ls_locks, lf_entry) { - LFPRINT(("lf_purgelocks: wakeup", lock), DEBUG_SETLOCK); + LFPRINT(("lf_purgespec: wakeup", lock), DEBUG_SETLOCK); lf_wakelock(lock, F_INTR); } while (!TAILQ_EMPTY(&ls->ls_pending)) @@ -757,6 +798,7 @@ lf_purgelocks(struct lockf_state **state out: rw_exit_write(&lockf_lock); + return (si); } /* Index: sys/kern/vfs_subr.c =================================================================== RCS file: /cvs/src/sys/kern/vfs_subr.c,v diff -u -p -r1.335 vfs_subr.c --- sys/kern/vfs_subr.c 30 Jun 2026 14:04:03 -0000 1.335 +++ sys/kern/vfs_subr.c 13 Nov 2026 20:18:41 -0000 @@ -106,6 +106,8 @@ struct freelst vnode_free_list; /* vnode struct mntlist mountlist; /* mounted filesystem list */ void vclean(struct vnode *, int, struct proc *); +static int vclean_start(struct vnode *, int, struct proc *); +static void vclean_finish(struct vnode *, int); void insmntque(struct vnode *, struct mount *); int getdevvp(dev_t, struct vnode **, enum vtype); @@ -127,6 +129,8 @@ void vfs_unmountall(void); void printlockedvnodes(void); #endif +struct specinfo *lf_purgespec(struct specinfo **); + struct pool vnode_pool; static inline int rb_buf_compare(const struct buf *b1, const struct buf *b2); @@ -426,6 +430,12 @@ getnewvnode(enum vtagtype tag, struct mo numvnodes++; } else { TAILQ_FOREACH(vp, listhd, v_freelist) { + mtx_enter(&vnode_mtx); + if (vp->v_lflag & VXLOCK) { + mtx_leave(&vnode_mtx); + continue; + } + mtx_leave(&vnode_mtx); if (VOP_ISLOCKED(vp) == 0) break; } @@ -1027,8 +1037,19 @@ vflush(struct mount *mp, struct vnode *s void vclean(struct vnode *vp, int flags, struct proc *p) { - int active, do_wakeup = 0, error; - int s; + int active; + + active = vclean_start(vp, flags, p); + vclean_finish(vp, active); +} + +/* + * Keep VXLOCK and any temporary reference until vclean_finish(). + */ +static int +vclean_start(struct vnode *vp, int flags, struct proc *p) +{ + int active, error; /* * Check to see if the vnode is in use. @@ -1110,16 +1131,6 @@ vclean(struct vnode *vp, int flags, stru */ if (VOP_RECLAIM(vp, p)) panic("vclean: cannot reclaim"); - if (active) { - vp->v_usecount--; - if (vp->v_usecount == 0) { - s = splbio(); - if (vp->v_holdcnt > 0) - panic("vclean: not clean"); - vputonfreelist(vp); - splx(s); - } - } cache_purge(vp); /* @@ -1131,7 +1142,28 @@ vclean(struct vnode *vp, int flags, stru #ifdef VFSLCKDEBUG vp->v_flag &= ~VLOCKSWORK; #endif + return (active); +} + +static void +vclean_finish(struct vnode *vp, int active) +{ + int do_wakeup = 0; + int s; + + if (active) { + vp->v_usecount--; + if (vp->v_usecount == 0) { + s = splbio(); + if (vp->v_holdcnt > 0) + panic("vclean: not clean"); + vputonfreelist(vp); + splx(s); + } + } + mtx_enter(&vnode_mtx); + KASSERT(vp->v_lflag & VXLOCK); vp->v_lflag &= ~VXLOCK; if (vp->v_lflag & VXWANT) { vp->v_lflag &= ~VXWANT; @@ -1172,9 +1204,10 @@ vgone(struct vnode *vp) void vgonel(struct vnode *vp, struct proc *p) { + struct specinfo *si; struct vnode *vq; struct vnode *vx; - int s; + int active, s, purgespec = 0; KASSERT(vp->v_uvcount == 0); @@ -1194,7 +1227,7 @@ vgonel(struct vnode *vp, struct proc *p) /* * Clean out the filesystem specific data. */ - vclean(vp, DOCLOSE, p); + active = vclean_start(vp, DOCLOSE, p); /* * Delete from old mount point vnode list, if on one. */ @@ -1228,16 +1261,20 @@ vgonel(struct vnode *vp, struct proc *p) vx->v_flag &= ~VALIASED; vp->v_flag &= ~VALIASED; } - lf_purgelocks(&vp->v_speclockf); - free(vp->v_specinfo, M_VNODE, sizeof(struct specinfo)); - vp->v_specinfo = NULL; + purgespec = 1; } + /* * If it is on the freelist and not already at the head, * move it to the head of the list. */ vp->v_type = VBAD; + if (purgespec) { + si = lf_purgespec(&vp->v_specinfo); + free(si, M_VNODE, sizeof(*si)); + } + /* * Move onto the free list, unless we were called from * getnewvnode and we're not on any free list @@ -1254,6 +1291,8 @@ vgonel(struct vnode *vp, struct proc *p) } } splx(s); + + vclean_finish(vp, active); } /*