Index: sys/kern/vfs_vnops.c =================================================================== --- sys/kern/vfs_vnops.c +++ sys/kern/vfs_vnops.c @@ -3463,8 +3463,10 @@ static int vn_deallocate_impl(struct vnode *vp, off_t *offset, off_t *length, int flags, - int ioflag, struct ucred *active_cred, struct ucred *file_cred) + int ioflag, struct ucred *active_cred, struct ucred *file_cred, + bool from_fops) { + struct ucred *cred; struct mount *mp; void *rl_cookie; off_t off, len; @@ -3508,9 +3510,14 @@ error = mac_vnode_check_write(active_cred, file_cred, vp); #endif - if (error == 0) + if (error == 0) { + if (file_cred != NULL && !from_fops) + cred = file_cred; + else + cred = active_cred; error = VOP_DEALLOCATE(vp, &off, &len, flags, ioflag, - active_cred); + cred); + } if ((ioflag & IO_NODELOCKED) == 0) { VOP_UNLOCK(vp); @@ -3541,7 +3548,7 @@ return (ENODEV); return (vn_deallocate_impl(vp, offset, length, flags, ioflag, - active_cred, file_cred)); + active_cred, file_cred, false)); } static int @@ -3565,7 +3572,7 @@ switch (cmd) { case SPACECTL_DEALLOC: error = vn_deallocate_impl(vp, offset, length, flags, ioflag, - active_cred, fp->f_cred); + active_cred, fp->f_cred, true); break; default: panic("vn_fspacectl: unknown cmd %d", cmd);