From 38250e34b77717721846d58a00c2adb7af815fb3 Mon Sep 17 00:00:00 2001 From: Taylor R Campbell Date: Wed, 19 Jan 2022 01:11:45 +0000 Subject: [PATCH 17/37] specfs: sn_gone cannot be set while we hold the vnode lock. vrevoke suspends the file system, which waits for the vnode lock to be released, before it sets sn_gone and changes v_op so nothing can re-enter spec_open with this vnode. --- sys/miscfs/specfs/spec_vnops.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/sys/miscfs/specfs/spec_vnops.c b/sys/miscfs/specfs/spec_vnops.c index 07bc9f4cfdb5..887240602d54 100644 --- a/sys/miscfs/specfs/spec_vnops.c +++ b/sys/miscfs/specfs/spec_vnops.c @@ -544,11 +544,8 @@ spec_open(void *v) /* * Acquire an open reference -- as long as we hold onto it, and - * the vnode isn't revoked, it can't be closed. - * - * But first check whether it has been revoked -- if so, we - * can't acquire more open references and we must fail - * immediately with EBADF. + * the vnode isn't revoked, it can't be closed, and the vnode + * can't be revoked until we release the vnode lock. */ mutex_enter(&device_lock); switch (vp->v_type) { @@ -557,10 +554,7 @@ spec_open(void *v) * Character devices can accept opens from multiple * vnodes. */ - if (sn->sn_gone) { - error = EBADF; - break; - } + KASSERT(!sn->sn_gone); sd->sd_opencnt++; sn->sn_opencnt++; break; @@ -573,10 +567,7 @@ spec_open(void *v) * Treat zero opencnt with non-NULL mountpoint as open. * This may happen after forced detach of a mounted device. */ - if (sn->sn_gone) { - error = EBADF; - break; - } + KASSERT(!sn->sn_gone); if (sd->sd_opencnt != 0 || sd->sd_mountpoint != NULL) { error = EBUSY; break;